
      subroutine getinp(ieof)
      include 'tracsat.h'
      parameter(mxt=3*mxtms,kmxtimes=45)
      character*8 flabs(nftot)
      dimension ifields(nftot),ht_scale(3)
      namelist/input/ histvol,mt,iden,ifields,ionvel,satfile,iseclim,
     +  norbfr,inttime,ht_scale,iwrdat,unixdat,unixcgm,iydgcm,
     +  cmin,cmax,cint
      data histvol/mxvols*'                        '/
      data mt /mxt*ispval/
      data iden/1/, ionvel/ispval/, iwrdat/ispval/, iydgcm/ispval/
      data ifields/nftot*ispval/, ht_scale/3*spval/
      data iseclim/2*ispval/, norbfr/ispval/, inttime/ispval/
      data cmin/nftot*spval/, cmax/nftot*spval/, cint/nftot*spval/
c
c Read input namelist:
c
      call clearstr(satfile)
      call clearstr(unixdat)
      call clearstr(unixcgm)
      ieof = 0
      read(5,input,end=900)
c
c Sat file name (mss path):
c
      if (lenstr(satfile).le.0) then
        write(6,"('>>> Need sat file name (mss path) <<<')")
        stop 'satfile'
      endif
c
c Ut limits:
c
      if (iseclim(1).eq.ispval.or.iseclim(2).eq.ispval) then
        write(6,"('>>> Need ISECLIM (ut min,max in secs) <<<')")
        stop 'iseclim'
      endif
c
c Number of orbits per frame:
c
      if (norbfr.eq.ispval) then
        write(6,"('>>> Need norbfr (number of orbits per frame) <<<')")
        stop 'norbfr'
      endif
c
c Do gcm ut interpolation?
c
      if (inttime.eq.ispval) then
        write(6,"('>>> Need inttime (time interp flag) <<<')")
        stop 'inttime'
      endif 
c
c History volumes (nhvols = number of volumes):
c
      nhvols = 0
      do i=1,mxvols
        if (lenstr(histvol(i)).gt.0) nhvols = nhvols+1
      enddo
      if (nhvols.le.0) then
        write(6,"('>>> Need at least one mss history volume (histvol)',
     +    ' <<<')")
        stop 'histvol'
      endif
c
c Model times (ntms = number of model times):
c
      ntms = 0
      do i=1,mxtms
        if (mt(1,i).ne.ispval) ntms = ntms+1
      enddo
      if (ntms.le.0) then
        write(6,"('>>> Need at least one model time (mt) <<<')")
        stop 'mt'
      endif
c
c Model yrday:
c
      if (iydgcm.eq.ispval) then
        write(6,"('>>> need iydgcm <<<')")
        stop 'iydgcm'
      endif
c
c Height scale:
c
      do i=1,3
        if(ht_scale(i).eq.spval) then
          write(6,"('>>> Need ht_scale=hmin,hmax,del <<<')")
          stop 'ht_scale'
        endif
      enddo
      if (ht_scale(1).ge.ht_scale(2)) then
        write(6,"('>>> ht_scale: top must be > bot: bot=',
     +    f10.2,' top=',f10.2)") ht_scale(1),ht_scale(2)
        stop 'ht_scale'
      endif
      if (ht_scale(3).le.0.) then
        write(6,"('>>> ht_scale: bad delta ht=',f10.2)")
     +    ht_scale(3)
        stop 'ht_scale'
      endif
      htbot = ht_scale(1)
      httop = ht_scale(2)
      delht = ht_scale(3)
      nhtscale = ifix((httop-htbot) / delht + 1.0000001)
      call hpalloc(phtscale,nhtscale,ier,1)
      if (ier.ne.0) then
        write(6,"('hpalloc error = ',i6,' for phtscale')") ier
        stop 'phtscale'
      endif
      do i=1,nhtscale
        htscale(i) = htbot + (i-1)*delht
      enddo
c
c Density conversion flag:
c
      if (iden.lt.0.or.iden.gt.3) then
        write(6,"('>>> getinp: bad iden=',i3)") iden
        stop 'iden'
      endif
c
c Field flags:
c (ifplt(nftot) > 0 -> field desired by original user input)
c
      nf = 0
      do i=1,nftot
        if (ifields(i).ne.ispval) nf = nf+1
      enddo
      if (nf.ne.nftot) then
        write(6,"('>>> Need ',i2,' values for ifields (0 or 1) ',
     +    '(got ',i2,') <<<')") nftot,nf
        stop 'ifields'
      endif
      ifplt(:) = ifields(:)
      do i=1,nfhist
        ifget(i) = ifplt(i)
      enddo
      ifget(ixz) = 1 ! always get height
c
c Ion drifts flag (ionvel=1 -> ExB drifts, ionvel=2 -> "total" ion drifts,
c i.e., ExB + effect of neutral winds (see mkdrifts.f and mkuivi.f)
c
      if (ifplt(ixui).gt.0.or.ifplt(ixvi).gt.0.or.
     +    ifplt(ixwi).gt.0) then
c
c 5/94: ion drifts not yet available        
        write(6,"('>>> Sorry: ion drifts not yet availabl <<<')")
        ifplt(ixui) = 0 
        ifplt(ixvi) = 0 
        ifplt(ixwi) = 0 
      endif
c     if (ifplt(ixui).gt.0.or.ifplt(ixvi).gt.0.or.
c    +    ifplt(ixwi).gt.0) then
c       if (ionvel.eq.ispval) then
c         write(6,"('Did not get value for ionvel -- will default to ',
c    +      'ionvel=1 (ExB drifts)')") 
c         ionvel = 1
c       endif
c       ifplt(ixpot) = 1
c       if (ionvel.eq.2) then
c         ifget(ixu) = 1
c         ifget(ixv) = 1
c         ifget(ixw) = 1
c         ifget(ixo1) = 1
c         ifget(ixo2) = 1
c         ifget(ixn2) = 1
c       endif
c     else
c       ionvel = 0
c     endif
c
c 5/94: ver6300 not yet available:
      if (ifplt(ixver).gt.0) then
        write(6,"('>>> Sorry: ver6300 not yet available <<<')")
        ifplt(ixver) = 0
      endif
c
c 5/94: add 15 mic CO2 and 5.3 mic NO from John Wise:
      if (ifplt(ixver15m).gt.0) then
        ifget(ixt) = 1
        ifget(ixo1) = 1
        ifget(ixco2) = 1
      endif
      if (ifplt(ixver53m).gt.0) then
        ifget(ixt) = 1
        ifget(ixo1) = 1
        ifget(ixno) = 1
      endif
c
c Fields to get (nfget = number of fields to get (sum of ifget(i) > 0)
c (max nfget = nfhist)
c
      nfget = 0
      do ip=1,nfhist
        if (ifget(ip).gt.0) then
          nfget = nfget+1
          ifget(ip) = nfget
        endif
      enddo
c     nfget = 0
c     do ip=1,nfhist
c       if (ifget(ip).gt.0) nfget=nfget+1
c     enddo
c
      nfplt = 0
      do ip=1,nftot
        if (ifplt(ip).gt.0) then
          nfplt = nfplt+1
          flabs(nfplt) = flab(ip)
        endif
      enddo 
c
c cmin,cmax,cint:
c
      ncmin = 0
      do i=1,nftot
        if (cmin(i).ne.spval) ncmin = ncmin+1
      enddo
      if (ncmin.gt.0.and.ncmin.ne.nftot) then
        write(6,"('>>> Wrong number of values for cmin: got ',i3,
     +    ' values, need ',i3,' values')") ncmin,nftot
        stop 'cmin'
      endif
      if (ncmin.eq.0) cmin(:) = 1.
c
      ncmax = 0
      do i=1,nftot
        if (cmax(i).ne.spval) ncmax = ncmax+1
      enddo
      if (ncmax.gt.0.and.ncmax.ne.nftot) then
        write(6,"('>>> Wrong number of values for cmax: got ',i3,
     +    ' values, need ',i3,' values')") ncmax,nftot
        stop 'cmax'
      endif
      if (ncmax.eq.0) cmax(:) = 0.
c
      ncint = 0
      do i=1,nftot
        if (cint(i).ne.spval) ncint = ncint+1
      enddo
      if (ncint.gt.0.and.ncint.ne.nftot) then
        write(6,"('>>> Wrong number of values for cint: got ',i3,
     +    ' values, need ',i3,' values')") ncint,nftot
        stop 'cint'
      endif
      if (ncint.eq.0) cint(:) = 0.
c
c     write(6,"('getinp: nfhist=',i2,' nftot=',i2)") nfhist,nftot
c     write(6,"('getinp: nfget=',i2,' ifget=',/(10i3))") nfget,ifget 
c     write(6,"('getinp: nfplt=',i2,' ifplt=',/(10i3))") nfplt,ifplt 
c
c Report inputs to stdout:
c
      write(6,"(' ')")
      write(6,"('--------------------------------------------------',
     +  '----------------------')")
      write(6,"('TRACSAT INPUTS:')")
      write(6,"(' ')")
      write(6,"('nhvols =',i3,' histvol=',$)") nhvols
      do iv=1,nhvols
        write(6,"(a)") histvol(iv)(1:lenstr(histvol(iv))) 
      enddo
      write(6,"('ntms =',i3,' mt = ',$)") ntms
      write(6,"(6(2x,i2,':',i2,':',i2))") 
     +  ((mt(ii,i),ii=1,3),i=1,ntms)
      if (iden.eq.0) write(6,"('iden =',i2,' (leave species as on ',
     +  'history)')") iden
      if (iden.eq.1) write(6,"('iden =',i2,' (convert appropriate ',
     +  'species to number densities (cm3))')") iden
      if (iden.eq.2) write(6,"('iden =',i2,' (convert appropriate ',
     +  'species to number density mixing ratios)')") iden
      if (iden.eq.3) write(6,"('iden =',i2,' (convert appropriate ',
     +  'species to mass density (gm/cm3))')") iden
      write(6,"('nfplt=',i2,' requested fields = ')") nfplt
      write(6,"(8a8)") (flabs(ip),ip=1,nfplt)
      if (ifplt(ixui).gt.0.or.ifplt(ixvi).gt.0.or.
     +    ifplt(ixwi).gt.0)
     +  write(6,"('ionvel = ',i2)") ionvel
      write(6,"('Sat file=',a)") satfile(1:lenstr(satfile))
      write(6,"('iseclim=',2i12)") iseclim
      write(6,"('norbfr=',i2)") norbfr
      write(6,"('inttime=',i3)") inttime
      write(6,"('nhtscale=',i2,' linear height scale = ',
     +  /(6e10.3))") nhtscale,(htscale(i),i=1,nhtscale)
      write(6,"('--------------------------------------------------',
     +  '----------------------')")
      write(6,"(' ')")
      return
c
 900  continue
      write(6,"('getinp: EOF on standard in')")
      ieof = 1
      return
      end
