vd_ex4f.f



      PROGRAM vd_ex4f

      implicit none

C     Use vsfnpak and vsfcpak to pack field values into a buffer

      integer hopen, vsfatch, vsffdef, vsfsnam
      integer vsfscls, vsfsfld, vsfwrit, vsfdtch
      integer hclose, vsfnpak, vsfcpak, vfend, vfstart

C     Parameter definitions
      integer*4 DFACC_CREATE, DFNT_FLOAT32, DFNT_INT16, DFNT_CHAR8
      integer*4 FULL_INTERLACE, HDF_VSPACK, HDF_VSUNPACK
      parameter (DFACC_CREATE = 4,
     +           DFNT_FLOAT32 = 5,
     +           DFNT_INT16 = 22,
     +           DFNT_CHAR8 = 4,
     +           FULL_INTERLACE = 0,
     +           HDF_VSPACK = 0,
     +           HDF_VSUNPACK = 1)

C     Example parameters.
      integer NRECORDS
      parameter (NRECORDS = 10)

C     Vdata fields.
      real temp(10)
      integer*2 height(10)
      real speed(10)
      character*10 idents /"ABCDEFGHIJKLMNOPQRST"/
      DATA temp/1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9/
      DATA height/0, 1, 2, 3, 4, 5, 6, 7, 8, 9/
      DATA speed/6.0,6.1,6.2,6.3,6.4,6.5,6.6,6.7,6.8,6.9/ 

C     Packing buffer size bigger than (4+2+4+1)*NRECORDS = 110.
      integer buffer(100)

C     More local variables.
      integer retn
      integer*4 file_id, vdata_id

C     Create the file. 
      file_id = hopen('VD_Ex4f.hdf', DFACC_CREATE, 0)

C     Initialize the interface. 
      retn = vfstart(file_id)

C     Create a new vdata. 
      vdata_id = vsfatch(file_id, -1, 'w')

C     Define the fields to write. 

      retn = vsffdef(vdata_id, 'Temp', DFNT_FLOAT32, 1) 
      retn = vsffdef(vdata_id, 'Height', DFNT_INT16, 1) 
      retn = vsffdef(vdata_id, 'Speed', DFNT_FLOAT32, 1) 
      retn = vsffdef(vdata_id, 'Ident', DFNT_CHAR8, 1) 

C     Set the vdata name. 
      retn = vsfsnam(vdata_id, 'Example Vset Name')

C     Set the vdata class. 
      retn = vsfscls(vdata_id, 'Example Vset Class')

C     Set the field names. 
      retn = vsfsfld(vdata_id, 'Temp,Height,Speed,Ident')


C     Pack NRECORDS of data into buffer.

      retn = vsfnpak(vdata_id, HDF_VSPACK,' ',buffer,
     +          110, NRECORDS, 'Temp', temp)
      retn = vsfnpak(vdata_id, HDF_VSPACK,' ',buffer,
     +          110, NRECORDS, 'Height',height)
      retn = vsfnpak(vdata_id, HDF_VSPACK,' ',buffer,
     +          110, NRECORDS, 'Speed',speed)
      retn = vsfcpak(vdata_id, HDF_VSPACK,' ',buffer,
     +          110, NRECORDS, 'Ident',idents)


      retn = vsfwrit(vdata_id, buffer, NRECORDS, FULL_INTERLACE)

C     Terminate access to the vdata object, the interface 
C     and the file.
      retn = vsfdtch(vdata_id)
      retn = vfend(file_id)
      retn = hclose(file_id)

      end