/* * Copyright(c) 1997, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt */ /**** $Id: modsadir.c,v 1.24 2019/11/07 15:03:06 russd Tst $ ****/ /* ** Name: ** modsadir : ADDE directory server for HDF-EOS MODIS data. ** ** 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" int GetModsCards (int *, int*, float, float, float, float, 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 38 /* TERRA SATELLITE */ #define TERRA_RAW 101 #define TERRA_PRODUCT 102 #define AQUA_RAW 111 #define AQUA_PRODUCT 112 #define TERRA_MIN_BAND 1 #define TERRA_MAX_BAND 38 { /* * 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 dummy = 9999; char *group, *cAux; char *cBand; int listCount = 0; int rc; int i,j; const char server[] = {"MODSADIR"}; 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; char cards[24000]; char *cdate; char *cday; char *chms; char *cname; char *comment; /* ADDE dataset comment */ char **flist; char *file_list[1000]; char *format; /* ADDE dataset format */ char *info; /* ADDE dataset info */ char *mask; /* file mask */ char *type; /* ADDE dataset type */ 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; char attr_name[MAX_ATR_LEN]; char name[MAX_NC_NAME]; char *char_array; 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_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 bands[MAX_BANDS]; int rt_flag; int file_name_type; /* file naming convention 1=DACC, 2=Direct broadcast */ int N_tokens; int I_token; int B_token; 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", " "}; /* 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 NEW MODSADIR 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); } num_flist = VecLen(flist); /* screen the list for crefl files */ j = 0; for( i=0; i 0 ) { int i; rc = Mcargstr(0,"BAN.D",1,"ALL",(const char **) &cBand); if (strncmp(cBand, "ALL", 3) == 0) { sprintf(trace_string,"%s Looking for ALL bands", server); M0sxtrce( trace_string ); num_band = TERRA_MAX_BAND; for( i=0; i 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 = file_list[jPos-1]; /* SDS variable initialization */ image_n_bands= 0; image_line_size= 0; image_element_size= 0; /* Parse the file name into components */ file_handle = Mcargparse( file_name, &filesyntax, &length); /* BEGIN patch added to allow the file_name string to contain a "." character */ /* number of parsed tokens */ N_tokens = Mcargnum(file_handle, ""); /* scan IMG file name for file type */ B_token = 0; for( I_token=0; I_token 0 ) { if( (image_iyd < bDate) || (image_iyd > eDate) ) continue; } /* Evaluate the file name: Time (HHMMSS) */ rc = Mcargstr( file_handle, " ", B_token+2, " ", (const char **)&chms); rc = Mcstrtoint( chms, &image_hms ); image_hms = image_hms * 100; sprintf(trace_string, "%s image_hms %d", server, 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 FILEINFO 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; } /* build a directory block */ for( i=0; i