/////////////////////////////////////////////////////////////////////////// // NAME: isUSA.cpp // FUNCTION: This program is to read hdf SDS information // and decide if the granule passes the U.S.A. // DESCRIPTION: N/A // REFERENCE: none // CALLING SEQUENCE: N/A // INPUTS: none // OUTPUTS: none // DEPENDENCIES: none // RESTRICTIONS: none // HISTORY: none ////////////////////////////////////////////////////////////////////////// //#include "mfhdf.h" #include #include #include #include #include #include #include #include "ABI_GranuleData.h" #include "ABI_const.h" using namespace std; #define lat_name "Latitude" #define lon_name "Longitude" #define Y_size 2030 #define X_size 1354 #define north 50 #define south 25 #define west -125 #define east -65 int main(int argc, char *argv[]) { /**********************variable declaration**********************/ int32 sd_id, sds_id; intn status; int32 n_datasets, n_file_attrs, index; int32 dim_sizes[2]; int32 rank, data_type, n_attrs; int32 start[2], edges[2]; char name[256]; char FILE_NAME[256]; static float32 lat[Y_size][X_size],lon[Y_size][X_size]; int i, j; long int num; int stat; /****************************************************************/ if(argc <= 1) { printf("USAGE: inUSA filename\n"); printf("EX: ./isUSA.exe MOD03.P2011349.1905.hdf \n"); exit(0); } /* read input hdf files */ strcpy(FILE_NAME,argv[1]); printf("Input hdf file -- %s \n",FILE_NAME); sd_id = SDstart (FILE_NAME, DFACC_READ); status = SDfileinfo (sd_id, &n_datasets, &n_file_attrs); printf("n_datasets,%d\n",n_datasets); /*******************print out SDS information********************/ for (index = 0; index < n_datasets; index++) { sds_id = SDselect (sd_id, index); status = SDgetinfo (sds_id, name, &rank, dim_sizes, &data_type, &n_attrs); start[0] = 0; start[1] = 0; // the start position of the data to be read edges[0] = Y_size; edges[1] = X_size; // the size of the data to be read //printf ("name = %s %s %s \n", name, lat_name, lon_name); if (strcmp(name, lat_name) == 0) { printf ("\nindex = %d\n", index); printf ("sds_id = %d\n", sds_id); printf ("name = %s\n", name); SDreaddata(sds_id, start, NULL, edges, (VOIDP)lat); } if (strcmp(name,lon_name) == 0) { printf ("\nindex = %d\n", index); printf ("sds_id = %d\n", sds_id); printf ("name = %s\n", name); SDreaddata(sds_id, start, NULL, edges, (VOIDP)lon); } status = SDendaccess (sds_id); } /*******************end of SDS information********************/ status = SDend (sd_id); num=0l; for (i = 0; i < X_size; i++) for (j = 0; j < Y_size; j++) { //printf ("lon, lat= %6.2f %5.2f\n", lon[j][i], lat[j][i]); if ((lon[j][i] >= west) && (lon[j][i] <= east) && (lat[j][i] >= south) && (lat[j][i] <= north)) { num++; } } if (num >= 8000l) { printf ("Granule is in USA!\n"); printf ("%d\n",1); printf ("pixels= %ld \n", num); } else { printf ("Granule is not in USA!\n"); printf ("%d\n",0); printf ("pixels= %ld \n", num); } return 0; }