/****************************************************************************/ /* This program demonstrates how to read a field from a GMAO HDF-EOS */ /* product using the HDF-EOS library. It will take a file name and */ /* field name on the command line, read the first time of the given */ /* field, calculate an average of that time and print the average. */ /* */ /* usage: avg */ /* */ /* Rob Lucchesi */ /* rlucchesi@GMAO.gsfc.nasa.gov */ /* 2/12/1999 */ /****************************************************************************/ #include "hdf.h" #include "mfhdf.h" #include #define XDIM 288 #define YDIM 181 #define ZDIM 36 main(int argc,char *argv[]) { int32 sd_id, sds_id, status; int32 sds_index; int32 start[4], edges[4], stride[4]; char *fname, *vname; float32 data_array[ZDIM][YDIM][XDIM]; float32 avg, sum; int32 i,j,k; int32 file_id, gd_id; if (argc != 3) { printf("Usage: avg \n"); exit (-1); } fname = argv[1]; vname = argv[2]; /* Open the file (read-only) */ file_id = GDopen (fname, DFACC_RDONLY); if (file_id < 0) { printf ("Could not open %s\n",fname); exit(-1); } /* Attach to the EOS grid contained within the file. */ /* The GMAO uses the generic name "EOSGRID" for the grid in all products. */ gd_id = GDattach (file_id,"EOSGRID"); if (gd_id < 0) { printf ("Could not open %s\n",fname); exit(-1); } /* Set positioning arrays to read the entire field at the first time. */ start[0] = 0; start[1] = 0; start[2] = 0; start[3] = 0; stride[0] = 1; stride[1] = 1; stride[2] = 1; stride[3] = 1; edges[0] = 1; edges[1] = ZDIM; edges[2] = YDIM; edges[3] = XDIM; /* In this program, we read the entire field. By manipulating the start and edges arrays, it is possible to read a subset of the entire array. For example, to read a 3D section defined by x=100,224; y=50,149; z=15,16 you would set the start and edges arrays to the following: start[0] = 0; time start location start[1] = 15; z-dim start location start[2] = 50; y-dim start location start[3] = 100; x-dim start location edges[0] = 1; time length edges[1] = 2; z-dim length edges[2] = 100; y-dim length edges[3] = 125; x-dim length */ /* Read the data into data_array */ status = GDreadfield (gd_id, vname, start, stride, edges, data_array); printf ("Read status=%d\n",status); /* Calculate and print the average */ sum=0.0; for (i=0; i */ /* */ /* Rob Lucchesi */ /* rlucchesi@gmao.gsfc.nasa.gov */ /* 2/12/1999 */ /****************************************************************************/ #include "hdf.h" #include "mfhdf.h" #include #define XDIM 288 #define YDIM 181 #define ZDIM 36 main(int argc,char *argv[]) { int32 sd_id, sds_id, status; int32 sds_index; int32 start[4], edges[4], stride[4]; char *fname, *vname; float32 data_array[ZDIM][YDIM][XDIM]; float32 avg, sum; int32 i,j,k; if (argc != 3) { printf("Usage: avg \n"); exit (-1); } fname = argv[1]; vname = argv[2]; /* Open the file (read-only) */ sd_id = SDstart (fname, DFACC_RDONLY); if (sd_id < 0) { printf ("Could not open %s\n",fname); exit(-1); } /* Find the index and ID of the SDS for the given variable name. */ sds_index = SDnametoindex (sd_id, vname); if (sds_index < 0) { printf ("Could not find %s\n",vname); exit(-1); } sds_id = SDselect (sd_id,sds_index); /* Set positioning arrays to read the entire field at the first time. */ start[0] = 0; start[1] = 0; start[2] = 0; start[3] = 0; stride[0] = 1; stride[1] = 1; stride[2] = 1; stride[3] = 1; edges[0] = 1; edges[1] = ZDIM; edges[2] = YDIM; edges[3] = XDIM; /* In this program, we read the entire field. By manipulating the start and edges arrays, it is possible to read a subset of the entire array. For example, to read a 3D section defined by x=100,224; y=50,149; z=15,16 you would set the start and edges arrays to the following: start[0] = 0; time start location start[1] = 15; z-dim start location start[2] = 50; y-dim start location start[3] = 100; x-dim start location edges[0] = 1; time length edges[1] = 2; z-dim length edges[2] = 100; y-dim length edges[3] = 125; x-dim length */ /* Read the data into data_array */ status = SDreaddata (sds_id, start, stride, edges, (VOIDP) data_array); printf ("read status=%d\n",status); /* Calculate and print the average */ sum=0.0; for (i=0; i