📄 ptapi.c
字号:
/*Copyright (C) 1996 Hughes and Applied Research CorporationPermission to use, modify, and distribute this software and its documentation for any purpose without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.June 5, 2003 Abe Taaheri Removed declarations for unused variables idOffset, nlevels, and pID in PTrecnum Removed initialization code for unused variables in PTrecnum Removed declarations for unused variables idOffset and vdataID in PTregionrecs Removed initialization code for unused variables in PTregionrecs*/#include "hdf.h"#include "cfortHdf.h"#include "HdfEosDef.h"#define PTIDOFFSET 2097152#define NPOINT 64struct pointStructure{ int32 active; int32 IDTable; int32 VIDTable[3]; int32 fid; int32 vdID[8];};struct pointStructure PTXPoint[NPOINT];#define NPOINTREGN 256struct pointRegion { int32 fid; int32 pointID; int32 nrec[8]; int32 *recPtr[8];};struct pointRegion *PTXRegion[NPOINTREGN];/* Point Prototype (internal routines) */intn PTchkptid(int32, char *, int32 *, int32 *, int32 *);intn PTlinkinfo(int32, int32, int32, char *mode, char *);intn PTwrbckptr(int32, int32, int32, int32 []);intn PTrdbckptr(int32, int32, int32, int32 []);intn PTwrfwdptr(int32, int32);intn PTrdfwdptr(int32, int32, int32, int32 []);intn PTwritesetup(int32, int32, int32, int32, int32 *, int32 *);int32 PTrecnum(int32, int32, int32, int32, int32, int32 []);intn PTwrrdattr(int32, char *, int32, int32, char *, VOIDP);/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: PTopen || || DESCRIPTION: Opens an HDF file and returns file ID. || || || Return Value Type Units Description || ============ ====== ========= ===================================== || fid int32 HDF-EOS file ID || || INPUTS: || filename char Point Filename || access code intn Access Code || DFACC_CREATE || DFACC_RDWR || DFACC_READ || OUTPUTS: || None || || NOTES: || || || Date Programmer Description || ====== ============ ================================================= || Jun 96 Joel Gales Original Programmer || || END_PROLOG |-----------------------------------------------------------------------------*/int32PTopen(char *filename, intn access){ int32 fid /* HDF-EOS file ID */ ; /* Call EHopen to perform file access */ /* ---------------------------------- */ fid = EHopen(filename, access); return (fid);}/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: PTcreate || || DESCRIPTION: Creates a new point data set and returns a handle. || || || Return Value Type Units Description || ============ ====== ========= ===================================== || pointID int32 Point structure ID || || INPUTS: || fid int32 File ID || pointname char Point structure name || || || OUTPUTS: || None || || NOTES: || || || Date Programmer Description || ====== ============ ================================================= || Jun 96 Joel Gales Original Programmer || Aug 96 Joel Gales Make metadata ODL compliant || Aug 96 Joel Gales Check point name for length || || END_PROLOG |-----------------------------------------------------------------------------*/int32PTcreate(int32 fid, char *pointname){ intn i; /* Loop index */ intn npointopen = 0; /* # of point structures open */ intn status = 0; /* routine return status variable */ uint8 access; /* Read/Write file access code */ uint8 zerobuf[8] = {0, 0, 0, 0, 0, 0, 0, 0}; /* Data buffer for "Level Written Vdata" */ int32 HDFfid; /* HDF file id */ int32 vgRef; /* Vgroup reference number */ int32 vgid[4]; /* Vgroup ID array */ int32 pointID = -1; /* HDF-EOS point ID */ int32 vdataID; /* Vdata ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 idOffset = PTIDOFFSET; /* Point ID offset */ int32 nPoint = 0; /* Point counter */ char name[80]; /* Vgroup name */ char class[80]; /* Vgroup class */ char utlbuf[512];/* Utility buffer */ char utlbuf2[128]; /* Utility buffer 2 */ /* * Check HDF-EOS file ID, get back HDF file ID, SD interface ID and * access code */ status = EHchkfid(fid, pointname, &HDFfid, &sdInterfaceID, &access); /* Check pointname for length */ /* -------------------------- */ if ((intn) strlen(pointname) > VGNAMELENMAX) { status = -1; HEpush(DFE_GENAPP, "PTcreate", __FILE__, __LINE__); HEreport("Pointname \"%s\" must be less than %d characters.\n", pointname, VGNAMELENMAX); } if (status == 0) { /* Determine number of points currently opened */ /* ------------------------------------------- */ for (i = 0; i < NPOINT; i++) { npointopen += PTXPoint[i].active; } /* Setup file interface */ /* -------------------- */ if (npointopen < NPOINT) { /* Check that point has not been previously opened */ /* ----------------------------------------------- */ vgRef = -1; while (1) { vgRef = Vgetid(HDFfid, vgRef); /* If no more Vgroups then exist while loop */ /* ---------------------------------------- */ if (vgRef == -1) { break; } /* Get name and class of Vgroup */ /* ---------------------------- */ vgid[0] = Vattach(HDFfid, vgRef, "r"); Vgetname(vgid[0], name); Vgetclass(vgid[0], class); Vdetach(vgid[0]); /* If POINT then increment # point counter */ /* --------------------------------------- */ if (strcmp(class, "POINT") == 0) { nPoint++; } /* If point already exist, return error */ /* ------------------------------------ */ if (strcmp(name, pointname) == 0 && strcmp(class, "POINT") == 0) { status = -1; HEpush(DFE_GENAPP, "PTcreate", __FILE__, __LINE__); HEreport("\"%s\" already exists.\n", pointname); break; } } if (status == 0) { /* Create Root Vgroup for Point */ /* ---------------------------- */ vgid[0] = Vattach(HDFfid, -1, "w"); /* Set Name and Class (POINT) */ /* -------------------------- */ Vsetname(vgid[0], pointname); Vsetclass(vgid[0], "POINT"); /* Create Level Written Vdata */ /* -------------------------- */ vdataID = VSattach(HDFfid, -1, "w"); VSfdefine(vdataID, "LevelWritten", DFNT_UINT8, 1); VSsetfields(vdataID, "LevelWritten"); VSwrite(vdataID, zerobuf, 8, FULL_INTERLACE); VSsetname(vdataID, "LevelWritten"); Vinsert(vgid[0], vdataID); VSdetach(vdataID); /* Create Data Records Vgroup */ /* -------------------------- */ vgid[1] = Vattach(HDFfid, -1, "w"); Vsetname(vgid[1], "Data Vgroup"); Vsetclass(vgid[1], "POINT Vgroup"); Vinsert(vgid[0], vgid[1]); /* Create Linkage Records Vgroup */ /* ----------------------------- */ vgid[2] = Vattach(HDFfid, -1, "w"); Vsetname(vgid[2], "Linkage Vgroup"); Vsetclass(vgid[2], "POINT Vgroup"); Vinsert(vgid[0], vgid[2]); /* Create Point Attributes Vgroup */ /* ------------------------------ */ vgid[3] = Vattach(HDFfid, -1, "w"); Vsetname(vgid[3], "Point Attributes"); Vsetclass(vgid[3], "POINT Vgroup"); Vinsert(vgid[0], vgid[3]); /* Establish Point in Structural MetaData Block */ /* -------------------------------------------- */ sprintf(utlbuf, "%s%d%s%s%s", "\tGROUP=POINT_", nPoint + 1, "\n\t\tPointName=\"", pointname, "\"\n"); strcat(utlbuf, "\t\tGROUP=Level\n"); strcat(utlbuf, "\t\tEND_GROUP=Level\n"); strcat(utlbuf, "\t\tGROUP=LevelLink\n"); strcat(utlbuf, "\t\tEND_GROUP=LevelLink\n"); sprintf(utlbuf2, "%s%d%s", "\tEND_GROUP=POINT_", nPoint + 1, "\n"); strcat(utlbuf, utlbuf2); status = EHinsertmeta(sdInterfaceID, "", "p", 1003L, utlbuf, NULL); } } else { /* Too many files opened */ /* --------------------- */ status = -1; strcpy(utlbuf, "No more than %d points may be open simutaneously"); strcat(utlbuf, " (%s)"); HEpush(DFE_DENIED, "PTcreate", __FILE__, __LINE__); HEreport(utlbuf, NPOINT, pointname); } /* Assign pointID # & Load point and PTXPoint table entries */ /* -------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -