/* * 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.26 2019/05/15 11:56:07 russd Tst $ ****/ /* ** Name: ** abiadir : ADDE directory server for GOES-R series image format. ** ** 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 "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" /* NetCDF include files */ #include "netcdf.h" /* ABIN include files */ #include "abinparm.h" int **malloc2dint(int, int); int GetModsCards (int*, int*, int*, float, float, float, float, int*, int); #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 /* size of the directory block */ #define IMAGE_STARTING_LINE 1 /* image starting line */ #define IMAGE_STARTING_ELEMENT 1 /* image starting element */ #define IMAGE_FILE_VERSION 4 /* AREA ID type number */ #define MAX_STR_LEN 80 /* card length */ #define MAX_ATR_LEN 120 /* aux card length */ #define ABI_SSS 186 /* Satellite number */ #define ABI_MAX_BANDS 32 /* maximum number of bands supported */ #define ABI_MAX_SEGS 10 /* maximum number of bands supported */ #define ABI_AUX_OFFSET 0 /* AUX block offset */ #define ABI_CAL_OFFSET 768 /* CAL block offset */ #define ABI_NAV_OFFSET 256 /* NAV block offset */ #define ABI_AUX_ENTRIES 0 /* number of AUX block entries */ #define NORMAL_END 0 #define ERROR_END 100 #define ERROR_ALLOCATE 72 #define ERROR_READ 79 #define ERROR_DATA 80 #define M_PI 3.14159265358979323846 #define DEGTORAD (M_PI/180.0) #define RADTODEG (180.0/M_PI) #define SCLUNIT 1.525878906250000e-05 { /* Internal Varaiables */ char *dum; /* dummy for arg fetchers */ char *SysEnv; /* System Environment */ 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 *cdate; /* ADDE request sYMD number */ char *cday; /* ADDE request sYMD number */ char *request = NULL; /* ADDE request text */ char cards[24000]; /* ADDE return cards */ char *comment; /* ADDE dataset comment */ char **flist; /* Array of files matching ADDE mask */ char *format; /* ADDE dataset format */ char *info; /* ADDE dataset info */ char *mask; /* file mask */ char *type; /* ADDE dataset type */ char *coverage; /* coverage code */ char *resolution; /* resolution code */ char *segment; /* segment code */ char substr[5]; char llchar[4]={"LL "}; /* image tracking arrays */ int dim2; int dim3; int *seconds; int *sss; int *cover; int *imode; int *temp1; int **lines; int **elems; int **bands; int **iress; int **gress; int **temp2; int **positions; const char server[] = {"ABINADIR"}; /* server name */ double dparm; /* double variable */ double Dhms; /* double time variable */ 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 DQF_darray[512]; /* DQF array 16 values per 32 bands */ int auxFlag = 0; /* Auxillary block useage flag */ int bDate; /* beginning date */ int bTime; /* beginning time */ int bPos, ePos; /* Beginning and Ending ADDE position numbers */ int nPos; /* number of Pos for relative search */ int bSS, eSS; /* Beginning and Ending Satellite numbers */ int eDate; /* ending date */ int eTime; /* ending time */ 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,ii,jj; /* array index counters */ int trace = 0; /* tracing flags */ int transaction = 0; /* Transaction flag */ int user = 0; /* request USER id */ int ALL; /* transaction "ALL" constant */ int directory[64]; /* directory block array */ int DQF_iarray[512]; /* DQF array 16 values per 32 bands */ int file_handle; /* file handle */ int length; /* length of the parsed fle name */ int numArg; /* number of parsed parameters */ int YMD, Y, M, D; /* file Year, Month, and Day variables */ int HMS; /* file HourMinuteSecond */ int hiBound; /* ADDE dataset index maximum bounds */ int Pos; /* ADDE position number */ int rPos; /* relative ADDE poition */ int iPos; /* beginning ADDE position */ int jPos,jSeg; /* 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_cards; /* number of comment cards */ int num_flist; /* number of files matching ADDE mask */ int num_parm; int i_parm; int n_parm; int send_byte_total; /* number of bytes sent to client */ int aux_block_size; /* computed AUX block size */ 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 */ Fint image_cyd; /* image date in CCYYDDD format */ int image_iyd; /* image date in AREA format */ int image_hms; /* image time in HHMMSS format */ int image_tmin; /* rounded image time in HHMMSS format */ int image_tmax; /* rounded image time in HHMMSS format */ int image_n_bands; /* number of bands detected in the image file */ int image_geo_line_size; /* number of LALO lines */ int image_geo_element_size; /* number of LALO elements */ int image_geo_data_size; /* bytes per LALO element */ int ImageType; /* ABI file name - Image Type */ int ImageMode; /* ABI file name - Image Mode */ int ImageChannel; /* ABI file name - Image Channel */ int ImagePlatform; /* ABI file name - Image Platform */ int inc_time; /* bump time used to calculate start time of TARGET sectors */ int n_times; /* number of image times */ int Msegs; /* segment counter */ int ABI_MAX_TIMES; /* number of time in this dataset */ int gotTime; /* indicates 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 band; /* band number */ int bband; /* beginning band number */ int eband; /* ending band number */ int bandList[ABI_MAX_BANDS]; /* band list for comment cards */ int status; /* function status */ int indx; /* file index */ int iBand,iiBand; /* Band number */ int jBand,jjBand; /* Band number */ int NpBands; /* Number of Product Bands */ int pBands[ABI_MAX_BANDS]; /* Product Band number */ int theBand; /* Band number */ int iSSS; /* SSEC satellite number */ int iCoverage; /* Coverage Code */ int iSegment; /* Segment number (xx of nn format) */ int iResolution; /* SSEC image Resolution factor */ int gResolution; /* SSEC geo Resolution factor */ float fResolution; /* Resolution at SSP */ int imYY; int imMN; int imDD; int imHH; int imMM; int imSS; int imMS; int Iline; int Ielem; /* NetCDF related declaration */ int ncdf_id; int dim_id; int var_id; int image_cp_line; int image_cp_element; int NAV_BLOCK_SIZE = 128; int ONE = 1; int TWO = 2; int LL; Fint4 nav_block[128]; 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; Freal Felem; Freal Flat; Freal Flon; Freal Fdummy; short *Xarray; /* element coordinate array*/ short *Yarray; /* line coordinate array*/ size_t rows; size_t cells; /* NetCDF related declaration */ servacct requestBlock = {0}; /* length of the request block */ static char trace_string[500]; /* tracing text */ unsigned long long llparm; /* LongLong parm from parsed file name */ unsigned int ival; /* unsigned integer variable */ /* string contains parsing mask */ McArgSyntax filesyntax = {"/_.", "=", ".", "{\"", "}", "'", "'", NULL, "X", " "}; /* string contains variable for "ALL" */ memcpy(&ALL, "ALL ", 4 ); M0swbyt4(&ALL, 1); /* ************************************************************************* Step 1: process the transaction request Use standard function calls to retrieve the parameters in the comm block. ************************************************************************* */ /* 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 V1.7", 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 info = %s", server,info); 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,L1BSSS); 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); /* 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] ); } */ /* ************************************************************************* Step 2: Get a list of file names matching the ADDE file mask ************************************************************************* */ /* produce a list of files matching the pattern mask */ flist = M0GetMaskFileList(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); tprintf(trace_string, "%s Number of file 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)); /* read file name to get the day and time of the data */ ABI_MAX_TIMES = 0; for( Pos=0; Pos= 0 ) { /* satellite source */ rc = Mcargstr( file_handle, " ", i_parm+1, " ", &dum ); if( strstr( dum, "G16" ) != NULL ) iSSS = iSSS+186; if( strstr( dum, "G17" ) != NULL ) iSSS = iSSS+188; if( strstr( dum, "G18" ) != NULL ) iSSS = iSSS+190; if( strstr( dum, "G19" ) != NULL ) iSSS = iSSS+192; if( iSSS != 0 ) /* tprintf(trace_string, "%s iSSS=%d", server,iSSS); */ /* image descriptor */ rc = Mcargstr( file_handle, " ", i_parm, " ", &dum ); /* tprintf(trace_string, "%s PARAM=%s", server,dum); */ /* determine the coverage */ iCoverage = 0; if( strstr( dum, "-RadF" ) != NULL ) iCoverage = 1; if( strstr( dum, "-RadC" ) != NULL ) iCoverage = 2; if( strstr( dum, "-RadM1" ) != NULL ) iCoverage = 3; if( strstr( dum, "-RadM2" ) != NULL ) iCoverage = 4; if( iCoverage != 0 ) { n_parm = i_parm+2; } else { /* scan list of L2 Product names contained in abinparm.h */ for (i=0; i<=L2NPRODS; i++ ) { if( iCoverage==0 && strstr(dum,L2NAMES[i])!=NULL ) { iCoverage = L2COVERS[i]; iSSS = iSSS+1; n_parm = i_parm+2; } } } if( iCoverage == 0 ) { continue; } /* Evaluate the file name for image day (sCCYYDDDHHMMSSs) */ rc = Mcargstr( file_handle, " ", n_parm, " ", (const char **)&cdate); /* tprintf(trace_string, "%s Time Parameter = %s", server,cdate); */ length = strlen( cdate ); for( i=1; i0 && image_hms>=0 && iCoverage>0 ) { /* convert to absolute seconds */ status = Mcdaytimetosec( image_cyd, image_hms, &image_sec ); /* delta time is +/- 1 second */ image_tmin = image_sec-1; image_tmax = image_sec+1; /* is this a new time */ gotTime = 0; if( ABI_MAX_TIMES > 0 ) { for( j=0; j=image_tmin && seconds[j]<=image_tmax) && (cover[j]==iCoverage ) && (imode[j]==ImageMode ) && (sss[j]==iSSS ) ) { gotTime = 1; image_sec = seconds[j]; status = Mcsectodaytime( image_sec, &image_cyd, &image_hms ); } } } /* add new time to the list */ if( gotTime == 0 ) { seconds[ABI_MAX_TIMES] = image_sec; cover[ABI_MAX_TIMES] = iCoverage; imode[ABI_MAX_TIMES] = ImageMode; sss[ABI_MAX_TIMES] = iSSS; ABI_MAX_TIMES++; } } } /* free this memory */ rc = Mcargfree( file_handle ); } /* malloc the image tracking arrays */ if( ABI_MAX_TIMES == 0 ) { strcpy(requestBlock.errormsg, "No images satisfy selection criteria"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { tprintf(trace_string, "%s Number of unique times found = %d", server, ABI_MAX_TIMES); free( seconds ); free( cover ); free( imode ); free( sss ); /* malloc the 1D image tracking arrays */ seconds = (int*) malloc(ABI_MAX_TIMES * sizeof(int)); cover = (int*) malloc(ABI_MAX_TIMES * sizeof(int)); imode = (int*) malloc(ABI_MAX_TIMES * sizeof(int)); sss = (int*) malloc(ABI_MAX_TIMES * sizeof(int)); /* malloc the 2D image tracking arrays */ lines = malloc2dint( ABI_MAX_TIMES, ABI_MAX_BANDS ); elems = malloc2dint( ABI_MAX_TIMES, ABI_MAX_BANDS ); bands = malloc2dint( ABI_MAX_TIMES, ABI_MAX_BANDS ); iress = malloc2dint( ABI_MAX_TIMES, ABI_MAX_BANDS ); gress = malloc2dint( ABI_MAX_TIMES, ABI_MAX_BANDS ); positions = malloc2dint( ABI_MAX_TIMES, ABI_MAX_BANDS ); /* initialize the 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 = ABI_MAX_BANDS; } else { /* read the beginning band */ rc = Mcargint(0,"BAN.D",1,0,1,ABI_MAX_BANDS,&bband,&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,ABI_MAX_BANDS,&eband,&dum); if( rc < 0 ) { strcpy(requestBlock.errormsg, "Invalid band number specified"); requestBlock.returncode = -34; M0sxdone(&requestBlock); return (0); } } } else { bband = 1; eband = ABI_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, &dum); rc = Mcargihr(0, "TIM.E", 2, bTime, -1, 240000, &eTime, &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, &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; } /* 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, &dum); rc = Mcargint(0, "SS", 2, bSS, 999, -999, &eSS, &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; } /* ************************************************************************* Step 4: Analyze the file names (again) 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. ************************************************************************* */ /* open each file to get the day and time of the data */ n_times = 0; for( Pos=0; Pos= 0 ) { /* satellite source */ rc = Mcargstr( file_handle, " ", i_parm+1, " ", &dum ); if( strstr( dum, "G16" ) != NULL ) iSSS = iSSS+186; if( strstr( dum, "G17" ) != NULL ) iSSS = iSSS+188; if( strstr( dum, "G18" ) != NULL ) iSSS = iSSS+190; if( strstr( dum, "G19" ) != NULL ) iSSS = iSSS+192; if( iSSS != 0 ) /* image descriptor */ rc = Mcargstr( file_handle, " ", i_parm, " ", &dum ); /* ZERO the pBand array */ for( i=0; i 0 || image_lines > 0 || image_elems > 0 ) { if( n_times == 0 ) { /* fill the image context arrays */ sss[n_times] = iSSS; seconds[n_times] = image_sec; cover[n_times] = iCoverage; imode[n_times] = ImageMode; 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]; status = 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( ii=0; ii we exit the server */ if( n_times < 0 ) { strcpy(requestBlock.errormsg, "No data files found"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } else { 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. ************************************************************************* */ /* POS sort condition */ FPos = 0; rPos = 0; rc = Mcargint(0, " ", 2, 0, -99999, n_times, &bPos, &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, &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 */ status = Mcsectodaytime( seconds[jPos-1], &image_cyd, &image_hms ); /* Check client search conditions: DAY=bDAY eDAY */ /* image_cyd = dates[jPos-1]; */ status = 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 Past Checks",server); */ /* initialize the DQF values */ for( jj=0; jj<512; jj++ ) { DQF_iarray[jj] = 65530; DQF_darray[jj] = -998.0; } /* scan the band array for first band number */ iiBand = 0; /* loop through the bands */ for( j=0; j 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 exit\n", server); return (0); } #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 CAL_CARD "Valid calibration unit for band %d = %s \"%s\"" #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, int *cards, int auxFlag ) { int NUM_COMMENT = 63; int rc; int numCards = 0; int band; int i,ii; int n,k,kk; int L2INDX; int sss; char card[80]; char cval[16][8]; float fval; /* 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, CEN_LAT_RES_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, CEN_LON_RES_CARD, rlon); 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++; /* for L1B files */ if( sss == 186 || sss == 188 || sss == 190 || sss == 192 ) { /* rad card */ 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++; } /* for L2 files */ } else if( sss == 187 || sss == 189 || sss == 191 || sss == 193 ) { for( L2INDX=0; L2INDX