      use dflib
      parameter (mp=9999,ms=20)
      implicit real*8 (a-h,o-z)
      character*8 sch
      character*2 zz
      dimension dwnm(mp),flob(mp),flth(mp),depl(mp)
      dimension itn(ms),np(ms),wla(mp,ms),pobs(mp,ms),pthe(mp,ms)
      character*40 finput,foutput
      integer*2 narg1
      character*80 buf
      logical loexist
      narg1=1
      call getarg(narg1,buf)
      read(buf,'(a)') finput
      inquire (file=finput,exist=loexist)
      if (.not.loexist) then
      write(6,'(''file:'',(a))') finput
      write(6,'(''Not exist!'')')
      stop
      end if
c      write(6,*) 'Input file name (e.g., result.sav)?'
c      read(5,'(a40)') finput
      open (unit=9, file=finput)
      rewind 9
      n=0
    1 read(9,200,end=999) sch,zz
  200 format(a8,a2)
      if(sch.ne.' ITERAT#') go to 1
      n=n+1
      read(9,210) np(n),wnm0
  210 format(i4,f12.5)
      read(9,220) (dwnm(k),k=1,np(n))
      read(9,220) (flob(k),k=1,np(n))
      read(9,220) (flth(k),k=1,np(n))
      read(9,220) (depl(k),k=1,np(n))
  220 format(10f8.5)
c      in case fluxes are not yet normalized
       if(abs(flob(1)).gt.0.1) then
       base=flob(1)
       do 250 k=1,np(n)
       flob(k)=flob(k)-base
  250  flth(k)=flth(k)-base
       end if
c
      read(9,230) nv
  230 format(i4)
      do 290 i=1,nv-1
  290 read(9,240)
  240 format(80x)
      read(9,242) vrnm
  242 format(44x,f8.4)
      read(9,240)
      do 260 k=1,np(n)
      wla(k,n)=(wnm0+abs(dwnm(k))-vrnm)*10.
      pobs(k,n)=exp(2.3025851*flob(k))
      pthe(k,n)=exp(2.3025851*flth(k))
  260 continue
      read(zz,'(i2)') itn(n)
      write(6,*) 'n=',n,' --> Iteration No.',itn(n)
      go to 1
  999 continue
      close(unit=9)
c::::::
      write(6,*) 'Please input n you want:' 
      read(5,*) nsel
      write(6,*) 'Output file name ?'
      read(5,'(a40)') foutput
      open (unit=10, file=foutput)
      do 410 k=1,np(nsel)
      write(10,420) wla(k,nsel),pobs(k,nsel),pthe(k,nsel)
  410 continue
  420 format(f8.3,2f10.4)
      close(unit=10)
c::::::
      stop
      end
