JNIEXPORT jint JNICALL Java_hdf_hdflib_HDFLibrary_Vgettagrefs (JNIEnv *env, jclass clss, jlong vgroup_id, jintArray tags, jintArray refs, jint size) { jint *tagVal; jint *refVal; int32 retVal = -1; int copyMode = JNI_ABORT; jboolean iscopy; if (tags == NULL) { h4nullArgument(env, "Vgettagrefs: tags is NULL"); } /* end if */ else if (refs == NULL) { h4nullArgument(env, "Vgettagrefs: refs is NULL"); } /* end else if */ else if (ENVPTR->GetArrayLength(ENVPAR tags) < size) { h4badArgument(env, "Vgettagrefs: output array tags < order 'size'"); } /* end else if */ else if (ENVPTR->GetArrayLength(ENVPAR refs) < size) { h4badArgument(env, "Vgettagrefs: output array refs < order 'size'"); } /* end else if */ else { tagVal = ENVPTR->GetIntArrayElements(ENVPAR tags,&iscopy); if (tagVal == NULL) { h4JNIFatalError(env, "Vgettagrefs: tags not pinned"); } /* end if */ else { refVal = ENVPTR->GetIntArrayElements(ENVPAR refs,&iscopy); if (refVal == NULL) { h4JNIFatalError(env, "Vgettagrefs: refs not pinned"); } /* end if */ else { /* get the tag/ref pairs number in the vgroup */ retVal = Vgettagrefs((int32)vgroup_id, (int32 *)tagVal, (int32 *)refVal, size); if (retVal == FAIL) { CALL_ERROR_CHECK(); } else { copyMode = 0; } ENVPTR->ReleaseIntArrayElements(ENVPAR refs,refVal,copyMode); } /* end else */ ENVPTR->ReleaseIntArrayElements(ENVPAR tags,tagVal,copyMode); } /* end else */ } /* end else */ return (jint)retVal; }
int vgroup_insert(int32 infile_id, int32 outfile_id, int32 sd_id, /* SD interface identifier */ int32 sd_out, /* SD interface identifier */ int32 gr_id, /* GR interface identifier */ int32 gr_out, /* GR interface identifier */ int32 vgroup_id_out_par, /* output parent group ID */ char*path_name, /* absolute path for input group name */ int32* in_tags, /* tag list for parent group */ int32* in_refs, /* ref list for parent group */ int npairs, /* number tag/ref pairs for parent group */ list_table_t *list_tbl, dim_table_t *td1, dim_table_t *td2, options_t *options) { int32 vg_id; /* vgroup identifier for opened group in input */ int32 ntagrefs; /* number of tag/ref pairs in a vgroup */ int32 *tags=NULL; /* buffer to hold the tag numbers of vgroups */ int32 *refs=NULL; /* buffer to hold the ref numbers of vgroups */ int32 vgroup_id_out =-1; /* vgroup identifier for the created group in output */ char *vg_name; char *vg_class; char *path=NULL; uint16 name_len; int visited; int32 tag; int32 ref; int i; for ( i = 0; i < npairs; i++ ) { tag = in_tags[i]; ref = in_refs[i]; switch(tag) { /*------------------------------------------------------------------------- * DFTAG_VG *------------------------------------------------------------------------- */ case DFTAG_VG: visited = list_table_search(list_tbl,DFTAG_VG,ref); /*------------------------------------------------------------------------- * open input *------------------------------------------------------------------------- */ vg_id = Vattach (infile_id, ref, "r"); /* Get vgroup's name */ if (Vgetnamelen(vg_id, &name_len)==FAIL) { printf("Error: Could not get name length for group with ref <%d>\n", ref); goto out; } vg_name = (char *) HDmalloc(sizeof(char) * (name_len+1)); if (Vgetname (vg_id, vg_name)==FAIL) { printf( "Could not get name for group\n"); goto out; } /* Get vgroup's class name */ if (Vgetclassnamelen(vg_id, &name_len)==FAIL) { printf("Error: Could not get name length for group with ref <%d>\n", ref); goto out; } vg_class = (char *) HDmalloc(sizeof(char) * (name_len+1)); if (Vgetclass (vg_id, vg_class)==FAIL) { printf( "Could not get class for group\n"); goto out; } /* ignore reserved HDF groups/vdatas */ if( is_reserved(vg_class)) { if (Vdetach (vg_id)==FAIL) { printf( "Could not detach group\n"); goto out; } continue; } if(strcmp(vg_name,GR_NAME)==0) { if (Vdetach (vg_id)==FAIL) { printf( "Could not detach group\n"); goto out; } continue; } /*------------------------------------------------------------------------- * create the group in output or create the link *------------------------------------------------------------------------- */ if (options->trip==1) { if ( visited < 0 ) { /* * create the group in the output file. the vgroup reference number * is set to -1 for creating and the access mode is "w" for writing */ vgroup_id_out = Vattach (outfile_id, -1, "w"); if (Vsetname (vgroup_id_out, vg_name)==FAIL) { printf("Error: Could not create group <%s>\n", vg_name); goto out; } if (Vsetclass (vgroup_id_out, vg_class)==FAIL) { printf("Error: Could not create group <%s>\n", vg_name); goto out; } if (copy_vgroup_attrs(vg_id,vgroup_id_out,path,options)<0) goto out; if (copy_vg_an(infile_id,outfile_id,vg_id,vgroup_id_out,path,options)<0) goto out; } else { /* open previously visited group */ vgroup_id_out = Vattach (outfile_id, ref, "r"); } /* insert the created (or opened) vgroup into its parent */ if (Vinsert (vgroup_id_out_par, vgroup_id_out)==FAIL) { printf("Could not insert group <%s>\n", vg_name); goto out; } } /* create the group in output or create the link */ /*------------------------------------------------------------------------- * if group not visited, add to table and check for more tag/ref pairs *------------------------------------------------------------------------- */ /* check if already visited */ if ( visited < 0 ) { /* initialize path */ path=get_path(path_name,vg_name); /* add object to table */ list_table_add(list_tbl,tag,ref,path); if (options->verbose) printf(PFORMAT,"","","",path); if ( options->trip==0 ) { /*we must go to other groups always */ } /* insert objects for this group */ ntagrefs = Vntagrefs(vg_id); if ( ntagrefs > 0 ) { tags = (int32 *) malloc(sizeof(int32) * ntagrefs); refs = (int32 *) malloc(sizeof(int32) * ntagrefs); if (Vgettagrefs(vg_id, tags, refs, ntagrefs)<0) goto out; /* recurse */ if (vgroup_insert( infile_id, outfile_id, sd_id, sd_out, gr_id, gr_out, vgroup_id_out, path, tags, refs, ntagrefs, list_tbl, td1, td2, options)<0) { goto out; } free (tags); tags=NULL; free (refs); refs=NULL; } /* ntagrefs > 0 */ if (path) free(path); } /* check if already visited */ if(Vdetach (vg_id)==FAIL) { printf("Error: Could not detach group <%s>\n", vg_name); goto out; } if (options->trip==1) { if (Vdetach (vgroup_id_out)==FAIL) { printf("Error: Could not detach group <%s>\n", vg_name); goto out; } } break; /*------------------------------------------------------------------------- * SDS *------------------------------------------------------------------------- */ case DFTAG_SD: /* Scientific Data */ case DFTAG_SDG: /* Scientific Data Group */ case DFTAG_NDG: /* Numeric Data Group */ /* copy dataset */ if (copy_sds(sd_id, sd_out, tag,ref, vgroup_id_out_par, path_name, options, list_tbl, td1, td2, infile_id, outfile_id)<0) return FAIL; break; /*------------------------------------------------------------------------- * Image *------------------------------------------------------------------------- */ case DFTAG_RI: /* Raster Image */ case DFTAG_CI: /* Compressed Image */ case DFTAG_RIG: /* Raster Image Group */ case DFTAG_RI8: /* Raster-8 image */ case DFTAG_CI8: /* RLE compressed 8-bit image */ case DFTAG_II8: /* IMCOMP compressed 8-bit image */ /* copy GR */ if (copy_gr(infile_id, outfile_id, gr_id, gr_out, tag, ref, vgroup_id_out_par, path_name, options, list_tbl)<0) return FAIL; break; /*------------------------------------------------------------------------- * Vdata *------------------------------------------------------------------------- */ case DFTAG_VH: /* Vdata Header */ if (copy_vs(infile_id, outfile_id, tag, ref, vgroup_id_out_par, path_name, options, list_tbl, 0)<0) return FAIL; break; } /* switch */ } /* i */ return SUCCEED; out: if (tags!=NULL) free (tags); if (refs!=NULL) free (refs); return FAIL; }
int list_vg(int32 infile_id, int32 outfile_id, int32 sd_id, int32 sd_out, int32 gr_id, int32 gr_out, list_table_t *list_tbl, dim_table_t *td1, dim_table_t *td2, options_t *options) { int32 vg_id; /* vgroup identifier */ int32 nlones = 0; /* number of lone vgroups */ int32 ntagrefs; /* number of tag/ref pairs in a vgroup */ int32 *ref_array=NULL;/* buffer to hold the ref numbers of lone vgroups */ int32 *tags=NULL; /* buffer to hold the tag numbers of vgroups */ int32 *refs=NULL; /* buffer to hold the ref numbers of vgroups */ int32 vgroup_id_out=0;/* vgroup identifier */ int32 tag_vg; int32 ref_vg; char *vg_name; char *vg_class; uint16 name_len; int32 i; /*------------------------------------------------------------------------- * initialize the V interface *------------------------------------------------------------------------- */ if (Vstart(infile_id) == FAIL) { return FAIL; } if (options->trip==1) { if (Vstart(outfile_id) == FAIL) { return FAIL; } } /*------------------------------------------------------------------------- * get and print the names and class names of all the lone vgroups. * first, call Vlone with nlones set to 0 to get the number of * lone vgroups in the file, but not to get their reference numbers. *------------------------------------------------------------------------- */ nlones = Vlone (infile_id, NULL, nlones ); if (nlones > 0) { /* * use the nlones returned to allocate sufficient space for the * buffer ref_array to hold the reference numbers of all lone vgroups, */ ref_array = (int32 *) malloc(sizeof(int32) * nlones); /* * and call Vlone again to retrieve the reference numbers into * the buffer ref_array. */ nlones = Vlone (infile_id, ref_array, nlones); /* * iterate tru each lone vgroup. */ for (i = 0; i < nlones; i++) { int32 ref = ref_array[i]; uint16 name_len; /* * attach to the current vgroup then get its * name and class. note: the current vgroup must be detached before * moving to the next. */ if ((vg_id = Vattach (infile_id, ref, "r"))==FAIL) { printf("Error: Could not attach group with ref <%d>\n", ref); goto out; } /* Get vgroup's name */ if (Vgetnamelen(vg_id, &name_len)==FAIL) { printf("Error: Could not get name length for group with ref <%d>\n", ref); goto out; } vg_name = (char *) HDmalloc(sizeof(char) * (name_len+1)); if (Vgetname (vg_id, vg_name)==FAIL) { printf( "Could not get name for group\n"); goto out; } /* Get vgroup's class name */ if (Vgetclassnamelen(vg_id, &name_len)==FAIL) { printf("Error: Could not get name length for group with ref <%d>\n", ref); goto out; } vg_class = (char *) HDmalloc(sizeof(char) * (name_len+1)); if (Vgetclass (vg_id, vg_class)==FAIL) { printf( "Could not get class for group\n"); goto out; } /* ignore reserved HDF groups/vdatas */ if( is_reserved(vg_class)) { if (Vdetach (vg_id)==FAIL) { printf( "Could not detach group\n"); goto out; } continue; } if(strcmp(vg_name,GR_NAME)==0) { if (Vdetach (vg_id)==FAIL) { printf( "Could not detach group\n"); goto out; } continue; } /* get ref, tag */ if ((ref_vg = VQueryref(vg_id))==FAIL) { printf( "Failed to get ref for <%s>\n", vg_name); goto out; } if ((tag_vg = VQuerytag(vg_id))==FAIL) { printf( "Failed to get tag for <%s>\n", vg_name); goto out; } /*------------------------------------------------------------------------- * add object to table *------------------------------------------------------------------------- */ list_table_add(list_tbl,tag_vg,ref_vg,vg_name); if (options->verbose) printf(PFORMAT,"","","",vg_name); if (options->trip==1) { /* * create the group in the output file. the vgroup reference number is set * to -1 for creating and the access mode is "w" for writing */ vgroup_id_out = Vattach (outfile_id, -1, "w"); if (Vsetname (vgroup_id_out, vg_name)==FAIL) { printf("Error: Could not create group <%s>\n", vg_name); goto out; } if (Vsetclass (vgroup_id_out, vg_class)==FAIL) { printf("Error: Could not create group <%s>\n", vg_name); goto out; } if (copy_vgroup_attrs(vg_id,vgroup_id_out,vg_name,options)<0) goto out; if (copy_vg_an(infile_id,outfile_id,vg_id,vgroup_id_out,vg_name,options)<0) goto out; } /* insert objects for this group */ ntagrefs = Vntagrefs(vg_id); if ( ntagrefs > 0 ) { tags = (int32 *) malloc(sizeof(int32) * ntagrefs); refs = (int32 *) malloc(sizeof(int32) * ntagrefs); if (Vgettagrefs(vg_id, tags, refs, ntagrefs)<0) goto out; if (vgroup_insert(infile_id, outfile_id, sd_id, sd_out, gr_id, gr_out, vgroup_id_out, vg_name, tags, refs, ntagrefs, list_tbl, td1, td2, options)<0) { goto out; } free (tags); tags=NULL; free (refs); refs=NULL; } if(Vdetach (vg_id)==FAIL) { printf("Error: Could not detach group <%s>\n", vg_name); goto out; } if (options->trip==1) { if (Vdetach (vgroup_id_out)==FAIL) { printf("Error: Could not detach group <%s>\n", vg_name); goto out; } } free (vg_name); } /* for nlones */ /* free the space allocated */ if (ref_array!=NULL) free (ref_array); } /* if nlones */ /*------------------------------------------------------------------------- * terminate access to the V interface *------------------------------------------------------------------------- */ if (Vend (infile_id)==FAIL) { printf("Error: Could not end group interface in <%s>\n", vg_name); return FAIL; } if (options->trip==1) { if (Vend (outfile_id)==FAIL){ printf("Error: Could not end group interface in <%s>\n", vg_name); return FAIL; } } return SUCCEED; out: Vend (infile_id); if (options->trip==1) Vend (outfile_id); /* free the space allocated */ if (ref_array!=NULL) free (ref_array); if (tags!=NULL) free (tags); if (refs!=NULL) free (refs); return FAIL; }
static int init_Vgroups(coda_hdf4_product *product) { int32 vgroup_ref; int result; int i; vgroup_ref = Vgetid(product->file_id, -1); while (vgroup_ref != -1) { if (product->num_vgroup % BLOCK_SIZE == 0) { coda_hdf4_Vgroup **vgroup; int i; vgroup = realloc(product->vgroup, (product->num_vgroup + BLOCK_SIZE) * sizeof(coda_hdf4_Vgroup *)); if (vgroup == NULL) { coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)", (long)(product->num_vgroup + BLOCK_SIZE) * sizeof(coda_hdf4_Vgroup *), __FILE__, __LINE__); return -1; } product->vgroup = vgroup; for (i = product->num_vgroup; i < product->num_vgroup + BLOCK_SIZE; i++) { product->vgroup[i] = NULL; } } product->num_vgroup++; /* This will not yet create the links to the entries of the Vgroup */ product->vgroup[product->num_vgroup - 1] = coda_hdf4_Vgroup_new(product, vgroup_ref); if (product->vgroup[product->num_vgroup - 1] == NULL) { return -1; } vgroup_ref = Vgetid(product->file_id, vgroup_ref); } /* Now for each Vgroup create the links to its entries */ for (i = 0; i < product->num_vgroup; i++) { coda_hdf4_Vgroup *type; int32 num_entries; type = product->vgroup[i]; num_entries = Vntagrefs(type->vgroup_id); if (num_entries < 0) { coda_set_error(CODA_ERROR_HDF4, NULL); return -1; } if (num_entries > 0 && !type->hide) { int32 *tags; int32 *refs; int j; type->entry = malloc(num_entries * sizeof(coda_hdf4_type *)); if (type->entry == NULL) { coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)", (long)num_entries * sizeof(coda_hdf4_type *), __FILE__, __LINE__); return -1; } tags = malloc(num_entries * sizeof(int32)); if (tags == NULL) { coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)", (long)num_entries * sizeof(int32), __FILE__, __LINE__); return -1; } refs = malloc(num_entries * sizeof(int32)); if (refs == NULL) { coda_set_error(CODA_ERROR_OUT_OF_MEMORY, "out of memory (could not allocate %lu bytes) (%s:%u)", (long)num_entries * sizeof(int32), __FILE__, __LINE__); free(tags); return -1; } result = Vgettagrefs(type->vgroup_id, tags, refs, num_entries); if (result != num_entries) { coda_set_error(CODA_ERROR_HDF4, NULL); free(refs); free(tags); return -1; } for (j = 0; j < num_entries; j++) { int32 index; int k; switch (tags[j]) { case DFTAG_RIG: case DFTAG_RI: case DFTAG_RI8: index = GRreftoindex(product->gr_id, (uint16)refs[j]); if (index != -1) { for (k = 0; k < product->num_images; k++) { if (product->gri[k]->index == index) { product->gri[k]->group_count++; if (coda_type_record_create_field(type->definition, product->gri[k]->gri_name, (coda_type *)product->gri[k]->definition) != 0) { free(refs); free(tags); return -1; } type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->gri[k]; break; } } /* if k == product->num_images then the Vgroup links to a non-existent GRImage and * we ignore the entry */ } /* if index == -1 then the Vgroup links to a non-existent GRImage and we ignore the entry */ break; case DFTAG_SD: case DFTAG_SDG: case DFTAG_NDG: index = SDreftoindex(product->sd_id, refs[j]); if (index != -1) { for (k = 0; k < product->num_sds; k++) { if (product->sds[k]->index == index) { product->sds[k]->group_count++; if (coda_type_record_create_field(type->definition, product->sds[k]->sds_name, (coda_type *)product->sds[k]->definition) != 0) { free(refs); free(tags); return -1; } type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->sds[k]; break; } } /* if k == product->num_sds then the Vgroup links to a non-existent SDS and * we ignore the entry */ } /* if index == -1 then the Vgroup links to a non-existent SDS and we ignore the entry */ break; case DFTAG_VH: case DFTAG_VS: for (k = 0; k < product->num_vdata; k++) { if (product->vdata[k]->ref == refs[j]) { if (!product->vdata[k]->hide) { product->vdata[k]->group_count++; if (coda_type_record_create_field(type->definition, product->vdata[k]->vdata_name, (coda_type *)product->vdata[k]->definition) != 0) { free(refs); free(tags); return -1; } type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->vdata[k]; } break; } } /* if k == product->num_vdata then the Vgroup links to a non-existent Vdata and * we ignore the entry */ break; case DFTAG_VG: for (k = 0; k < product->num_vgroup; k++) { if (product->vgroup[k]->ref == refs[j]) { if (!product->vgroup[k]->hide) { product->vgroup[k]->group_count++; if (coda_type_record_create_field(type->definition, product->vgroup[k]->vgroup_name, (coda_type *)product->vgroup[k]->definition) != 0) { free(refs); free(tags); return -1; } type->entry[type->definition->num_fields - 1] = (coda_hdf4_type *)product->vgroup[k]; } break; } } /* if k == product->num_vgroup then the Vgroup links to a non-existent Vgroup and * we ignore the entry */ break; default: /* The Vgroup contains an unsupported item and we ignore the entry */ break; } } free(refs); free(tags); } } return 0; }