C Example - an_write.c
#include "hdf.h"
main( )
{
int32 file_id, an_id, ann_id, vgroup_id;
uint16 obj_tag, obj_ref;
intn status;
static char file_label[] = "This is a file label.";
static char file_desc[] = "This is a file description.";
static char data_label[] = "This is a data label.";
static char data_desc[] = "This is a data description.";
/* Create the HDF file. */
file_id = Hopen("an.hdf", DFACC_CREATE, 0);
/* Initialize the AN interface and obtain an interface id. */
an_id = ANstart(file_id);
/* Create a file label and obtain an annotation id. */
ann_id = ANcreatef(an_id, AN_FILE_LABEL);
/* Write the file label to the file. */
status = ANwriteann(ann_id, file_label, strlen(file_label));
/* Terminate access to the annotation. */
status = ANendaccess(ann_id);
/* Create a file description. */
ann_id = ANcreatef(an_id, AN_FILE_DESC);
/* Write the file description to the file. */
status = ANwriteann(ann_id, file_desc, strlen(file_desc));
/* Terminate access to the annotation. */
status = ANendaccess(ann_id);
/* Create a vgroup. */
status = Vstart(file_id);
vgroup_id = Vattach(file_id, -1, "w");
status = Vsetname (vgroup_id, "Vgroup w/Annotations");
status = Vdetach(vgroup_id);
status = Vend(file_id);
/* Get reference number of vgroup just created. */
status = Vstart(file_id);
obj_ref = Vfind (file_id, "Vgroup w/Annotations");
status = Vend(file_id);
obj_tag = DFTAG_VG;
/* Create a data label for the Vgroup just created. */
ann_id = ANcreate(an_id, obj_tag, obj_ref, AN_DATA_LABEL);
/* Write the data label to the file. */
status = ANwriteann(ann_id, data_label, strlen(data_label));
/* Terminate access to the annotation. */
status = ANendaccess(ann_id);
/* Create a data description for the Vgroup just created.*/
ann_id = ANcreate(an_id, obj_tag, obj_ref, AN_DATA_DESC);
/* Write the data description to the file. */
status = ANwriteann(ann_id, data_desc, strlen(data_desc));
/* Terminate access to the annotation. */
status = ANendaccess(ann_id);
/* Terminate access to the AN interface. */
status = ANend(an_id);
/* Close the file. */
status = Hclose(file_id);
}