⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdapi.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
    int32           sdInterfaceID;	/* HDF SDS interface ID */    int32           idOffset = GDIDOFFSET;	/* Grid ID offset */    int32           nGrid = 0;	/* Grid counter */    char            name[80];	/* Vgroup name */    char            class[80];	/* Vgroup class */    char            errbuf[256];/* Buffer for error message */    char            utlbuf[1024];	/* Utility buffer */    char            header[128];/* Structural metadata header string */    char            footer[256];/* Structural metadata footer string */    char            refstr1[128];	/* Upper left ref string (metadata) */    char            refstr2[128];	/* Lower right ref string (metadata) */    /*     * Check HDF-EOS file ID, get back HDF file ID, SD interface ID  and     * access code     */    status = EHchkfid(fid, gridname, &HDFfid, &sdInterfaceID, &access);    /* Check gridname for length */    /* ------------------------- */    if ((intn) strlen(gridname) > VGNAMELENMAX)    {	status = -1;	HEpush(DFE_GENAPP, "GDcreate", __FILE__, __LINE__);	HEreport("Gridname \"%s\" must be less than %d characters.\n",		 gridname, VGNAMELENMAX);    }    if (status == 0)    {	/* Determine number of grids currently opened */	/* ------------------------------------------- */	for (i = 0; i < NGRID; i++)	{	    ngridopen += GDXGrid[i].active;	}	/* Setup file interface */	/* -------------------- */	if (ngridopen < NGRID)	{	    /* Check that grid 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 GRID then increment # grid counter */		/* ------------------------------------- */		if (strcmp(class, "GRID") == 0)		{		    nGrid++;		}		/* If grid already exist, return error */		/* ------------------------------------ */		if (strcmp(name, gridname) == 0 &&		    strcmp(class, "GRID") == 0)		{		    status = -1;		    HEpush(DFE_GENAPP, "GDcreate", __FILE__, __LINE__);		    HEreport("\"%s\" already exists.\n", gridname);		    break;		}	    }	    if (status == 0)	    {		/* Create Root Vgroup for Grid */		/* ---------------------------- */		vgid[0] = Vattach(HDFfid, -1, "w");		/* Set Name and Class (GRID) */		/* -------------------------- */		Vsetname(vgid[0], gridname);		Vsetclass(vgid[0], "GRID");		/* Create Data Fields Vgroup */		/* ------------------------- */		vgid[1] = Vattach(HDFfid, -1, "w");		Vsetname(vgid[1], "Data Fields");		Vsetclass(vgid[1], "GRID Vgroup");		Vinsert(vgid[0], vgid[1]);		/* Create Attributes Vgroup */		/* ------------------------ */		vgid[2] = Vattach(HDFfid, -1, "w");		Vsetname(vgid[2], "Grid Attributes");		Vsetclass(vgid[2], "GRID Vgroup");		Vinsert(vgid[0], vgid[2]);		/* Establish Grid in Structural MetaData Block */		/* -------------------------------------------- */		sprintf(header, "%s%d%s%s%s%s%d%s%s%d%s",			"\tGROUP=GRID_", nGrid + 1,			"\n\t\tGridName=\"", gridname, "\"\n",			"\t\tXDim=", xdimsize, "\n",			"\t\tYDim=", ydimsize, "\n");		sprintf(footer,			"%s%s%s%s%s%s%s%d%s",			"\t\tGROUP=Dimension\n",			"\t\tEND_GROUP=Dimension\n",			"\t\tGROUP=DataField\n",			"\t\tEND_GROUP=DataField\n",			"\t\tGROUP=MergedFields\n",			"\t\tEND_GROUP=MergedFields\n",			"\tEND_GROUP=GRID_", nGrid + 1, "\n");		/* Build Ref point Col-Row strings */		/* ------------------------------- */		if (upleftpt == NULL ||		    (upleftpt[0] == 0 && upleftpt[1] == 0 &&		     lowrightpt[0] == 0 && lowrightpt[1] == 0))		{		    strcpy(refstr1, "DEFAULT");		    strcpy(refstr2, "DEFAULT");		}		else		{		    sprintf(refstr1, "%s%lf%s%lf%s",			    "(", upleftpt[0], ",", upleftpt[1], ")");		    sprintf(refstr2, "%s%lf%s%lf%s",			    "(", lowrightpt[0], ",", lowrightpt[1], ")");		}		sprintf(utlbuf,			"%s%s%s%s%s%s%s%s",			header,			"\t\tUpperLeftPointMtrs=", refstr1, "\n",			"\t\tLowerRightMtrs=", refstr2, "\n",			footer);		status = EHinsertmeta(sdInterfaceID, "", "g", 1002L,				      utlbuf, NULL);	    }	}	else	{	    /* Too many files opened */	    /* --------------------- */	    status = -1;	    strcpy(errbuf,		   "No more than %d grids may be open simutaneously");	    strcat(errbuf, " (%s)");	    HEpush(DFE_DENIED, "GDcreate", __FILE__, __LINE__);	    HEreport(errbuf, NGRID, gridname);	}	/* Assign gridID # & Load grid and GDXGrid.fid table entries */	/* --------------------------------------------------------- */	if (status == 0)	{	    for (i = 0; i < NGRID; i++)	    {		if (GDXGrid[i].active == 0)		{		    gridID = i + idOffset;		    GDXGrid[i].active = 1;		    GDXGrid[i].IDTable = vgid[0];		    GDXGrid[i].VIDTable[0] = vgid[1];		    GDXGrid[i].VIDTable[1] = vgid[2];		    GDXGrid[i].fid = fid;		    status = 0;		    break;		}	    }	}    }    return (gridID);}/*----------------------------------------------------------------------------||  BEGIN_PROLOG                                                               ||                                                                             ||  FUNCTION: GDattach                                                         ||                                                                             ||  DESCRIPTION: Attaches to an existing grid within the file.                 ||                                                                             ||                                                                             ||  Return Value    Type     Units     Description                             ||  ============   ======  =========   =====================================   ||  gridID         int32               grid structure ID                       ||                                                                             ||  INPUTS:                                                                    ||  fid            int32               HDF-EOS file id                         ||  gridname       char                grid sructure name                      ||                                                                             ||                                                                             ||  OUTPUTS:                                                                   ||             None                                                            ||                                                                             ||  NOTES:                                                                     ||                                                                             ||                                                                             ||   Date     Programmer   Description                                         ||  ======   ============  =================================================   ||  Jun 96   Joel Gales    Original Programmer                                 ||  Sep 99   Abe Taaheri   Modified test for memory allocation check when no   ||                         SDSs are in the grid, NCR24147                    ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/int32GDattach(int32 fid, char *gridname){    intn            i;		/* Loop index */    intn            j;		/* Loop index */    intn            ngridopen = 0;	/* # of grid structures open */    intn            status;	/* routine return status variable */    uint8           acs;	/* Read/Write file access code */    int32           HDFfid;	/* HDF file id */    int32           vgRef;	/* Vgroup reference number */    int32           vgid[3];	/* Vgroup ID array */    int32           gridID = -1;/* HDF-EOS grid ID */    int32          *tags;	/* Pnt to Vgroup object tags array */    int32          *refs;	/* Pnt to Vgroup object refs array */    int32           dum;	/* dummy varible */    int32           sdInterfaceID;	/* HDF SDS interface ID */    int32           nObjects;	/* # of objects in Vgroup */    int32           nSDS;	/* SDS counter */    int32           index;	/* SDS index */    int32           sdid;	/* SDS object ID */    int32           idOffset = GDIDOFFSET;	/* Grid ID offset */    char            name[80];	/* Vgroup name */    char            class[80];	/* Vgroup class */    char            errbuf[256];/* Buffer for error message */    char            acsCode[1];	/* Read/Write access char: "r/w" */    /* Check HDF-EOS file ID, get back HDF file ID and access code */    /* ----------------------------------------------------------- */    status = EHchkfid(fid, gridname, &HDFfid, &dum, &acs);    if (status == 0)    {	/* Convert numeric access code to character */	/* ---------------------------------------- */	acsCode[0] = (acs == 1) ? 'w' : 'r';	/* Determine number of grids currently opened */	/* ------------------------------------------- */	for (i = 0; i < NGRID; i++)	{	    ngridopen += GDXGrid[i].active;	}	/* If room for more ... */	/* -------------------- */	if (ngridopen < NGRID)	{	    /* Search Vgroups for Grid */	    /* ------------------------ */	    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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -