/* * 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: abinaget.c,v 1.45 2019/05/15 11:56:07 russd Tst $ ****/ /* ** Name: ** abinaget : ADDE data 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: ** This program is reads GOES-R series images from NetCDF data format ** ** Categories: ** ADDE server */ #include #include #include #if defined(__APPLE__) #include #endif #include #include "mcidas.h" #include "mcidasp.h" #include "mcncdf.h" #include "m0arg.h" #include "AreaDir.h" #include "SDIUtil.h" #include "m0glue.h" #include "math.h" /* NetCDF include files */ #include "netcdf.h" /* ABIN include files */ #include "abinparm.h" /* Prototypes */ int **malloc2dint(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 TRUE 1 /* TRUE flag */ #define FALSE 0 /* FALSE flag */ #define DIR_SIZE 64 /* size of the diectory block */ #define IMAGE_FILE_VERSION 4 /* AREA ID type element */ #define MAX_STR_LEN 80 /* card length */ #define ABI_MAX_L1B 16 /* maximum number of bands supported */ #define ABI_MAX_BANDS 32 /* maximum number of bands supported */ #define ABI_MAX_SEGS 10 /* size of file arrays */ #define ABI_MASK 30 /* size of the no data region */ #define ABI_SSS 186 /* SSEC satellite number */ #define ABI_NAV_OFFSET 256 /* NAV block offset */ #define ABI_AUX_ENTRIES 0 /* AUX block entries */ #define SSEC_INVALID 0 /* SSEC INVALID_VALUE */ { /* internal Variables */ char llchar[4]={"LL "}; char substr[5]; /* segment substring buffer */ char level_map[ABI_MAX_BANDS]; /* prefix level map */ char *SysEnv; /* System Environment */ char *file_name; /* name of NetCDF file */ char *sector_type; /* image source type */ char *image_stype; /* image source type */ char *last_stype; /* previous source type */ char *dataset; /* dataset name */ char *def_unit; /* default UNIT */ char *dir_unit; /* directory UNIT */ char *var_name[ABI_MAX_BANDS]; /* variable name */ char *comment; /* ADDE comment field */ char *format; /* ADDE dataset format */ char *group; /* dataset group */ char *info; /* ADDE dataset info */ char *mask; /* dataset file mask */ char *place; /* coordinate system */ char *punit; /* parameter UNITS */ char *request; /* request string */ char *type; /* ADDE dataset type */ char *unit; /* UNITS keyword */ char *csstr; /* UNITS ORIG or EXP stretch */ char *cBand; /* file name BAND */ char *cdate; /* file date */ char *cday; /* file day */ char *coverage; /* file name COVERAGE */ char *resolution; /* file name RESOLUTION */ char *segment; /* file name SEGMENT */ char *prefix; /* line prefix */ char **flist = NULL; /* hdf file list */ /* image tracking arrays */ int dim2; int dim3; int *seconds; int *cover; int *imode; int *sss; int *temp1; int **lines; int **elems; int **bands; int **ivars; int **iress; int **gress; int **temp2; int **positions; const char *dum; /* dummy variable for arg routines */ const char server[] = {"ABINAGET"}; /* server name */ double request_center_latitude; /* requested center latitude */ double request_center_longitude; /* requested center longitude */ double dparm; /* generic double parameter */ double Dhms; /* double time parameter */ double MJD; /* MJD */ double INVALID_VALUE = 0; /* Invalid data value */ float ABI_RAW_SCALE = 1.0; /* scaling for RAW data */ float ABI_RAD_SCALE = 1000.0; /* scaling for RAD data */ float ABI_TEMP_SCALE = 100.0; /* scaling for TEMP data */ float ABI_ALB_SCALE = 100.0; /* scaling for ALB data */ float ABI_BRIT_SCALE = 1.0; /* scaling for BRIT data */ float *float_array; /* generic float array */ float temp; /* temperature */ float lat_diff; /* latitude difference */ float lon_diff; /* longitude difference */ float minimum; /* minimum difference */ float image_geo_latitude; /* CP latitude */ float image_geo_longitude; /* CP longitude */ float image_geo_line_resolution; /* image LALO line resolution */ float image_geo_element_resolution; /* image LALO element resolution */ float sector_min_lat; /* request sector minimum latitude */ float sector_min_lon; /* request sector minimum longitude */ float sector_max_lat; /* request sector maximum latitude */ float sector_max_lon; /* request sector maximum longitude */ float image_line_resolution; /* image line resolution */ float image_element_resolution; /* image element resolution */ float fResolution; /* file resolution */ float save_sspLon; float save_cfac; float save_lfac; float save_coff; float save_loff; float rvalue; float chunk_preempt; int DQF_iarray[512]; unsigned short DQF_sarray[16]; float DQF_fvalue; /* Calibration block */ Fint4 calb_BlockLen; Fint4 calb_bandNo; Fint4 calb_bitPix; Fint4 calb_errorCount; Fint4 calb_outCount; float calb_waveLen; float calb_gainCnt2rad; float calb_cnstCnt2rad; float calb_rad2btpC0; float calb_rad2btpC1; float calb_rad2btpC2; float calb_btp2radC0; float calb_btp2radC1; float calb_btp2radC2; float calb_lightSpeed; float calb_planckConst; float calb_bolzConst; float calb_rad2albedo; float calb_invalidValue; Fint4 aux_head[100]; /* AUX block header */ Fint4 directory[DIR_SIZE]; /* image directory block */ Fint4 cal_block[577]; /* calibration block */ Fint4 cal_opt[2]; /* calibration options*/ double Cal_Table[65536]; int ABI_MAX_TIMES; /* size of file arrays */ int file_handle; /* handle to parsed file name */ int length; /* length of parsed file name */ int num_parm; /* number of parameters from parsed file name */ int i_parm; /* file name parameter index */ int n_parm; /* file name parameter increment */ int YMD, Y, M, D, HMS; /* Year,Month,Day varaibles */ int aux_block_size; /* size of the AUX block */ int bdate; /* geginning CCYYDDD */ int btime; /* beginning time */ int curDate; /* current CCYYDDD */ int curTime; /* current HHMMSS */ int dat_block_size; /* data block size */ int def_space; /* default SPACE */ int file_byte; /* file buytes per data element */ int edate; /* ending range date */ int etime; /* ending time */ int hiBound; /* ending dataset position */ int PIXBYTE; int L2INDX; int i, ii; /* loop index */ int j, jj; /* loop index */ int k, kk; /* array index */ int xx; int IX, IY; int NJ, NK; int iSSS; /* satellite number */ int MJD_day; int MJD_hms; int indx; /* index pointer */ int lalo_array_size; /* lat/lon array size */ int lalo_array_line_size; /* lat/lon array line size */ int lalo_array_elem_size; /* lat/lon array elem size */ int line; /* image line number */ int loBound; /* starting dataset position */ int num_flist; /* number of files */ int ounit_flag; /* output unit flag */ int pscale; /* parameter scale */ int psize; /* prefix size */ int rc; /* function return code */ int rt_flag; /* ADDE realtime flag */ int irem; /* modulus remainder */ int space; /* output spacing */ int totalSize; /* transfer byte count */ int trace = 0; /* trace flag */ int transaction = 0; /* transaction flag */ int user = 0; /* user id */ int nbad; /* number of bad lines */ int status; /* function status */ int band; /* band number */ int Pos; /* ADDE position number */ int bPos; /* Beginning ADDE position number */ int ePos; /* Ending ADDE position number */ int iPos; /* ADDE position increment */ int elem; /* image lement */ int image_stype_flag; /* image source type flag */ int image_hms; /* image time */ int image_tmin; /* image delta min time */ int image_tmax; /* image delta max time */ int image_nhms; /* rounded image time */ int image_cyd; /* image date CCYYDDD format */ int image_iyd; /* image date AREA format */ int image_sec; /* image time in seconds */ int image_Nsegs; /* max segments expected */ int image_Isegs; /* this segment number */ int image_data_size; /* size of a data element in bytes */ int image_band; /* file image band */ int adde_pos; /* number of times */ int image_n_bands; /* number of image bands */ int ImageMode; int ImagePlatform; int NOBAND_SPECIFIED; /* FLAG: Indicates if user specified a BAND */ int iBand; /* band from file name */ int pBands[ABI_MAX_BANDS]; /* band list for the current file */ int NpBands; /* Number of bands for the current file */ int iCoverage; /* coverage from file name */ int iSegment; /* segment from file name */ int iResolution; /* SSEC resolution */ int gResolution; /* SSEC resolution */ int gotTime; int n_times; int image_bands[ABI_MAX_BANDS]; /* array of image bands */ int var_ids[ABI_MAX_BANDS]; /* NetCDF variable id array */ int image_starting_line; /* image starting line */ int image_starting_element; /* image starting element */ int image_dataset_position; /* image position */ int ADDE_dataset_position; /* ADDE position */ int image_segment_position; /* image segment sub-position */ int image_Nline_size; /* segment image line size */ int image_Nseg_size; /* segment size */ int image_line_size; /* image line size */ int image_element_size; /* image element size */ int image_line_base_resolution; /* image base line resolution */ int image_element_base_resolution; /* image base element resolution */ int bRes; int image_geo_line_size; /* image LALO line resolution */ int image_geo_element_size; /* image LALO element resolution */ int image_geo_line_magnification; /* image LALO line magnification */ int image_geo_element_magnification; /* image LALO element magnification */ int image_geo_data_size; /* image LALO byte size */ int image_geo_latitude_resolution; /* image LALO latitude resolution */ int image_geo_longitude_resolution; /* image LALO longitude resolution */ int image_geo_nav_offset; /* LALO navigation element offset */ int image_lines[ABI_MAX_BANDS]; /* image lines/rows */ int image_elems[ABI_MAX_BANDS]; /* image elements/cells */ int ABI_CAL_OFFSET = 768; /* CAL block offset */ int ABI_AUX_OFFSET = 3076; /* AUX block offset */ int CAL_BLOCK_SIZE = 577; /* size of the calibration block in words */ int nav_offset; /* naviagtion element offset */ int request_data_size; /* request element byte size */ int request_n_bands; /* request number of bands */ int request_bands[ABI_MAX_BANDS]; /* request band array */ int request_lalo_flag; /* request LALO flag */ int request_image_flag; /* request image flag */ int request_area_flag; /* request area flag */ int request_line_size; /* request line size */ int request_element_size; /* request element size */ int request_element_size_orig; /* request element size orig */ int request_line_resolution; /* request line resoluton */ int request_element_resolution; /* request element resolution */ int request_line_magnification; /* request line magnification */ int request_element_magnification; /* request element magnification */ int request_starting_line; /* request starting line */ int request_starting_element; /* request starting element */ int found_n_bands; /* image number of bands */ int found_bands[ABI_MAX_BANDS]; /* array of image bands */ int read_line_size; /* image read line size */ int read_element_size; /* image read element size */ int read_starting_line; /* image read startng line */ int read_starting_element; /* image read starting eleemnt */ int read_ending_line; /* image read ending line */ int read_ending_element; /* image read ending element */ int read_geo_line_size; /* image LALO line size */ int read_geo_element_size; /* image LALO element size */ int read_geo_starting_line; /* image LALO starting line */ int read_geo_starting_element; /* image LALO starting element */ int read_geo_ending_line; /* image LALO ending line */ int read_geo_ending_element; /* image LALO ending element */ int test; /* test for value */ int extend; /* test for multiple of 4 */ int size; /* size test variable */ int OUTSIZE; /* output line size */ int SAMPLE_size; /* input data sample size */ int LALO_size; /* input LALO sample size */ int Lat_size; /* input Latitude array size */ int Lon_size; /* input Longitude array size */ int DATA_size; /* input data array size */ int init; int TimeBaseSearch; int TimeBasePos; int Valid_line; int init_line; int init_elem; int rse; int currentSeg; int currentOpn; int missingSeg; int seg_i; int thisSeg; int thisPos; int startPos; int inc_time; /* bump time needed to calculate target image start time */ int options[5]; int options_out[5]; int len_unit; int var_iname; servacct requestBlock; /* request block text */ short *SAMPLE_array; /* input sample array */ short *DATA_array; /* output sample array */ static char trace_string[500]; /* traceing text */ unsigned char *uchar_array; /* 1 byte output array */ unsigned int iexp; /* band map varaible */ unsigned int *ulong_array; /* 4 byte output array */ unsigned int value; /* 4 byte output variable */ unsigned long long llparm; /* LongLong output variable */ unsigned short int *ushort_array; /* 2 byte output array */ /* MultiBand variables */ int this_band; int this_resolution; int lowest_resolution; int highest_resolution; int Nfound; int iband; int linc; int einc; int lsize; int esize; int iline; int jelem; int band_step; int band_sample[ABI_MAX_BANDS]; int band_nav; int band_alloc; int MultiBand_flag; int MultiBandL2_flag; int MultiBand_res; int MultiBand_resBand; int MultiBand_Nmap; int MultiBand_map[ABI_MAX_BANDS]; /* NetCDF related declaration */ int ncdf_ids[ABI_MAX_BANDS]; int dim_id; int var_id; int WaveLength_id; int kappa_id; int planckFK1_id; int planckFK2_id; int planckBC1_id; int planckBC2_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[ABI_MAX_BANDS]; /* line scale factor */ float cfac[ABI_MAX_BANDS]; /* element scale factor */ float loff[ABI_MAX_BANDS]; /* line add offset */ float coff[ABI_MAX_BANDS]; /* element add offset */ float ssp_lat; /* subpoint latitude */ float ssp_lon; /* subpoint longitude */ float pro_lon; /*projection lon - WCS3 */ float VAR_scale[ABI_MAX_BANDS]; float VAR_offset[ABI_MAX_BANDS]; float WaveLength[ABI_MAX_BANDS]; float kappa[ABI_MAX_BANDS]; float planckFK1[ABI_MAX_BANDS]; float planckFK2[ABI_MAX_BANDS]; float planckBC1[ABI_MAX_BANDS]; float planckBC2[ABI_MAX_BANDS]; Freal Fline; Freal Felem; Freal Flat; Freal Flon; Freal Fdummy; short *Xarray; /* element coordinate array */ short *Yarray; /* line coordinate array */ unsigned short *Cnt_array; /* unsigned short array */ unsigned int *Wrd_array; short VAR_FillValue[ABI_MAX_BANDS]; float *Dat_array; /* Albedo or Tb */ float Rad_value; /* Radiance */ float Tbb_value; double Alb_value; double Dat_value; int *BRIT_array; /* image display */ size_t rows; size_t cells; size_t start[] = {0,0}; size_t stride[] = {0,0}; size_t chunk_size; size_t chunk_nelems; /* string contains parsing mask */ McArgSyntax filesyntax = {"/_.", "=", ".", "{\"", "}", "'", "'", NULL, "X", " "}; /* ************************************************************************* 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 DATA SERVER VN4.0",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]); (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); /* 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); */ /* 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] ); */ /* } */ /* tprintf(trace_string, "%s File Mask = %s", server,mask); */ /* ************************************************************************* Step 2: Get a list of file names matching the ADDE file mask ************************************************************************* */ /* produce a list of files matching the file mask */ flist = M0GetMaskFileList(mask); if( flist == (char **)NULL ) { (void)strcpy(requestBlock.errormsg, "Failed to generate file mask list"); 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 files found = %d", server,num_flist); } /* ************************************************************************* Step 3: Analyze the request parameters POS - ADDE position number DAY - image Bday<->Eday TIME - image Btime<->Etime PLACE - request sector reference positioning A=AREA, I-IMAGE, E=EARTH U=UPPER, C= CENTER example: EC = EARTH CENTER LMAG - line magnification EMAG - element magnification SIZE - line and element request size BAND - image band STYPE - Source type (RAW, BRIT) SPACE - bytes per element (1,2 or 4) UNIT - output units (RAW, BRIT) ************************************************************************* */ /* PLACE */ rc = Mcargstr(0, "", 3, "AU", (const char **)&place); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Coordinate format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } request_lalo_flag = FALSE; request_image_flag = FALSE; request_area_flag = FALSE; if( strncmp(place,"EC",2) == 0 || strncmp(place,"EU",2) == 0 ) request_lalo_flag = TRUE; if( strncmp(place,"IC",2) == 0 || strncmp(place,"IU",2) == 0 ) request_image_flag = TRUE; if( strncmp(place,"AC",2) == 0 || strncmp(place,"AU",2) == 0 ) request_area_flag = TRUE; /* Process the request: Latitude/Longitude*/ if( request_lalo_flag == TRUE ) { rc = Mcargdll(0, " ", 4, (double)999.0, (double)-90.0, (double)90.0, &request_center_latitude, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid LATitude format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } rc = Mcargdll(0, " ", 5, (double)999.0, (double)-180.0, (double)180.0, &request_center_longitude, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid LONgitude format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } request_center_longitude = -request_center_longitude; tprintf(trace_string,"%s Center Earth COORD: Lat=%f Lon=%f" ,server,request_center_latitude,request_center_longitude); } /* Image LINELE */ else if( request_image_flag == TRUE ) { rc = Mcargint(0, "", 4, 1, 1, 0, &request_starting_line, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid LINe format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } rc = Mcargint(0, "", 5, 1, 1, 0, &request_starting_element, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid ELEment format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } tprintf(trace_string,"%s Starting Image COORD: Lin=%d Ele=%d" ,server,request_starting_line,request_starting_element); } /* Area LINELE */ else if( request_area_flag == TRUE ) { rc = Mcargint(0, "", 4, 0, 1, 0, &read_starting_line, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid LINe format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } rc = Mcargint(0, "", 5, 0, 1, 0, &read_starting_element, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid ELEment format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } tprintf(trace_string,"%s Starting Area COORD: Lin=%d Ele=%d" ,server,read_starting_line,read_starting_element); } /* Process the request: Line Magnification */ rc = Mcargint(0, "LMA.G", 1, 1, 0, -1, &request_line_magnification, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Line MAG specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_line_magnification == 0 ) request_line_magnification = 1; if( request_line_magnification < 0 ) request_line_magnification = -(request_line_magnification);; /* Process the request: Element Magnification */ rc = Mcargint(0, "EMA.G", 1, 1, 0, -1, &request_element_magnification, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Element MAG specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_element_magnification == 0 ) request_element_magnification = 1; if( request_element_magnification < 0 ) request_element_magnification = -(request_element_magnification);; tprintf(trace_string,"%s MAG: Lin=%d Ele=%d" ,server,request_line_magnification,request_element_magnification); /* SIZE */ rc = Mcargint(0, "", 7, 480, 1, 99999, &request_line_size, &dum ); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Line SIZE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } rc = Mcargint(0, "", 8, 640, 1, 99999, &request_element_size_orig, &dum ); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Element SIZE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* alter request elements to 4 byte boundry */ request_element_size = request_element_size_orig; if( request_element_size != 99999 ) { irem = request_element_size % 4; if( irem != 0 ) request_element_size = request_element_size + (4-irem); } tprintf(trace_string,"%s SIZE: Lin=%d Ele=%d" ,server,request_line_size,request_element_size); /* BAND */ NOBAND_SPECIFIED = 0; request_n_bands = Mcargnum(0, "BAN.D" ); if( request_n_bands == 0 ) { NOBAND_SPECIFIED = 1; } else { /* Transfer ALL bands */ char *cALL; /* BAND=ALL*/ rc = Mcargstr(0, "BAN.D", 1, " ", (const char **)&cALL); if( strncmp( cALL, "ALL",3 ) == 0 ) { request_n_bands = ABI_MAX_L1B; for( i=0; i 1 ) { /* Multi-band transfer list */ for( i=0; i 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer is not permitted for this data type"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } */ /* Now we are sure that the list is greater than 1 */ if( MultiBand_Nmap == 1 ) { request_n_bands = 1; } else { /* re-construct the request list into ascending band order */ request_n_bands = 0; for( i=0; i= 6 ) { if( MultiBand_res < 4 ) { MultiBand_res = 4; MultiBand_resBand = request_bands[i]; } } } /* Multi-band transfer requires that the calibration is UNITS=RAW */ rc = Mcargstr(0, "UNI.T", 1, "RAW", (const char **)&unit); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid UNIT specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } rc = Mcargstr(0, "UNI.T", 2, " ", (const char **)&csstr); if( strncmp( unit, "RAW",3 ) != 0 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer only permits RAW units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* tprintf(trace_string,"%s MultiBand: Flag=%d Res=%d Band=%d Unit=%s", server,MultiBand_flag,MultiBand_res,MultiBand_resBand,unit); */ } } /* STYPE */ image_stype_flag = Mcargnum(0, "STY.PE" ); if( image_stype_flag != 0 ) { char *cstype; /* STYPE keyword */ rc = Mcargstr(0, "STY.PE", 1, "VISR", (const char **)&cstype); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid STYPE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( strncmp( cstype, "VISR",4 ) != 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid STYPE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "STYPE with Multi-band not allowed"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } image_stype = stralloc( "VISR", NULL); def_unit = stralloc( "BRIT", NULL); last_stype = stralloc( "ABIN", NULL); def_space = 1; CAL_BLOCK_SIZE = 0; ABI_CAL_OFFSET = 0; ABI_AUX_OFFSET = 768; } else { image_stype = stralloc( "ABIN", NULL); def_unit = stralloc( "RAW",NULL); last_stype = stralloc( " ", NULL); def_space = 2; } /* SPACE */ rc = Mcargint(0, "SPA.CE", 1, def_space, 0, 4, &space, &dum); if( rc < 0 || space == 3 ) { (void)strcpy(requestBlock.errormsg, "Invalid SPACE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* UNIT */ rc = Mcargstr(0, "UNI.T", 1, def_unit, (const char **)&unit); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid UNIT specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } rc = Mcargstr(0, "UNI.T", 2, " ", (const char **)&csstr); if( strncmp( unit, "RAW",3 ) == 0 ) { if( space == 0 ) space = 2; if( space < 2 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for RAW specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "RAW ",NULL); request_data_size = space; pscale = ABI_RAW_SCALE; punit = stralloc(" ",NULL); ounit_flag = 0; } else if( strncmp( unit, "RAD" ,3) == 0 ) { if( space == 0 ) space = 4; if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "RAD ",NULL); request_data_size = space; pscale = ABI_RAD_SCALE; punit = stralloc("MW**",NULL); /* Different radiance units for visible bands */ if( request_bands[0] < 7 ) punit = stralloc("WM**",NULL); ounit_flag = 1; } else if( strncmp( unit, "TEMP" ,4) == 0 ) { if( space == 0 ) space = 2; if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "TEMP",NULL); request_data_size = space; pscale = ABI_TEMP_SCALE; punit = stralloc("K ",NULL); ounit_flag = 2; } else if( strncmp( unit, "ALB" ,3) == 0 ) { if( space == 0 ) space = 2; if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "ALB ",NULL); request_data_size = space; pscale = ABI_ALB_SCALE; punit = stralloc("% ",NULL); ounit_flag = 3; } else if( strncmp( unit, "BRIT" ,4) == 0 ) { if( space == 0 ) space = 1; if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "BRIT",NULL); request_data_size = space; pscale = ABI_BRIT_SCALE; punit = stralloc(" ",NULL); ounit_flag = 4; /* did not find a L1b base unit but it could be a product */ } else { if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } ounit_flag = -1; } /* tprintf(trace_string,"%s SPACE: %d",server,space); */ /* tprintf(trace_string,"%s UNIT: %s",server,unit); */ /* ************************************************************************* Step 4: Analyze the file names Use the file name to get the image date and time. ************************************************************************* */ /* 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)); /* open each file to get the day and time of the data */ adde_pos = 0; 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 = 186; if( strstr( dum, "G17" ) != NULL ) iSSS = 188; if( strstr( dum, "G18" ) != NULL ) iSSS = 190; if( strstr( dum, "G19" ) != NULL ) iSSS = 192; /* image descriptor */ rc = Mcargstr( file_handle, " ", i_parm, " ", &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 ) { tprintf(trace_string, "%s FAILED: to determine the Image Type", server); continue; } /* Evaluate the file name for image day (sCCYYDDDHHMMSSs) */ rc = Mcargstr( file_handle, " ", n_parm, " ", (const char **)&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 ); /* image deltas */ 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 ) { (void)strcpy(requestBlock.errormsg, "No images satisfy selection criteria"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { /* tprintf(trace_string, "%s FIRST PASS: Number of unique times = %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 ); ivars = 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; i= 0 ) { /* satellite source */ rc = Mcargstr( file_handle, " ", i_parm+1, " ", &dum ); if( strstr( dum, "G16" ) != NULL ) iSSS = 186; if( strstr( dum, "G17" ) != NULL ) iSSS = 188; if( strstr( dum, "G18" ) != NULL ) iSSS = 190; if( strstr( dum, "G19" ) != NULL ) iSSS = 192; /* tprintf(trace_string, "%s iSSS = %s", server, dum); */ /* image descriptor */ rc = Mcargstr( file_handle, " ", i_parm, " ", &dum ); /* tprintf(trace_string, "%s iDESC = %s", server, dum); */ /* determine the Image Type */ iCoverage = 0; NpBands = 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 ) { var_name[0] = L1BVNAMES[0]; var_iname = 0; fResolution = 0.0; n_parm = i_parm+2; } else { /* scan list of L2 Product names contained in abinparm.h */ for (i=0; i 0 || image_lines[0] > 0 || image_elems[0] > 0 ) { if( n_times == 0 ) { /* zero the file position array */ for( i=0; i= image_tmin && seconds[i] <= image_tmax ) && ( iCoverage == cover[i] ) && ( ImageMode == imode[i] ) && ( iSSS == sss[i] ) ) { if( image_sec != seconds[i] ) { image_sec = seconds[i]; status = Mcsectodaytime( image_sec, &image_cyd, &image_hms ); } 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 ) { (void)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); */ /* New location of POS, DATE and TIME argument handlers. Moved because we need to organize the file list based on image DATE and TIME instead of number of files returned from the glob function */ /* Position number specified */ adde_pos = n_times; rc = Mcargint(0, " ", 2, 0, -99999, adde_pos, &iPos, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Beginning Position"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return (0); } bPos = iPos; if( bPos <= 0 ) { ePos = adde_pos+bPos; if( ePos < 1 ) ePos = 1; bPos = ePos; } else { ePos = bPos; } /* tprintf(trace_string, "%s iPos=%d adde_pos=%d rc=%d", server,iPos,adde_pos,rc); */ /* tprintf(trace_string, "%s bPos=%d NPos=%d", server, iPos,adde_pos); */ /* tprintf(trace_string, "%s bPos: %d, ePos: %d", server, bPos, ePos); */ /* Current Day and Time */ rc = Mcgetdaytime(&curDate, &curTime); /* switch for time based search =0 --> FALSE */ TimeBaseSearch = 0; /* DAY */ if( Mcargnum(0, "DAY") != 0 ) { /* set TIME Base switch to TRUE */ /* get the specified DATE */ rc = Mcargiyd(0, "DAY", 1, curDate, 1972001, curDate, &bdate, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid DAY format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( iPos <= 0 && rc != 300) { bPos = 1; ePos = adde_pos; TimeBaseSearch = 1; TimeBasePos = iPos; } rc = Mcargiyd(0, "DAY", 2, bdate, bdate, curDate, &edate, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid DAY format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } } else { bdate = 1972001; edate = curDate; } /* TIME */ if( Mcargnum(0, "TIM.E" ) != 0 ) { rc = Mcargihr(0, "TIM.E", 1, 0, 0, 235959, &btime, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid TIME format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( iPos <= 0 && rc != 400) { bPos = 1; ePos = adde_pos; TimeBaseSearch = 1; TimeBasePos = iPos; } rc = Mcargihr(0, "TIM.E", 2, btime, 0, 235959, &etime, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid TIME format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( rc == 400 ) etime = 235959; } else { btime = 0; etime = 235959; } /* Process the request: Dataset Position */ loBound = (adde_pos * -1) +1; hiBound = adde_pos; rc = Mcargint(0, "", 2, 0, loBound, hiBound, &image_dataset_position, &dum); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Dataset Position format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* ************************************************************************* 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 an image file passes the condition tests we read the file datasets to locate all of the "parts" we need to satisfy a data transfer. The necessary parts are: - navigation info - calibration info - Data array ************************************************************************* */ tprintf(trace_string, "%s BEFORE MAIN LOOP --- bPos=%d, ePos=%d", server, bPos, ePos); /* initailize the band DQF array for this image (16values for 32bands = 512) */ for( i=0; i<512; i++ ) DQF_iarray[i] = 65530; found_n_bands = 0; for( ADDE_dataset_position=bPos; ADDE_dataset_position<=ePos; ADDE_dataset_position++) { /* for Time Based Search invert the position */ if( TimeBaseSearch == 0 ) { image_dataset_position = ADDE_dataset_position; } else { image_dataset_position = adde_pos - (ADDE_dataset_position-1); } /* convert seconds to date and time */ status = Mcsectodaytime( seconds[image_dataset_position-1], &image_cyd, &image_hms ); /* convert julian date to image date */ status = Mccydtoiyd( image_cyd, &image_iyd ); /* Check client search conditions: DAY=bDAY eDAY */ if( (image_cyd < bdate) || (image_cyd > edate) ) continue; /* tprintf(trace_string, "%s PASS DAY CHECK = %d", server, image_cyd ); */ /* Check client search conditions: TIME=bTIME eTIME */ if( (image_hms < btime) || (image_hms > etime) ) continue; /* tprintf(trace_string, "%s PASS TIME CHECK = %d", server, image_hms ); */ /* Multi-band transfer of L2 data is NOT permitted */ MultiBandL2_flag = 0; if( (sss[image_dataset_position-1] == 187 || sss[image_dataset_position-1] == 189 || sss[image_dataset_position-1] == 191 || sss[image_dataset_position-1] == 193 ) && MultiBand_Nmap > 1 ) { tprintf(trace_string, "%s SSS=%d Multi=%d", server, sss[image_dataset_position-1], MultiBand_Nmap); tprintf(trace_string, "%s Multiband request ...BUT... Image is L2 --> NOT ALLOWED", server); MultiBandL2_flag = 1; continue; } Nfound = 0; lowest_resolution = 0; /* highest_resolution= 4; */ highest_resolution= 999; band_nav = 0; for( i=0; i 1 ) { (void)strcpy(requestBlock.errormsg, "No BAND(s) specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { for(i=0; i= lowest_resolution ) { lowest_resolution = iress[image_dataset_position-1][image_band-1]; band_nav = image_band; } if( this_resolution <= highest_resolution ) { highest_resolution = iress[image_dataset_position-1][image_band-1]; band_alloc = image_band; } } } if( Nfound != request_n_bands ) continue; /* tprintf(trace_string, "%s Found all requested bands", server); */ /* tprintf(trace_string, "%s LOWEST RESOLUTION = %d ", server,lowest_resolution); */ /* compute the sampling for each band in the request */ for(i=0; i get NetCDF handles for each */ for( iband=0; iband image_line_size || read_ending_line < 0 || read_starting_element > image_element_size || read_ending_element < 0 ) { (void)strcpy(requestBlock.errormsg, "The portion of the image requested does not exist"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } GEO_REQEST: /* tprintf(trace_string,"%s GEO REQUEST",server); */ /* determine the size of the geo request */ read_geo_line_size = image_line_size; read_geo_element_size = image_element_size; /* determine the coordinates of the geo request */ read_geo_starting_line = 0; read_geo_starting_element = 0; read_geo_ending_line = read_geo_starting_line + read_geo_line_size - 1; read_geo_ending_element = read_geo_starting_element + read_geo_element_size - 1; tprintf(trace_string,"%s READ GEO: line size=%d",server,read_geo_line_size); tprintf(trace_string,"%s READ GEO: element size=%d",server,read_geo_element_size); tprintf(trace_string,"%s READ GEO: starting line=%d",server,read_geo_starting_line); tprintf(trace_string,"%s READ GEO: starting element=%d",server,read_geo_starting_element); tprintf(trace_string,"%s READ GEO: ending line=%d",server,read_geo_ending_line); tprintf(trace_string,"%s READ GEO: ending element=%d",server,read_geo_ending_element); /* ************************************************************************* Step 9: Transfer starts here Construct and send the following blocks: DIRECTORY NAVIGATION CALIBRATION AUXILLARY DATA ************************************************************************* */ /* tprintf(trace_string,"%s TRANSFER",server); */ /* size of the AUX block */ aux_block_size = 0; /* size of the line prefix */ psize = 0; if( request_n_bands > 1 ) { psize = request_n_bands / 4; if( (request_n_bands % 4) != 0 ) psize = psize+1; psize = psize * 4; } /* tprintf(trace_string,"%s PREFIX size=%d",server,psize); */ /* size of the DAT block */ dat_block_size = (read_line_size / request_line_magnification) * ( (read_element_size / request_element_magnification) * request_n_bands * request_data_size + psize ); /* tprintf(trace_string,"%s DATA size=%d",server,dat_block_size); */ /* send the size of the total transmission */ totalSize = (DIR_SIZE*4) + (NAV_BLOCK_SIZE*4) + (CAL_BLOCK_SIZE*4) + (aux_block_size) + (dat_block_size); /* tprintf(trace_string,"%s total_block_size=%d",server,totalSize); */ requestBlock.reply_length += totalSize; M0swbyt4(&totalSize, 1); rc = M0sxsend(4, &totalSize ); tprintf(trace_string,"%s **************** SATELLITE =%d",server, sss[image_dataset_position-1] ); tprintf(trace_string,"%s **************** VAR =%s", server, var_name[0]); /* ***************** DIRECTORY BLOCK ****************** */ /* initialize the directory block */ for( i=0; i 1 ) { directory[14] = psize; directory[50] = psize; for( i=0; i 1 ) { memcpy( (void *)&uchar_array[0], (void *)&level_map[0], psize ); } } else if( space == 2 ) { OUTSIZE = (psize/2) + (request_n_bands*request_element_size); ushort_array=calloc(OUTSIZE,sizeof(unsigned short int)); if( ushort_array == NULL ) { (void)strcpy(requestBlock.errormsg, "Failed malloc of line array"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { memcpy( (void *)&ushort_array[0], (void *)&level_map[0], psize ); } } else if( space == 4 ) { OUTSIZE = (psize/4) + (request_n_bands*request_element_size); ulong_array=calloc(OUTSIZE,sizeof(unsigned int)); if( ulong_array == NULL ) { (void)strcpy(requestBlock.errormsg, "Failed malloc of line array"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { memcpy( (void *)&ulong_array[0], (void *)&level_map[0], psize ); } } /* IMAGE LINE LOOP */ iBand = request_bands[0]; currentOpn = 0; init_line = 0; init_elem = 0; /* only do this for single bands. Multibands can only transfer RAW data */ if( MultiBand_flag == 0 ) { /* get the RADiance variable id */ if( status != NC_NOERR ) { tprintf(trace_string, "%s Did not find the %s variable", server, var_name[0]); } else { status = nc_get_att_float( ncdf_ids[image_band-1], var_ids[image_band-1], "scale_factor", &VAR_scale[image_band-1]); if( status != NC_NOERR ) { tprintf(trace_string, "%s Could not read the band scale factor", server); } status = nc_get_att_float( ncdf_ids[image_band-1], var_ids[image_band-1], "add_offset", &VAR_offset[image_band-1]); if( status != NC_NOERR ) { tprintf(trace_string, "%s Could not read the band add offset", server); } } /* initialize the calibration */ status = kbprep_(&ONE,"ABIN"); if( status == -1 ) { (void)strcpy(requestBlock.errormsg, "Failed to Prep the Calibration"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* tprintf(trace_string,"%s request_data_size=%d", server,space); */ options[0] = PIXBYTE; options[1] = 4; options[2] = sss[image_dataset_position-1]; options[3] = request_bands[0]; status = kb1ini_("RAW ", &directory[52], options, 4, 4); if( status == -1 ) { (void)strcpy(requestBlock.errormsg, "Failed to Initialize the Calibration 1"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { options[0] = band; status = kb1opt_("CALB", cal_block, options_out, 4); if (status == -1) { (void)strcpy(requestBlock.errormsg, "Failed to Initialize the Calibration 2"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } } if( strncmp( unit, "BRIT",4 ) == 0 && strncmp( csstr, "EXP" ,3) == 0) { options[0] = band; options[1] = sss[image_dataset_position-1]; options[2] = 1; tprintf(trace_string,"%s options=%d %d ", server,options[0], options[1]); status = kb1opt_("STR ", options, options_out, 4); tprintf(trace_string,"%s kb1opt return=%d ", server,status); if(status == 0) { directory[EXP_BRIT_FLAG] = 1; memcpy(&directory[EXP_BRIT_NAME1], options_out, 8); } } /* tprintf(trace_string, "%s PASSED: Calibration init", server); */ } /* send the directory to client */ 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); rc = M0sxsend( DIR_SIZE*4, 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); /* tprintf(trace_string, "%s sent directory: bytes=%d", server,DIR_SIZE*4); */ /* send the navigation */ M0swbyt4( &nav_block[1], NAV_BLOCK_SIZE-1 ); rc = M0sxsend( NAV_BLOCK_SIZE*4, nav_block ); /* tprintf(trace_string, "%s sent navigation: bytes=%d", server,NAV_BLOCK_SIZE*4); */ /* send the calibration */ M0swbyt4( &cal_block[1], CAL_BLOCK_SIZE-1 ); rc = M0sxsend( CAL_BLOCK_SIZE*4, cal_block ); M0swbyt4( &cal_block[1], CAL_BLOCK_SIZE-1 ); /* IMAGE LINE LOOP */ /* tprintf(trace_string, "%s START SENDING THE DATA type=%d",server,ounit_flag); */ for( i=read_starting_line; i<=read_ending_line; i=i+request_line_magnification ) { /* IMAGE BAND LOOP */ for( k=0; k=0 && iline output units */ if( strncmp( unit, "RAW",3 ) != 0 ) { status = kb1cal_( prefix, directory, &SAMPLE_size, &band, Wrd_array ); if( status == -1 ) { (void)strcpy(requestBlock.errormsg, "FAILED Line Calibration"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } } } else { (void) memset(Cnt_array, INVALID_VALUE, sizeof(short)*SAMPLE_size); (void) memset(Wrd_array, INVALID_VALUE, sizeof(int)*SAMPLE_size); } /* At this point you have a line of data for a particular band. Read the data based on the requested magnification and insert the elements into the output line array based on the number of bands */ /* IMAGE ELEMENT LOOP */ jj = k + psize/2; for( j=read_starting_element; j<=read_ending_element; j=j+request_element_magnification ) { /* only send valid elements */ value = 0; jelem = j*einc; if( jelem>=0 && jelem 1 ) { memcpy( (void *)&uchar_array[0], (void *)&level_map[0], psize ); } } else if( space == 2 ) { rc = M0sxsend( size*sizeof(short), ushort_array ); (void) memset(ushort_array, INVALID_VALUE, size*sizeof(short)); if( request_n_bands > 1 ) { memcpy( (void *)&ushort_array[0], (void *)&level_map[0], psize ); } } else if( space == 4 ) { rc = M0sxsend( size*sizeof(int), ulong_array ); (void) memset(ulong_array, INVALID_VALUE, size*sizeof(int)); if( request_n_bands > 1 ) { memcpy( (void *)&ulong_array[0], (void *)&level_map[0], psize ); } } /* tprintf(trace_string, "%s Sent Line = %d ",server,i+1); */ } /* ***************** House Keeping **************** */ /* CLOSE the NCDF file(s) */ for( i=0; i