

      subroutine linezpht(utkmx,htutkmx,l)
c
c Make line plots with ut on x-axis at selected zp and/or ht,
c at location l:
c
      include 'tigcmloc.h'
      dimension utkmx(ntms,kmx,nfplt,nloc),htutkmx(ntms,kmx,nloc)
      dimension vp(4),plt(ntms)
      character*56 toplab
      character*80 rec80
      character*16 ylab
c     data vp /0.14,0.95,0.20,0.90/
      data vp /0.14,0.95,0.24,0.90/
c
c Set up AG:
c
      call agsetf('DASH/PATTERNS/1.',65535.)
      call agsetc ('LABEL/NAME.','T')
      call agsetr("AXIS/TOP/CONTROL.",-1.)
      call agseti ('LINE/NUMBER.', 100)
      call agsetf ('LINE/CHARACTER.', .025)
      call agsetc("LABEL/NAME.","B")
      call agsetr("LABEL/DEF/SUPPRESSION.",1.)
      call agsetr("AXIS/BOT/CONTROL.",-1.)
      call set(vp(1),vp(2),vp(3),vp(4),0.,1.,0.,1.,1)
c
c lset=2 -> AG will use only fractional from set call
      lset = 2 
c
c Field loop:
c
      do 100 ip=1,nftot
        if (ifplt(ip).le.0) goto 100
c
c Loop for selected pressure/height:
c
        do 200 k=1,nzphtlin
          if (k.gt.1.and.(ip.eq.ixfof2.or.ip.eq.ixhmf2)) goto 200
          call clearstr(toplab)
          if (izphtlin(k).gt.0) then
            if (ip.ne.ixfof2.and.ip.ne.ixhmf2) then
              if (gloc(1,l).eq.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('GLOBAL MEANS  ZP=',f4.1)") zphtline(k)
              elseif (gloc(1,l).ne.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('LAT= ',f6.2,' LON=ZONAL MEANS  ZP=',
     +            f4.1)") gloc(1,l),zphtline(k)
              else
                if (locname(1).eq.'xxxxxxxxxxxxxxxx') then
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' ZP=',
     +              f4.1)") gloc(1,l),gloc(2,l),zphtline(k)
                else
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' (',a,')',
     +              ' ZP=',f4.1)") gloc(1,l),gloc(2,l),
     +              locname(l)(1:lenstr(locname(l))),zphtline(k)
                endif
              endif
            else
              if (gloc(1,l).eq.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('GLOBAL MEANS')")
              elseif (gloc(1,l).ne.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('LAT= ',f6.2,' LON=ZONAL MEANS')")
     +            gloc(1,l)
              else
                if (locname(1).eq.'xxxxxxxxxxxxxxxx') then
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2)")
     +              gloc(1,l),gloc(2,l)
                else
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,
     +              ' (',a,')')") gloc(1,l),gloc(2,l),
     +              locname(l)(1:lenstr(locname(l)))
                endif
              endif
            endif
          else
            if (ip.ne.ixfof2.and.ip.ne.ixhmf2) then
              if (gloc(1,l).eq.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('GLOBAL MEANS  HT=',f5.1)") zphtline(k)
              elseif (gloc(1,l).ne.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('LAT= ',f6.2,' LON=ZONAL MEANS  HT=',
     +            f5.1)") gloc(1,l),zphtline(k)
              else
                if (locname(1).eq.'xxxxxxxxxxxxxxxx') then
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' HT=',
     +              f5.1)") gloc(1,l),gloc(2,l),zphtline(k)
                else
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' (',a,')',
     +              ' HT=',f5.1)") gloc(1,l),gloc(2,l),
     +              locname(l)(1:lenstr(locname(l))),zphtline(k)
                endif
              endif
            else
              if (gloc(1,l).eq.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('GLOBAL MEANS')")
              elseif (gloc(1,l).ne.gmflag.and.gloc(2,l).eq.gmflag) then
                write(toplab,"('LAT= ',f6.2,' LON=ZONAL MEANS')")
     +            gloc(1,l)
              else
                if (locname(1).eq.'xxxxxxxxxxxxxxxx') then
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2)")
     +              gloc(1,l),gloc(2,l)
                else
                  write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,
     +              ' (',a,')')") gloc(1,l),gloc(2,l),
     +              locname(l)(1:lenstr(locname(l)))
                endif
              endif
            endif
          endif
          len = lenstr(toplab)
          call clearstr(rec80)
          write(rec80,"(a)") toplab(1:len)
c
c At selected zp:
          if (izphtlin(k).gt.0) then
            plt(:) = utkmx(:,izphtlin(k),ifplt(ip),l)
c
c At selected ht:
c     dimension utkmx(ntms,kmx,nfplt,nloc),htutkmx(ntms,kmx,nloc)
c
          else
            call intloc(utkmx(1,1,ifplt(ip),l),htutkmx(1,1,l),kmx,
     +        zphtline(k),1,logterp(ip),plt,ntms,ntms,1,ier,cpspval,1)
          endif
          call clearstr(ylab)
          if (logloc.gt.0.and.logterp(ip).gt.0) then
            call log10f(plt,ntms,1.e-20,cpspval)
            write(ylab,"('LOG10 ',a)") labshort(ip)
          else
            write(ylab,"(a)") labshort(ip)
          endif
          call displa(2,1,1)
          call anotat('UT',ylab(1:lenstr(ylab)),0,lset,-1,l)
          call ezxy(utinc,plt,ntms,toplab(1:len))
          call fminmax(plt,ntms,rmin,rmax,cpspval)
          if (rmin.lt.0..and.rmax.gt.0.) 
     +      call line(utinc(1),0.,utinc(ntms),0.)
          isltax = 0
          if (gloc(1,l).ne.gmflag.and.gloc(2,l).ne.gmflag) isltax=1
          call labutxy(mtimes,ntms,0.,0,' ',0.,1,gloc(2,l))
c
c Field label:
          call clearstr(toplab)
          lenflab = lenstr(flab(ip))
          if (logloc.gt.0.and.logterp(ip).gt.0) then
            write(toplab,"('LOG10 ',a)") flab(ip)(1:lenflab)
          else
            write(toplab,"(a)") flab(ip)(1:lenflab)
          endif
          call wrlablq(toplab(1:lenstr(toplab)),
     +      0.5*(vp(1)+vp(2)),vp(4)+.07,.019)
c
c History volume label at bottom:
c
          call clearstr(toplab)
          if (nhvols.eq.1) then
            write(toplab,"('HISTORY=',a)") histvol(ivol)
          else
            write(toplab,"('FIRST HISTORY VOL=',a)") histvol(1)
          endif
          call wrlablq(toplab(1:lenstr(toplab)),.5*(vp(1)+vp(2)),
     +      vp(3)-.22,.012)
c
          call frame
          iframe = iframe+1
          if (iwrascii.gt.0) then
            call wrascii(iwrascii,luascii,plt,ntms,1,utinc,dum,
     +        'UT (HRS)',' ',histvol(ivol),ylab,iframe,rec80,
     +        'tigcmloc',dirascii)
          endif
          write(6,"('zphtline frame ',i4,' field ',a,' ',a)") iframe,
     +      ylab(1:lenstr(ylab)),rec80(1:len)
c
c End k loop (selected zp/ht):
 200    continue
c
c End field loop:
 100  continue
c
c Plot ve,vu (ion drifts perpendicular to mag field, calculated
c from mkuivi only if ionvel=2):
c
      if (ionvel.eq.2.and.(ifplt(ixui).gt.0.or.ifplt(ixvi).gt.0.or.
     +                     ifplt(ixwi).gt.0)) then
        do k=1,nzphtlin
          call clearstr(toplab)
          if (izphtlin(k).gt.0) then
            if (gloc(1,l).eq.gmflag.and.gloc(2,l).eq.gmflag) then
              write(toplab,"('GLOBAL MEANS  ZP=',f4.1)") zphtline(k)
            elseif (gloc(1,l).ne.gmflag.and.gloc(2,l).eq.gmflag) then
              write(toplab,"('LAT= ',f6.2,' LON=ZONAL MEANS  ZP=',
     +          f4.1)") gloc(1,l),zphtline(k)
            else
              if (locname(1).eq.'xxxxxxxxxxxxxxxx') then
                write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' ZP=',
     +            f4.1)") gloc(1,l),gloc(2,l),zphtline(k)
              else
                write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' (',a,')',
     +            ' ZP=',f4.1)") gloc(1,l),gloc(2,l),
     +              locname(l)(1:lenstr(locname(l))),zphtline(k)
              endif
            endif
          else
            if (gloc(1,l).eq.gmflag.and.gloc(2,l).eq.gmflag) then
              write(toplab,"('GLOBAL MEANS  HT=',f5.1)") zphtline(k)
            elseif (gloc(1,l).ne.gmflag.and.gloc(2,l).eq.gmflag) then
              write(toplab,"('LAT= ',f6.2,' LON=ZONAL MEANS  HT=',
     +          f5.1)") gloc(1,l),zphtline(k)
            else
              if (locname(1).eq.'xxxxxxxxxxxxxxxx') then
                write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' HT=',
     +            f5.1)") gloc(1,l),gloc(2,l),zphtline(k)
              else
                write(toplab,"('LAT,LON = ',f6.2,', ',f7.2,' (',a,
     +            ')  HT=',f5.1)") gloc(1,l),gloc(2,l),
     +              locname(l)(1:lenstr(locname(l))),zphtline(k)
              endif
            endif
          endif
          len = lenstr(toplab)
          call clearstr(rec80)
          write(rec80,"(a)") toplab(1:len)
c
c Loop for ve,vu:
c
          do ip=1,2
            call clearstr(ylab)
            if (ip.eq.1) then
              call getvevu(veutkmx,ntms,kmx,nloc,plt,htutkmx,izphtlin,
     +          zphtline,k,l)
              write(ylab,"('VE (M/S)')")
            else
              call getvevu(vuutkmx,ntms,kmx,nloc,plt,htutkmx,izphtlin,
     +          zphtline,k,l)
              write(ylab,"('VU (M/S)')")
            endif
            call displa(2,1,1)
            call anotat('UT',ylab(1:lenstr(ylab)),0,lset,-1,l)
            call ezxy(utinc,plt,ntms,rec80(1:len))
            call fminmax(plt,ntms,rmin,rmax,cpspval)
            if (rmin.lt.0..and.rmax.gt.0.) 
     +        call line(utinc(1),0.,utinc(ntms),0.)
            isltax = 0
            if (gloc(1,l).ne.gmflag.and.gloc(2,l).ne.gmflag) isltax=1
            call labutxy(mtimes,ntms,0.,0,' ',0.,1,gloc(2,l))
c
c Field label at top:
c
            call clearstr(toplab)
            if (ip.eq.1) 
     +        write(toplab,"('VE (MAG ION DRIFT, +EAST) (M/S)')")
            if (ip.eq.2) 
     +        write(toplab,"('VU (MAG ION DRIFT, +UP) (M/S)')")
            call wrlablq(toplab(1:lenstr(toplab)),
     +        0.5*(vp(1)+vp(2)),vp(4)+.07,.019)
c
c History volume label at bottom:
c
            call clearstr(toplab)
            if (nhvols.eq.1) then
              write(toplab,"('HISTORY=',a)") histvol(ivol)
            else
              write(toplab,"('FIRST HISTORY VOL=',a)") histvol(1)
            endif
            call wrlablq(toplab(1:lenstr(toplab)),.5*(vp(1)+vp(2)),
     +        vp(3)-.22,.012)
c
            call frame
            iframe = iframe+1
            write(6,"('zphtline frame ',i4,' field ',a,' ',a)") iframe,
     +        ylab(1:lenstr(ylab)),rec80(1:lenstr(rec80))
c
c Write ascii data file:
c
            if (iwrascii.gt.0) then
              call wrascii(iwrascii,luascii,plt,ntms,1,utinc,dum,
     +          'UT (HRS)',' ',histvol(ivol),ylab,iframe,rec80,
     +          'tigcmloc',dirascii)
            endif
          enddo
        enddo
      endif
      return
      end
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      subroutine getvevu(v,ntms,kmx,nloc,plt,htutkmx,izphtlin,
     +  zphtline,k,l,cpspval)
      dimension v(ntms,kmx,nloc),izphtlin(kmx),plt(ntms),
     +  htutkmx(ntms,kmx,nloc),zphtline(kmx)
c
      if (izphtlin(k).gt.0) then
        plt(:) = v(:,izphtlin(k),l)
      else
        call intloc(v(1,1,l),htutkmx(1,1,l),kmx,
     +    zphtline(k),1,0,plt,ntms,ntms,1,ier,cpspval,1)
      endif
      return
      end
