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

📄 ehapi.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.*/#ifdef WIN32#include <windows.h>	//bwf#include <winbase.h>	//bwf#define sleep Sleep#endif#include <errno.h>#include "mfhdf.h"#include "cfortHdf.h"#include "HdfEosDef.h"/* Set maximun number of HDF-EOS files to HDF limit (MAX_FILE) *//* #define NEOSHDF MAX_FILE */#define NEOSHDF 200uint8 EHXtypeTable[NEOSHDF];uint8 EHXacsTable[NEOSHDF];int32 EHXfidTable[NEOSHDF];int32 EHXsdTable[NEOSHDF];/* define a macro for the string size of the utility strings and some dimension   list strings. The value in previous versions of this code may not be    enough in some cases. The length now is 512 which seems to be more than    enough to hold larger strings. */   #define UTLSTR_MAX_SIZE 512#define UTLSTRSIZE  32000#define EHIDOFFSET 524288#define HDFEOSVERSION 2.10#define HDFEOSVERSION1 "2.10"#include <HDFEOSVersion.h>#define MAX_RETRIES 10/* HDF types used in FORTRAN bindings */#if defined(DEC_ALPHA) || defined(IRIX) || defined(UNICOS)#define INT32  INT#define INT32V INTV#define PINT32 PINT#else#define INT32  LONG#define INT32V LONGV#define PINT32 PLONG#endif/* Function Prototypes */intn EHmetalist(char *, char *);/*----------------------------------------------------------------------------||  BEGIN_PROLOG                                                               ||                                                                             ||  FUNCTION: EHopen                                                           ||                                                                             ||  DESCRIPTION: Opens HDF-EOS file and returns file handle                    ||                                                                             ||                                                                             ||  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                                 ||  Jul 96   Joel Gales    Add file id offset EHIDOFFSET                       ||  Aug 96   Joel Gales    Add "END" statment to structural metadata           ||  Sep 96   Joel Gales    Reverse order of Hopen ane SDstart statements       ||                         for RDWR and READ access                            ||  Oct 96   Joel Gales    Trap CREATE & RDWR (no write permission)            ||                         access errors                                       ||  Apr 97   Joel Gales    Fix problem with RDWR open when file previously     ||                         open for READONLY access                            ||                                                                             ||  END_PROLOG                                                                 |-----------------------------------------------------------------------------*/int32EHopen(char *filename, intn access){    intn            i;		/* Loop index */    intn            status = 0;	/* routine return status variable */    intn            dum;	/* Dummy variable */    int32           HDFfid;	/* HDF file ID */    int32           fid;	/* HDF-EOS file ID */    int32           sdInterfaceID;	/* HDF SDS interface ID */    int32           nfileopen = 0;	/* # of HDF files open */    int32           attrIndex;	/* Structural Metadata attribute index */    uint8           acs;	/* Read (0) / Write (1) access code */    char           *testname;	/* Test filename */    char            errbuf[256];/* Error report buffer */    char           *metabuf;	/* Pointer to structural metadata buffer */    char            hdfeosVersion[32];	/* HDFEOS version string */    intn            retryCount;    /* Determine number of files currently opened */    /* ------------------------------------------ */    for (i = 0; i < NEOSHDF; i++)    {	nfileopen += EHXtypeTable[i];    }    /* Setup file interface */    /* -------------------- */    if (nfileopen < NEOSHDF)    {	/*	 * Check that file has not been previously opened for write access if	 * current open request is not READONLY	 */	if (access != DFACC_READ)	{	    /* Loop through all files */	    /* ---------------------- */	    for (i = 0; i < NEOSHDF; i++)	    {		/* if entry is active file opened for write access ... */		/* --------------------------------------------------- */		if (EHXtypeTable[i] != 0 && EHXacsTable[i] == 1)		{		    /* Get filename (testname) */		    /* ----------------------- */		    Hfidinquire(EHXfidTable[i], &testname, &dum, &dum);		    /* if same as filename then report error */		    /* ------------------------------------- */		    if (strcmp(testname, filename) == 0)		    {			status = -1;			fid = -1;			HEpush(DFE_ALROPEN, "EHopen", __FILE__, __LINE__);			HEreport("\"%s\" already open.\n", filename);			break;		    }		}	    }	}	if (status == 0)	{	    /* Create HDF-EOS file */	    /* ------------------- */	    switch (access)	    {	    case DFACC_CREATE:		/* Get SDS interface ID */		/* -------------------- */		sdInterfaceID = SDstart(filename, DFACC_CREATE);		/* If SDstart successful ... */		/* ------------------------- */		if (sdInterfaceID != -1)		{		    /* Set HDFEOS version number in file */		    /* --------------------------------- */		    sprintf(hdfeosVersion, "%s%s", "HDFEOS_V",			    HDFEOSVERSION1);		    SDsetattr(sdInterfaceID, "HDFEOSVersion", DFNT_CHAR8,			      strlen(hdfeosVersion), hdfeosVersion);		    /* Get HDF file ID */		    /* --------------- */		    HDFfid = Hopen(filename, DFACC_RDWR, 0);		    /* Set open access to write */		    /* ------------------------ */		    acs = 1;		    /* Setup structural metadata */		    /* ------------------------- */		    metabuf = (char *) calloc(32000, 1);		    if(metabuf == NULL)		    { 			HEpush(DFE_NOSPACE,"EHopen", __FILE__, __LINE__);			return(-1);		    }		    strcpy(metabuf, "GROUP=SwathStructure\n");		    strcat(metabuf, "END_GROUP=SwathStructure\n");		    strcat(metabuf, "GROUP=GridStructure\n");		    strcat(metabuf, "END_GROUP=GridStructure\n");		    strcat(metabuf, "GROUP=PointStructure\n");		    strcat(metabuf, "END_GROUP=PointStructure\n");		    strcat(metabuf, "END\n");		    /* Write Structural metadata */		    /* ------------------------- */		    SDsetattr(sdInterfaceID, "StructMetadata.0",			      DFNT_CHAR8, 32000, metabuf);		    free(metabuf);		} else		{		    /* If error in SDstart then report */		    /* ------------------------------- */		    fid = -1;		    status = -1;		    HEpush(DFE_FNF, "EHopen", __FILE__, __LINE__);		    sprintf(errbuf, "%s%s%s", "\"", filename,			    "\" cannot be created.");		    HEreport("%s\n", errbuf);		}		break;		/* Open existing HDF-EOS file for read/write access */		/* ------------------------------------------------ */	    case DFACC_RDWR:		/* Get HDF file ID */		/* --------------- */#ifndef _PGS_OLDNFS/* The following loop around the function Hopen is intended to deal with the NFS cache    problem when opening file fails with errno = 150 or 151. When NFS cache is updated,   this part of change is no longer neccessary.              10/18/1999   */                retryCount = 0;                HDFfid = -1;                while ((HDFfid == -1) && (retryCount < MAX_RETRIES))                {                HDFfid = Hopen(filename, DFACC_RDWR, 0);                if((HDFfid == -1) && (errno == 150 || errno == 151))                    {                    HEpush(DFE_FNF, "EHopen", __FILE__, __LINE__);                    sprintf(errbuf, "\"%s\" cannot be opened for READ/WRITE access, will retry %d times.", filename,  (MAX_RETRIES - retryCount - 1));                    HEreport("%s\n", errbuf);                    sleep(1);                    }                retryCount++;                }#else                HDFfid = Hopen(filename, DFACC_RDWR, 0);#endif		/* If Hopen successful ... */		/* ----------------------- */		if (HDFfid != -1)		{		    /* Get SDS interface ID */		    /* -------------------- */		    sdInterfaceID = SDstart(filename, DFACC_RDWR);                    /* If SDstart successful ... */                    /* ------------------------- */                    if (sdInterfaceID != -1)                    {                       /* Set HDFEOS version number in file */                       /* --------------------------------- */		      		      attrIndex = SDfindattr(sdInterfaceID, "HDFEOSVersion");		      if (attrIndex == -1)			{			  sprintf(hdfeosVersion, "%s%s", "HDFEOS_V",				  HDFEOSVERSION1);			  SDsetattr(sdInterfaceID, "HDFEOSVersion", DFNT_CHAR8,				    strlen(hdfeosVersion), hdfeosVersion);			}		       /* Set open access to write */		       /* ------------------------ */		       acs = 1;		       /* Get structural metadata attribute ID */		       /* ------------------------------------ */		       attrIndex = SDfindattr(sdInterfaceID, "StructMetadata.0");		       /* Write structural metadata if it doesn't exist */		       /* --------------------------------------------- */		       if (attrIndex == -1)		       {		   	  metabuf = (char *) calloc(32000, 1);			  if(metabuf == NULL)			  { 			      HEpush(DFE_NOSPACE,"EHopen", __FILE__, __LINE__);			      return(-1);			  }			  strcpy(metabuf, "GROUP=SwathStructure\n");			  strcat(metabuf, "END_GROUP=SwathStructure\n");			  strcat(metabuf, "GROUP=GridStructure\n");			  strcat(metabuf, "END_GROUP=GridStructure\n");			  strcat(metabuf, "GROUP=PointStructure\n");			  strcat(metabuf, "END_GROUP=PointStructure\n");			  strcat(metabuf, "END\n");			  SDsetattr(sdInterfaceID, "StructMetadata.0",				  DFNT_CHAR8, 32000, metabuf);			  free(metabuf);		       }                    } else                    {                        /* If error in SDstart then report */                        /* ------------------------------- */                        fid = -1;                        status = -1;                        HEpush(DFE_FNF, "EHopen", __FILE__, __LINE__);                        sprintf(errbuf, "%s%s%s", "\"", filename,                            "\" cannot be opened for read/write access.");

⌨️ 快捷键说明

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