      program atmperso
      implicit undefined (a - z)
      integer STDIN
      parameter (STDIN = 5)
      integer STDOUT
      parameter (STDOUT = 6)

      integer DID
      parameter (DID = 18)
      integer DENG1
      parameter (DENG1 = 4719)
      integer DENG2
      parameter (DENG2 = 32256)
      integer DSCIEN
      parameter (DSCIEN = 55440)
      integer aload
      integer aidstr
      integer aid
      integer aeng1
      integer aeng2
      integer aline
      integer arast
      integer aspect
      character*128 idstr
      integer id(DID)
      integer eng1(DENG1)
      integer eng2(DENG2)
      integer scien(DSCIEN)


      integer n
      character*249 filename
      filename='s055image'
      call ouverture(filename)
      n = aload(filename)
      call daload(n)
      n = aidstr(idstr)
      call daidstr(n, idstr)
      n = aid(id)
      call daid(n, id, DID)
      n = aeng1(eng1)
      call daeng1(n, eng1, DENG1)
      n = aeng2(eng2)
      call daeng2(n, eng2, DENG2)
      n = aline(scien)
      call daline(n, scien, DSCIEN)
      n = arast(scien)
      call darast(n, scien, DSCIEN)
      n = aspect(scien)
      call daspec(n, scien, DSCIEN)
      stop
  101 format(a)
      end

      subroutine daload(n)
      implicit undefined (a - z)
      integer n
      integer STDOUT
      parameter (STDOUT = 10)

      if (n .gt. 0) then
          write(STDOUT, *) '[daload]', n, ' bytes obtained from file'
      else if (n .eq. 0) then
          write(STDOUT, *) '[daload] no data obtained from file'
      else if (n .eq. -1) then
          stop '[daload] no file opened'
      else
          write(STDOUT, *) '[daload]', n, 'bad value returned by aload'
      endif
      return
      end

      subroutine ouverture(filename)
      implicit undefined (a - z)
      character*6 filename

      continue
      open(unit=10, file=filename//'_load')
      open(unit=11, file=filename//'_id')
      open(unit=12, file=filename//'_idst')
      open(unit=13, file=filename//'_eng1')
      open(unit=14, file=filename//'_eng2')
      open(unit=15, file=filename//'_line')
      open(unit=16, file=filename//'_rast')
      open(unit=17, file=filename//'_spec')
      return
      end



      subroutine daid(n, id, dim)
      implicit undefined (a - z)
      integer n
      integer dim
      integer id(dim)
      integer STDOUT
      parameter (STDOUT = 11)
      integer i
      write(10, *) '[daid] ', n, ' integers returned by aid'
      write(STDOUT, 101) (id(i), i = 1, dim)
c     3600000 msec per hour, 60000 msec per minute, 1000 msec per second
      write(STDOUT, 111)
     $  id(6) / 3600000,
     $  mod(id(6), 3600000) / 60000,
     $  mod(id(6), 60000) / 1000,
     $  mod(id(6), 1000)
      return
  101 format(' ', 2i6, 4i10, 12i5)
  111 format(' ', 'time is ', i2, ':', i2, ":", i2, ".", i3, ' gmt')
      end


      subroutine daidstr(n, idstr)
      implicit undefined (a - z)
      integer n
      character*(*) idstr
      integer STDOUT
      parameter (STDOUT = 12)
      write(10, *) '[daidstr]', n, ' characters returned by aidstr'
      write(STDOUT, 101) idstr(1:67)
      write(STDOUT, 101) idstr(11:26)
      return
  101 format(a)
      end


      subroutine daeng1(n, eng1, dim)
      implicit undefined (a - z)
      integer n
      integer dim
      integer eng1(dim)
      integer STDOUT
      parameter (STDOUT = 13)
      integer i
      integer j
      write(10, *) '[daeng1]', n, ' integers returned by aeng1'
      do 1000, i = 1, n, 13
	  if((eng1(i+2).gt.8191).and.(eng1(i+2).lt.32767)) then 
		eng1(i+2)=8192-eng1(i+2) 
	  endif
	  if((eng1(i+1).gt.8191).and.(eng1(i+2).lt.32767)) then 
		eng1(i+1)=8192-eng1(i+1) 
	  endif
	  if((eng1(i+8).gt.0).and.(eng1(i+8).lt.8192)) then 
		eng1(i+8)=4.*eng1(i+8)/3 
	  else if((eng1(i+8).gt.8191).and.(eng1(i+8).lt.32767)) then 
		eng1(i+8)=-4.*(eng1(i+8)-8192)/3 
          endif

          write(STDOUT, 101) (eng1(j), j = i, i + 13 - 1)
 1000 continue
      return
  101 format(' ', 1i12, 12i7)
      end

      subroutine daeng2(n, eng2, dim)
      implicit undefined (a - z)
      integer n
      integer dim
      integer eng2(dim)
      integer STDOUT
      parameter (STDOUT = 14)
      integer i
      integer j
      write(10, *) '[daeng2]', n, ' integers returned by aeng2'
      do 1000, i = 1, n, 4
          write(STDOUT, 101) (eng2(j), j = i, i + 4 - 1)
 1000 continue
      return
  101 format(' ', 1i12, 3i6)
      end


      subroutine daline(n, line, dim)
      implicit undefined (a - z)
      integer n
      integer dim
      integer line(dim)
      integer STDOUT
      parameter (STDOUT = 15)
      integer i
      integer j
      write(10, *) '[daline]', n, ' integers returned by aline'
c     the use of 12 below needs to be confirmed against fiche
      do 1000, i = 1, n, 12
          write(STDOUT, 101) (line(j), j = i, i + 12 - 1)
 1000 continue
      return
  101 format(' ', 12i7)
      end


      subroutine darast(n, rast, dim)
      implicit undefined (a - z)
      integer n
      integer dim
      integer rast(dim)
      integer STDOUT
      parameter (STDOUT = 16)
      integer i
      write(10, *) '[darast]', n, ' integers returned by arast'
      do 1000, i = 1, n, 132 * 60
          call daras2(rast(i))
 1000 continue
      return
      end


      subroutine daras2(image)
      implicit undefined (a - z)
      integer image(132, 60)
      integer STDOUT
      parameter (STDOUT = 16)
      integer i
      integer j
      do 2000, i = 1, 132, 1
          do 1000, j = 1, 60, 1
              if (image(i, j) .eq. 32767) then
                  image(i, j) = -1
              endif
 1000     continue
 2000 continue
      do 3000, i = 132, 67, -1
          write(STDOUT, 301) (image(i, j), j = 1, 30, 1)
 3000 continue
      do 4000, i = 66, 1, -1
          write(STDOUT, 301) (image(i, j), j = 1, 30, 1)
 4000 continue
      do 5000, i = 132, 67, -1
          write(STDOUT, 301) (image(i, j), j = 31, 60, 1)
 5000 continue
      do 6000, i = 66, 1, -1
          write(STDOUT, 301) (image(i, j), j = 31, 60, 1)
 6000 continue
      return
  301 format(' ', 30i7)
      end


      subroutine daspec(n, spect, dim)
      implicit undefined (a - z)
      integer n
      integer dim
      integer spect(dim)
      integer STDOUT
      parameter (STDOUT = 17)
      integer i
      write(10, *) '[daspec]', n, ' integers returned by aspect'
c     the use of 12 below needs to be confirmed against fiche
      do 1000, i = 1, n, 1
          write(STDOUT, 101) spect(i)
 1000 continue
      return
  101 format(' ', 1i7)
      end
