/* * Copyright(c) 2015, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt */ /**** $Id: abinadir.c,v 1.44 2021/05/25 20:00:56 russd Tst $ ****/ /* ** Name: ** abinadir : ADDE directory server for GOES-R NOAAPort ABI images uses SQL database ** ** 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 */ #include #include #include #if defined(__APPLE__) #include #endif #include #include /* <<<<< UPC add 20190425 - for 'basename' >>>>> */ #include /* <<<<< UPC add 20190507 - for regcomp, regexec >>>>> */ #include /* <<<<< UPC add 20190507 - for regcomp, regexec >>>>> */ #include "mcidas.h" #include "mcidasp.h" #include "m0arg.h" #include "AreaDir.h" #include "SDIUtil.h" #include "m0glue.h" #include "math.h" #include "m0frame.h" #include "m0gpnav.h" #include "m0sysnav.h" /* SQLite database include */ #include "sqlite3.h" /* NetCDF include files */ #include "netcdf.h" /* ABIN include file(s) */ #include "abinparm.h" /* Function prototypes */ int GetModsCards (int*, int*, int*, float, float, float, float, float, float, int*, int, int); int **malloc2dint(int, int); char **GetRegexpMatchList( const char *, const char * ); Fint lit_( const char *, FsLen ); float **malloc2dfloat(int, int); char trace_string[500]; /* tracing text */ #define tprintf(str, ...) \ do { \ extern Fint trace_; \ if (trace_) { \ sprintf(str, __VA_ARGS__); \ M0sxtrce(str); \ } \ } while (0) int main ( int argc, char **argv ) /* CONSTANTS */ #define DIR_SIZE 64 /* directory block size [words] */ #define NAV_BLOCK_SIZE 128 /* NAV block size [words] */ #define CAL_BLOCK_SIZE 0 /* CAL block size [words] */ #define AUX_BLOCK_SIZE 0 /* AUX block size [words] */ #define ABI_NAV_OFFSET 4*DIR_SIZE /* NAV block offset [bytes] */ #define ABI_CAL_OFFSET ABI_NAV_OFFSET+4*NAV_BLOCK_SIZE /* CAL block offset [bytes] */ #define ABI_AUX_OFFSET 0 /* AUX block offset [bytes] */ #define ABI_IMG_OFFSET (DIR_SIZE+NAV_BLOCK_SIZE+CAL_BLOCK_SIZE+AUX_BLOCK_SIZE)*4 /* image data start [bytes] */ #define IMAGE_FILE_VERSION 4 /* AREA ID type number */ #define IMAGE_STARTING_LINE 1 /* image starting line */ #define IMAGE_STARTING_ELEMENT 1 /* image starting element */ #define ABI_MAX_BANDS 64 /* maximum number of ABI bands */ #define ADB_MAX_BANDS 16 /* maximum number of sqlite bands */ #define DQF_SIZE 16*ABI_MAX_BANDS /* size of the DQF array */ #define MAX_CARD_LEN 80 /* len of a single comment card */ #define SCMI 0 /* CAL type SCMI */ #define ABIN 1 /* CAL type ABIN */ #define ABI 0 /* image type ABIN aka L1b */ #define L2 1 /* image type L2 */ #define MATCH 11 #define QUERY_LEN 10240 /* size of the SQLite DB inquery */ #define NAME_LEN 50 /* size of database key name */ #define KEY_MAX 100 /* MAXIMUM number of key names */ #define FILE_MAX 24000 /* MAXIMUM number of file names */ #define SQLITE_OK 0 /* SQLite function result is OK */ { /* Internal Varaiables */ char llchar[4]={"LL "}; char *dum; /* dummy for arg fetchers */ char *dataset; /* dataset name */ char *file_name; /* name of file */ char *group; /* ADDE request dataset group */ char *cAux; /* ADDE request AUX flag */ char *cBand; /* ADDE request BAND number */ char *request = NULL; /* ADDE request text */ char cards[300*MAX_CARD_LEN]; /* ADDE comment cards */ char *comment; /* ADDE dataset comment */ char **flist; /* Array of files matching ADDE mask */ char **fdatabase; /* Array of files matching ADDE info */ char **mlist; /* Array of matches for regexp */ char *format; /* ADDE dataset format */ char *info; /* ADDE dataset info */ char *mask; /* file mask */ char *type; /* ADDE dataset type */ /* Image tracking arrays */ int *seconds; int *sss; int *Nbands; int *cover; int *imode; int *ssp_lats; int *ssp_lons; int *pro_lons; int **lines; int **elems; int **bands; int **paths; int **iress; int **gress; int **positions; int **DQF1s; int **DQF2s; int **DQF3s; int **DQF4s; int **DQF5s; int **DQF6s; int **DQF7s; int **DQF8s; int **YFacs; int **YOffs; int **XFacs; int **XOffs; const char server[] = {"ABINADIR"}; /* server name */ const char EREGEXP[] = ".._(ABI|GLM)-((L1b|L2)-(.{3,5})(F|C|M[12]|AK|HI|PR))-M([346])(_|C.._)G(1[6-9])_s(.{7})(.{6})"; double range; /* distance between image pixels */ double azimuth; /* bearing between image pixels */ float image_geo_latitude; /* Latitude value */ float image_geo_longitude; /* Longitude value */ float image_geo_line_resolution; /* LALO line resolution */ float image_geo_element_resolution; /* LALO element resolution */ float image_lat_resolution; /* Latitude resolution at image center */ float image_lon_resolution; /* Longitude resolution at image center */ float DQF_darray[DQF_SIZE]; /* DQF array 16 values per 64 bands */ int DQF_iarray[DQF_SIZE]; /* DQF array 16 values per 64 bands */ int auxFlag = 0; /* Auxillary block useage flag */ int bDate; /* beginning date */ int bTime; /* beginning time */ int bPos,ePos; /* Beginning, ending ADDE position #s */ int bSS,eSS; /* Beginning, ending satellite numbers */ int eDate; /* ending date */ int eTime; /* ending time */ int CalType; /* calibration type (SCMI, ABIN) */ int checkSS = 0; /* check SS number */ int checkTime = 0; /* check image time */ int checkDay = 0; /* check image day */ int dummy = 9999; /* ADDE dummy parameter */ int listCount = 0; /* number of files to process */ int rc; /* function status */ int i,j,k,N; /* array index counters */ int nmatch; /* number of matches expected */ int iscale; /* scale factor */ int trace = 0; /* tracing flags */ int transaction = 0; /* Transaction flag */ int user = 0; /* request USER id */ int ALL; /* transaction "ALL" constant */ int directory[DIR_SIZE]; /* directory block array */ int nav_block[NAV_BLOCK_SIZE]; /* NAV block */ int hiBound; /* ADDE dataset index maximum bounds */ int Pos; /* ADDE position number */ int rPos; /* relative ADDE poition */ int iPos; /* beginning ADDE position */ int jPos; /* ending ADDE position */ int FPos; /* flag indicates FIRST ADDE position */ int loBound; /* ADDE dataset index minimum bounds */ int num_band; /* number of bands */ int num_columns; /* number of DB columns */ int num_cards; /* number of comment cards */ int num_flist; /* number of files matching ADDE mask */ int num_fdatabase; /* number of files matching ADDE info */ int send_byte_total; /* number of bytes sent to client */ int image_dataset_position; /* current ADDE dataset position */ int image_satellite_number; /* SSEC satellite number */ int image_line_size; /* number of image lines */ int image_line_resolution; /* line resolution */ int image_element_size; /* number of image elements */ int image_element_resolution; /* element resolutions */ int image_data_size; /* bytes per data element */ int image_sec; /* image time in absolute seconds */ int image_cyd; /* image date [CCYYDDD] */ int image_iyd; /* image date [YYYDDD] */ int image_hms; /* image time [HHMMSS] */ int image_tmin; /* image min time [HHMMSS] */ int image_tmax; /* image max time [HHMMSS] */ int image_n_bands; /* # bands detected in the image file */ int ImageMode; /* ABI file name - Image Mode */ int ImagePlatform; /* ABI file name - Image Platform */ int ImageType; /* ABI file name - Image Type */ int n_times; /* number of image times */ int last_cyd; /* check for multiple days */ int gotTime; /* -> we found a valid date and time */ int image_lines; /* image rows/lines */ int image_elems; /* image cells/elements */ int rt_flag; /* real-time data flag */ int bband,eband; /* beginning and ending band numbers */ int bandList[64]; /* band list for comment cards */ int indx; /* file index */ int iBand,iiBand; /* Band number */ int NpBands; /* Number of Product Bands */ int pBands[64]; /* Product Band number */ int theBand; /* Band number */ int iSSS; /* SSEC satellite number */ int iCoverage; /* Coverage Code */ int iResolution; /* SSEC image Resolution factor */ int gResolution; /* SSEC geo Resolution factor */ int MAX_BANDS; /* Internal MAX Bands */ float fResolution; /* Resolution at SSP */ /* RESOLUTION TRACKING mods */ int JR; /* for resolution tracking */ int NFOUND; /* for resolution tracking */ int NRES; /* for resolution tracking */ int IRES[64]; /* for resolution tracking */ int PRES[64]; /* for resolution tracking */ float LaRES[64]; /* for resolution tracking */ float LoRES[64]; /* for resolution tracking */ /* RESOLUTION TRACKING mods */ /* SQLite Database mods */ char * query1; char * query2; char * params_query; char * database_query; char * table_query; char * key_name; char * fname; char * char_value; char * key_names[KEY_MAX][50]; char * *file_names; char *database; /* path to the SQLITE database */ char *tables; /* tables within the SQLITE database */ char *sqlite_errormsg = 0; int Nkey; int Nrec; int Nfile; int DBstep; int int_value1; int int_value2; int key_len; int file_len; int database_present; /* does the DB exist */ int database_use; /* if DB exists do we want to use it */ int database_switch; int status; int handle; int length; int Ntables; int sqlite_status=0; int NULLSelect=0; /* Is select string NULL?*/ int key_locs[KEY_MAX]; int THIS_SEC; int channel; int DQF1; int DQF2; int DQF3; int DQF4; int DQF5; int DQF6; int DQF7; int DQF8; int dbCount; typedef struct sqlite sqlite; McArgSyntax filesyntax = {" ", "=", ";", "{\"", "}", "'", "'", NULL, "X", " "}; McArgSyntax datasyntax = {" ", "=", ";", "'", "'", NULL, "X", " "}; sqlite3 *sqlite_conn; sqlite3_stmt *selectStatement; /* SQLite Database mods */ union abibnd { unsigned int lBand[2]; unsigned long bandmap; } abiband; /* NetCDF related declarations */ int ncdf_id; int dim_id; int var_id; int image_cp_line; int image_cp_element; int ONE = 1; int TWO = 2; int LL; float lfac; /* line scale factor */ float cfac; /* element scale factor */ float loff; /* line add offset */ float coff; /* element add offset */ float ssp_lat; /* subpoint latitude */ float ssp_lon; /* subpoint longitude */ float pro_lon; /* projection lon - WCS3 */ float DQF_file; float DQF_float; Freal Fline, Felem; Freal Flat, Flat1; Freal Flon, Flon1; Freal Fdummy; short *Xarray; /* element coordinate array*/ short *Yarray; /* line coordinate array*/ size_t rows; size_t cells; /* ADDE client request block */ servacct requestBlock = {0}; /* length of the request block */ /* string contains variable for "ALL" */ memcpy(&ALL, "ALL ", 4); M0swbyt4(&ALL, 1); /* ************************************************************************* ** Step 1.1: process the transaction request ** Use standard function calls to retrieve the parameters in the ** comm block. ** ************************************************************************* */ /* Initialize the MAX_BANDS to ABI_MAX_BANDS */ MAX_BANDS = ABI_MAX_BANDS; /* Initialize local server */ rc = M0InitLocalServer(server, argc, argv, &requestBlock, &request); /* See if logging should be done, determined by hidden TRACE= flag */ trace = M0IsTraceSet(request); tprintf(trace_string, "%s ABI DIRECTORY SERVER V2.2", server); /* 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]); memcpy(requestBlock.transaction, &transaction, sizeof(requestBlock.transaction)); /* Fill in the user */ user = atoi(argv[3]); 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); tprintf(trace_string, "%s group = %s", server,group); tprintf(trace_string, "%s dataset = %s", server,dataset); tprintf(trace_string, "%s type = %s", server,type); tprintf(trace_string, "%s format = %s", server,format); tprintf(trace_string, "%s mask = %s", server,mask); tprintf(trace_string, "%s comment = %s", server,comment); tprintf(trace_string, "%s Request = %s", server,request); tprintf(trace_string, "%s Dataset = %s", server,group); tprintf(trace_string, "%s L1b SS = %d", server,ABISSS); tprintf(trace_string, "%s L2 SS = %d", server,L2SSS); tprintf(trace_string, "%s L2 Nprods = %d", server,L2NPRODS); tprintf(trace_string, "%s File Mask = %s", server,mask); tprintf(trace_string, "%s Info Mask = %s", server,info); tprintf(trace_string, "%s rt_flag = %d", server,rt_flag); #if 0 for( i=0; i<=L2NPRODS-1; i++ ) { tprintf(trace_string,"%s L2 Names[%d]=%s Bands[%d]=%d Coverage[%d]=%d", server,i+1,L2NAMES[i], i+1,L2BANDS[i], i+1,L2COVERS[i] ); } #endif /* ************************************************************************* ** Step 1.2: Inquire if the DB is present ** ** Some Rules ** - set DB switch to ON by default ** - set DB switch to OFF if NOT archive dataset ** - set DB switch to OFF if transaction variable is OFF ** - set DB switch to OFF if DB is NOT present ** variable database_switch = 0 means NOT a sqlit3 dataset * ************************************************************************** */ /* check for DB switch */ database_switch = 0; if( rt_flag == 2 ) database_switch = 1; /* IF DATABASE IS NOT ON JUMP OVER DB CODE */ if( database_switch == 0 ) goto GREP_FOR_FILES; /* Set the MAX_BANDS to ADB_MAX_BANDS */ MAX_BANDS = ADB_MAX_BANDS; /* Allocate arrays for SQLite Query */ params_query = calloc((size_t)QUERY_LEN, sizeof(char)); database_query = calloc((size_t)QUERY_LEN, sizeof(char)); table_query = calloc((size_t)QUERY_LEN, sizeof(char)); query1 = calloc((size_t)QUERY_LEN, sizeof(char)); query2 = calloc((size_t)QUERY_LEN, sizeof(char)); key_name = calloc((size_t)NAME_LEN, sizeof(char)); if( params_query == NULL || database_query == NULL || table_query == NULL || query1 == NULL || query2 == NULL || key_name == NULL ) { tprintf(trace_string,"%s Can't allocate SQLite database Query strings", server); strcpy(requestBlock.errormsg, "Can't allocate SQLite Query strings"); /* sqlite3_close(sqlite_conn); */ requestBlock.returncode = -10; M0sxdone(&requestBlock); return(0); } if( database_switch == 1 ) { tprintf(trace_string, "%s DataBase Switch is ON", server); /* Parse the INFO string into its components */ handle = Mcargparse( info, &datasyntax, &length); status = Mcargstr(handle, "DATABASE", 1, (char *)NULL, &database ); /* Produce a list of files matching the pattern info */ fdatabase = M0GetMaskFileList(database); if( fdatabase == (char **)NULL ) { strcpy(requestBlock.errormsg, "No images satisfy database selection criteria"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { num_fdatabase = VecLen(fdatabase); if( num_fdatabase <= 0 ) { (void)strcpy(requestBlock.errormsg, "No files found matching file info"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } } } /* test for SQLite3 database */ status = M0ImgSQLiteDB_tables( fdatabase[0], Ntables, tables ); /* open the SQLite database */ /* tprintf(trace_string, "%s Opening SQLite database",server); */ rc= sqlite3_open_v2(fdatabase[0],&sqlite_conn,SQLITE_OPEN_READONLY,NULL); if( rc != 0 ){ tprintf(trace_string,"%s Can't open SQLite database: %s", server,sqlite3_errmsg(sqlite_conn)); strcpy(requestBlock.errormsg, "Can't Open SQLite database"); sqlite3_close(sqlite_conn); requestBlock.returncode = -10; M0sxdone(&requestBlock); return(0); } /* tprintf(trace_string,"%s SQLite database is OPEN\n", server); */ /* Add SQLite Query directives */ rc=sqlite3_exec(sqlite_conn,"PRAGMA synchronous = OFF", NULL, NULL, &sqlite_errormsg); tprintf(trace_string,"%s PAST PRAGMA synchronous rc=%d %s\n", server, rc, sqlite_errormsg); /* *************************************************************************************** */ /* Step 1 - Get a list of the keys Save a list of the key names construct the SELECT clause for the Entries Table */ /* Append to Select clause GET EVERYTHING from the keys table` */ sprintf(table_query,"SELECT * FROM Keys"); tprintf(trace_string,"%s table_query string >%s<\n", server,table_query); /* PREPARE the tranaction */ rc=sqlite3_prepare_v2(sqlite_conn,table_query,QUERY_LEN,&selectStatement,0); tprintf(trace_string,"%s PAST PREPARE rc=%d\n", server,rc); /* Begin the transaction */ rc=sqlite3_exec(sqlite_conn,"BEGIN TRANSACTION", NULL, NULL, &sqlite_errormsg); tprintf(trace_string,"%s PAST EXECUTE rc=%d %s\n", server,rc, sqlite_errormsg); if( rc != SQLITE_OK ) { tprintf(trace_string,"%s FAILED to fetch Keys table", server); strcpy(requestBlock.errormsg, "Can't Query Keys Table"); sqlite3_close(sqlite_conn); requestBlock.returncode = -10; M0sxdone(&requestBlock); return(0); } /* Initialize the param_query string */ sprintf(query1, "SELECT "); strcat(params_query,query1); /* Initialize the database_query string */ sprintf(query2, "FROM Entries "); strcat(database_query,query2); /* step through the transaction */ Nkey = 0; rc = sqlite3_step(selectStatement); while ( rc == SQLITE_ROW ) { /* Save the key names */ /* tprintf(trace_string,"%s THIS KEY = %s", server,sqlite3_column_text(selectStatement,0)); */ key_name = (char*) (sqlite3_column_text(selectStatement, 0)); key_len = strlen( key_name ); strncpy(key_names[Nkey], key_name, key_len+1); /* tprintf(trace_string,"%s KEY = %s LEN=%d", server,key_names[Nkey],key_len); */ /* construct the params_query clause */ sprintf(query1, "%s_Keys.value,", sqlite3_column_text(selectStatement,0) ); strcat(params_query,query1); /* construct the database_query clause */ sprintf(query2, "LEFT JOIN %s_Keys ON Entries.%s = %s_Keys.key ", sqlite3_column_text(selectStatement,0), sqlite3_column_text(selectStatement,0), sqlite3_column_text(selectStatement,0) ); strcat(database_query,query2); Nkey++; rc = sqlite3_step(selectStatement); } /* Append non-keyed values to the Keys list */ strcpy(key_names[Nkey], "Channel"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "NominalSubpointLatitude"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "NominalSubpointLongitude"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "ProjectionLongitude"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "YScaleFactor"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "YAddOffset"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "XScaleFactor"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "XAddOffset"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQGoodPct"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQCondUnusablePct"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQOutOfRangePct"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQNoValuePct"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQFPTExceedPct"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQFPTMaximumTemp"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQFPTThreshIncreaseTemp"); key_len = strlen( key_names[Nkey] ); Nkey++; strcpy(key_names[Nkey], "DQFPTThreshDecreaseTemp"); key_len = strlen( key_names[Nkey] ); Nkey++; /* Append non-keyed values to the query1 string */ sprintf(query1, "Entries.Channel,"); strcat(params_query,query1); sprintf(query1, "Entries.NominalSubpointLatitude,"); strcat(params_query,query1); sprintf(query1, "Entries.NominalSubpointLongitude,"); strcat(params_query,query1); sprintf(query1, "Entries.ProjectionLongitude,"); strcat(params_query,query1); sprintf(query1, "Entries.YScaleFactor,"); strcat(params_query,query1); sprintf(query1, "Entries.YAddOffset,"); strcat(params_query,query1); sprintf(query1, "Entries.XScaleFactor,"); strcat(params_query,query1); sprintf(query1, "Entries.XAddOffset,"); strcat(params_query,query1); sprintf(query1, "Entries.DQGoodPct,"); strcat(params_query,query1); sprintf(query1, "Entries.DQCondUnusablePct,"); strcat(params_query,query1); sprintf(query1, "Entries.DQOutOfRangePct,"); strcat(params_query,query1); sprintf(query1, "Entries.DQNoValuePct,"); strcat(params_query,query1); sprintf(query1, "Entries.DQFPTExceedPct,"); strcat(params_query,query1); sprintf(query1, "Entries.DQFPTMaximumTemp,"); strcat(params_query,query1); sprintf(query1, "Entries.DQFPTThreshIncreaseTemp,"); strcat(params_query,query1); sprintf(query1, "Entries.DQFPTThreshDecreaseTemp,"); strcat(params_query,query1); /* Terminate the param_query string */ sprintf(query1, "Entries.* "); strcat(params_query,query1); /* combine the two query strings */ strcat(params_query,database_query); /* NEW 03/11/21 - append ORDER BY to time sort the query results */ sprintf(query1, "ORDER BY Time_Keys.value "); strcat(params_query,query1); /* This is the database querycommand */ tprintf(trace_string,"%s SQLITE QUERY = %s", server,params_query); /* End the transaction */ rc=sqlite3_exec(sqlite_conn,"END TRANSACTION", NULL, NULL, &sqlite_errormsg); tprintf(trace_string,"%s PAST EXECUTE rc=%d %s\n", server,rc, sqlite_errormsg); /* initialize pointers to key names */ for( i=0; i 1 ) { /* Close database[0] */ sqlite3_close(sqlite_conn); /* loop through additional DBs */ for( N=1; N 0 ) { /* open the SQLite database */ tprintf(trace_string, "%s Opening SQLite database",server); rc= sqlite3_open_v2(fdatabase[N],&sqlite_conn,SQLITE_OPEN_READONLY,NULL); if( rc != 0 ){ tprintf(trace_string,"%s Can't open SQLite database: %s", server,sqlite3_errmsg(sqlite_conn)); strcpy(requestBlock.errormsg, "Can't Open SQLite database"); sqlite3_close(sqlite_conn); requestBlock.returncode = -10; M0sxdone(&requestBlock); return(0); } } /* GET EVERYTHING from the Filenames table` */ sprintf(table_query,"SELECT * FROM Filenames"); /* tprintf(trace_string,"%s table_query string >%s<\n", server,table_query); */ /* PREPARE the tranaction */ rc=sqlite3_prepare_v2(sqlite_conn,table_query,QUERY_LEN,&selectStatement,0); /* tprintf(trace_string,"%s PAST PREPARE rc=%d\n", server,rc); */ /* Begin the transaction */ rc=sqlite3_exec(sqlite_conn,"BEGIN TRANSACTION", NULL, NULL, &sqlite_errormsg); if( rc != SQLITE_OK ) { /* tprintf(trace_string,"%s FAILED to fetch Filenames table", server); */ strcpy(requestBlock.errormsg, "Can't Query Filenames Table"); sqlite3_close(sqlite_conn); requestBlock.returncode = -10; M0sxdone(&requestBlock); return(0); } /* tprintf(trace_string,"%s PAST EXECUTE rc=%d %s\n", server,rc, sqlite_errormsg); */ /* step through the transaction */ rc = sqlite3_step(selectStatement); while ( rc == SQLITE_ROW ) { /* Save the key names */ fname = (char*) (sqlite3_column_text(selectStatement, 1)); file_len = strlen( fname ); strncpy(file_names[Nfile], fname, file_len+1); /* tprintf(trace_string,"%s FILENAME = %s LEN=%d", server,file_names[Nfile],file_len); */ Nfile++; rc = sqlite3_step(selectStatement); } /* End the transaction */ rc=sqlite3_exec(sqlite_conn,"END TRANSACTION", NULL, NULL, &sqlite_errormsg); /* tprintf(trace_string,"%s PAST EXECUTE rc=%d %s\n", server,rc, sqlite_errormsg); */ /* deallocate memory used by the sqlite_exec */ sqlite3_finalize(selectStatement); /* CLOSE the SQLite database */ sqlite3_close(sqlite_conn); /* ******** end of DB loop ********** */ } /* *************************************************************************************** */ /* Step 4 - Read the Entries tables` */ /* Initalization */ DBstep = 0; THIS_SEC = -1; n_times = 0; last_cyd = 0; Nrec = 0; /* ********* loop through the DBs ******** */ for( N=0; N lines */ for( i=0; i elems */ for( i=0; i BAND */ for( i=0; i 0 ) { for( i=0; i= 0 ) { Nbands[j]++; bands[j][iBand-1] = 1; positions[j][iBand-1] = DBstep-1; lines[j][iBand-1] = image_lines; elems[j][iBand-1] = image_elems; iress[j][iBand-1] = iResolution; gress[j][iBand-1] = gResolution; DQF1s[j][iBand-1] = DQF1; DQF2s[j][iBand-1] = DQF2; DQF3s[j][iBand-1] = DQF3; DQF4s[j][iBand-1] = DQF4; DQF5s[j][iBand-1] = DQF5; DQF6s[j][iBand-1] = DQF6; DQF7s[j][iBand-1] = DQF7; DQF8s[j][iBand-1] = DQF8; YFacs[j][iBand-1] = (int)(lfac*iscale); YOffs[j][iBand-1] = (int)(loff*iscale); XFacs[j][iBand-1] = (int)(cfac*iscale); XOffs[j][iBand-1] = (int)(coff*iscale); } /* go get another record */ rc = sqlite3_step(selectStatement); if( rc != SQLITE_ROW ) tprintf(trace_string,"%s NO MORE ROWS: rc=%d", server,rc); } /* End the transaction */ rc=sqlite3_exec(sqlite_conn,"END TRANSACTION", NULL, NULL, &sqlite_errormsg); /* tprintf(trace_string,"%s END TRANSACTION rc=%d %s\n", server,rc, sqlite_errormsg); */ /* deallocate memory used by the sqlite_exec */ sqlite3_finalize(selectStatement); /* CLOSE the SQLite database */ sqlite3_close(sqlite_conn); /* ******** end of DB loop ********** */ } tprintf(trace_string,"%s Number of Data Entries = %d", server,num_flist); tprintf(trace_string,"%s Number of Unique Times = %d\n", server,n_times); /* using the SQLITE database */ database_switch = 1; /* ************************************************************************************ */ /* tprintf(trace_string, "%s MySQL Database TERMINATION ", server); */ goto REQUEST_CHECK; /* JUMP HERE IF WE ARE NOT USING A SQLITE DATABASE */ GREP_FOR_FILES: /* ************************************************************************* ** Step 2A: Get a list of file names matching the ADDE file mask ** ** ************************************************************************* */ /* ** Example file names to be supported ** OR_ABI-L1b-RadM2-M6C13_G16_s20191270804043_e20191270804112_c20191270804149.nc ** ** GRB ** OR_ABI-L1b-RadC-M6C01_G16_s20191252001256_e20191252004029_c20191252004076.nc ** OR_ABI-L1b-RadF-M6C07_G16_s20191261220296_e20191261230015_c20191261230053.nc ** OR_ABI-L1b-RadM1-M6C09_G16_s20191270803343_e20191270803406_c20191270803448.nc ** OR_ABI-L1b-RadM2-M6C13_G16_s20191270804043_e20191270804112_c20191270804149.nc ** ** NOAAPort L2 CMIP ** OR_ABI-L2-CMIPC-M6C01_G16_s20191262006260_e20191262006260_c20191262006260.nc ** OR_ABI-L2-CMIPF-M6C07_G16_s20191270400290_e20191270400290_c20191270400290.nc ** OR_ABI-L2-CMIPM1-M6C09_G16_s20191271405340_e20191271405340_c20191271405340.nc ** OR_ABI-L2-CMIPM2-M6C13_G16_s20191271400040_e20191271400040_c20191271400040.nc ** OR_ABI-L2-CMIPPR-M6C16_G16_s20191270410290_e20191270410290_c20191270410290.nc ** ** OR_ABI-L2-CMIPC-M6C01_G17_s20191262006190_e20191262006190_c20191262006190.nc ** OR_ABI-L2-CMIPF-M6C07_G17_s20191270400330_e20191270400330_c20191270400330.nc ** OR_ABI-L2-CMIPM1-M6C09_G17_s20191271408270_e20191271408270_c20191271408270.nc ** OR_ABI-L2-CMIPM2-M6C13_G17_s20191271406570_e20191271406570_c20191271406570.nc ** OR_ABI-L2-CMIPAK-M6C02_G17_s20191270410330_e20191270410330_c20191270410330.nc ** OR_ABI-L2-CMIPHI-M6C11_G17_s20191270410330_e20191270410330_c20191270410330.nc ** ** NOAAPort L2 other than CMIP ** OR_ABI-L2-ADPC-M6_G16_s20191242001251_e20191242004024_c20191242004591.nc ** OR_ABI-L2-AODC-M6_G16_s20191262006263_e20191262009036_c20191262011216.nc ** OR_ABI-L2-ACMF-M6_G16_s20191270410296_e20191270420004_c20191270420288.nc ** OR_ABI-L2-CODC-M6_G16_s20191262016263_e20191262019036_c20191262021128.nc ** OR_ABI-L2-CPSF-M6_G16_s20191270400296_e20191270410004_c20191270411208.nc ** OR_ABI-L2-ACHAC-M6_G16_s20191262016263_e20191262019036_c20191262020467.nc ** OR_ABI-L2-ACTPM1-M6_G16_s20191271418344_e20191271418402_c20191271419094.nc ** OR_ABI-L2-CTPF-M6_G16_s20191270410296_e20191270420004_c20191270421179.nc ** OR_ABI-L2-ACHTM1-M6_G16_s20191271418344_e20191271418402_c20191271419491.nc ** OR_ABI-L2-DMWC-M6C09_G16_s20191241946251_e20191241949030_c20191242021171.nc ** OR_ABI-L2-DSIF-M6_G16_s20191270410296_e20191270420004_c20191270422395.nc ** OR_ABI-L2-FDCF-M6_G16_s20191270410296_e20191270420004_c20191270420114.nc ** OR_GLM-L2-GLMC-M3_G16_s20191252115000_e20191252116000_c20191252116520.nc ** OR_ABI-L2-LSTC-M6_G16_s20191152101204_e20191152103576_c20191152104367.nc ** OR_ABI-L2-LVMPC-M6_G16_s20191212021230_e20191212024003_c20191212025509.nc ** OR_ABI-L2-LVTPC-M6_G16_s20191212021230_e20191212024003_c20191212025509.nc ** OR_ABI-L2-RRQPEF-M6_G16_s20191270420296_e20191270430004_c20191270430102.nc ** OR_ABI-L2-SSTF-M6_G16_s20191231910276_e20191232009585_c20191232015316.nc ** OR_ABI-L2-TPWM1-M6_G16_s20191271422344_e20191271422402_c20191271423088.nc ** OR_ABI-L2-VAAF-M6_G16_s20191270420296_e20191270430004_c20191270430543.nc ** ** GRB GLM ** OR_GLM-L2-LCFA_G16_s20191262106200_e20191262106400_c20191262106425.nc ** ** .._(ABI|GLM)-((L1b|L2)-(.{3,5})(F|C|M[12]|AK|HI|PR))-M([346])(_|C.._)G(1[6-9])_s(.{7})(.{6}) ** mlist: 1 2 3 4 5 6 7 8 9 10 ** */ /* Produce a list of files matching the pattern mask */ flist = M0GetMaskFileList(mask); tprintf(trace_string, "%s looking for MASK = %s", server, mask ); if( flist == (char **)NULL ) { strcpy(requestBlock.errormsg, "No images satisfy selection criteria"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { num_flist = VecLen(flist); if( num_flist <= 0 ) { (void)strcpy(requestBlock.errormsg, "No files found matching file mask"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } tprintf(trace_string, "%s Number of MASK file(s) found = %d", server, num_flist); } /* malloc the 1D image tracking arrays */ seconds = (int*) malloc(num_flist * sizeof(int)); cover = (int*) malloc(num_flist * sizeof(int)); imode = (int*) malloc(num_flist * sizeof(int)); sss = (int*) malloc(num_flist * sizeof(int)); tprintf(trace_string, "%s FIRST PASS: 1D image tracking arrays malloced", server); /* malloc the 2D image tracking arrays */ lines = malloc2dint( num_flist, MAX_BANDS ); elems = malloc2dint( num_flist, MAX_BANDS ); bands = malloc2dint( num_flist, MAX_BANDS ); iress = malloc2dint( num_flist, MAX_BANDS ); gress = malloc2dint( num_flist, MAX_BANDS ); positions = malloc2dint( num_flist, MAX_BANDS ); tprintf(trace_string, "%s FIRST PASS: 2D image tracking arrays malloced", server); /* Initialize the 2D image tracking arrays */ for( i=0; iEband ** POS - ADDE position number ** TIME - image Btime<->Etime ** DAY - image Bday<->Eday ** SS - satellite number ** AUX - Auxillary block flag ** ** ************************************************************************* */ /* BAND sort condition */ num_band = Mcargnum(0, "BAN.D"); if( num_band > 0 ) { rc = Mcargstr(0,"BAN.D",1,"ALL",(const char **) &cBand); if (strncmp(cBand, "ALL", 3) == 0) { bband = 1; eband = MAX_BANDS; } else { /* Read the beginning band */ rc = Mcargint(0,"BAN.D",1,0,1,MAX_BANDS,&bband,(const char **)&dum); if( rc < 0 ) { 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,MAX_BANDS,&eband,(const char **)&dum); if( rc < 0 ) { strcpy(requestBlock.errormsg, "Invalid band number specified"); requestBlock.returncode = -34; M0sxdone(&requestBlock); return (0); } } } else { bband = 1; eband = MAX_BANDS; } tprintf(trace_string,"%s bband=%d eband=%d", server,bband,eband); /* TIME sort condition */ checkTime = Mcargnum(0, "TIM.E"); if( checkTime != 0 ) { rc = Mcargihr(0, "TIM.E", 1, -1, -1, 240000, &bTime, (const char **)&dum); rc = Mcargihr(0, "TIM.E", 2, bTime, -1, 240000, &eTime, (const char **)&dum); /* tprintf(trace_string, "%s bTime: %d, eTime: %d", server, bTime, eTime); */ } /* DAY sort condition */ checkDay = Mcargnum(0, "DAY" ); if( checkDay != 0 ) { rc = Mcargiyd(0, "DAY", 1, -1, 999, -999, &bDate, (const char **)&dum); rc = Mcargiyd(0, "DAY", 2, bDate, 999, -999, &eDate, (const char **)&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; } /* tprintf(trace_string, "%s bDate: %d, eDate: %d", server, bDate, eDate); */ } /* SS sort condition */ checkSS = Mcargnum(0, "SS" ); if( checkSS != 0 ) { rc = Mcargint(0, "SS", 1, -1, 999, -999, &bSS, (const char **)&dum); rc = Mcargint(0, "SS", 2, bSS, 999, -999, &eSS, (const char **)&dum); /* tprintf(trace_string, "%s bSS: %d, eSS: %d", server, bSS, eSS); */ } /* AUX sort condition */ rc = Mcargstr(0, "AUX", 1, "NO", (const char **) &cAux); if (strncmp(cAux, "YES", 3) == 0) { auxFlag = 1; } else { auxFlag = 0; } /* tprintf(trace_string, "%s auxFlag: %d", server, auxFlag); */ /* Go forward to the Main Loop */ if( database_switch == 1 ) goto MAIN_LOOP; /* ************************************************************************* ** Step 4: Analyze the file names ** ** We used the previous pass to determine the number of unique image times and ** coverages. We then used this info to allocate memory for arrays to hold all ** the necessary info from the file name. ** ** ************************************************************************* */ /* Examine each file name to get the day and time of the data */ n_times = 0; for( Pos=0; Pos>>>> */ tprintf(trace_string, "%s file_name = %s", server, file_name); /* Does the file name match the filemask regular expression? */ mlist = GetRegexpMatchList( EREGEXP, file_name ); nmatch = VecLen( mlist ); if ( nmatch != MATCH ) { tprintf(trace_string, "%s SECOND PASS #match from GetRegexpMatchList = %d expected %d", server, nmatch, MATCH); continue; } /* ** mlist meanings: ** ** mlist[ 0] - name: OR_... ** mlist[ 1] - inst: ABI, GLM ** mlist[ 2] - pnam: L1b-Rad(C|F|...), L2-CMIP(C|F|...), L2-ADP(C|F|...), etc. ** mlist[ 3] - levl: L2, L1b ** mlist[ 4] - type: Rad, CMIP, ADP, ADC, ACM, etc. ** mlist[ 5] - covr: F, C, M1, M2, AK, HI, PR ** mlist[ 6] - mode: 3, 4, 6 ** mlist[ 7] - band: _, C01_, ..., C16_ ** mlist[ 8] - sat: 16, 17, 18, 19 ** mlist[ 9] - image_cyd: CCYYDDD (7 characters long) ** mlist[10] - image_hms: HHMMSS (6 characters long) */ for( i=0; i 0 || image_lines > 0 || image_elems > 0 ) { if( n_times == 0 ) { /* Fill the image context arrays */ seconds[n_times] = image_sec; cover[n_times] = iCoverage; imode[n_times] = ImageMode; sss[n_times] = iSSS; for( i=0; i= image_tmin && seconds[i] <= image_tmax ) && (iCoverage == cover[i] ) && (ImageMode == imode[i] ) && (iSSS == sss[i] ) ) { /* If necessary, use time delta to rest time if */ if( image_sec != seconds[i] ) { image_sec = seconds[i]; rc = Mcsectodaytime( image_sec, &image_cyd, &image_hms ); } /* Record the band */ for( j=0; ji; j-- ) { seconds[j] = seconds[j-1]; cover[j] = cover[j-1]; imode[j] = imode[j-1]; sss[j] = sss[j-1]; for( k=0; k we exit the server */ if( n_times < 0 ) { strcpy(requestBlock.errormsg, "No data files found"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } tprintf(trace_string, "%s SECOND PASS: Number of Unique times=%d", server, n_times); /* ************************************************************************* ** Step 7: MAIN LOOP ** ** At this point we have a list of files that have passed the ** date, time and dimension tests. The next step is to scan this ** list to verify that the dates and times meet any transaction conditions. ** If a file passes, we construct a directory entry and send it to ** the client. ** ** ************************************************************************* */ MAIN_LOOP: /* POS sort condition */ FPos = 0; rPos = 0; rc = Mcargint(0, " ", 2, 0, -99999, n_times, &bPos, (const char **)&dum); if( bPos == ALL ) { bPos = 1; ePos = n_times; iPos = 1; } else { if( rc < 0 ) { strcpy(requestBlock.errormsg, "Invalid Beginning Position"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } if( bPos <= 0 ) { /* rPos=-1 indicates a time relative search */ rPos = 1; /* FPos is the counter of how many images to return */ FPos = (bPos*-1)+1; bPos = n_times; ePos = 1; iPos = -1; } else { rc = Mcargint(0, " ", 3, bPos, bPos, 99999, &ePos, (const char **)&dum); if( rc < 0 ) { strcpy(requestBlock.errormsg, "Invalid Ending Position"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } if( ePos > n_times ) ePos = n_times; iPos = 1; } } tprintf(trace_string, "%s bPos: %d, ePos: %d ", server, bPos, ePos); tprintf(trace_string, "%s BEFORE MAIN LOOP --- bpos=%d epos=%d ipos=%d", server, bPos, ePos, iPos); /* Initialization */ listCount= 0; iiBand = iBand; /* Dataset Loop starts here */ for( image_dataset_position=bPos*iPos; image_dataset_position<=ePos*iPos; image_dataset_position++ ) { /* Set list position */ jPos = iPos * image_dataset_position; tprintf(trace_string, "%s POS=%d",server, jPos); /* Convert seconds to date and time */ rc = Mcsectodaytime( seconds[jPos-1], &image_cyd, &image_hms ); tprintf(trace_string, "%s SEC=%d DAY=%d TIME=%d",server,seconds[jPos-1],image_cyd,image_hms); /* Check client search conditions: DAY=bDAY eDAY */ /* image_cyd = dates[jPos-1]; */ rc = Mccydtoiyd( image_cyd, &image_iyd ); if (checkDay > 0 ) { if( (image_iyd < bDate) || (image_iyd > eDate) ) continue; } /* Check client search conditions: TIME=bTIME eTIME */ /* image_hms = times[jPos-1]; */ if (checkTime > 0 ) { if( (image_hms < bTime) || (image_hms > eTime) ) continue; } /* Check client search conditions: SS=bSS eSS */ image_satellite_number = sss[jPos-1]; tprintf(trace_string, "%s Check SSS = %d",server, image_satellite_number); if (checkSS > 0 ) { if( (image_satellite_number < bSS) || (image_satellite_number > eSS) ) continue; } tprintf(trace_string, "%s Passed Checks",server); /* Initialize the DQF values */ for( k=0; k>>>> */ k = j*16; /* Look for the DQF variable in the file */ file_name = flist[ positions[jPos-1][j] ]; rc = nc_open( file_name, NC_NOWRITE, &ncdf_id ); rc = nc_inq_varid(ncdf_id, "DQF", &var_id); if( rc == NC_NOERR ) { rc = nc_get_att_float(ncdf_id, var_id, "percent_good_pixel_qf", &DQF_file); if( rc == NC_NOERR ) { DQF_darray[k] = DQF_file; DQF_iarray[k] = (int)(DQF_file*10000.0 +0.5); } rc = nc_get_att_float(ncdf_id, var_id, "percent_conditionally_usable_pixel_qf", &DQF_file); if( rc == NC_NOERR ) { DQF_darray[k+1] = DQF_file; DQF_iarray[k+1] = (int)(DQF_file*10000.0 +0.5); } rc = nc_get_att_float(ncdf_id, var_id, "percent_out_of_range_pixel_qf", &DQF_file); if( rc == NC_NOERR ) { DQF_darray[k+2] = DQF_file; DQF_iarray[k+2] = (int)(DQF_file*10000.0 +0.5); } rc = nc_get_att_float(ncdf_id, var_id, "percent_no_value_pixel_qf", &DQF_file); if( rc == NC_NOERR ) { DQF_darray[k+3] = DQF_file; DQF_iarray[k+3] = (int)(DQF_file*10000.0 +0.5); } rc = nc_get_att_float(ncdf_id, var_id, "percent_focal_plane_temperature_threshold_exceeded_qf", &DQF_file); if( rc == NC_NOERR ) { DQF_darray[k+4] = DQF_file; DQF_iarray[k+4] = (int)(DQF_file*10000.0 +0.5); } } /* Look for the "maximum_focal_plane_temperature" variable in the file */ rc = nc_inq_varid(ncdf_id, "maximum_focal_plane_temperature", &var_id); if( rc == NC_NOERR ) { rc = nc_get_var_float(ncdf_id, var_id, &DQF_float ); if( rc == NC_NOERR ) { tprintf(trace_string, "%s maximum focal plane temperature=%f" ,server,DQF_float); if( DQF_float == -999.0 ) { DQF_darray[k+5] = DQF_float; DQF_iarray[k+5] = 65531; } else { DQF_darray[k+5] = DQF_float; DQF_iarray[k+5] = (int)(DQF_float*100.0 +0.5); } } else { tprintf(trace_string, "%s FAILED: GET maximum focal plane temperature" ,server); } } else { printf(trace_string, "%s FAILED: FIND maximum focal plane temperature" ,server); } /* look for the "focal_plane_temperature_threshold_increasing" variable in the file */ rc = nc_inq_varid(ncdf_id, "focal_plane_temperature_threshold_increasing", &var_id); if( rc == NC_NOERR ) { rc = nc_get_var_float(ncdf_id, var_id, &DQF_float ); if( rc == NC_NOERR ) { if( DQF_float == -999.0 ) { DQF_darray[k+6] = DQF_float; DQF_iarray[k+6] = 65531; } else { DQF_darray[k+6] = DQF_float; DQF_iarray[k+6] = (int)(DQF_float*100.0 +0.5); } } } else { printf(trace_string, "%s FAILED: FIND focal plane temperature threshold increasing" ,server); } /* look for the "focal_plane_temperature_threshold_decreasing" variable in the file */ rc = nc_inq_varid(ncdf_id, "focal_plane_temperature_threshold_decreasing", &var_id); if( rc == NC_NOERR ) { rc = nc_get_var_float(ncdf_id, var_id, &DQF_float ); if( rc == NC_NOERR ) { if( DQF_float == -999.0 ) { DQF_darray[k+7] = DQF_float; DQF_iarray[k+7] = 65531; } else { DQF_darray[k+7] = DQF_float; DQF_iarray[k+7] = (int)(DQF_float*100.0 +0.5); } } } else { printf(trace_string, "%s FAILED: FIND focal plane temperature threshold decreasing" ,server); } /* close the file */ nc_close( ncdf_id ); /* IF we are using the database THEN we can just copy the values from the DB arrays */ } else if( database_switch == 1 && bands[jPos-1][j] == 1 ) { tprintf(trace_string, "%s SQLITE DB", server ); k = j*16; DQF_darray[k] = (float)(DQF1s[jPos-1][j])*0.01; DQF_iarray[k] = DQF1s[jPos-1][j]; DQF_darray[k+1] = (float)(DQF2s[jPos-1][j])*0.01; DQF_iarray[k+1] = DQF2s[jPos-1][j]; DQF_darray[k+2] = (float)(DQF3s[jPos-1][j])*0.01; DQF_iarray[k+2] = DQF3s[jPos-1][j]; DQF_darray[k+3] = (float)(DQF4s[jPos-1][j])*0.01; DQF_iarray[k+3] = DQF4s[jPos-1][j]; DQF_darray[k+4] = (float)(DQF5s[jPos-1][j])*0.01; DQF_iarray[k+4] = DQF5s[jPos-1][j]; DQF_darray[k+5] = (float)(DQF6s[jPos-1][j])*0.01; DQF_iarray[k+5] = DQF6s[jPos-1][j]; DQF_darray[k+6] = (float)(DQF7s[jPos-1][j])*0.01; DQF_iarray[k+6] = DQF7s[jPos-1][j]; DQF_darray[k+7] = (float)(DQF8s[jPos-1][j])*0.01; DQF_iarray[k+7] = DQF8s[jPos-1][j]; } /* tprintf(trace_string, "%s BAND=%d DQF=%d (%f) %d (%f) %d (%f) %d (%f) %d (%f) %d (%f) %d %f) %d (%f)", server ,j+1 ,DQF_iarray[k], DQF_darray[k] ,DQF_iarray[k+1], DQF_darray[k+1] ,DQF_iarray[k+2], DQF_darray[k+2] ,DQF_iarray[k+3], DQF_darray[k+3] ,DQF_iarray[k+4], DQF_darray[k+4] ,DQF_iarray[k+5], DQF_darray[k+5] ,DQF_iarray[k+6], DQF_darray[k+6] ,DQF_iarray[k+7], DQF_darray[k+7] ); */ } /* RESOLUTION TRACKING mods */ /* ******* STARTS the RESOLUTION TRACKING LOOP ***** We are performing a NC_OPEN on the files with unique base resolutions to compute the actual image CP resolution. */ tprintf(trace_string, "%s SQLITE DB; NRES=%d ", server, NRES ); for (k=0; k eband ) continue; /* Zero the directory block */ for( i=0; i decremnet the counter */ if( rPos == 1 ) FPos = FPos-1; } /* If no images were listed, send an "error" message */ if (listCount == 0) { (void) strncpy(requestBlock.errormsg, "No images satisfy the search criteria", sizeof(requestBlock.errormsg)); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } /* Termination */ M0sxdone(&requestBlock); tprintf(trace_string, "%s Exiting\n", server); return (0); } #define CALC_LAT_RES_CARD "Calculated Latitude resolution (km) = %f" #define CALC_LON_RES_CARD "Calculated Longitude resolution (km) = %f" #define DQF_CARD "DQF for band %d= %.4s %.4s %.4s %.4s %.4s %.4s %.4s %.4s" int GetModsCards ( int *areaDir, int *bandList, int *dqf, float lat, float lon, float rlat, float rlon, float clatres, float clonres, int *cards, int auxFlag, int database_switch ) { int NUM_COMMENT = 63; int rc; int numCards = 0; int band; int i; int n,k,kk; int L2INDX; int sss; int MAX_BANDS; char card[80]; char cval[16][8]; float fval; /* set the MAX_BANDS */ MAX_BANDS = ABI_MAX_BANDS; if( database_switch == 1 ) MAX_BANDS = ADB_MAX_BANDS; /* Get the satellite number */ sss = areaDir[2]; /* Build cards for center point */ sprintf(card, CEN_LAT_CARD, lat); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; sprintf(card, COMP_LAT_CARD, rlat); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; sprintf(card, CEN_LON_CARD, lon); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; sprintf(card, COMP_LON_CARD, rlon); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; sprintf(card, CALC_LAT_RES_CARD, clatres); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; sprintf(card, CALC_LON_RES_CARD, clonres); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; /* AUX cal cards if needed */ if (auxFlag) { for( i=0; i 0 ) { band = i+1; /* Data Quality Flag card */ n=i*16; for( k=0; k<8; k++ ) { /* TDQF index reorder */ if( k == 0 ) kk=4; if( k == 1 ) kk=5; if( k == 2 ) kk=6; if( k == 3 ) kk=7; if( k == 4 ) kk=0; if( k == 5 ) kk=1; if( k == 6 ) kk=2; if( k == 7 ) kk=3; if( dqf[n+kk] == 65530 ) { sprintf(cval[k], "NA" ); } else if( dqf[n+kk] == 65531 ) { sprintf(cval[k], "ND" ); } else { fval = ((float)(dqf[n+kk]))/100.00; if( kk < 5 ) { sprintf(cval[k], "%3.0f%s", fval, "%" ); } else { sprintf(cval[k], "%3.0f%s", fval, "K" ); } } } sprintf(card, DQF_CARD, band, cval[0],cval[1],cval[2],cval[3],cval[4],cval[5],cval[6],cval[7]); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; /* RAW card */ sprintf(card, CAL_CARD, band, "RAW ", "SCALED COUNTS"); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; if( sss == 186 || sss == 188 || sss == 190 || sss == 192 ) { /* For L1b files */ /* RAD card */ if( areaDir[51] == lit_("ABIN",4) ) { sprintf(card, CAL_CARD, band, "RAD ", "RADIANCE"); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; } /* ALB/TEMP card */ if( band >= 7 ) { sprintf(card, CAL_CARD, band, "TEMP", "TEMPERATURE"); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; } else { sprintf(card, CAL_CARD, band, "ALB ", "ALBEDO"); rc = AddCard(card, (char *) cards, MAX_CARD_LEN, numCards); numCards++; } } else if( sss == 187 || sss == 189 || sss == 191 || sss == 193 ) { /* For L2 files */ for( L2INDX=0; L2INDX