many_ris_hdf.f

      program many_ris_hdf
      character*1 image(128,128)
      character number1*1,number2*2, numbert*2, number3*3
      character file1*16, file2*16, file3*16
      character*1 colors(768)
      integer k  
      integer ivals(128,128,62)
      integer DFR8setpalette,DFR8putimage,ret
c
      open(5,file='fan.128_ascii',status='old',err=888)
c
      ret=DFR8setpalette(colors)
c
c  read in integer values from input file
c
      ix=128
      iy=128
      iz=62
c 
      do 200 k=1,iz
  200 read(5,10)((ivals(i,j,k),i=1,ix),j=1,iy)
   10 format(20(1x,i3))
c
c  convert first slice to character (8-bit) data
c
      do 300 k=1,iz
      do 100 j=1,iy
      do 100 i=1,ix
      image(i,j)=char(ivals(i,j,k))
  100 continue
c
c  create filename character string
c
      if (k.le.9) then
        number1=char(48+k)
        file1='fan_00' // number1 // '_ris.hdf'
c
c  Write image to an HDF file    
c
        ret=DFR8putimage(file1,image, 128, 128, 0)
      endif
c
      if ((k.ge.10).and.(k.le.99)) then
        temp=int(aint(float(k)/10))
        number2= char(temp+48) // char(k-temp*10+48)
        file2='fan_0' // number2 // '_ris.hdf'
        ret=DFR8putimage(file2, image, 128, 128, 0)
      endif
c
      if (k.ge.100) then
        temp1=int(aint(float(k)/100))
        temp2=int(aint(float(k-temp1*100)/10))
        numbert= char(temp1+48) // char(temp2+48)
        number3= numbert // char(k-temp1*100-temp2*10+48)
        file3='fan_' // number3 // '_ris.hdf'
        ret=DFR8putimage(file3, image, 128, 128, 0)
      endif 
c
  300 continue
c      
      if (istat .ne. 0)then
	 write(*,*)'Error Writing HDF File'
      endif
c  
  888 stop
      end