int do_lone(char* file_name, int do_diffs) { char sds_name[] = "lone"; int32 rank = 1; int32 dim_sds[1] = {5}; /* dimension of the data set */ int32 data[5] = {1, 2, 3, 4, 5}; int32 start[1]; /* start position to write for each dimension */ int32 edges[1]; /* number of elements to be written along each dimension */ int32 sds_id; int32 dim_id; int32 sd_id; if ( do_diffs ) { data[1] = data[2] = 0; } sd_id = SDstart(file_name, DFACC_CREATE); /* create the SDS */ if ((sds_id = SDcreate (sd_id, sds_name, DFNT_INT32, rank, dim_sds))<0) { printf( "Could not create SDS <%s>\n",sds_name); goto fail; } dim_id = SDgetdimid(sds_id, 0); SDsetdimname(dim_id, sds_name); /* define the location and size of the data to be written to the data set */ start[0] = 0; edges[0] = 5; /* write the stored data to the data set */ if (SDwritedata (sds_id, start, NULL, edges, (VOIDP)data)==FAIL) { printf( "Failed to set write for SDS <%s>\n", sds_name); goto fail; } SDendaccess(sds_id); /* create the SDS */ if ((sds_id = SDcreate (sd_id, "sds", DFNT_INT32, rank, dim_sds))<0) { printf( "Could not create SDS <%s>\n"); goto fail; } if (SDwritedata (sds_id, start, NULL, edges, (VOIDP)data)==FAIL) { printf( "Failed to set write for SDS <%s>\n"); goto fail; } SDendaccess(sds_id); SDend(sd_id); { int32 file1_id; /* HDF file identifier */ int32 an_id; /* AN interface identifier */ int32 file_label_id; /* file label identifier */ /* open file */ if ((file1_id = Hopen (file_name, DFACC_WRITE, (int16)0))<0) { printf("Error: Could not open file <%s>\n",file_name); return FAIL; } /* Initialize the AN interface */ an_id = ANstart (file1_id); /* Create the file label */ file_label_id = ANcreatef (an_id, AN_FILE_LABEL); /* Write the annotations to the file label */ if (ANwriteann (file_label_id,FILE_LABEL_TXT,strlen (FILE_LABEL_TXT))==FAIL) { printf( "Could not write AN\n"); return FAIL; } /* Terminate access to annotation */ if (ANendaccess (file_label_id)==FAIL) { printf( "Could not end AN\n"); return FAIL; } /* Terminate access to the AN interface */ if (ANend (an_id)==FAIL) { printf( "Could not end AN\n"); return FAIL; } /* close the HDF file */ if (Hclose (file1_id)==FAIL) { printf( "Could not close file\n"); return FAIL; } } return SUCCEED; fail: SDend(sd_id); return FAIL; }
int list_an(int32 infile_id, int32 outfile_id, options_t *options) { int32 an_id, /* AN interface identifier */ ann_id, /* an annotation identifier */ ann_length, /* length of the text in an annotation */ an_out, /* AN interface identifier */ file_label_id, /* file label identifier */ file_desc_id, /* file description identifier */ n_file_labels, n_file_descs, n_data_labels, n_data_descs; char *ann_buf=NULL; /* buffer to hold the read annotation */ int i; /* position of an annotation in all of the same type*/ if ( options->trip==0 ) { return SUCCEED; } /* Initialize the AN interface */ an_id = ANstart (infile_id); an_out = ANstart (outfile_id); /* * Get the annotation information, e.g., the numbers of file labels, file * descriptions, data labels, and data descriptions. */ if (ANfileinfo (an_id,&n_file_labels,&n_file_descs,&n_data_labels,&n_data_descs)==FAIL) { printf( "Could not get AN info\n"); goto out; } /*------------------------------------------------------------------------- * AN_FILE_LABEL *------------------------------------------------------------------------- */ for (i = 0; i < n_file_labels; i++) { /* Get the identifier of the current data label */ ann_id = ANselect (an_id, i, AN_FILE_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 file 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. * */ if (ANreadann (ann_id, ann_buf, ann_length+1)==FAIL) { printf( "Could not read AN\n"); goto out; } /* Create the file label */ file_label_id = ANcreatef (an_out, AN_FILE_LABEL); /* Write the annotations */ if (ANwriteann (file_label_id, ann_buf, ann_length)==FAIL) { printf("Failed to write file label %d\n", i); goto out; } /* Terminate access to the current data label */ if (ANendaccess (ann_id)==FAIL || ANendaccess (file_label_id)==FAIL) { printf( "Could not end AN\n"); goto out; } /* Free the space allocated for the annotation buffer */ if (ann_buf) free (ann_buf); } /*------------------------------------------------------------------------- * AN_FILE_DESC *------------------------------------------------------------------------- */ for (i = 0; i < n_file_descs; i++) { /* Get the identifier of the current data label */ ann_id = ANselect (an_id, i, AN_FILE_DESC); /* 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)); if (ANreadann (ann_id, ann_buf, ann_length+1)==FAIL) { printf( "Could not read AN\n"); goto out; } /* Create the label */ file_desc_id = ANcreatef (an_out, AN_FILE_DESC); /* Write the annotations */ if (ANwriteann (file_desc_id, ann_buf, ann_length)==FAIL) { printf("Failed to write file description %d\n", i); goto out; } /* Terminate access to the current data label */ if (ANendaccess (ann_id)==FAIL || ANendaccess (file_desc_id)==FAIL) { printf( "Could not read AN\n"); goto out; } /* Free the space allocated for the annotation buffer */ if (ann_buf) { free (ann_buf); ann_buf = NULL; } } /* Terminate access to the AN interface */ if (ANend (an_id)==FAIL || ANend (an_out)==FAIL) { printf( "Could not end AN\n"); goto out; } return SUCCEED; out: if (ANend (an_id)==FAIL || ANend (an_out)==FAIL) { printf( "Could not end AN\n"); } if (ann_buf!=NULL) free (ann_buf); return FAIL; }