/* * Copyright(c) 2006, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt */ /**** $Id: mod3adir.c,v 1.3 2006/05/19 19:44:43 rickk Tst $ ****/ /* ** Name: ** mod3adir : ADDE directory server for MODIS geo arrays ** ** Interface: ** int ** main(int argc, char *argv[]) ** ** Input: ** argc : argument count ** argv : argument vector ** ** Input and Output: ** none ** ** Output: ** none ** ** Return values: ** 0 : success ** < 0 : failure, enumerated by text message returned to client ** ** Remarks: ** ** Categories: ** ADDE server */ /* C include files */ #include #include #include #include /* McIDAS include files */ #include "mcidas.h" #include "mcidasp.h" #include "m0glue.h" #include "m0arg.h" /* HDF include files */ #include "mfhdf.h" #include "hdf.h" #include "modx.h" int GetModsCards (int *, int*, float, float, float, float, int *, int, int); int main ( int argc, char **argv ) #define DIR_SIZE 64 #define IMAGE_STARTING_LINE 1 #define IMAGE_STARTING_ELEMENT 1 #define IMAGE_FILE_VERSION 4 #define MAX_STR_LEN 80 #define MAX_ATR_LEN 80 #define MAX_BANDS 64 { /* * variables used: * * dum dummy for arg fetchers * bDate, eDate beginning, ending day * bTime, eTime beginning, ending time * bPos, ePos beginning, ending position number * bSS, eSS beginning, ending sensor source number * checkSS flag to indicate SS keyword was used * checkTime flag to indicate TIME keyword was used * checkDay flag to indicate DAY keyword was used * dummy dummy position number * cAux holder for AUX keyword text * group descriptor name desired, ie CONUS, NH, etc. * mask file search patterm mask * dscInfo descriptor file info structure * dfp, ifp descriptor and index file pointers * ALL variable to hold & compare text for "ALL " * imgCount number of images currently available this type * tmpCount temp image count * negCount num positions to skip if client gave neg position range * listCount count of number of images listed * posNum position number * rc return code holder * numBytes number of bytes sent to client each transaction * areaDir area directory * navCod navigation codicil * cards area file comment cards * firstNode pointer to first position list node * tmpNode temporary position node pointer * oldNode, newNode old, new position node pointers * curDate, curTime current date, time * tmpDate, tmpTime temporary date, time * i loop control variable * tp time struct * gmtPtr pointer to gmt time struct * loBound, hiBound low, high position bounds for argument validation * server text name for server started * request pointer to client request text * requestBlock request block servacct struct * auxFlag flag to indicate whether AUX=YES keyword was used */ const char *dum; /* dummy for arg fetchers */ char *dataset; /* dataset name */ char *file_name; /* name of HDF file */ char *char_band; /* band name string */ int bufsize; int bDate; /* beginning date */ int bTime; /* beginning time */ int eDate; /* ending date */ int eTime; /* ending time */ int bPos, ePos; int bSS, eSS; int checkSS = 0; int checkTime = 0; int checkDay = 0; int checkBand = 0; int dummy = 9999; char *group, *cAux; char *cBand; int listCount = 0; int rc; int i; const char server[] = {"MOD3ADIR"}; char *request = NULL; servacct requestBlock = {0}; int auxFlag = 0; int trace = 0; int transaction = 0; int user = 0; /* stuff I added */ int MODIS_AUX_OFFSET = 1280; int MODIS_CAL_OFFSET = 768; int MODIS_NAV_OFFSET = 256; int MODIS_AUX_ENTRIES = 3; int MODIS_GEO_BAND_RES[12] = { 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000, 10000 }; char cards[24000]; char chhmm[5]; char *cdate; char *cday; char *chms; char *cname; char *cprod; char **flist; char *type; char *format; char *info; char *comment; char *mask; int ALL; int data_prefix; int directory[64]; int hiBound; int iPos; int jPos; int FPos; int length; int loBound; int num_band; int num_cards; int num_flist; int send_byte_total; int FLAG_5km_band; int FLAG_1km_band; int FLAG_250m_band; int minimum_band; int maximum_band; int bands[MAX_BANDS]; int band_res[MAX_BANDS]; int res_list[MAX_BANDS]; int got_bands[MAX_BANDS]; char attr_name[MAX_ATR_LEN]; char name[MAX_NC_NAME]; char *char_array; int bband; int eband; int file_handle; int image_dataset_position; int image_satellite_number; int image_line_size; int image_line_resolution; int image_element_size; int image_element_size_5km; int image_element_size_1km; int image_element_size_250m; int image_element_resolution; int image_data_size; int image_cyd; int image_iyd; int image_hms; int image_n_bands; int image_geo_line_size; int image_geo_element_size; int image_geo_data_size; int rt_flag; int ii; int jj; int atmos_type; int file_name_type; /* file naming convention 1=DACC, 2=DB */ intn status; int32 n_datasets; int32 n_file_attrs; int32 n_attr; int32 index; int32 sd_id; int32 sds_id; int32 sds_rank; int32 data_type; int32 sds_data_type; int32 count; int32 sds_n_attrs; int32 sds_dim_sizes[MAX_VAR_DIMS]; int32 start[MAX_VAR_DIMS]; int32 stride[MAX_VAR_DIMS]; int32 edge[MAX_VAR_DIMS]; uint16 *uint16_array; float image_geo_latitude; float image_geo_longitude; float image_geo_line_resolution; float image_geo_element_resolution; float image_km_resolution; float32 *float32_array; float32 float32_val; unsigned int ival; McArgSyntax filesyntax = {".", "=", ";", "{\"", "}", "'", "'", NULL, "X", " "}; static char trace_string[500]; /* tracing text */ /* stuff I added */ /* variable for "ALL" */ (void) memcpy(&ALL, "ALL ", 4 ); M0swbyt4( &ALL, 1); /* initialize local server */ rc = M0InitLocalServer(server, argc, argv, &requestBlock, &request); /* see if logging should be done, determined by hidden TRACE= flag */ trace = M0IsTraceSet(request); (void *)sprintf(trace_string, "%s MOD3ADIR Trace Level = %d", server, trace); M0sxtrce( trace_string ); /* move the request back into the comm block */ (void) strncpy(requestBlock.text, request, sizeof(requestBlock.text)); /* fill in the data type */ transaction = atoi(argv[5]); (void) memcpy(requestBlock.transaction, &transaction, sizeof(requestBlock.transaction)); /* fill in the user */ user = atoi(argv[3]); (void) memcpy(requestBlock.user, &user, sizeof(requestBlock.user)); /* initialize accounting */ m0vserv_(&requestBlock); /* get dataset info */ rc = M0sxdatasetinfo(request, &group, &dataset, &type, &format, &mask, &info, &comment, &loBound, &hiBound, &rt_flag); sprintf(trace_string, "%s group = %s", server,group); M0sxtrce( trace_string ); sprintf(trace_string, "%s dataset = %s", server,dataset); M0sxtrce( trace_string ); sprintf(trace_string, "%s type = %s", server,type); M0sxtrce( trace_string ); sprintf(trace_string, "%s format = %s", server,format); M0sxtrce( trace_string ); sprintf(trace_string, "%s mask = %s", server,mask); M0sxtrce( trace_string ); sprintf(trace_string, "%s info = %s", server,info); M0sxtrce( trace_string ); sprintf(trace_string, "%s comment = %s", server,comment); M0sxtrce( trace_string ); /* log the request text string */ sprintf(trace_string, "%s Request = %s", server,request); M0sxtrce( trace_string ); /* DATASET name */ sprintf(trace_string,"%s Dataset = %s", server,group); M0sxtrce( trace_string ); /* must read ADDE dataset info file to get the file mask */ sprintf(trace_string, "%s File Mask = %s", server,mask); M0sxtrce( trace_string ); /* produce a list of files matching the pattern mask */ flist = M0GetMaskFileList(mask); if( flist == (char **)NULL ) { (void)strcpy(requestBlock.errormsg, "No images satisfy selection criteria"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* number of files found -> log the list */ num_flist = VecLen(flist); sprintf(trace_string, "%s Number of file found = %d", server, num_flist); M0sxtrce( trace_string ); for( i=0; i 0 ) { rc = Mcargstr(0,"BAN.D",1,"ALL",(const char **) &cBand); if (strncmp(cBand, "ALL", 3) == 0) { bband = 99999; eband = 99999; } else { /* read the beginning band */ rc = Mcargint(0,"BAN.D",1,1,1,64,&bband,&dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid band number specified"); requestBlock.returncode = -34; M0sxdone(&requestBlock); return (0); } /* read the ending band */ rc = Mcargint(0,"BAN.D",2,bband,bband,64,&eband,&dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid band number specified"); requestBlock.returncode = -34; M0sxdone(&requestBlock); return (0); } } } sprintf(trace_string,"%s bband=%d eband=%d", server,bband,eband); M0sxtrce( trace_string ); /* POS sort condition */ rc = Mcargint(0, " ", 2, 0, -99999, num_flist, &bPos, &dum); if( bPos == ALL ) { bPos = 1; ePos = num_flist; iPos = 1; } else { if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Beginning Position"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } if( bPos <= 0 ) { ePos = num_flist + bPos; if( ePos <= 0 ) ePos = 1; /* FPos is a flag to indicate only latest image */ FPos = 0; if( bPos == 0 ) { FPos = 1; ePos = 1; } bPos = num_flist; iPos = -1; } else { rc = Mcargint(0, " ", 3, bPos, bPos, 99999, &ePos, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Ending Position"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } if( ePos > num_flist ) ePos = num_flist; iPos = 1; } } sprintf(trace_string, "%s bPos: %d, ePos: %d", server, bPos, ePos); M0sxtrce( trace_string ); /* TIME sort condition */ checkTime = Mcargnum(0, "TIM.E"); if( checkTime != 0 ) { rc = Mcargihr(0, "TIM.E", 1, -1, -1, 240000, &bTime, &dum); rc = Mcargihr(0, "TIM.E", 2, bTime, -1, 240000, &eTime, &dum); sprintf(trace_string, "%s bTime: %d, eTime: %d", server, bTime, eTime); M0sxtrce( trace_string ); } /* DAY sort condition */ checkDay = Mcargnum(0, "DAY" ); if( checkDay != 0 ) { rc = Mcargiyd(0, "DAY", 1, -1, 999, -999, &bDate, &dum); rc = Mcargiyd(0, "DAY", 2, bDate, 999, -999, &eDate, &dum); /* put in YYYDDD format (year modulo 1900) */ if ((bDate / 1000) >= 2000) { bDate = ((bDate / 1000) % 1900) * 1000 + (bDate % 1000); } else { bDate = bDate % 100000; } if ((eDate / 1000) >= 2000) { eDate = ((eDate / 1000) % 1900) * 1000 + (eDate % 1000); } else { eDate = eDate % 100000; } sprintf(trace_string, "%s bDate: %d, eDate: %d", server, bDate, eDate); M0sxtrce( trace_string ); } /* SS sort condition */ checkSS = Mcargnum(0, "SS" ); if( checkSS != 0 ) { rc = Mcargint(0, "SS", 1, -1, 999, -999, &bSS, &dum); rc = Mcargint(0, "SS", 2, bSS, 999, -999, &eSS, &dum); sprintf(trace_string, "%s bSS: %d, eSS: %d", server, bSS, eSS); M0sxtrce( trace_string ); } /* AUX sort condition */ rc = Mcargstr(0, "AUX", 1, "NO", (const char **) &cAux); if (strncmp(cAux, "YES", 3) == 0) { auxFlag = 1; } else { auxFlag = 0; } sprintf(trace_string, "%s value for AUX flag: %d", server, auxFlag); M0sxtrce( trace_string ); sprintf(trace_string, "%s BEFORE MAIN LOOP --- bpos=%d epos=%d ipos=%d", server, bPos, ePos, iPos); M0sxtrce( trace_string ); /* initialization */ listCount= 0; /* Dataset Loop starts here */ for( image_dataset_position=bPos*iPos; image_dataset_position<=ePos*iPos; image_dataset_position++ ) { jPos = iPos * image_dataset_position; /* copy the file name from the list */ file_name = flist[jPos-1]; /* SDS variable initialization */ image_n_bands= 0; image_line_size= 0; image_element_size= 0; image_data_size= 0; /* Parse the file name into components */ file_handle = Mcargparse( file_name, &filesyntax, &length); /* Initialize band traping array */ for( i=0; i 0 ) { if( (image_iyd < bDate) || (image_iyd > eDate) ) continue; } /* Evaluate the file name for image time (HHMMSS) */ rc = Mcargstr( file_handle, " ", 2, " ", (const char **)&chms); (void) strncpy(chhmm, chms, 4 ); chhmm[4] = '\0'; rc = Mcstrtoint( chhmm, &image_hms ); image_hms = image_hms * 100; sprintf(trace_string, "%s image_hms: char=%s int=%d", server, chhmm, image_hms); M0sxtrce( trace_string ); /* Check client search conditions: TIME=bTIME eTIME */ if (checkTime > 0 ) { if( (image_hms < bTime) || (image_hms > eTime) ) continue; } /* start the HDF file */ sd_id = SDstart( file_name, DFACC_READ ); if( sd_id == FAIL ) { sprintf(trace_string, "%s START: FAILED for %s", server, file_name); M0sxtrce( trace_string ); continue; } /* determine the number of SDS's in the file */ status = SDfileinfo( sd_id, &n_datasets, &n_file_attrs ); if( status == FAIL ) { sprintf(trace_string, "%s FILE INFO FAILED for %s", server, file_name ); M0sxtrce( trace_string ); continue; } /* loop through the individual SDS's */ for( index=0; index 0 ) { if( (image_satellite_number < bSS) || (image_satellite_number > eSS) ) break; } /* Check : BAND=bSS eSS */ for( i=bband; i<=eband; ++i ) { if( got_bands[i-1] == 1 ) checkBand = 1; } if( checkBand == 0 ) break; /* build the directory block */ for( i=0; i