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; }
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 coda_hdf4_reopen(coda_product **product) { coda_hdf4_product *product_file; product_file = (coda_hdf4_product *)malloc(sizeof(coda_hdf4_product)); if (product_file == NULL) { coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)", sizeof(coda_hdf4_product), __FILE__, __LINE__); coda_close(*product); return -1; } product_file->filename = NULL; product_file->file_size = (*product)->file_size; product_file->format = coda_format_hdf4; product_file->root_type = NULL; product_file->product_definition = NULL; product_file->product_variable_size = NULL; product_file->product_variable = NULL; product_file->mem_size = 0; product_file->mem_ptr = NULL; product_file->is_hdf = 0; product_file->file_id = -1; product_file->gr_id = -1; product_file->sd_id = -1; product_file->an_id = -1; product_file->num_gr_file_attributes = 0; product_file->num_sd_file_attributes = 0; product_file->num_sds = 0; product_file->sds = NULL; product_file->num_images = 0; product_file->gri = NULL; product_file->num_vgroup = 0; product_file->vgroup = NULL; product_file->num_vdata = 0; product_file->vdata = NULL; product_file->filename = strdup((*product)->filename); if (product_file->filename == NULL) { coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not duplicate filename string) (%s:%u)", __FILE__, __LINE__); coda_hdf4_close((coda_product *)product_file); coda_close(*product); return -1; } coda_close(*product); product_file->is_hdf = Hishdf(product_file->filename); /* is this a real HDF4 file or a (net)CDF file */ if (product_file->is_hdf) { product_file->file_id = Hopen(product_file->filename, DFACC_READ, 0); if (product_file->file_id == -1) { coda_set_error(CODA_ERROR_HDF4, NULL); coda_hdf4_close((coda_product *)product_file); return -1; } if (Vstart(product_file->file_id) != 0) { coda_set_error(CODA_ERROR_HDF4, NULL); coda_hdf4_close((coda_product *)product_file); return -1; } product_file->gr_id = GRstart(product_file->file_id); if (product_file->gr_id == -1) { coda_set_error(CODA_ERROR_HDF4, NULL); coda_hdf4_close((coda_product *)product_file); return -1; } product_file->an_id = ANstart(product_file->file_id); if (product_file->an_id == -1) { coda_set_error(CODA_ERROR_HDF4, NULL); coda_hdf4_close((coda_product *)product_file); return -1; } } product_file->sd_id = SDstart(product_file->filename, DFACC_READ); if (product_file->sd_id == -1) { coda_set_error(CODA_ERROR_HDF4, NULL); coda_hdf4_close((coda_product *)product_file); return -1; } product_file->root_type = NULL; if (init_SDSs(product_file) != 0) { coda_hdf4_close((coda_product *)product_file); return -1; } if (product_file->is_hdf) { if (init_GRImages(product_file) != 0) { coda_hdf4_close((coda_product *)product_file); return -1; } if (init_Vdatas(product_file) != 0) { coda_hdf4_close((coda_product *)product_file); return -1; } /* initialization of Vgroup entries should happen last, so we can build the structural tree */ if (init_Vgroups(product_file) != 0) { coda_hdf4_close((coda_product *)product_file); return -1; } } if (coda_hdf4_create_root(product_file) != 0) { coda_hdf4_close((coda_product *)product_file); return -1; } *product = (coda_product *)product_file; return 0; }