home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / ann / file_annF.f < prev    next >
Encoding:
Text File  |  1991-10-25  |  4.3 KB  |  155 lines

  1. C
  2. C $Header: /pita/work/HDF/dev/RCS/test/annotations/file_ann_testF.f,v 1.1 90/06/27 11:18:51 mfolk beta $
  3. C
  4. C $Log:    file_ann_testF.f,v $
  5. c Revision 1.1  90/06/27  11:18:51  mfolk
  6. c Initial revision
  7. C
  8.  
  9.  
  10.       program file_ann_test
  11.  
  12. C Program to test routines for writing file IDs and file descriptions
  13. C
  14. C Mike Folk
  15.  
  16. C****||************************************************************
  17.  
  18.       integer dfile, i, ret, first, length
  19.       character*64 filename
  20.       character*7  baselabel
  21.       character*10 outlabel, inlabel
  22.       character*400 outdescr, indescr
  23.  
  24.       integer DFopen, DFclose, DFerrno, DFerror
  25.       integer DFANaddfid, DFANaddfds, DFANgetfid, DFANgetfds
  26.       integer DFANgetfidlen,  DFANgetfdslen
  27.  
  28.       integer DFE_NOERROR, DFACC_READ, DFACC_WRITE
  29.       integer DFAN_LABEL,DFAN_DESC
  30.       integer DFE_NOMATCH
  31.       integer MAXLABLEN, MAXDESCLEN
  32.  
  33.       character*1 CR
  34.  
  35.       parameter (DFE_NOERROR = 0, 
  36.      $           DFACC_READ  = 1, 
  37.      $           DFACC_WRITE = 2, 
  38.      $           DFAN_LABEL  = 0,  
  39.      $           DFAN_DESC   = 1,
  40.      $           MAXLABLEN   =10,
  41.      $           MAXDESCLEN  =400,
  42.      $           FIRST       = 1,
  43.      $           NOTFIRST    = 0,
  44.      $           DFE_NOMATCH = -29)
  45.  
  46. C****||***** store four file IDs in file ************************
  47.  
  48.       DFerror = DFE_NOERROR
  49.       CR      = char(10)
  50.  
  51.       print *, 'Enter HDF file name:'
  52.       read *, filename
  53.   
  54.       dfile = DFopen(filename, DFACC_WRITE, 0)
  55.       if (dfile .eq. 0) call fatalerror('Error opening file to write')
  56.  
  57.       baselabel = 'Label #'
  58.   
  59.       do 100 i=1,4
  60.           outlabel = baselabel//char(48+i)
  61.           ret = DFANaddfid (dfile, outlabel) 
  62.           if (ret .lt. 0) call fatalerror('Error adding label.')
  63.   100 continue 
  64.  
  65. C****||***** get and store file description in file ************
  66.  
  67.       call getdescr(outdescr)
  68.       ret = DFANaddfds (dfile, outdescr,len(outdescr))
  69.       if (ret .lt. 0) call fatalerror('Error adding description.')
  70.  
  71.       ret = DFclose(dfile)
  72.   
  73.   
  74. C****||***** read all file IDs from file *********************** 
  75.  
  76.       dfile = DFopen(filename, DFACC_READ, 0)
  77.       if (dfile .eq. 0) call fatalerror('Error opening file to read.')
  78.  
  79.       print *, '***** Now reading file ID lengths and IDs ******'
  80. C     *** first ID ***
  81.       length = DFANgetfidlen(dfile, FIRST)
  82.       ret = DFANgetfid(dfile,inlabel, MAXLABLEN, FIRST)
  83.   
  84. C     *** rest of IDs ***
  85.       do 200 while ( ret .ge. 0) 
  86.           print *,'Length: ',length,'  Ret:',ret,'  Label:',inlabel
  87.           length = DFANgetfidlen(dfile, NOTFIRST)
  88.           ret = DFANgetfid(dfile,inlabel, MAXLABLEN, NOTFIRST)
  89.   200 continue 
  90.  
  91.       if (DFerrno() .ne. DFE_NOMATCH) then 
  92.           call fatalerror('Error reading label.')
  93.       endif
  94.       print *, '*** End of file IDs ***'
  95.  
  96. C     *** read file description length and description ***
  97.       length = DFANgetfdslen(dfile, FIRST)
  98.       print *, 'Description length: ', length
  99.       ret = DFANgetfds (dfile, indescr, MAXDESCLEN, 1) 
  100.       if (ret .lt. 0) call fatalerror('Error reading description.')
  101.  
  102.       print *, '*** just read description.***'
  103.       print *, 'Description:',CR,indescr
  104.       print *, '*** End of description ***',CR
  105.       ret = DFclose(dfile)
  106.   
  107.       print *
  108.       print *
  109.       print *, '+++++++++++++++++++++++++'
  110.       print *
  111.       print *
  112.  
  113.       stop
  114.       end
  115.   
  116. C************************************************************
  117. * fatalerror: subroutine to report fatal error and abort
  118. *
  119. C****||***********************************************************
  120.  
  121.       subroutine fatalerror(s)
  122.       character*(*) s
  123.  
  124.       print *, s
  125.       print *, 'DFerror:', DFerrno()
  126.       print *, 'Program aborted.'
  127.       print *, ' '
  128.       stop
  129.       end
  130.  
  131.  
  132. C******************************************************************
  133. * getdescr: subroutine to put description in array
  134. *
  135. C****||************************************************************
  136.  
  137.       subroutine getdescr(s)
  138.       character*(*) s
  139.  
  140.       character*1  CR
  141.  
  142.       CR = char(10)
  143.  
  144.       s = ' This loop was used to write out labels.'//CR//CR
  145.      * // '      do 100 i=1,4' // CR
  146.      * // '        outlabel = baselabel//char(48+i)' // CR
  147.      * // '        ret = DFANaddfid(dfile,outlabel,len(outlabel))'//CR
  148.      * // '        if (ret.lt.0)fatalerror(''Error adding label.'')'//CR 
  149.      * // '  100 continue' // CR // CR
  150.      * // 'This is the end of the description.' // CR // CR
  151.  
  152.       return
  153.       end
  154.