/* ** NAME ** DFdescriptors -- return a list of the data descriptors in the file ** USAGE ** int DFdescriptors(dfile, ptr, begin, num) ** DF *dfile; IN: pointer to an open DF file ** DFdesc ptr[]; IN: pointer to space for the list of DDs ** int begin; IN: starting DD number ** int num; IN: number of entries ** RETURNS ** number of DDs returned in the list ** DESCRIPTION ** Fills in a list of all DDs in the file beginning with DD begin and ** including a maximum of num entries. The number of DDs actually entered ** into the list is returned. ** GLOBAL VARIABLES ** COMMENTS, BUGS, ASSUMPTIONS ** EXAMPLES ** REVISION LOG */ int DFdescriptors(DF * dfile, DFdesc ptr[], int begin, int num) { int i, ret; int32 aid; if (DFIcheck(dfile) != 0) { DFerror = DFE_NOTOPEN; return (-1); } else DFerror = DFE_NONE; aid = Hstartread(DFid, DFTAG_WILDCARD, DFREF_WILDCARD); if (aid == FAIL) { DFerror = (int)HEvalue(1); return (-1); } for (i = 2; i <= begin; i++) { ret = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT); if (ret == FAIL) { Hendaccess(aid); DFerror = (int)HEvalue(1); return (-1); } } Hinquire(aid, NULL, &ptr[0].tag, &ptr[0].ref, &ptr[0].length, &ptr[0].offset, NULL, NULL, NULL); for (i = 1; i < num; i++) { ret = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT); if (ret == FAIL) { Hendaccess(aid); return (i); } Hinquire(aid, NULL, &ptr[i].tag, &ptr[i].ref, &ptr[i].length, &ptr[i].offset, NULL, NULL, NULL); } Hendaccess(aid); return (i); }
/* ** NAME ** DFfind -- perform wildcard searches ** USAGE ** int DFfind(dfile, ptr) ** DF *dfile; IN: pointer to an open DF file ** DFdesc *ptr; IN: pointer to put in DD when found ** RETURNS ** 0 on success, -1 on failure ** DESCRIPTION ** If desired tag/ref is found, its DD is copied to *ptr. ** GLOBAL VARIABLES ** COMMENTS, BUGS, ASSUMPTIONS ** EXAMPLES ** REVISION LOG */ int DFfind(DF * dfile, DFdesc * ptr) { int ret; if (DFIcheck(dfile) != 0) { DFerror = DFE_NOTOPEN; return (-1); } else DFerror = DFE_NONE; if (search_stat == DFSRCH_NEW) { search_aid = Hstartread(DFid, search_tag, search_ref); search_stat = DFSRCH_OLD; ret = 0; } else { ret = Hnextread(search_aid, search_tag, search_ref, DF_CURRENT); } if ((search_aid == FAIL) || (ret == FAIL)) { DFerror = DFE_NOMATCH; ptr->tag = 0; ptr->ref = 0; return (-1); } Hinquire(search_aid, NULL, &ptr->tag, &ptr->ref, &ptr->length, &ptr->offset, NULL, NULL, NULL); return (0); }
int main(int argc, char *argv[]) { int32 infile, aid, ret; char *filename; char datafilename[DF_MAXFNLEN]; uint16 tag; uint16 ref; int32 offset, fileoffset; int32 length; int16 special; /* Get invocation name of program */ progname = *argv++; argc--; /* parse arguments */ while (argc > 0 && **argv == '-') { switch ((*argv)[1]) { case 'd': argc--; argv++; if (argc > 0) { strcpy(datafilename, *argv++); argc--; } else { usage(); exit(1); } break; default: usage(); exit(1); } } if (argc == 1) { filename = *argv++; argc--; } else { usage(); exit(1); } if (datafilename[0] == '\0') strcpy(datafilename, DefaultDatafile); /* Check to make sure input file is HDF */ ret = (int) Hishdf(filename); if (ret == FALSE) { error("given file is not an HDF file\n"); } /* check if datafile already exists. If so, set offset to its length. */ { struct stat buf; if (stat(datafilename, &buf) == 0) { printf("External file %s already exists. Using append mode.\n", datafilename); fileoffset = (int32)buf.st_size; } else fileoffset = 0; } /* Open HDF file */ infile = Hopen(filename, DFACC_RDWR, 0); if (infile == FAIL) { error("Can't open the HDF file\n"); } /* Process the file */ ret = aid = Hstartread(infile, DFTAG_SD, DFREF_WILDCARD); while (ret != FAIL) { /* * Get data about the current one */ ret = Hinquire(aid, NULL, &tag, &ref, &length, &offset, NULL, NULL, &special); /* check the tag value since external element object are returned the same. */ if (tag == DFTAG_SD) { printf("moving Scientific Data (%d,%d) to %s\n", tag, ref, datafilename); ret = HXcreate(infile, tag, ref, datafilename, fileoffset, length); fileoffset += length; } /* * Move to the next one */ ret = Hnextread(aid, DFTAG_SD, DFREF_WILDCARD, DF_CURRENT); } /* * Close the access element */ ret = Hendaccess(aid); if (ret == FAIL) hdferror(); /* done; close files */ Hclose(infile); return (0); }
/*-------------------------------------------------------------------------- NAME DFPgetpal -- get next palette from file USAGE intn DFPgetpal(filename,palette) char *filename; IN: name of HDF file void * palette; OUT: ptr to the buffer to store the palette in RETURNS SUCCEED on success, FAIL on failure. DESCRIPTION Gets the next palette from the file specified. GLOBAL VARIABLES Lastref, Refset COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ intn DFPgetpal(const char *filename, void * palette) { CONSTR(FUNC, "DFPgetpal"); int32 file_id; int32 aid; int32 length; intn ret_value = SUCCEED; HEclear(); if (!palette) HGOTO_ERROR(DFE_ARGS, FAIL); if ((file_id = DFPIopen(filename, DFACC_READ)) == FAIL) HGOTO_ERROR(DFE_BADOPEN, FAIL); if (Refset) { aid = Hstartread(file_id, DFTAG_IP8, Refset); if (aid == FAIL) aid = Hstartread(file_id, DFTAG_LUT, Refset); } /* end if */ else if (Readref) { aid = Hstartread(file_id, DFTAG_IP8, Readref); if (aid == FAIL) aid = Hstartread(file_id, DFTAG_LUT, Readref); if (aid != FAIL && (Hnextread(aid, DFTAG_IP8, DFREF_WILDCARD, DF_CURRENT) == FAIL)) { if (Hnextread(aid, DFTAG_LUT, DFREF_WILDCARD, DF_CURRENT) == FAIL) { Hendaccess(aid); aid = FAIL; } /* end if */ } /* end if */ } /* end if */ else { aid = Hstartread(file_id, DFTAG_IP8, DFREF_WILDCARD); if (aid == FAIL) aid = Hstartread(file_id, DFTAG_LUT, DFREF_WILDCARD); } /* end else */ Refset = 0; /* on error, close file and return -1 */ if (aid == FAIL) { ret_value = (HDerr(file_id)); goto done; } if (Hinquire(aid, (int32 *) NULL, (uint16 *) NULL, &Readref, &length, (int32 *) NULL, (int32 *) NULL, (int16 *) NULL, (int16 *) NULL) == FAIL) { Hendaccess(aid); ret_value = HDerr(file_id); goto done; } /* end if */ /* read palette */ if (Hread(aid, length, (uint8 *) palette) == FAIL) { Hendaccess(aid); ret_value = (HDerr(file_id)); goto done; } /* end if */ Hendaccess(aid); Lastref = Readref; ret_value = Hclose(file_id); done: if(ret_value == FAIL) { /* Error condition cleanup */ } /* end if */ /* Normal function cleanup */ return ret_value; } /* end DFPgetpal() */
int updateDesc(void) { int32 fid; int32 groupID; int32 aid, status; int i, j; if ((fid = Hopen(he_file, DFACC_READ, 0)) == 0) { printf("failed opening\n"); HEprint(stdout, 0); return FAIL; } aid = Hstartread(fid, DFTAG_WILDCARD, DFREF_WILDCARD); if (aid == FAIL) { HEprint(stderr, 0); return FAIL; } status = SUCCEED; for (i = 0; (i < HE_DESC_SZ) && (status != FAIL); i++) { Hinquire(aid, NULL, &he_desc[i].tag, &he_desc[i].ref, &he_desc[i].length, &he_desc[i].offset, NULL, (int16 *) NULL, (int16 *) NULL); status = Hnextread(aid, DFTAG_WILDCARD, DFREF_WILDCARD, DF_CURRENT); } he_numDesc = i; /* get informations about the groups */ he_numGrp = 0; for (i = 0; i < he_numDesc; i++) { if (isGrp(he_desc[i].tag)) { he_grp[he_numGrp].desc = i; /* he_grp[he_numGrp].size = (int) (he_desc[i].length / sizeof(tag_ref)); he_grp[he_numGrp].ddList = (tag_ref_ptr) HDmalloc(he_desc[i].length); */ he_grp[he_numGrp].size = (int) (he_desc[i].length / 4); he_grp[he_numGrp].ddList = (tag_ref_ptr) HDmalloc(he_grp[he_numGrp].size*sizeof(tag_ref)); if (!he_grp[he_numGrp].ddList) { fprintf(stderr, "Out of memory. Closing file.\n"); closeFile(1); /* keep the backup */ return FAIL; } groupID = DFdiread(fid, he_desc[i].tag, he_desc[i].ref); if (groupID < 0) { HEprint(stderr, 0); return FAIL; } for (j = 0; j < he_grp[he_numGrp].size; j++) DFdiget(groupID, &he_grp[he_numGrp].ddList[j].tag, &he_grp[he_numGrp].ddList[j].ref); he_numGrp++; } } Hendaccess(aid); Hclose(fid); return SUCCEED; }
int32 vimakecompat(HFILEID f) { VGROUP *vg; VDATA *vs; uint8 *buf = NULL; /* to store an old vdata or vgroup descriptor */ int32 old_bsize = 0, bsize=0; int32 aid; int32 ret; uintn u; uint16 tag=DFTAG_NULL, ref=DFTAG_NULL; CONSTR(FUNC, "vimakecompat"); /* ============================================= */ /* --- read all vgs and convert each --- */ /* allocate space for vg */ if (NULL == (vg =VIget_vgroup_node())) HRETURN_ERROR(DFE_NOSPACE, 0); ret = aid = Hstartread(f, (uint16) OLD_VGDESCTAG, DFREF_WILDCARD); while (ret != FAIL) { HQuerytagref(aid, &tag, &ref); HQuerylength(aid, &bsize); if (buf == NULL || bsize > old_bsize) { if (buf != NULL) HDfree((VOIDP) buf); if ((buf = (uint8 *) HDmalloc(bsize)) == NULL) HRETURN_ERROR(DFE_NOSPACE, 0); old_bsize = bsize; } /* end if */ ret = Hgetelement(f, (uint16) OLD_VGDESCTAG, ref, (uint8 *) buf); if (ret == FAIL) { HDfree((VOIDP) buf); HRETURN_ERROR(DFE_READERROR, 0) } /* end if */ oldunpackvg(vg, buf, &bsize); /* add new items */ vg->vgclass = NULL; /* vg->vgclass[0] = '\0'; */ vg->extag = 0; vg->exref = 0; vg->version = 2; /* version 2 */ vg->more = 0; /* inside each vgroup, change the old tags to new */ for (u = 0; u < (uintn)vg->nvelt; u++) if (vg->tag[u] == OLD_VGDESCTAG) vg->tag[u] = NEW_VGDESCTAG; else if (vg->tag[u] == OLD_VSDESCTAG) vg->tag[u] = NEW_VSDESCTAG; else /* BAD */ HERROR(DFE_NOTINSET); vpackvg(vg, buf, &bsize); ret = Hputelement(f, VGDESCTAG, ref, (uint8 *) buf, bsize); HDfree((VOIDP) buf); if (ret == FAIL) HRETURN_ERROR(DFE_WRITEERROR, 0); ret = Hnextread(aid, (uint16) OLD_VGDESCTAG, DFREF_WILDCARD, DF_CURRENT); } /* while */