/* * Copyright(c) 2008, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt */ /**** $Id: nssxadir.c,v 1.0 2008/10/01 19:13:50 russd Exp $ ****/ /* ** Name: ** nssxadir : ADDE directory server for NSS product images ** serves Observed radiances ** serves Cloud product ** serves Sea Surface Temperature product ** ** 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 GetNSSCards (int *, 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 30 #define MAX_AUX_SIZE 20000000 { /* * 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 *nav_name; /* name of GEO file */ char nav_string[6]; /* holds nav mask */ 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; int j; int ij; const char server[] = {"NSSXADIR"}; char *request = NULL; servacct requestBlock = {0}; int auxFlag = 0; int trace = 0; int transaction = 0; int user = 0; /* stuff I added */ int AUX_OFFSET = 1280; int CAL_OFFSET = 768; int NAV_OFFSET = 256; int AUX_ENTRIES = 2; int AUX_SIZE; char cards[24000]; char chhmm[5]; char *cdate; char *cstime; char *cyear; char *cday; char *chms; char *coverage; char *satellite_id; 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 num_sort; 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]; int got_nav[2]; int wrong; int NumKeys; int Key; int ThisKey; int NSort; int SortDay[5000]; int SortTime[5000]; int SortSeconds[5000]; int SortPos[5000]; int NSS_product_type; 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 SSEC_satellite_id; 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_ccyy; int image_ddd; int image_iyd; int image_hms; int image_sec; int image_n_bands; int image_geo_line_size; int image_geo_element_size; int image_geo_line_res; int image_geo_element_res; int image_geo_data_size; int MCIDAS_element_size; int MCIDAS_geo_element_size; int rt_flag; int ii; int jj; int jjj; int found; int sort_flist[5000]; int sort_secs[5000]; int atmos_type; int file_name_type; /* file naming convention 1=DACC, 2=DB */ int file_syntax_type; /* file syntax type 0=NSS, 1=goes */ 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; float unscaled; unsigned int ival; McArgSyntax filesyntax0 = {".", "=", ";", "{\"", "}", "'", "'", NULL, "X", " "}; McArgSyntax filesyntax1 = {"_.", "=", ";", "{\"", "}", "'", "'", 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 NSSXADIR 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,dataset); 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 ); num_sort = 0; for( ii=0; ii=jj; jjj-- ) { sort_secs[jjj] = sort_secs[jjj-1]; sort_flist[jjj] = sort_flist[jjj-1]; } sort_secs[jj] = image_sec; sort_flist[jj] = ii; found = 1; } if( found == 1 ) break; } if( found == 0 ) { sort_flist[num_sort] = ii; sort_secs[num_sort] = image_sec; } } num_sort++; /* free the handle */ Mcargfree( file_handle ); } 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[sort_flist[jPos-1]]; /* test for syntax */ file_syntax_type = 0; /* rc = strstr( file_name, "/goes" ); if( rc != NULL ) file_syntax_type = 1;*/ /*Took logic from catgadir to get syntax type */ if( strstr( file_name, "/goes" ) != NULL ) { file_syntax_type = 1; } else if( strstr( file_name, "/mtsat" ) != NULL ) { file_syntax_type = 2; } else if( strstr( file_name, "/met" ) != NULL ) { file_syntax_type = 3; } else if( strstr( file_name, "/fy-2" ) != NULL ) { file_syntax_type = 4; } else if( strstr( file_name, "/patmosx" ) != NULL ) { file_syntax_type = 5; } else if( strstr( file_name, "/coms" ) != NULL ) { file_syntax_type = 6; } else if( strstr( file_name, "/H08" ) != NULL ) { file_syntax_type = 7; } else if( strstr( file_name, "/npp" ) != NULL ) { file_syntax_type = 8; } /* SDS variable initialization */ image_n_bands= 0; image_line_size= 0; image_element_size= 0; image_data_size= 0; /* Zero the directory block */ for( i=0; i=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/goes11" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 76; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-11 ",32); } rc = strstr( coverage, "/goes12" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 78; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-12 ",32); } rc = strstr( coverage, "/goes13" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 180; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-13 ",32); } rc = strstr( coverage, "/goes14" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 182; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-14 ",32); } rc = strstr( coverage, "/goes15" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 184; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-15 ",32); } rc = strstr( coverage, "/goes16" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 186; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-16 ",32); } } } else if( file_syntax_type == 2 ) { /* close file_syntax_type == 1 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/mtsat-1r" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 84; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MTSAT-1R ",32); } rc = strstr( coverage, "/mtsat-2" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 85; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MTSAT-2 ",32); } } } else if( file_syntax_type == 3 ) { /* close file_syntax_type == 2 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/met8" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 3; image_element_resolution = 3; SSEC_satellite_id = 51; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MSG1 ",32); } rc = strstr( coverage, "/met9" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 3; image_element_resolution = 3; SSEC_satellite_id = 52; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MSG2 ",32); } rc = strstr( coverage, "/met10" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 3; image_element_resolution = 3; SSEC_satellite_id = 53; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MSG3 ",32); } } } else if( file_syntax_type == 4 ) { /* close file_syntax_type == 3 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/fy-2d" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 36; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM FY-2D ",32); } rc = strstr( coverage, "/fy-2e" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 37; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM FY-2E ",32); } } } else if( file_syntax_type == 5 ) { /* close file_syntax_type == 3 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/patmosx" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 10; memcpy( (void *)&directory[24], (void *)"CLAVRX GLOBAL COMPOSITE PRODUCT ",32); } } } else if( file_syntax_type == 6 ) { /* close file_syntax_type == 5 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/coms1" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 250; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM COMS-1 ",32); } } } else if( file_syntax_type == 7 ) { /* close file_syntax_type == 6 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/H08" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 2; image_element_resolution = 2; SSEC_satellite_id = 86; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM HIMAWARI-8 ",32); } } } else if( file_syntax_type == 8 ) { /* close file_syntax_type == 7 */ NumKeys = Mcargnum( file_handle, " " ); sprintf(trace_string, "%s Number of keywords=%d", server, NumKeys); M0sxtrce( trace_string ); ThisKey = 0; for( Key=NumKeys; Key>=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s Coverage = %s", server, coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/npp" ); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 300; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM SOUMI-NPP ",32); } } } if( file_name_type == 0 ) { sprintf(trace_string, "%s FAILED: Unknown Coverage = %s", server, coverage); M0sxtrce( trace_string ); continue; } sprintf(trace_string, "%s Coverage=%s FileType=%d", server, coverage,file_name_type); M0sxtrce( trace_string ); /* Satellite ID */ rc = Mcargstr( file_handle, "", 2, "", (const char **)&satellite_id); M0sxtrce( trace_string ); if ( strncmp( satellite_id, "TN", 2 ) == 0 ) { SSEC_satellite_id = 41; } else if ( strncmp( satellite_id, "NA", 2 ) == 0 ) { SSEC_satellite_id = 42; } else if ( strncmp( satellite_id, "NC", 2 ) == 0 ) { SSEC_satellite_id = 43; } else if ( strncmp( satellite_id, "NE", 2 ) == 0 ) { SSEC_satellite_id = 44; } else if ( strncmp( satellite_id, "NF", 2 ) == 0 ) { SSEC_satellite_id = 45; } else if ( strncmp( satellite_id, "NG", 2 ) == 0 ) { SSEC_satellite_id = 60; } else if ( strncmp( satellite_id, "NH", 2 ) == 0 ) { SSEC_satellite_id = 61; } else if ( strncmp( satellite_id, "ND", 2 ) == 0 ) { SSEC_satellite_id = 62; } else if ( strncmp( satellite_id, "NI", 2 ) == 0 ) { SSEC_satellite_id = 63; } else if ( strncmp( satellite_id, "NJ", 2 ) == 0 ) { SSEC_satellite_id = 64; } else if ( strncmp( satellite_id, "NK", 2 ) == 0 ) { SSEC_satellite_id = 65; } else if ( strncmp( satellite_id, "NL", 2 ) == 0 ) { SSEC_satellite_id = 66; } else if ( strncmp( satellite_id, "NM", 2 ) == 0 ) { SSEC_satellite_id = 67; } else if ( strncmp( satellite_id, "NN", 2 ) == 0 ) { memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM NOAA-18 ",32); SSEC_satellite_id = 68; } else if ( strncmp( satellite_id, "NP", 2 ) == 0 ) { memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM NOAA-19 ",32); SSEC_satellite_id = 69; } else if ( strncmp( satellite_id, "M1", 2 ) == 0 ) { SSEC_satellite_id = 241; memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM METOP-B ",32); } else if ( strncmp( satellite_id, "M2", 2 ) == 0 ) { SSEC_satellite_id = 240; memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM METOP-A ",32); } else if ( strncmp( satellite_id, "M3", 2 ) == 0 ) { SSEC_satellite_id = 240; } /* check for Unknown Satellite ID */ if( SSEC_satellite_id == 0 ) { sprintf(trace_string, "%s FAILED: Unknown Satellite = %s", server, satellite_id); M0sxtrce( trace_string ); continue; } sprintf(trace_string, "%s image_id = %d", server, SSEC_satellite_id); M0sxtrce( trace_string ); /* Based on the image type, set the band specific constants */ if( bband == 99999 && eband == 99999 ) { ii = 1; jj = MAX_BAND; bband = ii; eband = jj; } else { ii = bband; jj = eband; } /* set band list arrays */ num_band = 0; for( i=minimum_band; i<=maximum_band; i++ ) { bands[num_band] = i; band_res[num_band] = 1.00; ++num_band; } /* Evaluate the file name for image day (CCYYDDD) */ if( file_syntax_type ==0 ) { rc = Mcargstr( file_handle, " ", 3, " ", (const char **)&cdate); length = strlen( cdate ); for( i=0; i 0 ) { if( (image_iyd < bDate) || (image_iyd > eDate) ) { Mcargfree( file_handle ); continue; } } /* Evaluate the file name for image time (HHMMSS) */ if( file_syntax_type == 0 ) { rc = Mcargstr( file_handle, " ", 4, " ", (const char **)&cstime); length = strlen( cstime ); for( i=0; i 0 ) { if( (image_hms < bTime) || (image_hms > eTime) ) { Mcargfree( file_handle ); continue; } } /* Free the handle here */ Mcargfree( file_handle ); /* start the data file */ sd_id = SDstart( file_name, DFACC_READ ); if( sd_id == FAIL ) { sprintf(trace_string, "%s DATA: FAILED for %s", server, file_name); M0sxtrce( trace_string ); } else { sprintf(trace_string, "%s DATA: SUCCESS for %s", server, file_name); M0sxtrce( trace_string ); /* 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 ); } /* loop through the individual SDS's */ wrong = 0; for( index=0; index 90.0 ) { f_latitude[ij] = -999.0; nmis++; } } else { nmis++; } } } i = (sds_dim_sizes[0]/2)-1; j = (sds_dim_sizes[1]/2)-1; ij = (i*sds_dim_sizes[1]) + j; image_geo_latitude = f_latitude[ij]; sprintf(trace_string, "%s CPlat=%f Nmiss = %d Nmax=%d Nmin=%d ", server,image_geo_latitude,nmis,nmax, nmin); M0sxtrce( trace_string ); /* record this as the image size */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; MCIDAS_element_size = image_element_size; if( (MCIDAS_element_size % 4) != 0 ) MCIDAS_element_size = (MCIDAS_element_size/4+1)*4; /* record the size of the geo field */ image_geo_line_size = sds_dim_sizes[0]; image_geo_element_size = sds_dim_sizes[1]; MCIDAS_geo_element_size = sds_dim_sizes[1]; if( (MCIDAS_geo_element_size % 4) != 0 ) MCIDAS_geo_element_size = (MCIDAS_geo_element_size/4+1)*4; sprintf(trace_string, "%s Line Size=%d Element Size=%d", server,image_geo_line_size,image_geo_element_size); M0sxtrce( trace_string ); /* record the size of a geo element */ image_geo_data_size = 4; /* record the size of a data element */ image_data_size = 2; /* Latitude is nav 1 */ got_nav[0] = 1; /* Geo Fields - Longitude */ } else if( strncmp( name, "longitude", 9 ) == 0 ) { short *i_longitude; i_longitude = malloc( 4*sizeof(short) ); sprintf(trace_string, "%s Found Longitude SDS", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = ( sds_dim_sizes[0] / 2) - 1; start[1] = ( sds_dim_sizes[1] / 2) - 1; stride[0] = 1; stride[1] = 1; edge[0] = 1; edge[1] = 1; /* reserve memory for the Longitude array */ status = SDreaddata( sds_id, start, stride, edge, i_longitude); sprintf(trace_string, "%s Read Longitude SDS: status=%d", server,status); M0sxtrce( trace_string ); /* compute the unscaled latitude */ unscaled = ((float)(i_longitude[0] - (-32767))) / (float)(32767 -(-32767)); image_geo_longitude = -180.0 + ((180.0-(-180.0)) * unscaled); /* invert the longitude for mcidas */ image_geo_longitude = -1*image_geo_longitude; sprintf(trace_string, "%s Unscaled factor=%f longitude = %f", server,unscaled,image_geo_longitude); M0sxtrce( trace_string ); /* Longitude is nav 2 */ got_nav[1] = 1; } else if( strncmp( name, "cloud_type", 10 ) == 0 ) { if( strncmp( name, "cloud_type_", 11 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=1: Cloud Type SDS", server); M0sxtrce( trace_string ); got_bands[0] = 1; image_n_bands++; } } else if( strncmp( name, "cld_temp_sw", 11 ) == 0 || strncmp( name, "cld_temp_acha", 13 ) == 0 ) { if(strncmp( name, "cld_temp_acha_", 14 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=2: Cloud Temp SDS", server); M0sxtrce( trace_string ); got_bands[1] = 1; image_n_bands++; } } else if( strncmp( name, "cld_height_sw", 13 ) == 0 || strncmp( name, "cld_height_acha", 15 ) == 0 ) { if( strncmp( name, "cld_height_acha_", 16 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=3: Cloud Height SDS", server); M0sxtrce( trace_string ); got_bands[2] = 1; image_n_bands++; } } else if( strncmp( name, "cld_press_acha", 14 ) == 0 ) { if( strncmp( name, "cld_press_acha_", 15 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=4: Cloud Top Pressure SDS", server); M0sxtrce( trace_string ); got_bands[3] = 1; image_n_bands++; } } else if( strncmp( name, "cld_opd_vis", 11 ) == 0 || strncmp( name, "cld_opd_dcomp", 13 ) == 0 ) { if( strncmp( name, "cld_opd_dcomp_", 14 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=5: Cloud Optical Depth SDS", server); M0sxtrce( trace_string ); got_bands[4] = 1; image_n_bands++; } } else if( strncmp( name, "cld_reff_vis", 12 ) == 0 || strncmp( name, "cld_reff_dcomp", 15 ) == 0 ) { if( strncmp( name, "cld_reff_dcomp_", 16 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=6: Cloud Effective Radius SDS", server); M0sxtrce( trace_string ); got_bands[5] = 1; image_n_bands++; } } else if( strncmp( name, "pixel_sst_masked", 16 ) == 0 ) { if( strncmp( name, "pixel_sst_masked_", 17 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=8: SST Masked SDS", server); M0sxtrce( trace_string ); got_bands[7] = 1; image_n_bands++; } } else if( strncmp( name, "pixel_sst", 9 ) == 0 || strncmp( name, "pixel_sst_unmasked", 18 ) == 0 ) { if(strncmp( name, "pixel_sst_unmasked_", 19 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=7: SST UnMasked SDS", server); M0sxtrce( trace_string ); got_bands[6] = 1; image_n_bands++; } } else if( strncmp( name, "ch1_reflectance", 15 ) == 0 || strncmp( name, "refl_0_65um_nom_unnormalized", 28 ) == 0 ) { sprintf(trace_string, "%s Found BAND=9: Chanel 1 Reflectance SDS", server); M0sxtrce( trace_string ); got_bands[8] = 1; image_n_bands++; } else if( strncmp( name, "ch2_reflectance", 15 ) == 0 || strncmp( name, "refl_0_86um_nom_unnormalized", 28 ) == 0 ) { sprintf(trace_string, "%s Found BAND=10: Chanel 2 Reflectance SDS", server); M0sxtrce( trace_string ); got_bands[9] = 1; image_n_bands++; } else if( strncmp( name, "refl_1_60um_nom_unnormalized", 28 ) == 0 ) { sprintf(trace_string, "%s Found BAND=11: Chanel 3A Reflectance SDS", server); M0sxtrce( trace_string ); got_bands[10] = 1; image_n_bands++; } else if( strncmp( name, "ch3B_reflectance", 16 ) == 0 || strncmp( name, "refl_3_75um_nom", 15 ) == 0 ) { if( strncmp( name, "refl_3_75um_nom_", 16 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=12: Chanel 3B Reflectance SDS", server); M0sxtrce( trace_string ); got_bands[11] = 1; image_n_bands++; } } else if( strncmp( name, "temp_3_75um_nom", 15 ) == 0 ) { if(strncmp( name, "temp_3_75um_nom_", 16 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=13: Chanel 3B Temperature SDS", server); M0sxtrce( trace_string ); got_bands[12] = 1; image_n_bands++; } } else if( strncmp( name, "ch4_temperature", 15 ) == 0 || strncmp( name, "temp_11_0um_nom", 15 ) == 0 ) { if( strncmp( name, "temp_11_0um_nom_", 16 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=14: Chanel 4 Teperature SDS", server); M0sxtrce( trace_string ); got_bands[13] = 1; image_n_bands++; } } else if( strncmp( name, "ch5_temperature", 15 ) == 0 || strncmp( name, "temp_12_0um_nom", 15 ) == 0 ) { if( strncmp( name, "temp_12_0um_nom_", 16 ) == 0 ) { wrong++; } else { sprintf(trace_string, "%s Found BAND=15: Chanel 5 Temperature SDS", server); M0sxtrce( trace_string ); got_bands[14] = 1; image_n_bands++; } } else if( strncmp( name, "cld_emiss_acha", 14 ) == 0 ) { sprintf(trace_string, "%s Found BAND=16: CLD emissivity SDS", server); M0sxtrce( trace_string ); got_bands[15] = 1; image_n_bands++; } else if( strncmp( name, "cloud_probability", 17 ) == 0 ) { sprintf(trace_string, "%s Found BAND=17: CLD Probability SDS", server); M0sxtrce( trace_string ); got_bands[16] = 1; image_n_bands++; } else if( strncmp( name, "cloud_fraction", 14 ) == 0 ) { sprintf(trace_string, "%s Found BAND=18: CLD Fraction SDS", server); M0sxtrce( trace_string ); got_bands[17] = 1; image_n_bands++; } else if( strncmp( name, "cloud_mask", 10 ) == 0 ) { sprintf(trace_string, "%s Found BAND=19: CLD Mask SDS", server); M0sxtrce( trace_string ); got_bands[18] = 1; image_n_bands++; } else if( strncmp( name, "cld_altitude_acha", 17 ) == 0 ) { sprintf(trace_string, "%s Found BAND=20: CLD FLT HGHT SDS", server); M0sxtrce( trace_string ); got_bands[19] = 1; image_n_bands++; } else if( strncmp( name, "cloud_transmission_0_65um_nom", 29 ) == 0 ) { sprintf(trace_string, "%s Found BAND=21: CLD OPD TRANS SDS", server); M0sxtrce( trace_string ); got_bands[20] = 1; image_n_bands++; } else if( strncmp( name, "cld_base_altitude_acha", 22 ) == 0 ) { sprintf(trace_string, "%s Found BAND=22: CLD FLT BASE SDS", server); M0sxtrce( trace_string ); got_bands[21] = 1; image_n_bands++; } else if( strncmp( name, "cld_layer", 9 ) == 0 ) { sprintf(trace_string, "%s Found BAND=23: CLD LAYER SDS", server); M0sxtrce( trace_string ); got_bands[22] = 1; image_n_bands++; } else if( strncmp( name, "conv_cloud_probability", 22) == 0 ) { sprintf(trace_string, "%s Found BAND=24: CONV CLD PROB SDS", server); M0sxtrce( trace_string ); got_bands[23] = 1; image_n_bands++; } else if( strncmp( name, "sensor_zenith_angle", 22) == 0 ) { sprintf(trace_string, "%s Found BAND=25: SENSOR ZENITH ANGLE SDS", server); M0sxtrce( trace_string ); got_bands[24] = 1; image_n_bands++; } else if( strncmp( name, "refl_sol_dnb_nom", 22) == 0 ) { sprintf(trace_string, "%s Found BAND=26: DNB REFL", server); M0sxtrce( trace_string ); got_bands[25] = 1; image_n_bands++; } /* end access to the SDS */ status = SDendaccess( sds_id ); } } /* Check client search conditions: SS=bSS eSS */ if (checkSS > 0 ) { if( (SSEC_satellite_id < bSS) || (SSEC_satellite_id > eSS) ) break; } /* Check : BAND=bSS eSS */ sprintf(trace_string, "%s bband = %d eband = %d", server,bband, eband); M0sxtrce( trace_string ); checkBand = 0; for( i=bband; i<=eband; i++ ) { if( got_bands[i-1] == 1 ) checkBand++; } if( checkBand == 0 ) break; /* compute the size of the highest resolution LALO nav block */ for( i=1; i<10; i++ ) { image_geo_line_res = image_geo_line_size / i; image_geo_element_res = MCIDAS_geo_element_size / i; AUX_SIZE = image_geo_line_res * image_geo_element_res * image_geo_data_size * 2 + 52; if( (AUX_SIZE % 4) != 0 ) AUX_SIZE = (AUX_SIZE/4+1)*4; if( AUX_SIZE < MAX_AUX_SIZE ) break; } sprintf(trace_string, "%s AUX resolution will be %d", server,i); M0sxtrce( trace_string ); /* build the directory block */ sprintf(trace_string, "%s Build directory", server); M0sxtrce( trace_string ); directory[0] = iPos * image_dataset_position; directory[1] = IMAGE_FILE_VERSION; directory[2] = SSEC_satellite_id; directory[3] = image_iyd; directory[4] = image_hms; directory[5] = IMAGE_STARTING_LINE; directory[6] = IMAGE_STARTING_ELEMENT; directory[8] = image_line_size; directory[9] = MCIDAS_element_size; directory[10] = image_data_size; directory[11] = image_line_resolution; directory[12] = image_element_resolution; directory[13] = image_n_bands; directory[14] = (image_n_bands/4+1)*4+4; directory[16] = image_iyd; directory[17] = image_hms; directory[33] = AUX_OFFSET+AUX_SIZE; directory[34] = NAV_OFFSET; directory[50] = (image_n_bands/4+1)*4; memcpy( (void *)&directory[51], (void *)"NSSX",4); memcpy( (void *)&directory[52], (void *)"RAW ",4); directory[59] = AUX_OFFSET; directory[60] = AUX_ENTRIES; directory[62] = CAL_OFFSET; /* set the bits in the band map words */ directory[18] = 0; directory[19] = 0; for( ii=bband; ii<=eband; ii++ ) { i = ii-1; if( got_bands[i] == 1 ) { ival = pow(2,i); directory[18] = directory[18] + ival; } } sprintf(trace_string, "%s directory(18) = %d", server, directory[18]); M0sxtrce( trace_string ); if( directory[18]!=0 ) { sprintf(trace_string, "%s Build comment cards", server); M0sxtrce( trace_string ); /* build the comment block */ image_km_resolution = 1.00; status = GetNSSCards( directory, got_bands, NSS_product_type, image_geo_latitude, image_geo_longitude, image_km_resolution, image_km_resolution, cards, auxFlag ); num_cards = directory[63]; /* compute and send byte total, and one dummy word */ sprintf(trace_string, "%s Dir Size = %d Num Cards = %d", server, DIR_SIZE, num_cards); M0sxtrce( trace_string ); send_byte_total = (DIR_SIZE * sizeof(int)) + 4 + (num_cards*80); sprintf(trace_string, "%s Send Byte Total = %d", server, send_byte_total); M0sxtrce( trace_string ); requestBlock.reply_length += send_byte_total; M0swbyt4(&send_byte_total, 1); M0sxsend(4, &send_byte_total); M0sxsend(4, &dummy); /* send the directory to client */ send_byte_total = DIR_SIZE * 4; M0swbyt4(&directory[0], 20); M0swbyt4(&directory[21], 3); M0swbyt4(&directory[32], 19); M0swbyt4(&directory[53], 2); M0swbyt4(&directory[58], 6); if( ischar_(&directory[20]) == 0) M0swbyt4(&directory[20], 1); M0sxsend( send_byte_total, (void *)directory); M0swbyt4(&directory[0], 20); M0swbyt4(&directory[21], 3); M0swbyt4(&directory[32], 19); M0swbyt4(&directory[53], 2); M0swbyt4(&directory[58], 6); if( ischar_(&directory[20]) == 0) M0swbyt4(&directory[20], 1); /* send cards to client */ send_byte_total = num_cards * 80; M0sxsend( send_byte_total, (void *)cards); } /* increment the number of directories sent */ listCount++; /* end HDF access */ status = SDend( sd_id ); /* check for break from loop */ if( FPos == 1 ) break; } /* if no images were listed, send an "error" message */ if (listCount == 0) { (void) strncpy(requestBlock.errormsg, "No images satisfy the selection criteria", sizeof(requestBlock.errormsg)); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } /* termination */ M0sxdone(&requestBlock); sprintf(trace_string, "%s exit\n", server); M0sxtrce( trace_string ); return (0); } /* *| Name: *| GetNSSCards - Extract info for and create comment cards. *| *| Interface: *| int *| GetNSSCards ( *| int *areaDir, *| int *bands, *| int prodFlag, *| float latcp, *| float loncp, *| float latres, *| float lonres, *| int *cards, *| int auxFlag *| ) *| *| Input: *| none *| *| Input and Output: *| none *| *| Output: *| none *| *| Return values: *| 0: success *| -1: failure *| *| Remarks: *| *| Categories: *| ingest/decode */ /* #define BAND_MAP "BAND MAP = 1-38" */ #define CEN_LAT_CARD "Center latitude = %f" #define CEN_LAT_RES_CARD "Computed Latitude resolution (km) = %f" #define CEN_LON_CARD "Center longitude = %f" #define CEN_LON_RES_CARD "Computed Longitude resolution (km) = %f" #define RES_LON_CARD "Longitude resolution (km) = %f" #define RES_LAT_CARD "Latitude resolution (km) = %f" #define CAL_CARD "Valid calibration unit for band %d = %s \"%s\"" int GetNSSCards ( int *areaDir, int *bands, int prodFlag, float lat, float lon, float rlat, float rlon, int *cards, int auxFlag ) { int MAX_CARD_LEN = 80; int NUM_COMMENT = 63; int NUM_BAND = 30; int rc; int numCards = 0; int band; int nbands; int i; char card[80]; /* number of bands */ nbands = areaDir[NUM_BAND]; /* build cards for center point */ (void) sprintf(card, CEN_LAT_CARD, lat); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; (void) sprintf(card, CEN_LAT_RES_CARD, rlat); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; (void) sprintf(card, CEN_LON_CARD, lon); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; (void) sprintf(card, CEN_LON_RES_CARD, rlon); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; (void) sprintf(card, RES_LAT_CARD, rlat); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; (void) sprintf(card, RES_LON_CARD, rlon); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; /* aux cal cards if needed */ if (auxFlag) { for( i=0; i