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

📄 swapi.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
			refs = (int32 *) malloc(sizeof(int32) * nObjects);			if(refs == NULL)			{ 			    HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);			    free(tags);			    return(-1);			}			Vgettagrefs(vgid[2], tags, refs, nObjects);			/* Count number of SDS & allocate SDS ID array */			/* ------------------------------------------- */			nSDS = 0;			for (j = 0; j < nObjects; j++)			{			    if (tags[j] == DFTAG_NDG)			    {				nSDS++;			    }			}			SWXSwath[i].sdsID = (int32 *)			    realloc((void *) SWXSwath[i].sdsID,				    (SWXSwath[i].nSDS + nSDS) * 4);			if(SWXSwath[i].sdsID == NULL && nSDS != 0)			{ 			    HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);			    return(-1);			}			/* Fill SDS ID array */			/* ----------------- */			for (j = 0; j < nObjects; j++)			{			    /* If object is SDS then get id */			    /* ---------------------------- */			    if (tags[j] == DFTAG_NDG)			    {				index = SDreftoindex(sdInterfaceID, refs[j]);				sdid = SDselect(sdInterfaceID, index);				SWXSwath[i].sdsID[SWXSwath[i].nSDS] = sdid;				SWXSwath[i].nSDS++;			    }			}			free(tags);			free(refs);		    }		    break;		}		/* Detach Vgroup if not desired Swath */		/* ---------------------------------- */		Vdetach(vgid[0]);	    }	    /* If Swath not found then set up error message */	    /* -------------------------------------------- */	    if (swathID == -1)	    {		HEpush(DFE_RANGE, "SWattach", __FILE__, __LINE__);		HEreport("Swath: \"%s\" does not exist within HDF file.\n",			 swathname);	    }	}	else	{	    /* Too many files opened */	    /* --------------------- */	    swathID = -1;	    strcpy(errbuf,		   "No more than %d swaths may be open simutaneously");	    strcat(errbuf, " (%s)");	    HEpush(DFE_DENIED, "SWattach", __FILE__, __LINE__);	    HEreport(errbuf, NSWATH, swathname);	}    }    return (swathID);}/*----------------------------------------------------------------------------||  BEGIN_PROLOG                                                               ||                                                                             ||  FUNCTION: SWchkswid                                                        ||                                                                             ||  DESCRIPTION: Checks for valid swathID and returns file ID, SDS ID, and     ||               swath Vgroup ID                                               ||                                                                             ||                                                                             ||  Return Value    Type     Units     Description                             ||  ============   ======  =========   =====================================   ||  status         intn                return status (0) SUCCEED, (-1) FAIL    ||                                                                             ||  INPUTS:                                                                    ||  swathID        int32               swath structure ID                      ||  routname       char                Name of routine calling SWchkswid       ||                                                                             ||  OUTPUTS:                                                                   ||  fid            int32               File ID                                 ||  sdInterfaceID  int32               SDS interface ID                        ||  swVgrpID       int32               swath Vgroup ID                         ||                                                                             ||  NOTES:                                                                     ||                                                                             ||                                                                             ||   Date     Programmer   Description                                         ||  ======   ============  =================================================   ||  Jun 96   Joel Gales    Original Programmer                                 ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/intnSWchkswid(int32 swathID, char *routname,	  int32 * fid, int32 * sdInterfaceID, int32 * swVgrpID){    intn            status = 0;	/* routine return status variable */    uint8           access;	/* Read/Write access code */    int32           idOffset = SWIDOFFSET;	/* Swath ID offset */    char            message1[] =    "Invalid swath id: %d in routine \"%s\".  ID must be >= %d and < %d.\n";    char            message2[] =    "Swath id %d in routine \"%s\" not active.\n";    /* Check for valid swath id */    /* ------------------------ */    if (swathID < idOffset || swathID >= NSWATH + idOffset)    {	status = -1;	HEpush(DFE_RANGE, "SWchkswid", __FILE__, __LINE__);	HEreport(message1, swathID, routname, idOffset, NSWATH + idOffset);    }    else    {	/* Check for active swath ID */	/* ------------------------- */	if (SWXSwath[swathID % idOffset].active == 0)	{	    status = -1;	    HEpush(DFE_GENAPP, "SWchkswid", __FILE__, __LINE__);	    HEreport(message2, swathID, routname);	}	else	{	    /* Get file & SDS ids and Swath Vgroup */	    /* ----------------------------------- */	    status = EHchkfid(SWXSwath[swathID % idOffset].fid, " ", fid,			      sdInterfaceID, &access);	    *swVgrpID = SWXSwath[swathID % idOffset].IDTable;	}    }    return (status);}/*----------------------------------------------------------------------------||  BEGIN_PROLOG                                                               ||                                                                             ||  FUNCTION: SWdefdim                                                         ||                                                                             ||  DESCRIPTION: Defines numerical value of dimension                          ||                                                                             ||                                                                             ||  Return Value    Type     Units     Description                             ||  ============   ======  =========   =====================================   ||  status         intn                return status (0) SUCCEED, (-1) FAIL    ||                                                                             ||  INPUTS:                                                                    ||  swathID        int32               swath structure ID                      ||  dimname        char                Dimension name to define                ||  dim            int32               Dimemsion value                         ||                                                                             ||  OUTPUTS:                                                                   ||             None                                                            ||                                                                             ||  NOTES:                                                                     ||                                                                             ||                                                                             ||   Date     Programmer   Description                                         ||  ======   ============  =================================================   ||  Jun 96   Joel Gales    Original Programmer                                 ||  Dec 96   Joel Gales    Check that dim value >= 0                           ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/intnSWdefdim(int32 swathID, char *dimname, int32 dim){    intn            status;	/* routine return status variable */    int32           fid;	/* HDF-EOS file id */    int32           sdInterfaceID;	/* HDF SDS interface ID */    int32           swVgrpID;	/* Swath root Vgroup ID */    int32           idOffset = SWIDOFFSET;	/* Swath ID offset */    char            swathname[80] /* Swath name */ ;    /* Check for valid swath id */    /* ------------------------ */    status = SWchkswid(swathID, "SWdefdim", &fid, &sdInterfaceID, &swVgrpID);    /* Make sure dimension >= 0 */    /* ------------------------ */    if (dim < 0)    {	status = -1;	HEpush(DFE_GENAPP, "SWdefdim", __FILE__, __LINE__);	HEreport("Dimension value for \"%s\" less than zero: %d.\n",		 dimname, dim);    }    /* Write Dimension to Structural MetaData */    /* -------------------------------------- */    if (status == 0)    {	Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname);	status = EHinsertmeta(sdInterfaceID, swathname, "s", 0L,			      dimname, &dim);    }    return (status);}/*----------------------------------------------------------------------------||  BEGIN_PROLOG                                                               ||                                                                             ||  FUNCTION: SWdiminfo                                                        ||                                                                             ||  DESCRIPTION: Returns size in bytes of named dimension                      ||                                                                             ||                                                                             ||  Return Value    Type     Units     Description                             ||  ============   ======  =========   =====================================   ||  size           int32               Size of dimension                       ||                                                                             ||  INPUTS:                                                                    ||  swathID        int32               swath structure id                      ||  dimname        char                Dimension name                          ||                                                                             ||                                                                             ||  OUTPUTS:                                                                   ||             None                                                            ||                                                                             ||  NOTES:                                                                     ||                                                                             ||                                                                             ||   Date     Programmer   Description                                         ||  ======   ============  =================================================   ||  Jun 96   Joel Gales    Original Programmer                                 ||  Aug 96   Joel Gales    Make metadata ODL compliant                         ||  Jan 97   Joel Gales    Check for metadata error status from EHgetmetavalue ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/int32SWdiminfo(int32 swathID, char *dimname){    intn            status;	/* routine return status variable */    int32           fid;	/* HDF-EOS file ID */    int32           sdInterfaceID;	/* HDF SDS interface ID */    int32           swVgrpID;	/* Swath root Vgroup ID */    int32           size;	/* Dimension size */    int32           idOffset = SWIDOFFSET;	/* Swath ID offset */    char           *metabuf;	/* Pointer to structural metadata (SM) */    char           *metaptrs[2];/* Pointers to begin and end of SM section */    char            swathname[80];	/* Swath Name */    char           *utlstr;	/* Utility string */    /* Allocate space for utility string */    /* --------------------------------- */    utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));    if(utlstr == NULL)    { 	HEpush(DFE_NOSPACE,"SWdiminfo", __FILE__, __LINE__);	return(-1);    }    /* Initialize return value */    size = -1;    /* Check Swath ID */    status = SWchkswid(swathID, "SWdiminfo", &fid, &sdInterfaceID, &swVgrpID);    if (status == 0)    {	/* Get swath name */	Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname);	/* Get pointers to "Dimension" section within SM */	metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",				       "Dimension", metaptrs);	if(metabuf == NULL)	{	    free(utlstr);	    return(-1);	}  	/* Search for dimension name (surrounded by quotes) */	sprintf(utlstr, "%s%s%s", "\"", dimname, "\"\n");	metaptrs[0] = strstr(metaptrs[0], utlstr);	/*	 * If dimension found within swath structure then get dimension value	 */	if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)	{	    /* Set endptr at end of dimension definition entry */	    metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");	    status = EHgetmetavalue(metaptrs, "Size", utlstr);	    if (status == 0)	    {		size = atol(utlstr);	    }	    else	    {		HEpush(DFE_GENAPP, "SWdiminfo", __FILE__, __LINE__);		HEreport("\"Size\" string not found in metadata.\n");	    }	}	else	{	    HEpush(DFE_GENAPP, "SWdiminfo", __FILE__, __LINE__);	    HEreport("Dimension \"%s\" not found.\n", dimname);	}	free(metabuf);    }    free(utlstr);    return (size);}

⌨️ 快捷键说明

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