      program     he5_za_readdimscaleF_32

      implicit    none

      include     'hdfeos5.inc'

      integer     status
      integer     i, j, jj
      integer     he5_zaopen
      integer     he5_zaattach
      integer     he5_zawrfld
      integer     he5_zawrattr
      integer     he5_zawrgattr
      integer     he5_ehwrglatt
      integer     he5_zawrlattr 
      integer     he5_zadetach
      integer     he5_zaclose
      integer     HE5_ZAdscaleattrinfo, HE5_ZAreaddscaleattr
      integer     HE5_ZAgetdimscale, HE5_ZAinqdscaleattrs
      integer     ntype
      integer     zafid,zaid1
      real*4      datbuf_f(1) 
      integer*4   datbuf_i(3)
      integer*4   nbands
      integer     bands(3)
      integer*4   datbuf_i2(2) 
      integer     count(2)
      integer         attr_int(25)
      real*4          attr_flt(25)
      real*8          attr_dbl(25)
      character       attr_char(25)
      integer         dimsize
      integer         bufsize, nattr 
      integer         data(30)
      integer         FAIL
      parameter       (FAIL=-1)
      character*100   attrlist
      character*100   strbufsize
      character*15    attrname(10)
      integer         numtype

!  /*
!   * Open the HDF zaath file, "za.he5".
!   */

      zafid = HE5_ZAopen("za.he5", HE5F_ACC_RDWR)
 
!  /*
!   * If the zaath file cannot be found, HE5_ZAopen will return -1 for the file
!   * handle (zafid).  We there check that this is not the case before
!   * proceeding with the other routines.
!   * 
!   * The HE5_ZAattach routine returns the handle to the existing zaath "ZA1",
!   * ZAid.  If the zaath is not found, HE5_ZAattach returns -1 for the handle.
!   */ 

      if (zafid .ne. FAIL) then
     
         ZAid1 = HE5_ZAattach(zafid, "ZA1")

!      /* the field Pollution has Time,YDim,XDim dimensions. 
!	 xdim = 120
!	 ydim = 200
!	 Time dim is set to 10
!      */

         if (ZAid1 .eq. FAIL) then
            
            write(*,*) 'Error: Cannot attach to zaath  ZA1'
            status = HE5_ZAclose(zafid)
            stop
         endif

         bufsize = HE5_ZAgetdimscale(ZAid1, "Spectra", "Bands", 
     1        dimsize, numtype, data)
         if (bufsize .eq. -1) then
	
            write(*,*) 'Error:Cannot get Dimension Scale size of Bands',
     1           ' dimemnsion in field Spectra'
            status = HE5_ZAdetach(ZAid1)
            status = HE5_ZAclose(zafid)
            stop
            
         else
            
            write(*,*) 'bufsize = ',bufsize
            write(*,*) 'dimsize = ',dimsize
            write(*,*) 'numtype = ',numtype
            
            write(*,*) 'Values are:'
            do i = 1,dimsize
               write(*,*) 'DimscaleValue[',i,'] = ',data(i)
            enddo
         endif
         
         nattr = HE5_ZAinqdscaleattrs(ZAid1, "Bands", attrlist, 
     1        strbufsize)
         if ( nattr .lt. 0 ) then
            
            write(*,*) 'Error: Cannot get Dimension Scale attribute',
     1           ' list for Bands'
            status = HE5_ZAdetach(ZAid1)
            status = HE5_ZAclose(zafid)
            stop
         endif
         write(*,*) ' '
         write(*,*) 'Dimension scale for Bands Attribute:'

         attrname(1) = 'label'
         attrname(2) = 'unit'
         attrname(3) = 'format'
         attrname(4) = 'MissingValue'
         attrname(5) = 'IntValues'
         do j = 1,5
            attr_char = ''
            count(1)= 0
            count(2)= 0

            status = HE5_ZAdscaleattrinfo(ZAid1,"Bands", attrname(j), 
     1        ntype, count)
                              
            if( ntype .eq. 0) then
               status = HE5_ZAreaddscaleattr(ZAid1,"Bands", attrname(j), 
     1              attr_int)
            endif

            if( ntype .eq. 10) then
               status = HE5_ZAreaddscaleattr(ZAid1,"Bands", attrname(j), 
     1              attr_flt)
            endif
            
            if( ntype .eq. 11) then
               status = HE5_ZAreaddscaleattr(ZAid1,"Bands", attrname(j), 
     1              attr_dbl)
            endif
            
            if( ntype .eq. 57) then
               status = HE5_ZAreaddscaleattr(ZAid1,"Bands", attrname(j), 
     1              attr_char)
            endif

            write(*,*) ' '
            write(*,*) 'Status returned by HE5_ZAreaddscaleattr() :', 
     1           status
            write(*,*) 'Attribute Name: ',attrname(j)
            write(*,*) 'Number of attribute elements: ', count(1),
     1     '   ',count(2)
            write(*,*) 'Data type of attribute: ', ntype
            
            if( ntype .eq. 0) then
               do jj = 1,count(1)
                  write(*,*) 'Attrvalue[',jj,']: ', attr_int(jj)
               enddo
            endif
            
            if( ntype .eq. 10) then
               do jj = 1,count(1)
                  write(*,*) 'Attrvalue[',jj,']: ',attr_flt(jj)
               enddo
            endif

            if( ntype .eq. 11) then
               do jj = 1,count(1)
                  write(*,*) 'Attrvalue[',jj,']: ',attr_dbl(jj)
               enddo
            endif

            if( ntype .eq. 57) then
               write(*,*) 'Attrvalue: ', attr_char
            endif
         enddo
      endif

      status = HE5_ZAdetach(ZAid1)
      
      status = HE5_ZAclose(zafid)
      
      stop
      end

