      program rs3f
C
C Program to read 3 SDSs from  bctest.hdf which contains an
C SDS written by ws.c, an SDS written by wsf.f and one by wsf31.f.
C It then print a table of the contents of each SDG for comparisons.
C SDG/1 -- SDG/2 should have the same internal memory storage
C sequence in terms of the data arrays; the dimension sizes
C in C are reversed comparing with those in Fortran. 
C In hdf file 3231hdf.dat, these two SDGs should have the same
C sequences in terms of dimension sizes, dim scales, dim strings,
C and data arrays.
C 
C Input file: bctest.hdf


      integer dsgdata, dsgdims, dsgdisc, dsgdist, dsgrang
      integer dspre32
      integer ret, np, nr,nc, di(3)
      integer id1(3),id2(3),id3(3), ispre32
      integer rank,irank1,irank2,irank3
      real    scpln(2), scrow(3), sccol(4), da(4,3,2)
      real    maxi, mini
      real    iscpln1(4), iscrow1(4), isccol1(4), ida1(4,3,2)
      real    iscpln2(4), iscrow2(4), isccol2(4), ida2(4,3,2)
      real    iscpln3(4), iscrow3(4), isccol3(4), ida3(4,3,2)
      real    imaxi(3), imini(3)
      integer i, j, k, no_err
      character*7 l0(3), u0(3), fm0(3)
      character*15 fn
C      character*15 rslfn
      character*12 il1(3),iu1(3), ifm1(3)
      character*12 il2(3),iu2(3), ifm2(3)
      character*12 il3(3),iu3(3), ifm3(3)

      di(1) = 4
      di(2) = 3
      di(3) = 2
      np = 2
      nr = 3
      nc = 4
      rank = 3
      scpln(1) =   0.0
      scpln(2) = 100.0
      scrow(1) =   0.0
      scrow(2) =  10.0
      scrow(3) =  20.0
      sccol(1) =   0.0
      sccol(2) =   1.0
      sccol(3) =   2.0
      sccol(4) =   3.0
      maxi = 123.0
      mini = -1.0
      l0(1) = 'Column'
      u0(1) = 'Cm'
      fm0(1) = 'Int32'
      l0(2) = 'Line'
      u0(2) = 'Inch'
      fm0(2) = 'Int16'
      l0(3) = 'Time'
      u0(3) = 'Second'
      fm0(3) = 'Int32'
      fn = 'bctest.hdf'
C      rslfn = 'rs3f.rsl'
      no_err = 0

      do 200 i=1, np
         do 180 j=1, nr
            do 150 k=1, nc
		da(k,j,i) = scpln(i) + scrow(j) + sccol(k)
C     		print *, da(k,j,i)
150	    continue
180      continue
200   continue

          ret = dsgdims(fn, irank1, id1, 3)
          no_err = no_err + ret
          ispre32 = dspre32()
          if (ispre32 .eq. 0) then
              print *, 'SDG1 was written by HDF3.2'
          else 
              print *, '>>>>>>>>>>>>>>>>>>>>>>>>>'
              print *, 'dspre32() returned wrong value for SDG1'
              no_err = no_err-1
          endif
          do 250 i=1, rank
              ret = dsgdist(i, il1(i), iu1(i), ifm1(i))
              no_err = no_err + ret
250       continue
          ret = dsgdisc(1, id1(1), isccol1)
          no_err = no_err + ret
          ret = dsgdisc(2, id1(2), iscrow1)
          no_err = no_err + ret
          ret = dsgdisc(3, id1(3), iscpln1)
          no_err = no_err + ret
          ret = dsgrang(imaxi(1), imini(1))
          no_err = no_err + ret
          ret = dsgdata(fn, irank1, id1, ida1)
          no_err = no_err + ret

          ret = dsgdims(fn, irank2, id2, 3)
          no_err = no_err + ret
          ispre32 = dspre32()
          if (ispre32 .eq. 0) then
              print *, 'SDG2 was written by HDF3.2'
          else
              print *, '>>>>>>>>>>>>>>>>>>>>>>>>>'
              print *, 'dspre32() returned wrong value for SDG2'
              no_err = no_err-1
          endif

          do 300 i=1, rank
              ret = dsgdist(i, il2(i), iu2(i), ifm2(i))
              no_err = no_err + ret
300       continue
          ret = dsgdisc(1, id2(1), isccol2)
          no_err = no_err + ret
          ret = dsgdisc(2, id2(2), iscrow2)
          no_err = no_err + ret
          ret = dsgdisc(3, id2(3), iscpln2)
          no_err = no_err + ret
          ret = dsgrang(imaxi(2), imini(2))
          no_err = no_err + ret
          ret = dsgdata(fn, irank2, id2, ida2)
          no_err = no_err + ret

          ret = dsgdims(fn, irank3, id3, 3)
          no_err = no_err + ret
          ispre32 = dspre32()
          if (ispre32 .eq. 1) then
              print *,'SDG3 was written by HDF prior to 3.2'
          else
              print *, '>>>>>>>>>>>>>>>>>>>>>>>>>'
              print *, 'dspre32() returned wrong value for SDG3'
              no_err = no_err-1
          endif
          do 350 i=1, rank
              ret = dsgdist(i, il3(i), iu3(i), ifm3(i))
              no_err = no_err + ret
350       continue
          ret = dsgdisc(1, id3(1), isccol3)
          no_err = no_err + ret
          ret = dsgdisc(2, id3(2), iscrow3)
          no_err = no_err + ret
          ret = dsgdisc(3, id3(3), iscpln3)
          no_err = no_err + ret
          ret = dsgrang(imaxi(3), imini(3))
          no_err = no_err + ret
          ret = dsgdata(fn, irank3, id3, ida3)
          no_err = no_err + ret

C 
C Print results
C

C      OPEN(UNIT=8, FILE=rslfn, STATUS='new')
C      print *,'>>> rs3f:',abs(no_err),' calls failed >>>'
      write(*, *)  '                     Print Results'
      write(*, *) '        Origl  SDG/1  SDG/2  SDG/3  '
      write (*, 560) rank, irank1,irank2,irank3
560   format (1x,4Hrank, 1x, 4I7)

      do 600 i=1,3
          write (*,605) i, di(i),id1(i),id2(i), id3(i)
600   continue
605   format (1x,3Hdim,I1,2x,4(1x,I5,1x))

      do 610 i=1,4
          write (*,612) i, sccol(i),isccol1(i),isccol2(i),
     *            isccol3(i)
610   continue
612   format (5Hd1_sc,I1,1x,4(1x,F5.1,1x))

      do 615 i=1,3
          write (*,618) i,scrow(i),iscrow1(i),iscrow2(i),
     *        iscrow3(i)
615   continue
618   format (5Hd2_sc,I1,1x,4(1x,F5.1,1x))

      do 620 i=1,2
          write (*,625) i,scpln(i),iscpln1(i),iscpln2(i),
     *         iscpln3(i)
620   continue
625   format (5Hd3_sc,I1,1x,4(1x,F5.1,1x))

      write (*,631) maxi,imaxi(1),imaxi(2), 
     *        imaxi(3)
631   format (4Hmaxi,3x,4(1x,F5.1,1x))

      write (*,635) mini,imini(1),imini(2),imini(3)
635   format (4Hmini,3x,4(1x,F5.1,1x))

      write (*,638)  l0(1),il1(1),il2(1),il3(1)
638   format (6Hlabel1,1x,4(A6,1x))
      write (*,642)  l0(2),il1(2),il2(2),il3(2)
642   format (6Hlabel2,1x,A6,1x,2(A4,3x),1(A6,1x))
      write (*,648)  l0(3),il1(3),il2(3),il3(3)
648   format (6Hlabel3,1x,A6,1x,2(A4,3x),1(A6,1x))

      write (*,650) u0(1),iu1(1),iu2(1),iu3(1)
650   format (1x, 5Hunit1,1x,A6,1x,2(A2,5x),1(A6,1x))
      write (*,654) u0(2),iu1(2),iu2(2),iu3(2)
654   format (1x, 5Hunit2,1x,A6,1x,2(A4,3x),1(A6,1x))
      write (*,658) u0(3),iu1(3),iu2(3),iu3(3)
658   format (1x, 5Hunit3,1x,4(A6,1x))

      do 660 i=1,3
          write (*,665) fm0(i),ifm1(i),ifm2(i),ifm3(i)
660   continue
665   format (6Hformat,1x,A6,2(1x,A5,1x),1(1x,A6))

      write(*, *)  'Data:'
      do 1000 i=1,np
          do 900 j=1,nr
              do 800 k=1,nc
                 write (*, 1005) k,j,i, da(k,j,i),ida1(k,j,i),
     *           ida2(k,j,i),ida3(k,j,i)
800           continue
900       continue
1000   continue
1005   format (3I2, 4(1x,F5.1,1x))

      print *,'>>> rs3f:',abs(no_err),' calls failed >>>'

      stop 
      end


     



