[Top] [Prev] [Next]

create_annotation.c

 
#include "hdf.h"

#define  FILE_NAME      "General_HDFobjects.hdf"
#define  VG_NAME        "AN Vgroup"
#define  FILE_LABEL_TXT "General HDF objects"
#define  FILE_DESC_TXT  "This is an HDF file that contains general HDF objects"
#define  DATA_LABEL_TXT "Common AN Vgroup"
#define  DATA_DESC_TXT  "This is a vgroup that is used to test data annotations"

main( )
{
   /************************* Variable declaration **************************/

   intn   status_n;     /* returned status for functions returning an intn  */
   int32  status_32,    /* returned status for functions returning an int32 */
          file_id,      /* HDF file identifier */
          an_id,        /* AN interface identifier */
          file_label_id,  /* file label identifier */
          file_desc_id,   /* file description identifier */
          data_label_id,  /* data label identifier */
          data_desc_id,   /* data description identifier */
          vgroup_id;
   uint16 vgroup_tag, vgroup_ref;

   /********************** End of variable declaration **********************/

   /*
   * Create the HDF file.
   */
   file_id = Hopen (FILE_NAME, DFACC_CREATE, 0);

   /*
   * Initialize the AN interface.
   */
   an_id = ANstart(file_id);

   /*
   * Create the file label.
   */
   file_label_id = ANcreatef(an_id, AN_FILE_LABEL);

   /*
   * Write the annotations to the file label.
   */
   status_32 = ANwriteann(file_label_id, FILE_LABEL_TXT, 
                          strlen (FILE_LABEL_TXT));

   /*
   * Create file description.
   */
   file_desc_id = ANcreatef(an_id, AN_FILE_DESC);

   /*
   * Write the annotation to the file description.  
   */
   status_32 = ANwriteann(file_desc_id, FILE_DESC_TXT, 
                          strlen (FILE_DESC_TXT));

   /*
   * Create a vgroup in the V interface.  Note that the vgroup's ref number 
   * is set to -1 for creating and the access mode is "w" for writing.
   */
   status_n = Vstart(file_id);
   vgroup_id = Vattach(file_id, -1, "w");
   status_32 = Vsetname (vgroup_id, VG_NAME);

   /*
   * Obtain the tag and ref number of the vgroup for subsequent
   * references.  
   */
   vgroup_tag = (uint16) VQuerytag (vgroup_id);
   vgroup_ref = (uint16) VQueryref (vgroup_id);

   /*
   * Create the data label for the vgroup identified by its tag 
   * and ref number.
   */
   data_label_id = ANcreate(an_id, vgroup_tag, vgroup_ref, AN_DATA_LABEL);

   /*
   * Write the annotation text to the data label.
   */
   status_32 = ANwriteann(data_label_id, DATA_LABEL_TXT, 
                          strlen(DATA_LABEL_TXT));

   /*
   * Create the data description for the vgroup identified by its tag 
   * and ref number.
   */
   data_desc_id = ANcreate(an_id, vgroup_tag, vgroup_ref, AN_DATA_DESC);

   /*
   * Write the annotation text to the data description.
   */
   status_32 = ANwriteann(data_desc_id, DATA_DESC_TXT, strlen(DATA_DESC_TXT));

   /*
   * Teminate access to the vgroup and to the V interface.
   */
   status_32 = Vdetach(vgroup_id);
   status_n = Vend(file_id);

   /*
   * Terminate access to each annotation explicitly.
   */
   status_n = ANendaccess(file_label_id);
   status_n = ANendaccess(file_desc_id);
   status_n = ANendaccess(data_label_id);
   status_n = ANendaccess(data_desc_id);

   /*
   * Terminate access to the AN interface and close the HDF file.
   */
   status_32 = ANend(an_id);
   status_n = Hclose(file_id);
}

create_annotation.f

      program create_annotation
      implicit none
C
C     Parameter declaration
C
      character*22 FILE_NAME
      character*9  VG_NAME
      character*19 FILE_LABEL_TXT
      character*53 FILE_DESC_TXT
      character*16 DATA_LABEL_TXT
      character*54 DATA_DESC_TXT
C
      parameter (FILE_NAME      = 'General_HDFobjects.hdf',
     +           VG_NAME        = 'AN Vgroup',
     +           FILE_LABEL_TXT = 'General HDF objects',
     +           DATA_LABEL_TXT = 'Common AN Vgroup',
     +           FILE_DESC_TXT  = 
     + 'This is an HDF file that contains general HDF objects',
     +           DATA_DESC_TXT  = 
     + 'This is a vgroup that is used to test data annotations')
      integer DFACC_CREATE
      parameter (DFACC_CREATE = 4)
      integer AN_FILE_LABEL, AN_FILE_DESC, AN_DATA_LABEL, AN_DATA_DESC
      parameter (AN_FILE_LABEL = 2,
     +           AN_FILE_DESC  = 3,
     +           AN_DATA_LABEL = 0,
     +           AN_DATA_DESC  = 1)
C
C     Function declaration
C
      integer hopen, hclose
      integer afstart, affcreate, afwriteann, afcreate,
     +        afendaccess, afend
      integer vfstart, vfatch, vfsnam, vqref, vqtag, vfdtch, vfend

C
C**** Variable declaration ******************************************* 
C
      integer status
      integer file_id, an_id
      integer file_label_id, file_desc_id
      integer data_label_id, data_desc_id
      integer vgroup_id, vgroup_tag, vgroup_ref
C
C**** End of variable declaration ************************************
C
C
C     Create the HDF file.
C
      file_id = hopen(FILE_NAME, DFACC_CREATE, 0)
C
C     Initialize the AN interface.
C
      an_id = afstart(file_id)
C
C     Create the file label.
C
      file_label_id = affcreate(an_id, AN_FILE_LABEL)
C
C     Write the annotation to the file label.
C
      status = afwriteann(file_label_id, FILE_LABEL_TXT,
     +                    len(FILE_LABEL_TXT))       
C
C     Create file description.
C
      file_desc_id = affcreate(an_id, AN_FILE_DESC)
C
C     Write the annotation to the file description.
C
      status = afwriteann(file_desc_id, FILE_DESC_TXT,
     +                    len(FILE_DESC_TXT))
C
C     Create a vgroup in the file. Note that the vgroup's ref number is
C     set to -1 for creating and the access mode is 'w' for writing.
C
      status    = vfstart(file_id)
      vgroup_id = vfatch(file_id, -1, 'w')
      status    = vfsnam(vgroup_id, VG_NAME)      
C
C     Obtain the tag and reference number of the vgroup for subsequent
C     references.
C
      vgroup_ref = vqref(vgroup_id)
      vgroup_tag = vqtag(vgroup_id)
C
C     Create the data label for the vgroup identified by its tag and ref 
C     number.
C
      data_label_id = afcreate(an_id, vgroup_tag, vgroup_ref,
     +                          AN_DATA_LABEL)
C
C     Write the annotation text to the data label.
C
      status = afwriteann(data_label_id, DATA_LABEL_TXT, 
     +                    len(DATA_LABEL_TXT))
      
C
C     Create the data description for the vgroup identified by its tag and ref.
C
      data_desc_id = afcreate(an_id, vgroup_tag, vgroup_ref, 
     +                        AN_DATA_DESC)
C
C     Write the annotation text to the data description.
C
      status = afwriteann(data_desc_id, DATA_DESC_TXT,
     +                    len(DATA_DESC_TXT))       
C      
C     Terminate access to the vgroup and to the V interface.
C
      status = vfdtch(vgroup_id)
      status = vfend(file_id)
C
C     Terminate access to each annotation explicitly.
C
      status = afendaccess(file_label_id)
      status = afendaccess(file_desc_id)
      status = afendaccess(data_label_id)
      status = afendaccess(data_desc_id)
C
C     Terminate access to the AN interface and close the HDF file.
C
      status = afend(an_id)
      status = hclose(file_id)
      end 

read_annotation.c

#include "hdf.h"

#define  FILE_NAME   "General_HDFobjects.hdf"

main( )
{
   /************************* Variable declaration **************************/

   intn  status_n;      /* returned status for functions returning an intn  */
   int32 status_32,     /* returned status for functions returning an int32 */
         file_id,       /* HDF file identifier */
         an_id,         /* AN interface identifier */
         ann_id,        /* an annotation identifier */
         index,         /* position of an annotation in all of the same type*/
         ann_length,    /* length of the text in an annotation */
         n_file_labels, n_file_descs, n_data_labels, n_data_descs;
   char *ann_buf;       /* buffer to hold the read annotation */

   /********************** End of variable declaration **********************/

   /*
   * Open the HDF file.
   */
   file_id = Hopen (FILE_NAME, DFACC_READ, 0);

   /*
   * Initialize the AN interface.
   */
   an_id = ANstart (file_id);

   /*
   * Get the annotation information, e.g., the numbers of file labels, file
   * descriptions, data labels, and data descriptions.
   */
   status_n = ANfileinfo (an_id, &n_file_labels, &n_file_descs,
                        &n_data_labels, &n_data_descs);

   /*
   * Get the data labels.  Note that this for loop can be used to
   * obtain the contents of each kind of annotation with the appropriate
   * number of annotations and the type of annotation, i.e., replace
   * n_data_labels with n_file_labels, n_file_descs, or n_data_descs, and
   * AN_DATA_LABEL with AN_FILE_LABEL, AN_FILE_DESC, or AN_DATA_DESC,
   * respectively.
   */
   for (index = 0; index < n_data_labels; index++)
   {
      /*
      * Get the identifier of the current data label.
      */
      ann_id = ANselect (an_id, index, AN_DATA_LABEL);

      /*
      * Get the length of the data label.
      */
      ann_length = ANannlen (ann_id);

      /*
      * Allocate space for the buffer to hold the data label text.
      */
      ann_buf = malloc ((ann_length+1) * sizeof (char));

      /*
      * Read and display the data label.  Note that the size of the buffer,
      * i.e., the third parameter, is 1 character more than the length of
      * the data label; that is for the null character.  It is not the case
      * when a description is retrieved because the description does not 
      * necessarily end with a null character.
      * 
      */
      status_32 = ANreadann (ann_id, ann_buf, ann_length+1);
      printf ("Data label index: %d\n", index);
      printf ("Data label contents: %s\n", ann_buf);

      /*
      * Terminate access to the current data label.
      */
C     references.
C
      vgroup_ref = vqref(vgroup_id)
      vgroup_tag = vqtag(vgroup_id)
C
C     Create the data label for the vgroup identified by its tag and ref 
C     number.
C
      data_label_id = afcreate(an_id, vgroup_tag, vgroup_ref,
     +                          AN_DATA_LABEL)
C
C     Write the annotation text to the data label.
C
      status = afwriteann(data_label_id, DATA_LABEL_TXT, 
     +                    len(DATA_LABEL_TXT))
      
C
C     Create the data description for the vgroup identified by its tag and ref.
C
      data_desc_id = afcreate(an_id, vgroup_tag, vgroup_ref, 
     +                        AN_DATA_DESC)
C
C     Write the annotation text to the data description.
C
      status = afwriteann(data_desc_id, DATA_DESC_TXT,
     +                    len(DATA_DESC_TXT))       
C      
C     Terminate access to the vgroup and to the V interface.
C
      status = vfdtch(vgroup_id)
      status = vfend(file_id)
C
C     Terminate access to each annotation explicitly.
C
      status = afendaccess(file_label_id)
      status = afendaccess(file_desc_id)
      status = afendaccess(data_label_id)
      status = afendaccess(data_desc_id)
C
C     Terminate access to the AN interface and close the HDF file.
C
      status = afend(an_id)
      status = hclose(file_id)
      end 

read_annotation.c

#include "hdf.h"

#define  FILE_NAME   "General_HDFobjects.hdf"

main( )
{
   /************************* Variable declaration **************************/

   intn  status_n;      /* returned status for functions returning an intn  */
   int32 status_32,     /* returned status for functions returning an int32 */
         file_id,       /* HDF file identifier */
         an_id,         /* AN interface identifier */
         ann_id,        /* an annotation identifier */
         index,         /* position of an annotation in all of the same type*/
         ann_length,    /* length of the text in an annotation */
         n_file_labels, n_file_descs, n_data_labels, n_data_descs;
   char *ann_buf;       /* buffer to hold the read annotation */

   /********************** End of variable declaration **********************/

   /*
   * Open the HDF file.
   */
   file_id = Hopen (FILE_NAME, DFACC_READ, 0);

   /*
   * Initialize the AN interface.
   */
   an_id = ANstart (file_id);

   /*
   * Get the annotation information, e.g., the numbers of file labels, file
   * descriptions, data labels, and data descriptions.
   */
   status_n = ANfileinfo (an_id, &n_file_labels, &n_file_descs,
                        &n_data_labels, &n_data_descs);

   /*
   * Get the data labels.  Note that this for loop can be used to
   * obtain the contents of each kind of annotation with the appropriate
   * number of annotations and the type of annotation, i.e., replace
   * n_data_labels with n_file_labels, n_file_descs, or n_data_descs, and
   * AN_DATA_LABEL with AN_FILE_LABEL, AN_FILE_DESC, or AN_DATA_DESC,
   * respectively.
   */
   for (index = 0; index < n_data_labels; index++)
   {
      /*
      * Get the identifier of the current data label.
      */
      ann_id = ANselect (an_id, index, AN_DATA_LABEL);

      /*
      * Get the length of the data label.
      */
      ann_length = ANannlen (ann_id);

      /*
      * Allocate space for the buffer to hold the data label text.
      */
      ann_buf = malloc ((ann_length+1) * sizeof (char));

      /*
      * Read and display the data label.  Note that the size of the buffer,
      * i.e., the third parameter, is 1 character more than the length of
      * the data label; that is for the null character.  It is not the case
      * when a description is retrieved because the description does not 
      * necessarily end with a null character.
      * 
      */
      status_32 = ANreadann (ann_id, ann_buf, ann_length+1);
      printf ("Data label index: %d\n", index);
      printf ("Data label contents: %s\n", ann_buf);

      /*
      * Terminate access to the current data label.
      */
C     references.
C
      vgroup_ref = vqref(vgroup_id)
      vgroup_tag = vqtag(vgroup_id)
C
C     Create the data label for the vgroup identified by its tag and ref 
C     number.
C
      data_label_id = afcreate(an_id, vgroup_tag, vgroup_ref,
     +                          AN_DATA_LABEL)
C
C     Write the annotation text to the data label.
C
      status = afwriteann(data_label_id, DATA_LABEL_TXT, 
     +                    len(DATA_LABEL_TXT))
      
C
C     Create the data description for the vgroup identified by its tag and ref.
C
      data_desc_id = afcreate(an_id, vgroup_tag, vgroup_ref, 
     +                        AN_DATA_DESC)
C
C     Write the annotation text to the data description.
C
      status = afwriteann(data_desc_id, DATA_DESC_TXT,
     +                    len(DATA_DESC_TXT))       
C      
C     Terminate access to the vgroup and to the V interface.
C
      status = vfdtch(vgroup_id)
      status = vfend(file_id)
C
C     Terminate access to each annotation explicitly.
C
      status = afendaccess(file_label_id)
      status = afendaccess(file_desc_id)
      status = afendaccess(data_label_id)
      status = afendaccess(data_desc_id)
C
C     Terminate access to the AN interface and close the HDF file.
C
      status = afend(an_id)
      status = hclose(file_id)
      end 

read_annotation.c

#include "hdf.h"

#define  FILE_NAME   "General_HDFobjects.hdf"

main( )
{
   /************************* Variable declaration **************************/

   intn  status_n;      /* returned status for functions returning an intn  */
   int32 status_32,     /* returned status for functions returning an int32 */
         file_id,       /* HDF file identifier */
         an_id,         /* AN interface identifier */
         ann_id,        /* an annotation identifier */
         index,         /* position of an annotation in all of the same type*/
         ann_length,    /* length of the text in an annotation */
         n_file_labels, n_file_descs, n_data_labels, n_data_descs;
   char *ann_buf;       /* buffer to hold the read annotation */

   /********************** End of variable declaration **********************/

   /*
   * Open the HDF file.
   */
   file_id = Hopen (FILE_NAME, DFACC_READ, 0);

   /*
   * Initialize the AN interface.
   */
   an_id = ANstart (file_id);

   /*
   * Get the annotation information, e.g., the numbers of file labels, file
   * descriptions, data labels, and data descriptions.
   */
   status_n = ANfileinfo (an_id, &n_file_labels, &n_file_descs,
                        &n_data_labels, &n_data_descs);

   /*
   * Get the data labels.  Note that this for loop can be used to
   * obtain the contents of each kind of annotation with the appropriate
   * number of annotations and the type of annotation, i.e., replace
   * n_data_labels with n_file_labels, n_file_descs, or n_data_descs, and
   * AN_DATA_LABEL with AN_FILE_LABEL, AN_FILE_DESC, or AN_DATA_DESC,
   * respectively.
   */
   for (index = 0; index < n_data_labels; index++)
   {
      /*
      * Get the identifier of the current data label.
      */
      ann_id = ANselect (an_id, index, AN_DATA_LABEL);

      /*
      * Get the length of the data label.
      */
      ann_length = ANannlen (ann_id);

      /*
      * Allocate space for the buffer to hold the data label text.
      */
      ann_buf = malloc ((ann_length+1) * sizeof (char));

      /*
      * Read and display the data label.  Note that the size of the buffer,
      * i.e., the third parameter, is 1 character more than the length of
      * the data label; that is for the null character.  It is not the case
      * when a description is retrieved because the description does not 
      * necessarily end with a null character.
      * 
      */
      status_32 = ANreadann (ann_id, ann_buf, ann_length+1);
      printf ("Data label index: %d\n", index);
      printf ("Data label contents: %s\n", ann_buf);

      /*
      * Terminate access to the current data label.
      */
C     references.
C
      vgroup_ref = vqref(vgroup_id)
      vgroup_tag = vqtag(vgroup_id)
C
C     Create the data label for the vgroup identified by its tag and ref 
C     number.
C
      data_label_id = afcreate(an_id, vgroup_tag, vgroup_ref,
     +                          AN_DATA_LABEL)
C
C     Write the annotation text to the data label.
C
      status = afwriteann(data_label_id, DATA_LABEL_TXT, 
     +                    len(DATA_LABEL_TXT))
      
C
C     Create the data description for the vgroup identified by its tag and ref.
C
      data_desc_id = afcreate(an_id, vgroup_tag, vgroup_ref, 
     +                        AN_DATA_DESC)
C
C     Write the annotation text to the data description.
C
      status = afwriteann(data_desc_id, DATA_DESC_TXT,
     +                    len(DATA_DESC_TXT))       
C      
C     Terminate access to the vgroup and to the V interface.
C
      status = vfdtch(vgroup_id)
      status = vfend(file_id)
C
C     Terminate access to each annotation explicitly.
C
      status = afendaccess(file_label_id)
      status = afendaccess(file_desc_id)
      status = afendaccess(data_label_id)
      status = afendaccess(data_desc_id)
C
C     Terminate access to the AN interface and close the HDF file.
C
      status = afend(an_id)
      status = hclose(file_id)
      end 

read_annotation.c

#include "hdf.h"

#define  FILE_NAME   "General_HDFobjects.hdf"

main( )
{
   /************************* Variable declaration **************************/

   intn  status_n;      /* returned status for functions returning an intn  */
   int32 status_32,     /* returned status for functions returning an int32 */
         file_id,       /* HDF file identifier */
         an_id,         /* AN interface identifier */
         ann_id,        /* an annotation identifier */
         index,         /* position of an annotation in all of the same type*/
         ann_length,    /* length of the text in an annotation */
         n_file_labels, n_file_descs, n_data_labels, n_data_descs;
   char *ann_buf;       /* buffer to hold the read annotation */

   /********************** End of variable declaration **********************/

   /*
   * Open the HDF file.
   */
   file_id = Hopen (FILE_NAME, DFACC_READ, 0);

   /*
   * Initialize the AN interface.
   */
   an_id = ANstart (file_id);

   /*
   * Get the annotation information, e.g., the numbers of file labels, file
   * descriptions, data labels, and data descriptions.