static void test_vgisinternal() { int32 fid, vgroup_id; intn is_internal = FALSE; int32 vref = -1; intn ii, status; char testfile[H4_MAX_NC_NAME] = ""; char internal_array2[2] = {TRUE, TRUE}; intn num_errs = 0; /* number of errors so far */ /* Use a GR file to test Vgisinternal on internal vgroups */ /* The file GR_FILE is an existing file in the test_files directory, make_datafilename builds the file name with correct path */ if (make_datafilename(GR_FILE, testfile, H4_MAX_NC_NAME) != FAIL) { /* Open the old GR file and initialize the V interface */ fid = Hopen(testfile, DFACC_READ, 0); CHECK_VOID(fid, FAIL, "Hopen: grtdfui83.hdf"); status = Vstart(fid); CHECK_VOID(status, FAIL, "Vstart"); ii = 0; while ((vref = Vgetid(fid, vref)) != FAIL) { /* until no more vgroups */ vgroup_id = Vattach(fid, vref, "r"); /* attach to vgroup */ /* Test that the current vgroup is or is not internal as specified in the array internal_array2 */ is_internal = Vgisinternal(vgroup_id); CHECK_VOID(is_internal, FAIL, "Vgisinternal"); VERIFY_VOID(is_internal, internal_array2[ii], "Vgisinternal"); status = Vdetach(vgroup_id); CHECK_VOID(status, FAIL, "Vdetach"); ii++; /* increment vgroup index */ } /* Terminate access to the V interface and close the file */ status = Vend(fid); CHECK_VOID(status, FAIL, "Vend"); status = Hclose(fid); CHECK_VOID(status, FAIL, "Hclose"); } else { fprintf(stderr, "ERROR>>> Unable to make filename for %s\n", GR_FILE); H4_FAILED() } } /* test_vgisinternal */
JNIEXPORT jlong JNICALL Java_hdf_hdflib_HDFLibrary_Vattach (JNIEnv *env, jclass clss, jlong fid, jint vgroup_ref, jstring accessmode) { int retVal = -1; const char *access; HFILEID id = (HFILEID)fid; PIN_JAVA_STRING(accessmode, access); if (access != NULL) { /* open HDF file specified by hdf_HDF_file */ retVal = Vattach(id, (int32)vgroup_ref, access); UNPIN_JAVA_STRING(accessmode, access); if (retVal == FAIL) CALL_ERROR_CHECK(); } return (jlong)retVal; }
static int do_groups(void) { int32 vg0_id, /* vgroup identifier */ vg1_id, /* vgroup identifier */ vg2_id, /* vgroup identifier */ file1_id; /* HDF file identifier */ /* create a HDF file */ if ((file1_id = Hopen (FILE7_NAME, DFACC_CREATE, (int16)0))<0) { printf("Error: Could not create file <%s>\n",FILE7_NAME); return FAIL; } /* initialize the V interface */ if (Vstart (file1_id)==FAIL) { printf( "Could not start VG\n"); return FAIL; } /* create a vgroup */ vg0_id = Vattach (file1_id, -1, "w"); if (Vsetname (vg0_id, "g0")==FAIL) { printf( "Could not name group\n"); goto out; } /* create the second vgroup */ vg1_id = Vattach (file1_id, -1, "w"); if (Vsetname (vg1_id, "g1")==FAIL) { printf( "Could not name group\n"); goto out; } /* create the third vgroup */ vg2_id = Vattach (file1_id, -1, "w"); if (Vsetname (vg2_id, "g1.1")==FAIL) { printf( "Could not name group\n"); goto out; } if (Vinsert (vg0_id, vg1_id)==FAIL) { printf( "Could not insert VG\n"); goto out; } if (Vinsert (vg0_id, vg2_id)==FAIL) { printf( "Could not insert VG\n"); goto out; } if (Vinsert (vg1_id, vg2_id)==FAIL) { printf( "Could not insert VG\n"); goto out; } if (Vinsert (vg2_id, vg1_id)==FAIL) { printf( "Could not insert VG\n"); goto out; } /* terminate access to the vgroup */ if (Vdetach (vg0_id)==FAIL) { printf( "Could not close group\n"); goto out; } /* terminate access to the vgroup */ if (Vdetach (vg1_id)==FAIL) { printf( "Could not close group\n"); goto out; } /* terminate access to the vgroup */ if (Vdetach (vg2_id)==FAIL) { printf( "Could not close group\n"); goto out; } /* terminate access to the V interface */ if (Vend (file1_id)==FAIL) { printf( "Could not end VG\n"); goto out; } /* close the HDF file */ if (Hclose (file1_id)==FAIL) { printf( "Could not close file\n"); return FAIL; } return SUCCEED; out: printf("Error...Exiting...\n"); return FAIL; }
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 void test_vglongnames(void) { int32 file_id; /* File ID */ int32 vg1; /* Vdata ID */ int32 ref; /* Vdata ref */ uint16 name_len; /* Length of a vgroup's name or class name */ char *vgname, *vgclass; intn is_internal; int32 status; /* Status values from routines */ /* Open the HDF file. */ file_id = Hopen(LONGNAMES, DFACC_CREATE, 0); CHECK_VOID(file_id,FAIL,"Hopen"); /* Initialize HDF for subsequent vgroup/vdata access. */ status = Vstart(file_id); CHECK_VOID(status,FAIL,"Vstart"); /* Create a new vgroup. */ vg1 = Vattach(file_id, -1, "w"); CHECK_VOID(vg1,FAIL,"VSattach"); status=Vsetname(vg1, VG_LONGNAME); CHECK_VOID(status,FAIL,"VSsetname"); status=Vsetclass(vg1, VG_LONGCLASS); CHECK_VOID(status,FAIL,"VSsetname"); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); /* Create another vgroup of the same class. */ vg1 = Vattach(file_id, -1, "w"); CHECK_VOID(vg1,FAIL,"VSattach"); status=Vsetname(vg1, VGROUP1); CHECK_VOID(status,FAIL,"VSsetname"); status=Vsetclass(vg1, VG_LONGCLASS); CHECK_VOID(status,FAIL,"VSsetname"); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); status = Vend(file_id); CHECK_VOID(status,FAIL,"Vend"); status = Hclose(file_id); CHECK_VOID(status,FAIL,"Hclose"); /* Re-open the HDF file. */ file_id = Hopen(LONGNAMES, DFACC_RDWR, 0); CHECK_VOID(file_id,FAIL,"Hopen"); /* Initialize HDF for subsequent vgroup/vdata access. */ status = Vstart(file_id); CHECK_VOID(status,FAIL,"Vstart"); /* Find the long name vgroup. */ ref=Vfind(file_id,VG_LONGNAME); CHECK_VOID(ref,FAIL,"VSfind"); vg1 = Vattach(file_id, ref, "r"); CHECK_VOID(vg1,FAIL,"VSattach"); /* Test Vgisinternal */ is_internal = Vgisinternal(vg1); CHECK_VOID(is_internal, FAIL, "Vgisinternal"); VERIFY_VOID(is_internal, FALSE, "Vgisinternal"); /* get the vgroup's name */ status = Vgetnamelen(vg1, &name_len); CHECK_VOID(status,FAIL,"Vgetnamelen"); vgname = (char *) HDmalloc(sizeof(char *) * (name_len+1)); CHECK_ALLOC(vgname, "vgname", "test_vglongnames" ); status=Vgetname(vg1, vgname); CHECK_VOID(status,FAIL,"VSgetname"); VERIFY_CHAR_VOID(vgname, VG_LONGNAME, "Vgetname"); if (vgname != NULL) HDfree(vgname); /* get the vgroup's class */ status = Vgetclassnamelen(vg1, &name_len); CHECK_VOID(status,FAIL,"Vgetnamelen"); vgclass = (char *) HDmalloc(sizeof(char *) * (name_len+1)); CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames" ); status=Vgetclass(vg1, vgclass); CHECK_VOID(status,FAIL,"VSgetclass"); VERIFY_CHAR_VOID(vgclass, VG_LONGCLASS, "Vgetclass"); if (vgclass != NULL) HDfree(vgclass); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); /* Find the vgroup VGROUP1. */ ref=Vfind(file_id,VGROUP1); CHECK_VOID(ref,FAIL,"VSfind"); vg1 = Vattach(file_id, ref, "r"); CHECK_VOID(vg1,FAIL,"VSattach"); /* get the vgroup's name */ status = Vgetnamelen(vg1, &name_len); CHECK_VOID(status,FAIL,"Vgetnamelen"); vgname = (char *) HDmalloc(sizeof(char *) * (name_len+1)); CHECK_ALLOC(vgname, "vgname", "test_vglongnames" ); status=Vgetname(vg1, vgname); CHECK_VOID(status,FAIL,"VSgetname"); if (HDstrcmp(vgname, VGROUP1)) { num_errs++; printf(">>> Got bogus Vgroup name : %s\n", vgname); } if (vgname != NULL) HDfree(vgname); /* get the vgroup's class */ status = Vgetclassnamelen(vg1, &name_len); CHECK_VOID(status,FAIL,"Vgetnamelen"); vgclass = (char *) HDmalloc(sizeof(char *) * (name_len+1)); CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames" ); status=Vgetclass(vg1, vgclass); CHECK_VOID(status,FAIL,"VSgetclass"); if (HDstrcmp(vgclass, VG_LONGCLASS)) { num_errs++; printf(">>> Got bogus Vgroup class : %s\n", vgclass); } if (vgclass != NULL) HDfree(vgclass); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); status = Vend(file_id); CHECK_VOID(status,FAIL,"Vend"); status = Hclose(file_id); CHECK_VOID(status,FAIL,"Hclose"); } /* test_vglongnames() */
static void test_undefined(void) { int32 status; /* Status values from routines */ int32 file_id; /* File ID */ int32 vg1; /* Vdata ID */ int32 ref; /* Vdata ref */ intn is_internal; /* to test Vgisinternal */ uint16 name_len; /* Length of a vgroup's name or class name */ /* to simulate calls to Vgetclass/Vgetname in older applications */ char vgname[VGNAMELENMAX+1], vgclass[VGNAMELENMAX+1]; /* Open the HDF file. */ file_id = Hopen(NONAMECLASS, DFACC_CREATE, 0); CHECK_VOID(file_id,FAIL,"Hopen"); /* Initialize HDF for subsequent vgroup/vdata access. */ status = Vstart(file_id); CHECK_VOID(status,FAIL,"Vstart"); /* Create a vgroup which will have name set but not class */ vg1 = Vattach(file_id, -1, "w"); CHECK_VOID(vg1,FAIL,"VSattach"); status=Vsetname(vg1, VG_LONGNAME); CHECK_VOID(status,FAIL,"VSsetname"); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); /* Create another vgroup which will have class but not name */ vg1 = Vattach(file_id, -1, "w"); CHECK_VOID(vg1,FAIL,"VSattach"); status=Vsetclass(vg1, VG_LONGCLASS); CHECK_VOID(status,FAIL,"VSsetname"); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); status = Vend(file_id); CHECK_VOID(status,FAIL,"Vend"); status = Hclose(file_id); CHECK_VOID(status,FAIL,"Hclose"); /* Re-open the HDF file. */ file_id = Hopen(NONAMECLASS, DFACC_RDWR, 0); CHECK_VOID(file_id,FAIL,"Hopen"); /* Initialize HDF for subsequent vgroup/vdata access. */ status = Vstart(file_id); CHECK_VOID(status,FAIL,"Vstart"); /* Find the long name vgroup. */ ref=Vfind(file_id,VG_LONGNAME); CHECK_VOID(ref,FAIL,"VSfind"); vg1 = Vattach(file_id, ref, "r"); CHECK_VOID(vg1,FAIL,"VSattach"); /* Test Vgisinternal */ is_internal = Vgisinternal(vg1); CHECK_VOID(is_internal, FAIL, "Vgisinternal"); VERIFY_VOID(is_internal, FALSE, "Vgisinternal"); /* Try getting the vgroup's class without calling first Vgetclassnamelen. This shows that bug HDFFR-1288 is fixed. */ status=Vgetclass(vg1, vgclass); CHECK_VOID(status,FAIL,"Vgetclass"); VERIFY_VOID(HDstrlen(vgclass), 0, "VSgetclass"); /* The length of the class name should be 0 */ status = Vgetclassnamelen(vg1, &name_len); CHECK_VOID(status,FAIL,"Vgetclassnamelen"); VERIFY_VOID(name_len, 0, "VSgetclassnamelen"); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); /* Find the vgroup with class VG_LONGCLASS. This vgroup doesn't have a name */ ref=Vfindclass(file_id, VG_LONGCLASS); CHECK_VOID(ref,FAIL,"VSfindclass"); vg1 = Vattach(file_id, ref, "r"); CHECK_VOID(vg1,FAIL,"VSattach"); /* Try getting the vgroup's name without calling first Vgetclassnamelen. Similar to class name in bug HDFFR-1288. */ status=Vgetname(vg1, vgname); CHECK_VOID(status,FAIL,"Vgetname"); VERIFY_VOID(HDstrlen(vgname), 0, "VSgetname"); /* The length of the name should be 0 */ status = Vgetnamelen(vg1, &name_len); CHECK_VOID(status,FAIL,"Vgetnamelen"); VERIFY_VOID(name_len, 0, "VSgetnamelen"); status = Vdetach(vg1); CHECK_VOID(status,FAIL,"Vdetach"); status = Vend(file_id); CHECK_VOID(status,FAIL,"Vend"); status = Hclose(file_id); CHECK_VOID(status,FAIL,"Hclose"); } /* test_undefined() */
int main( ) { /************************* Variable declaration **************************/ intn status_n; /* returned status for functions returning an intn */ int32 status_32, /* returned status for functions returning an int32 */ file_id, vgroup_id, vgroup_ref, vdata_id, vdata_ref, num_of_records, num_of_vals_per_rec, record_pos, obj_index, /* index of an object within a vgroup */ num_of_pairs, /* number of tag/ref number pairs, i.e., objects */ obj_tag, obj_ref, /* tag/ref number of an HDF object */ vgroup_pos = 0; /* position of a vgroup in the file */ float32 databuf[N_RECORDS][N_VALS_PER_REC]; int16 rec_num; /********************** End of variable declaration ***********************/ char FIELDNAME_LIST[MAX_FIELDNAME_LIST_LENGTH]; memset(FIELDNAME_LIST, 0x00, MAX_FIELDNAME_LIST_LENGTH); int i; for (i = 0; i < N_VALS_PER_REC; i++) { char buffer[256]; if (i == 0) { sprintf(buffer, "%d", i); } else { sprintf(buffer, " %d", i); } strcat(FIELDNAME_LIST, buffer); } file_id = Hopen (FILE_NAME, DFACC_READ, 0); status_n = Vstart (file_id); vgroup_ref = -1; vgroup_ref = Vgetid (file_id, vgroup_ref); if (vgroup_ref == -1) exit(1); vgroup_ref = Vgetid (file_id, vgroup_ref); if (vgroup_ref == -1) exit(1); vgroup_id = Vattach (file_id, vgroup_ref, "r"); num_of_pairs = Vntagrefs (vgroup_id); if (num_of_pairs > 0) { printf ("\nVgroup #%d contains:\n", vgroup_pos); for (obj_index = 0; obj_index < num_of_pairs; obj_index++) { status_n = Vgettagref (vgroup_id, obj_index, &obj_tag, &obj_ref); printf ("tag = %d, ref = %d", obj_tag, obj_ref); if (Visvg (vgroup_id, obj_ref)) printf (" <-- is a vgroup\n"); else if (Visvs (vgroup_id, obj_ref)) { printf (" <-- is a vdata\n"); vdata_ref = VSfind (file_id, VDATA_NAME); vdata_id = VSattach (file_id, vdata_ref, "r"); status_n = VSsetfields (vdata_id, FIELDNAME_LIST); record_pos = VSseek (vdata_id, RECORD_INDEX); num_of_records = VSread (vdata_id, (uint8 *)databuf, N_RECORDS, FULL_INTERLACE); for (rec_num = 0; rec_num < num_of_records; rec_num++) { for (num_of_vals_per_rec = 0; num_of_vals_per_rec < N_VALS_PER_REC; num_of_vals_per_rec++) { printf ("%6.2f\n", databuf[rec_num][num_of_vals_per_rec]); } } } else { printf (" <-- neither vdata nor vgroup\n"); } } /* for */ } /* if */ else printf ("Vgroup #%d contains no HDF objects\n", vgroup_pos); /* * Terminate access to the current vgroup. */ status_32 = Vdetach (vgroup_id); /* * Move to the next vgroup position. */ vgroup_pos++; /* * Terminate access to the V interface and close the file. */ status_n = Vend (file_id); status_n = Hclose (file_id); return 0; }