C Example - an_read.c




#include "hdf.h"

main( )
{

   int32 file_id, an_id, ann_id, ann_idx, i, ann_length;
   int32 n_file_label, n_file_desc, n_data_label, n_data_desc;
   int32 status, j;
   char ann_buf[28], ann_bufl[22];

   /* Open the HDF file for reading. */
   file_id = Hopen("an.hdf", DFACC_WRITE, 0);

   /* Initialize the AN interface and obtain an interface id. */
   an_id = ANstart(file_id);

   /* Get the annotation information. */
   status = ANfileinfo(an_id, &n_file_label, &n_file_desc, \
                        &n_data_label, &n_data_desc);

   /* Print out the number of file and data labels and descs. */
   printf ("\nNumber of file labels:       %i\n",n_file_label);
   printf ("Number of file descriptions: %i\n",n_file_desc);
   printf ("Number of data labels:       %i\n",n_data_label);
   printf ("Number of data descriptions: %i\n\n",n_data_desc);

   /* Get the file labels. */
   for (i = 0; i < n_file_label; i++) 
   { 
      /* Get the identifier for the current file label. */
      ann_id = ANselect(an_id, i, AN_FILE_LABEL);

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

      /* Read the file label. */
      status = ANreadann(ann_id, ann_bufl, ann_length+1);

      printf ("File Label:       ");
      for (j= 0; j < ann_length; j++)
          printf ("%c",ann_bufl[j]);
      printf ("\n");

      /* Terminate access to the annotation. */
      status = ANendaccess(ann_id);
   }

   /* Get the file description. */
   for (i = 0; i < n_file_desc; i++) 
   { 
      /* Get the identifier for the current file description. */
      ann_id = ANselect(an_id, i, AN_FILE_DESC);

      /* Get the length of the file description. */
      ann_length = ANannlen(ann_id);

      /* Read the file description. */
      status = ANreadann(ann_id, ann_buf, ann_length);

      printf ("File Description: ");
      for (j= 0; j < ann_length; j++)
          printf ("%c",ann_buf[j]);
      printf ("\n");

      /* Terminate access to the annotation. */
      status = ANendaccess(ann_id);

   }

   /* Get the data label. */
   for (i = 0; i < n_data_label; i++) 
   { 
      /* Get the identifier for the current data label */ 
      ann_id = ANselect(an_id, i, AN_DATA_LABEL);

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

      /* Read the data label */
      status = ANreadann(ann_id, ann_bufl, ann_length+1);

      printf ("Data Label:       ");
      for (j= 0; j < ann_length; j++)
          printf ("%c",ann_bufl[j]);
      printf ("\n");

      /* Terminate access to the annotation. */
      status = ANendaccess(ann_id);
   }

   /* Get the data description. */
   for (i = 0; i < n_data_desc; i++) 
   { 
      /* Get the identifier for the current data description. */
      ann_id = ANselect(an_id, i, AN_DATA_DESC);

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

      /* Read the data description. */
      status = ANreadann(ann_id, ann_buf, ann_length);

      printf ("Data Description: ");
      for (j= 0; j < ann_length; j++)
          printf ("%c",ann_buf[j]);
      printf ("\n");

      /* Terminate access to the annotation. */
      status = ANendaccess(ann_id);
   }

   printf ("\n");

   /* Terminate access to the AN interface. */
   status = ANend(an_id);

   /* Close the file. */
   status = Hclose(file_id);

}