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

📄 swapi.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
/*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.*//*****************************************************************************REVISIONS:Aug 31, 1999  Abe Taaheri    Changed memory allocation for utility strings to                             the size of UTLSTR_MAX_SIZE.			     Added error check for memory unavailibilty in 			     several functions.			     Added check for NULL metabuf returned from 			     EHmeta... functions. NULL pointer retruned from 			     EHmeta... functions indicate that memory could not			     be allocated for metabuf.June 05, 2003 Abe Taaheri / Bruce Beaumont                            Changed MAXNREGIONS to 1024 to support MOPITT data			    Supplied cast for compcode in call to 			      SDsetcompress to avoid compiler error			    Removed declaration for unused variable rstatus 			      in SWwrrdfield			    Removed initialization code for unused variables 			      in SWwrrdfield			    Removed declaration for unused variable tmpVal 			      in SWdefboxregion			    Added code in SWdefboxregion to check for index k			      exceeding NSWATHREGN to avoid overwriting 			      memory			    Removed declaration for unused variable retchar 			      in SWregionindex			    Removed initialization code for unused variables 			      in SWregionindex			    Removed declarations for unused variables tstatus,			      nfields, nflgs, and swathname in SWextractregion			    Removed initialization code for unused variables 			      in SWextractregion			    Removed declaration for unused variable 			      land_status in SWscan2longlat			    Removed initialization code for unused variables 			      in SWscan2longlat			    Added clear (0) of timeflag in SWextractperiod if 			      return status from SWextractregion is non-zero			    Removed declarations for unused variables tstatus,			      scandim, ndfields, ndflds, and swathname in 			      SWregioninfo			    Removed initialization code for unused variables 			      in SWregioninfo			    Added clear (0) of timeflag in SWperiodinfo if 			      return status from SWregioninfo is non-zero			    Removed declarations for unused variables size, 			      nfields, nflds, nswath, idxsz, cornerlon, and 			      cornerlat in SWdefscanregion			    Removed initialization code for unused variables 			      in SWdefscanregion			    Removed declarations for unused variables dims2, 			      rank, nt, swathname, dimlist, and buffer in 			      SWupdateidxmap			    Removed declaration for unused variable statmeta 			      in SWgeomapinfo******************************************************************************/#include "mfhdf.h"#include "hcomp.h"#include "cfortHdf.h"#include "HdfEosDef.h"#include <math.h>#define SWIDOFFSET 1048576int32 SWX1dcomb[512*3];int32 SWXSDcomb[512*5];char  SWXSDname[HDFE_NAMBUFSIZE];char  SWXSDdims[HDFE_DIMBUFSIZE];/* This flag was added to allow the Time field to have different Dimensions** than Longitude and Latitude and still be used for subsetting** 23 June,1997  DaW*/intn  timeflag = 0;/* Added for routine that converts scanline to Lat/long** for floating scene subsetting** Jul 1999 DaW*/#define PI      3.141592653589793238#define RADOE	6371.0		/* Radius of Earth in Km */#define NSWATH 200/* Swath Structure External Arrays */struct swathStructure {    int32 active;    int32 IDTable;    int32 VIDTable[3];    int32 fid;    int32 nSDS;    int32 *sdsID;    int32 compcode;    intn  compparm[5];    int32 tilecode;    int32 tilerank;    int32 tiledims[8];};struct swathStructure SWXSwath[NSWATH];#define NSWATHREGN 256#define MAXNREGIONS 1024struct swathRegion{    int32 fid;    int32 swathID;    int32 nRegions;    int32 StartRegion[MAXNREGIONS];    int32 StopRegion[MAXNREGIONS];    int32 StartVertical[8];    int32 StopVertical[8];    int32 StartScan[8];    int32 StopScan[8];    char *DimNamePtr[8];    intn band8flag;    intn  scanflag;};struct swathRegion *SWXRegion[NSWATHREGN];/* define a macro for the string size of the utility strings. The value   of 80 in previous version of this code was resulting in core dump (Array    Bounds Write and Array Bounds Read problem in SWfinfo function and the    functions called from there) for 7-8 dimensional fields where the    string length for "DimList" can exceed 80 characters, including " and    commas in the string. The length now is 512 which seems to be more    than enough to avoid the problem mentioned above. */   #define UTLSTR_MAX_SIZE 512/* Swath Prototypes (internal routines) */intn SWchkswid(int32, char *, int32 *, int32 *, int32 *);int32 SWimapinfo(int32, char *, char *, int32 []);int32 SWfinfo(int32, char *, char *, int32 *, int32 [], int32 *, char *);intn SWfldinfo(int32, char *, int32 *, int32 [], int32 *, char *);intn SWdefimap(int32, char *, char *, int32 []);intn SWdefinefield(int32, char *, char *, char *, int32, int32);intn SWdefgfld(int32, char *, char *, int32, int32);intn SWdefdfld(int32, char *, char *, int32, int32);intn SWwrgmeta(int32, char *, char *, int32);intn SWwrdmeta(int32, char *, char *, int32);intn SWwrrdattr(int32, char *, int32, int32, char *, VOIDP);intn SW1dfldsrch(int32, int32, char *, char *, int32 *, int32 *, int32 *);intn SWSDfldsrch(int32, int32, char *, int32 *, int32 *,                  int32 *, int32 *, int32 [], int32 *);intn SWwrrdfield(int32, char *, char *, int32 [], int32 [], int32 [], VOIDP);intn SWwrfld(int32, char *, int32 [], int32 [], int32 [], VOIDP);intn SWrdfld(int32, char *, int32 [], int32 [], int32 [], VOIDP);intn SWreginfo(int32, int32, char *, int32 *, int32 *, int32 [], int32 *);intn SWperinfo(int32, int32, char *, int32 *, int32 *, int32 [], int32 *);int32 SWinqfields(int32, char *, char *, int32 [], int32 []);int32 SWdefvrtreg(int32, int32, char *, float64 []);intn SWscan2longlat(int32, char *, VOIDP, int32 [], int32 [], int32 *,                    int32, int32);/*----------------------------------------------------------------------------||  BEGIN_PROLOG                                                               ||                                                                             ||  FUNCTION: SWopen                                                           ||                                                                             ||  DESCRIPTION:                                                               ||                                                                             ||                                                                             ||  Return Value    Type     Units     Description                             ||  ============   ======  =========   =====================================   ||  fid            int32               HDF-EOS file ID                         ||                                                                             ||  INPUTS:                                                                    ||  filename       char                Filename                                ||  access         intn                HDF access code                         ||                                                                             ||                                                                             ||  OUTPUTS:                                                                   ||             None                                                            ||                                                                             ||  NOTES:                                                                     ||                                                                             ||                                                                             ||   Date     Programmer   Description                                         ||  ======   ============  =================================================   ||  Jun 96   Joel Gales    Original Programmer                                 ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/int32SWopen(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: SWcreate                                                         ||                                                                             ||  DESCRIPTION: Creates a new swath structure and returns swath ID            ||                                                                             ||                                                                             ||  Return Value    Type     Units     Description                             ||  ============   ======  =========   =====================================   ||  swathID        int32               Swath structure ID                      ||                                                                             ||  INPUTS:                                                                    ||  fid            int32               File ID                                 ||  swathname      char                Swath structure name                    ||                                                                             ||  OUTPUTS:                                                                   ||             None                                                            ||                                                                             ||  NOTES:                                                                     ||                                                                             ||                                                                             ||   Date     Programmer   Description                                         ||  ======   ============  =================================================   ||  Jun 96   Joel Gales    Original Programmer                                 ||  Aug 96   Joel Gales    Make metadata ODL compliant                         ||  Sep 96   Joel Gales    Check swath name for length                         ||  Mar 97   Joel Gales    Enlarge utlbuf to 512                               ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/int32SWcreate(int32 fid, char *swathname){    intn            i;		/* Loop index */    intn            nswathopen = 0;	/* # of swath structures open */    intn            status = 0;	/* routine return status variable */    uint8           access;	/* Read/Write file access code */    int32           HDFfid;	/* HDF file id */    int32           vgRef;	/* Vgroup reference number */    int32           vgid[4];	/* Vgroup ID array */    int32           swathID = -1;	/* HDF-EOS swath ID */    int32           sdInterfaceID;	/* HDF SDS interface ID */    int32           idOffset = SWIDOFFSET;	/* Swath ID offset */    int32           nSwath = 0;	/* Swath counter */    char            name[80];	/* Vgroup name */    char            class[80];	/* Vgroup class */    char            errbuf[256];/* Buffer for error message */    char            utlbuf[512];/* Utility buffer */    char            utlbuf2[32];/* Utility buffer 2 */    /*     * Check HDF-EOS file ID, get back HDF file ID, SD interface ID  and     * access code     */    status = EHchkfid(fid, swathname, &HDFfid, &sdInterfaceID, &access);    /* Check swathname for length */    /* -------------------------- */    if ((intn) strlen(swathname) > VGNAMELENMAX)    {	status = -1;	HEpush(DFE_GENAPP, "SWcreate", __FILE__, __LINE__);	HEreport("Swathname \"%s\" must be less than %d characters.\n",		 swathname, VGNAMELENMAX);    }    if (status == 0)    {	/* Determine number of swaths currently opened */	/* ------------------------------------------- */	for (i = 0; i < NSWATH; i++)	{	    nswathopen += SWXSwath[i].active;	}	/* Setup file interface */	/* -------------------- */	if (nswathopen < NSWATH)	{	    /* Check that swath 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 SWATH then increment # swath counter */		/* --------------------------------------- */		if (strcmp(class, "SWATH") == 0)		{		    nSwath++;		}		/* If swath already exist, return error */		/* ------------------------------------ */		if (strcmp(name, swathname) == 0 &&		    strcmp(class, "SWATH") == 0)		{		    status = -1;		    HEpush(DFE_GENAPP, "SWcreate", __FILE__, __LINE__);		    HEreport("\"%s\" already exists.\n", swathname);		    break;		}	    }	    if (status == 0)	    {		/* Create Root Vgroup for Swath */		/* ---------------------------- */		vgid[0] = Vattach(HDFfid, -1, "w");		/* Set Name and Class (SWATH) */		/* -------------------------- */

⌨️ 快捷键说明

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