/* * Copyright(c) 2008, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt */ /**** $Id: nssxaget.c,v 1.0 2011/05/01 19:13:50 russd Exp $ ****/ /* ** Name: ** nssxaget : ADDE directory server for NSS product images ** serves Observed product ** serves Cloud product ** serves Sea Surface Temperature product ** ** Interface: ** int ** main(int argc, char *argv[]) ** ** Input: ** argc : argument count ** argv : argument vector ** ** Input and Output: ** none ** ** Output: ** none ** ** Return values: ** 0 : success ** < 0 : failure, enumerated by text message returned to client ** ** Remarks: ** ** Categories: ** ADDE server */ /* C include files */ #include #include #include #include /* McIDAS include files */ #include "mcidas.h" #include "mcidasp.h" #include "m0glue.h" #include "m0arg.h" /* HDF include files */ #include "mfhdf.h" #include "hdf.h" int GetModsCards (int *, int*, float, float, float, float, int *, int, int); int TEMPtoBRIT( float ); int REFFtoBRIT (float) ; int CODtoBRIT (float); int ALTtoBRIT (float); int TRANStoBRIT (float); int ZENtoBRIT (float); int main ( int argc, char **argv ) #define DIR_SIZE 64 #define IMAGE_STARTING_LINE 1 #define IMAGE_STARTING_ELEMENT 1 #define IMAGE_FILE_VERSION 4 #define MAX_STR_LEN 80 #define MAX_ATR_LEN 80 #define MAX_BANDS 30 #define MAX_AUX_SIZE 20000000 #define LAT_AUX 24 #define LON_AUX 28 { /* * variables used: * * dum dummy for arg fetchers * bDate, eDate beginning, ending day * bTime, eTime beginning, ending time * bPos, ePos beginning, ending position number * bSS, eSS beginning, ending sensor source number * checkSS flag to indicate SS keyword was used * checkTime flag to indicate TIME keyword was used * checkDay flag to indicate DAY keyword was used * dummy dummy position number * cAux holder for AUX keyword text * group descriptor name desired, ie CONUS, NH, etc. * mask file search patterm mask * dscInfo descriptor file info structure * dfp, ifp descriptor and index file pointers * ALL variable to hold & compare text for "ALL " * imgCount number of images currently available this type * tmpCount temp image count * negCount num positions to skip if client gave neg position range * listCount count of number of images listed * posNum position number * rc return code holder * numBytes number of bytes sent to client each transaction * areaDir area directory * navCod navigation codicil * cards area file comment cards * firstNode pointer to first position list node * tmpNode temporary position node pointer * oldNode, newNode old, new position node pointers * curDate, curTime current date, time * tmpDate, tmpTime temporary date, time * i loop control variable * tp time struct * gmtPtr pointer to gmt time struct * loBound, hiBound low, high position bounds for argument validation * server text name for server started * request pointer to client request text * requestBlock request block servacct struct * auxFlag flag to indicate whether AUX=YES keyword was used */ const char *dum; /* dummy for arg fetchers */ char *dataset; /* dataset name */ char *file_name; /* name of HDF file */ char *char_band; /* band name string */ int bufsize; int bDate; /* beginning date */ int bTime; /* beginning time */ int eDate; /* ending date */ int eTime; /* ending time */ int bPos, ePos; int bSS, eSS; int checkSS = 0; int checkTime = 0; int checkDay = 0; int checkBand = 0; int dummy = 9999; char *group, *cAux; char *cBand; int listCount = 0; int rc; int i; const char server[] = {"NSSXAGET"}; char *request = NULL; servacct requestBlock = {0}; int auxFlag = 0; int trace = 0; int transaction = 0; int user = 0; int DIR_BLOCK_SIZE = 64; int NAV_BLOCK_SIZE = 128; int CAL_OFFSET = 768; int CAL_BLOCK_SIZE = 128; int NAV_OFFSET = 256; int AUX_ENTRIES = 2; int AUX_MAGIC_NUMBER = 0x04030201; int AUX_OFFSET; int AUX_SIZE; float RAW_SCALE = 1. ; /* scaling for RAW data */ float MASS_SCALE = 1000. ; /* scaling for MASS data */ float DIST_SCALE = 1000. ; /* scaling for DIST data */ float TEMP_SCALE = 100. ; /* scaling for TEMP data */ float HGHT_SCALE = 10. ; /* scaling for HGHT data */ float EMIS_SCALE = 100. ; /* scaling for EMIS data */ float BRIT_SCALE = 1. ; /* scaling for BRIT data */ int CLOUD_MASK_SCALE = 1; /* scaling for CLOUD MASK data */ char cards[24000]; char chhmm[5]; char *cyear; char *cdate; char *cstime; char *cday; char *chms; char *coverage; char *satellite_id; char **flist; char **nlist; char *type; char *format; char *info; char *comment; char *mask; char *navproj; char *punit; char *place; char *nav_name; int ALL; int data_prefix; int directory[64]; int hiBound; int iPos; int jPos; int FPos; int length; int loBound; int num_band; int num_cards; int num_flist; int num_nlist; int send_byte_total; int FLAG_5km_band; int FLAG_1km_band; int FLAG_250m_band; int minimum_band; int maximum_band; int bands[MAX_BANDS]; int band_res[MAX_BANDS]; int res_list[MAX_BANDS]; int got_bands[MAX_BANDS]; int got_nav[2]; int curDate; int curTime; int bdate; int edate; int btime; int etime; int NSS_product_type; char *image_stype; char *unit; char *def_unit; char *dir_unit; char *last_stype; double request_center_latitude; double request_center_longitude; int request_data_size; int request_n_bands; int request_bands[MAX_BANDS]; int request_band_type[MAX_BANDS]; int request_lalo_flag; int request_image_flag; int request_area_flag; int request_line_size; int request_element_size; int request_line_resolution; int request_element_resolution; int request_line_magnification; int request_element_magnification; int request_starting_line; int request_starting_element; int read_starting_line; int read_starting_element; int read_line_size; int read_element_size; int read_ending_line; int read_ending_element; int read_geo_line_size; int read_geo_element_size; int read_geo_starting_line; int read_geo_starting_element; int read_geo_ending_line; int read_geo_ending_element; int image_starting_line; int image_starting_element; int image_stype_flag; int image_line_size; int image_line_resolution; int image_element_size; int image_element_size_5km; int image_element_size_1km; int image_element_size_250m; int image_element_resolution; int image_data_size; int image_ccyy; int image_ddd; int image_cyd; int image_iyd; int image_hms; int image_sec; int image_n_bands; int image_line_base_resolution; int image_element_base_resolution; int image_geo_line_size; int image_geo_element_size; int image_geo_line_magnification; int image_geo_element_magnification; int image_geo_data_size; int image_geo_latitude_resolution; int image_geo_longitude_resolution; int image_geo_nav_offset; int LALO_step; int LALO_size; int New_line_size; int New_elem_size; int New_size; float image_geo_latitude; float image_geo_longitude; float image_km_resolution; float image_geo_minimum_latitude; float image_geo_maximum_latitude; float image_geo_minimum_longitude; float image_geo_maximum_longitude; float image_geo_center_latitude; float image_geo_center_longitude; float image_geo_line_resolution; float image_geo_element_resolution; float minimum; float lat_diff; float lon_diff; float sector_min_lat; float sector_max_lat; float sector_min_lon; float sector_max_lon; float raw; float brit; int min; int max; int fil; int lineSampleRate; int elemSampleRate; int ounit_flag; int def_space; int space; int sum; int band; int band_all; int pscale; int extend; int test; int HDF_Latitude_flag; int HDF_Longitude_flag; int HDF_All_Data_flag; int j; int k; int ie; int offset; int lalo_array_line_size; int lalo_array_elem_size; int lalo_array_size; int aux_block_size; int dat_block_size; int totalSize; int psize; int iexp; int starting_line; int starting_elem; int ending_line; int ending_elem; int band_ptr; int size; int min_value; int max_value; int mis_value; int process; int trap; char level_map[MAX_BANDS]; int HDF_Data_flag[MAX_BANDS]; float range_mins[MAX_BANDS]; float range_maxs[MAX_BANDS]; float range_miss[MAX_BANDS]; int scale_mins[MAX_BANDS]; int scale_maxs[MAX_BANDS]; int scale_miss[MAX_BANDS]; char attr_name[MAX_ATR_LEN]; char name[MAX_NC_NAME]; char nav_string[6]; int bband; int eband; int file_handle; int image_dataset_position; int SSEC_satellite_id; int MCIDAS_element_size; int MCIDAS_geo_element_size; int rt_flag; int ii; int jj; int jjj; int sort_secs[5000]; int sort_flist[5000]; int num_sort; int found; int atmos_type; int file_name_type; int wrong; int minval; int maxval; int misval; int file_syntax_type; int ThisKey; int Key; int NumKeys; intn status; Fint4 nav_block[128]; Fint4 cal_block[128]; Fint4 aux_head[100]; int32 n_datasets; int32 n_file_attrs; int32 n_attr; int32 index; int32 sd_id; int32 sds_id; int32 sds_rank; int32 data_type; int32 sds_data_type; int32 count; int32 sds_n_attrs; int32 sds_dim_sizes[MAX_VAR_DIMS]; int32 start[MAX_VAR_DIMS]; int32 stride[MAX_VAR_DIMS]; int32 edge[MAX_VAR_DIMS]; int32 sd_data_index[MAX_BANDS]; float unscaled; uint16 *uint16_array; int8 *char_array; short *short_array; short *Data_array; float *float_array; float *Latitude_array; float *Longitude_array; short int *Band1_array; short int *Band2_array; short int *Band3_array; short int *Band4_array; short int *Band5_array; short int *Band6_array; short int *Band7_array; short int *Band8_array; short int *Band9_array; short int *Band10_array; short int *Band11_array; short int *Band12_array; short int *Band13_array; short int *Band14_array; short int *Band15_array; short int *Band16_array; short int *Band17_array; short int *Band18_array; short int *Band19_array; short int *Band20_array; short int *Band21_array; short int *Band22_array; short int *Band23_array; short int *Band24_array; short int *Band25_array; short int *Band26_array; unsigned char *uchar_array; unsigned short int *ushort_array; unsigned int *ulong_array; unsigned int ival; unsigned int value; McArgSyntax filesyntax0 = {".", "=", ";", "{\"", "}", "'", "'", NULL, "X", " "}; McArgSyntax filesyntax1 = {"_.", "=", ";", "{\"", "}", "'", "'", NULL, "X", " "}; static char trace_string[500]; /* tracing text */ /* variable for "ALL" */ (void) memcpy(&ALL, "ALL ", 4 ); M0swbyt4( &ALL, 1); /* initialize local server */ rc = M0InitLocalServer(server, argc, argv, &requestBlock, &request); /* see if logging should be done, determined by hidden TRACE= flag */ trace = M0IsTraceSet(request); (void *)sprintf(trace_string, "%s NSSXAGET Trace Level = %d", server, trace); M0sxtrce( trace_string ); /* move the request back into the comm block */ (void) strncpy(requestBlock.text, request, sizeof(requestBlock.text)); /* fill in the data type */ transaction = atoi(argv[5]); (void) memcpy(requestBlock.transaction, &transaction, sizeof(requestBlock.transaction)); /* fill in the user */ user = atoi(argv[3]); (void) memcpy(requestBlock.user, &user, sizeof(requestBlock.user)); /* initialize accounting */ m0vserv_(&requestBlock); /* get dataset info */ rc = M0sxdatasetinfo(request, &group, &dataset, &type, &format, &mask, &info, &comment, &loBound, &hiBound, &rt_flag); sprintf(trace_string, "%s group = %s", server,group); M0sxtrce( trace_string ); sprintf(trace_string, "%s dataset = %s", server,dataset); M0sxtrce( trace_string ); sprintf(trace_string, "%s type = %s", server,type); M0sxtrce( trace_string ); sprintf(trace_string, "%s format = %s", server,format); M0sxtrce( trace_string ); sprintf(trace_string, "%s mask = %s", server,mask); M0sxtrce( trace_string ); sprintf(trace_string, "%s info = %s", server,info); M0sxtrce( trace_string ); sprintf(trace_string, "%s comment = %s", server,comment); M0sxtrce( trace_string ); /* log the request text string */ sprintf(trace_string, "%s Request = %s", server,request); M0sxtrce( trace_string ); /* DATASET name */ sprintf(trace_string,"%s Dataset = %s", server,group); M0sxtrce( trace_string ); /* must read ADDE dataset info file to get the file mask */ sprintf(trace_string, "%s File Mask = %s", server,mask); M0sxtrce( trace_string ); /* produce a list of files matching the data mask */ flist = M0GetMaskFileList(mask); if( flist == (char **)NULL ) { (void)strcpy(requestBlock.errormsg, "No images satisfy DATA 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 DATA file mask"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } sprintf(trace_string, "%s Number of DATA files found = %d", server, num_flist); M0sxtrce( trace_string ); } /* number of files found -> log the list */ num_sort = 0; for( ii=0; ii=jj; jjj-- ) { sort_secs[jjj] = sort_secs[jjj-1]; sort_flist[jjj] = sort_flist[jjj-1]; } sort_secs[jj] = image_sec; sort_flist[jj] = ii; found = 1; } if( found == 1 ) break; } if( found == 0 ) { sort_flist[num_sort] = ii; sort_secs[num_sort] = image_sec; } } num_sort++; /* free the handle */ Mcargfree( file_handle ); } /* What kind of NSS product are these */ sprintf(trace_string, "%s File Mask = %s", server,mask); M0sxtrce( trace_string ); NSS_product_type = 0; minimum_band = 1; maximum_band = 18; /* POS sort condition */ rc = Mcargint(0, " ", 2, 0, -99999, num_flist, &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 = num_flist + bPos; if( ePos <= 0 ) ePos = 1; bPos = ePos; } else { ePos = bPos; } sprintf(trace_string, "%s bPos: %d, ePos: %d", server, bPos, ePos); M0sxtrce( trace_string ); /* Current Day and Time */ rc = Mcgetdaytime(&curDate, &curTime); /* DAY */ checkDay = Mcargnum(0, "DAY"); if( checkDay != 0 ) { 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 = num_flist; } 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; } (void *)sprintf(trace_string,"%s DAY: range= %d to %d",server,bdate,edate); M0sxtrce( trace_string ); /* TIME */ checkTime = Mcargnum(0, "TIM.E"); if( checkTime != 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 = num_flist; } 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; } (void *)sprintf(trace_string,"%s TIME: range= %d to %d",server,btime,etime); M0sxtrce( trace_string ); /* Process the request: Dataset Position */ loBound = (num_flist * -1) +1; hiBound = num_flist; 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); } /* NAV */ rc = Mcargstr(0, "NAV", 1, "", (const char **)&navproj); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid NAV parameter format"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* 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; (void *)sprintf(trace_string,"%s Center Earth COORD: Lat=%f Lon=%f" ,server,request_center_latitude,request_center_longitude); M0sxtrce( trace_string ); } /* 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); } (void *)sprintf(trace_string,"%s Starting Image COORD: Lin=%d Ele=%d" ,server,request_starting_line,request_starting_element); M0sxtrce( trace_string ); } /* 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); } (void *)sprintf(trace_string,"%s Starting Area COORD: Lin=%d Ele=%d" ,server,read_starting_line,read_starting_element); M0sxtrce( trace_string ); } /* Process the request: Line Magnification */ rc = Mcargint(0, "LMA.G", 1, 1, -50, 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, -50, 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);; (void *)sprintf(trace_string,"%s MAG: Lin=%d Ele=%d" ,server,request_line_magnification,request_element_magnification); M0sxtrce( trace_string ); /* constants */ image_starting_line = 1; image_starting_element = 1; image_line_base_resolution = 1; image_element_base_resolution = 1; image_line_resolution = 1.00; image_element_resolution = 1.00; image_geo_line_resolution = 1.00; image_geo_element_resolution = 1.00; image_geo_line_magnification = request_line_magnification; image_geo_element_magnification = request_element_magnification; image_geo_latitude_resolution = 1; image_geo_longitude_resolution = 1; /* 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, &dum ); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid Element SIZE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } (void *)sprintf(trace_string,"%s SIZE: Lin=%d Ele=%d" ,server,request_line_size,request_element_size); M0sxtrce( trace_string ); /* BAND */ request_n_bands = Mcargnum(0, "BAN.D" ); if( request_n_bands == 0 ) { (void)strcpy(requestBlock.errormsg, "No BAND(s) specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } else { char *cALL; /* BAND=ALL*/ rc = Mcargstr(0, "BAN.D", 1, " ", (const char **)&cALL); (void *)sprintf(trace_string,"%s BAND=%s",server,cALL); M0sxtrce( trace_string ); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid BAND specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Transfer ALL bands */ band_all = 0; if( strncmp( cALL, "ALL",3 ) == 0 ) { request_n_bands = 9999; band_all = 1; /* Transfer a subset of the bands */ } else { for( i=0; i 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( "NSSX", NULL); def_space = 1; CAL_BLOCK_SIZE = 0; CAL_OFFSET = 0; AUX_OFFSET = 768; } else { image_stype = stralloc( "NSSX", NULL); def_unit = stralloc( "RAW",NULL); last_stype = stralloc( " ", NULL); def_space = 2; AUX_OFFSET = (DIR_BLOCK_SIZE + NAV_BLOCK_SIZE + CAL_BLOCK_SIZE)*4; } /* 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, "RAW", (const char **)&unit); if( rc < 0 ) { (void)strcpy(requestBlock.errormsg, "Invalid UNIT specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Requested UNITS = RAW */ 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 = 1; punit = stralloc(" ",NULL); ounit_flag = 0; /* Requested UNITS = TYPE (Cloud TYPE) */ } else if( strncmp( unit, "TYPE",4 ) == 0 ) { if( space == 0 ) space = 1; if( space < 1 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for TYPE specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this calibration */ if( band != 1 ) { (void)strcpy(requestBlock.errormsg, "Band is not available in TYPE units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); } dir_unit = stralloc( "TYPE",NULL); request_data_size = space; pscale = 1; punit = stralloc(" ",NULL); ounit_flag = 3; /* Requested UNITS = REFF (Effective Radius) */ } else if( strncmp( unit, "REFF",4 ) == 0 ) { if( space == 0 ) space = 1; if( space < 1 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for REFF specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this calibration */ if( band != 6 ) { (void)strcpy(requestBlock.errormsg, "Band is not available in REFF units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); } dir_unit = stralloc( "REFF",NULL); request_data_size = space; pscale = 1; pscale = 100; punit = stralloc(" uM ",NULL); ounit_flag = 4; /* Requested UNITS = REFlectance */ } else if( strncmp( unit, "REF" ,3) == 0 ) { if( space == 0 ) space = 2; if( space < 2 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for REF specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this band */ if( band < 9 || band > 12 ) { (void)strcpy(requestBlock.errormsg, "Band is not available in REF units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "REF ",NULL); request_data_size = space; pscale = 10; punit = stralloc(" % ",NULL); ounit_flag = 1; /* Requested UNITS = HGT (Height) */ } else if( strncmp( unit, "HGT",3 ) == 0 ) { /* if( space == 0 ) space = 1; if( space < 1 ) {*/ /* WCS EDIT */ if( space == 0 ) space = 2; if( space < 2 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for RERA specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this band */ if( band != 3 ) { (void)strcpy(requestBlock.errormsg, "Band is not available in HGT units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "HGT ",NULL); request_data_size = space; /* pscale = 1;*/ pscale = 10; /* Changed 4/5/2012 - WCS3 */ punit = stralloc(" KM ",NULL); ounit_flag = 2; /* Requested UNITS = DPTH */ } else if( strncmp( unit, "DPTH" ,4) == 0 ) { if( space == 0 ) space = 2; if( space < 2 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for DPTH specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this calibration */ if( band != 5 ) { (void)strcpy(requestBlock.errormsg, "Band is not available in DPTH units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0);} dir_unit = stralloc( "DPTH ",NULL); request_data_size = space; pscale = 1; punit = stralloc(" ",NULL); ounit_flag = 9; /* Reqested UNITS = PRESsure */ } else if( strncmp( unit, "PRES" ,4) == 0 ) { if( space == 0 ) space = 2; if( space < 2 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for DIST specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this calibration */ if( band != 4 ) { (void)strcpy(requestBlock.errormsg, "Band is not available in PRES units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "PRES",NULL); request_data_size = space; pscale = 1; punit = stralloc(" MB ",NULL); ounit_flag = 7; /* Requested UNITS = TEMPerature */ } else if( strncmp( unit, "TEMP" ,4) == 0 ) { if( space == 0 ) space = 2; if( space < 2 ) { (void)strcpy(requestBlock.errormsg, "Invalid Spacing for TEMP specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } if( request_n_bands > 1 ) { (void)strcpy(requestBlock.errormsg, "Multi-band transfer UNITS must be RAW"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Are units valid for this calibration */ if( band == 2 || band ==7 || band == 8 || band == 13 || band == 14 || band == 15 ) { ounit_flag = 8; } else { (void)strcpy(requestBlock.errormsg, "Band is not available in TEMP units"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } dir_unit = stralloc( "TEMP",NULL); request_data_size = space; pscale = 100; punit = stralloc(" K ",NULL); ounit_flag = 8; /* Requested UNITS = BRIT (Brightness) */ } 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 = BRIT_SCALE; punit = stralloc(" ",NULL); ounit_flag = 10; /* UNKOWN UNITS */ } else { (void)strcpy(requestBlock.errormsg, "Invalid UNIT specified"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } (void *)sprintf(trace_string,"%s SPACE: %d",server,space); M0sxtrce( trace_string ); (void *)sprintf(trace_string,"%s UNIT: %s",server,unit); M0sxtrce( trace_string ); /* *** Beginning HDF file access *** */ sprintf(trace_string, "%s Loop bPos: %d, ePos: %d", server, bPos, ePos); M0sxtrce( trace_string ); for( image_dataset_position=bPos; image_dataset_position<=ePos; image_dataset_position++) { /* copy the file name from the list */ file_name = flist[sort_flist[image_dataset_position-1]]; /* test for syntax type */ file_syntax_type = 0; /* rc = strstr( file_name, "/goes" ); if( rc != NULL ) file_syntax_type = 1;*/ /*Took logic from catgadir to get syntax type */ if( strstr( file_name, "/goes" ) != NULL ) { file_syntax_type = 1; } else if( strstr( file_name, "/mtsat" ) != NULL ) { file_syntax_type = 2; } else if( strstr( file_name, "/met" ) != NULL ) { file_syntax_type = 3; }else if( strstr( file_name, "/fy-2" ) != NULL ) { file_syntax_type = 4; } else if( strstr( file_name, "/patmosx" ) != NULL ) { file_syntax_type = 5; } else if( strstr( file_name, "/coms" ) != NULL ) { file_syntax_type = 6; } else if( strstr( file_name, "/H08" ) != NULL ) { file_syntax_type = 7; } else if( strstr( file_name, "/npp" ) != NULL ) { file_syntax_type = 8; } sprintf(trace_string, "%s FILE=%s Syntax=%d", server, file_name, file_syntax_type ); M0sxtrce( trace_string ); /* SDS variable initialization */ image_n_bands= 0; image_line_size= 0; image_element_size= 0; image_data_size= 0; /* intialize the SD data field flags */ HDF_Latitude_flag = FALSE; HDF_Longitude_flag = FALSE; HDF_All_Data_flag = FALSE; for( i=0; i=0; Key-- ) { rc = Mcargstr( file_handle, "", Key, "", (const char **)&coverage); sprintf(trace_string, "%s coverage=%s", server,coverage); M0sxtrce( trace_string ); rc = strstr( coverage, "/goes11"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 76; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-11 ",32); } rc = strstr( coverage, "/goes12"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 78; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-12 ",32); } rc = strstr( coverage, "/goes13"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 180; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-13 ",32); } rc = strstr( coverage, "/goes14"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 182; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-14 ",32); } rc = strstr( coverage, "/goes15"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 184; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-15 ",32); } rc = strstr( coverage, "/goes16"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 186; memcpy( (void *)&directory[24], (void *)"GOES PRODUCT FROM G-16 ",32); } rc = strstr( coverage, "/mtsat-1r"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 84; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MTSAT-1R ",32); } rc = strstr( coverage, "/mtsat-2"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 85; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MTSAT-2 ",32); } rc = strstr( coverage, "/met8"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 3; image_element_resolution = 3; SSEC_satellite_id = 51; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MSG-1 ",32); } rc = strstr( coverage, "/met9"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 3; image_element_resolution = 3; SSEC_satellite_id = 52; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MSG-2 ",32); } rc = strstr( coverage, "/met10"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 3; image_element_resolution = 3; SSEC_satellite_id = 53; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM MSG-3 ",32); } rc = strstr( coverage, "/fy-2d"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 36; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM FY2-D ",32); } rc = strstr( coverage, "/fy-2e"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 37; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM FY2-E ",32); } rc = strstr( coverage, "/patmosx"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 10; memcpy( (void *)&directory[24], (void *)"COMPOSITE CLAVRX PRODUCT ",32); } rc = strstr( coverage, "/coms1"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 4; image_element_resolution = 4; SSEC_satellite_id = 250; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM COMS-1 ",32); } rc = strstr( coverage, "/H08"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 2; image_element_resolution = 2; SSEC_satellite_id = 86; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM HIMAWARI-8 ",32); } rc = strstr( coverage, "/npp"); if( rc != NULL && ThisKey == 0 ) { ThisKey = Key; file_name_type = 3; image_line_resolution = 1; image_element_resolution = 1; SSEC_satellite_id = 300; memcpy( (void *)&directory[24], (void *)"ACHA PRODUCT FROM SUOMI-NPP ",32); } } } sprintf(trace_string, "%s Coverage=%s FileType=%d ThisKey=%d ", server, coverage,file_name_type,ThisKey ); M0sxtrce( trace_string ); /* AVHRR Satellites */ /*WCS3 - corrected METOP-A (M2) call - 11/7/2011 */ rc = Mcargstr( file_handle, "", 2, "", (const char **)&satellite_id); M0sxtrce( trace_string ); if ( strncmp( satellite_id, "TN", 2 ) == 0 ) { SSEC_satellite_id = 41; } else if ( strncmp( satellite_id, "NA", 2 ) == 0 ) { SSEC_satellite_id = 42; } else if ( strncmp( satellite_id, "NC", 2 ) == 0 ) { SSEC_satellite_id = 43; } else if ( strncmp( satellite_id, "NE", 2 ) == 0 ) { SSEC_satellite_id = 44; } else if ( strncmp( satellite_id, "NF", 2 ) == 0 ) { SSEC_satellite_id = 45; } else if ( strncmp( satellite_id, "NG", 2 ) == 0 ) { SSEC_satellite_id = 60; } else if ( strncmp( satellite_id, "NH", 2 ) == 0 ) { SSEC_satellite_id = 61; } else if ( strncmp( satellite_id, "ND", 2 ) == 0 ) { SSEC_satellite_id = 62; } else if ( strncmp( satellite_id, "NI", 2 ) == 0 ) { SSEC_satellite_id = 63; } else if ( strncmp( satellite_id, "NJ", 2 ) == 0 ) { SSEC_satellite_id = 64; } else if ( strncmp( satellite_id, "NK", 2 ) == 0 ) { SSEC_satellite_id = 65; } else if ( strncmp( satellite_id, "NL", 2 ) == 0 ) { SSEC_satellite_id = 66; } else if ( strncmp( satellite_id, "NM", 2 ) == 0 ) { SSEC_satellite_id = 67; } else if ( strncmp( satellite_id, "NN", 2 ) == 0 ) { memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM NOAA-18 ",32); SSEC_satellite_id = 68; } else if ( strncmp( satellite_id, "NP", 2 ) == 0 ) { memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM NOAA-19 ",32); SSEC_satellite_id = 69; } else if ( strncmp( satellite_id, "M1", 2 ) == 0 ) { memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM METOP-B ",32); SSEC_satellite_id = 241; } else if ( strncmp( satellite_id, "M2", 2 ) == 0 ) { memcpy( (void *)&directory[24], (void *)"AVHRR PRODUCT FROM METOP-A ",32); SSEC_satellite_id = 240; } else if ( strncmp( satellite_id, "M3", 2 ) == 0 ) { SSEC_satellite_id = 243; } if( SSEC_satellite_id == 0 ) { sprintf(trace_string, "%s FAILED: Unknown Satellite = %s", server, satellite_id); M0sxtrce( trace_string ); continue; } sprintf(trace_string, "%s image_id = %d", server, SSEC_satellite_id); M0sxtrce( trace_string ); /* compute the SSEC resolution of the requested data */ request_line_resolution = image_line_base_resolution * request_line_magnification; request_element_resolution = image_element_base_resolution * request_element_magnification; sprintf(trace_string, "%s RES: Line=%d Elem=%d", server, request_line_resolution, request_element_resolution); M0sxtrce( trace_string ); /* Based on the image type, set the band specific constants */ if( bband == 99999 && eband == 99999 ) { ii = 1; jj = MAX_BANDS; bband = ii; eband = jj; } else { ii = bband; jj = eband; } /* set band list arrays */ num_band = 0; for( i=minimum_band; i<=maximum_band; i++ ) { bands[num_band] = i; band_res[num_band] = 1.00; ++num_band; } /* Evaluate the file name for image day (CCYYDDD) */ if( file_syntax_type == 0 ) { rc = Mcargstr( file_handle, " ", 3, " ", (const char **)&cdate); length = strlen( cdate ); for( i=0; i 0 ) { sprintf(trace_string, "%s CHECKING DATE image_cyd = %d, bdate=%d edate=%d ",server, image_cyd, bdate, edate); M0sxtrce( trace_string ); if( (image_cyd < bdate) || (image_cyd > edate) ) continue; sprintf(trace_string, "%s PASSED DATE CHECK ",server); M0sxtrce( trace_string ); } /* Evaluate the file name for image time (HHMMSS) */ if( file_syntax_type == 0 ) { rc = Mcargstr( file_handle, " ", 4, " ", (const char **)&cstime); length = strlen( cstime ); for( i=0; i 0 ) { if( (image_hms < btime) || (image_hms > etime) ) continue; } /* start the HDF file */ sd_id = SDstart( file_name, DFACC_READ ); if( sd_id == FAIL ) { sprintf(trace_string, "%s START: FAILED for %s", server, file_name); M0sxtrce( trace_string ); continue; } /* determine the number of SDS's in the file */ status = SDfileinfo( sd_id, &n_datasets, &n_file_attrs ); if( status == FAIL ) { sprintf(trace_string, "%s FILE INFO FAILED for %s", server, file_name ); M0sxtrce( trace_string ); continue; } /* loop through the individual SDS's */ wrong = 0; for( index=0; indeximage_geo_maximum_latitude ) image_geo_maximum_latitude = Latitude_array[i]; } } free( short_array ); /* Center Latitude */ i = ((sds_dim_sizes[0]/2 - 1) * sds_dim_sizes[1]) + (sds_dim_sizes[1]/2) - 1; image_geo_center_latitude = Latitude_array[i]; sprintf(trace_string, "%s min=%f max=%f cp=%f", server,image_geo_minimum_latitude,image_geo_maximum_latitude,image_geo_center_latitude); M0sxtrce( trace_string ); /* set the Latitude component flag */ HDF_Latitude_flag = TRUE; } /* Geo Fields - Longitude */ else if( ((strncmp( name, "longitude", 9 ) == 0))) { sprintf(trace_string, "%s Found Longitude SDS", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1]) * sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the Longitudes iinto the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* reserve memory for the floating point Longitude array */ Longitude_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1]) * sizeof(float) ); if( Longitude_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* record the size of the geo field */ image_geo_line_size = sds_dim_sizes[0]; image_geo_element_size = sds_dim_sizes[1]; /* record the size or a geo element */ image_geo_data_size = 4; /* construct Longitude array */ image_geo_minimum_longitude = Longitude_array[0]; image_geo_maximum_longitude = Longitude_array[0]; for (i=0; i<(image_geo_line_size*image_geo_element_size); i++ ) { /* compute the unscaled latitude */ if( short_array[i] == -32768 ) { Longitude_array[i] = -999.0; } else { unscaled = ((float)(short_array[i] - (-32767))) / (float)(32767 -(-32767)); Longitude_array[i] = -180.0 + ((180.0-(-180.0)) * unscaled); /* MIN/MAX Longitude */ if( Longitude_array[i]image_geo_maximum_longitude ) image_geo_maximum_longitude = Longitude_array[i]; } } /* discard the short array */ free( short_array ); /* Center Longitude */ i = ((sds_dim_sizes[0]/2 - 1) * sds_dim_sizes[1]) + (sds_dim_sizes[1]/2) - 1; image_geo_center_longitude = Longitude_array[i]; sprintf(trace_string, "%s min=%f max=%f cp=%f", server,image_geo_minimum_longitude,image_geo_maximum_longitude,image_geo_center_longitude); M0sxtrce( trace_string ); /* Set Longitude Flag */ HDF_Longitude_flag = TRUE; /* CLOUD: Type */ } else if( strncmp( name, "cloud_type", 10 ) == 0 ) { if( strncmp( name, "cloud_type_", 11 ) == 0 ) { wrong++; } else { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=1: Cloud Type", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ uchar_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( uchar_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the uchar array */ status = SDreaddata( sds_id, start, stride, edge, uchar_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cloud_type is band 1 */ got_bands[0] = 1; image_n_bands++; HDF_Data_flag[0] = TRUE; /* Calibration */ range_mins[0] = 0.0; range_maxs[0] = 12.0; range_miss[0] = -128.0; scale_mins[0] = 0; scale_maxs[0] = 12; scale_miss[0] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band1 array */ Band1_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band1_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band1_array */ size = image_line_size * image_element_size; for( i=0; i maxval ) maxval = Band1_array[i]; } } sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server,minval,maxval,misval); M0sxtrce( trace_string ); /* discard the uchar array */ free( uchar_array ); } } /* CLOUD: Temperature */ } else if( strncmp( name, "cld_temp_sw", 11 ) == 0 || strncmp( name, "cld_temp_acha", 13 ) == 0 ) { if( strncmp( name, "cld_temp_acha_", 14 ) == 0 ) { wrong++; } else { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=2: Cloud Temperature", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the char array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cld_temp is band 2 */ got_bands[1] = 1; image_n_bands++; HDF_Data_flag[1] = TRUE; /* Calibration */ range_mins[1] = 180.0; range_maxs[1] = 320.0; range_miss[1] = -999.0; scale_mins[1] = -32767; scale_maxs[1] = 32767; scale_miss[1] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band2 array */ Band2_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band2_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band2_array */ size = image_line_size * image_element_size; for( i=0; i maxval ) maxval = Band2_array[i]; } } sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server,minval,maxval,misval); M0sxtrce( trace_string ); /* discard the uchar array */ free( short_array ); } } /* CLOUD: Height */ } else if( strncmp( name, "cld_height_sw", 13 ) == 0 || strncmp( name, "cld_height_acha", 15 ) == 0 ) { if( strncmp( name, "cld_height_acha_", 16 ) == 0 ) { wrong++; } else { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=3: Cloud Height", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the uchar array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cld_height_acha is band 3 */ got_bands[2] = 1; image_n_bands++; HDF_Data_flag[2] = TRUE; /* Calibration */ range_mins[2] = 0.0; range_maxs[2] = 20.0; range_miss[2] = -999.0; scale_mins[2] = -32767; scale_maxs[2] = 32767; scale_miss[2] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band3 array */ Band3_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band3_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band3_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=4: Cloud Top Pressure", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the Band 4 array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cld_press_acha band 4 */ got_bands[3] = 1; image_n_bands++; HDF_Data_flag[3] = TRUE; /* Calibration */ range_mins[3] = 0.0; range_maxs[3] = 1100.0; range_miss[3] = -999.0; scale_mins[3] = -32767; scale_maxs[3] = 32767; scale_miss[3] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band4 array */ Band4_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band4_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } min = 9999; max = -9999; fil = 0; size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=5: Cloud Optical Depth", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the Band 5 array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cld_reff_vis band 4 */ got_bands[4] = 1; image_n_bands++; HDF_Data_flag[4] = TRUE; /* Calibration */ range_mins[4] = -0.2; range_maxs[4] = 160.0; range_miss[4] = -999.0; scale_mins[4] = -32767; scale_maxs[4] = 32767; scale_miss[4] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band5 array */ Band5_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band5_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band4_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=6 Cloud Effective Radius", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* Mark that we have band 6 */ got_bands[5] = 1; image_n_bands++; HDF_Data_flag[5] = TRUE; /* Calibration */ range_mins[5] = 0.0; range_maxs[5] = 160.0; range_miss[5] = -999.0; scale_mins[5] = -32767; scale_maxs[5] = 32767; scale_miss[5] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band6 array */ Band6_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band6_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band6_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=8 pixel_sst SDS", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* pixel_sst_masked is band 8 */ got_bands[7] = 1; image_n_bands++; HDF_Data_flag[7] = TRUE; /* Calibration */ range_mins[7] = 265.0; range_maxs[7] = 315.0; range_miss[7] = -999.0; scale_mins[7] = -127; scale_maxs[7] = 127; scale_miss[7] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band8 array */ Band8_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band8_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band8_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=7 SST Unmasked", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mask_sst is band 1 */ got_bands[6] = 1; image_n_bands++; HDF_Data_flag[6] = TRUE; /* Calibration */ range_mins[6] = 265.0; range_maxs[6] = 315.0; range_miss[6] = -999.0; scale_mins[6] = -127; scale_maxs[6] = 127; scale_miss[6] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band7 array */ Band7_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band7_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band7_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=9 0.65 Reflectance ", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 9*/ got_bands[8] = 1; image_n_bands++; HDF_Data_flag[8] = TRUE; /* Calibration */ range_mins[8] = -2.0; range_maxs[8] = 120.0; range_miss[8] = -999.0; scale_mins[8] = -32767; scale_maxs[8] = 32767; scale_miss[8] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band9 array */ Band9_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band9_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band9_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=10 0.86um Reflectance ", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 10 */ got_bands[9] = 1; image_n_bands++; HDF_Data_flag[9] = TRUE; /* Calibration */ range_mins[9] = -2.0; range_maxs[9] = 120.0; range_miss[9] = -999.0; scale_mins[9] = -32767; scale_maxs[9] = 32767; scale_miss[9] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band1 array */ Band10_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band10_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band1_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=11 1.60um Reflectance", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 11 */ got_bands[10] = 1; image_n_bands++; HDF_Data_flag[10] = TRUE; /* Calibration */ range_mins[10] = -2.0; range_maxs[10] = 120.0; range_miss[10] = -999.0; scale_mins[10] = -32767; scale_maxs[10] = 32767; scale_miss[10] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band11 array */ Band11_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band11_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band1_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=12 3.75um Reflectance", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 12 */ got_bands[11] = 1; image_n_bands++; HDF_Data_flag[11] = TRUE; /* Calibration */ range_mins[11] = -20.0; range_maxs[11] = 80.0; range_miss[11] = -999.0; scale_mins[11] = -32767; scale_maxs[11] = 32767; scale_miss[11] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band12 array */ Band12_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band12_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band12_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=13 3.75um Temperature", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 13 */ got_bands[12] = 1; image_n_bands++; HDF_Data_flag[12] = TRUE; /* Calibration */ range_mins[12] = 180.0; range_maxs[12] = 340.0; range_miss[12] = -999.0; scale_mins[12] = -32767; scale_maxs[12] = 32767; scale_miss[12] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band13 array */ Band13_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band13_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band13_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=14 11.0um Temperature", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 14 */ got_bands[13] = 1; image_n_bands++; HDF_Data_flag[13] = TRUE; /* Calibration */ range_mins[13] = 180.0; range_maxs[13] = 340.0; range_miss[13] = -999.0; scale_mins[13] = -32767; scale_maxs[13] = 32767; scale_miss[13] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band14 array */ Band14_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band14_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band14_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=15 12.0um Temperature", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 15 */ got_bands[14] = 1; image_n_bands++; HDF_Data_flag[14] = TRUE; /* Calibration */ range_mins[14] = 180.0; range_maxs[14] = 340.0; range_miss[14] = -999.0; scale_mins[14] = -32767; scale_maxs[14] = 32767; scale_miss[14] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band15 array */ Band15_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band15_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band15_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=16: Cloud Emissivity", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the Band 16 array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cld_reff_vis band 4 */ got_bands[15] = 1; image_n_bands++; HDF_Data_flag[15] = TRUE; /* Calibration */ range_mins[15] = 0.0; range_maxs[15] = 1.0; range_miss[15] = -999.0; scale_mins[15] = -127; scale_maxs[15] = 127; scale_miss[15] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band16 array */ Band16_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band16_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band16_array */ min = 255; max = -255; fil = 0; size = image_line_size * image_element_size; for( i=0; i max ) max = char_array[i]; } Band16_array[i] = char_array[i]; } sprintf(trace_string, "%s Found BAND=16: min=%d max=%d fil=%d", server, min, max, fil ); M0sxtrce( trace_string ); /* discard the short array */ free( char_array ); } /* CLD: Cloud Probability */ } else if( strncmp( name, "cloud_probability", 17 ) == 0 ) { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=17 Cloud Probability", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 17 */ got_bands[16] = 1; image_n_bands++; HDF_Data_flag[16] = TRUE; /* Calibration */ range_mins[16] = 0.0; range_maxs[16] = 1.0; range_miss[16] = -999.0; scale_mins[16] = -32767; scale_maxs[16] = 32767; scale_miss[16] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band17 array */ Band17_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band17_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band17_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=18 Cloud Fraction", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the char array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 18 */ got_bands[17] = 1; image_n_bands++; HDF_Data_flag[17] = TRUE; /* Calibration */ range_mins[17] = 0.0; range_maxs[17] = 1.0; range_miss[17] = -999.0; scale_mins[17] = -127; scale_maxs[17] = 127; scale_miss[17] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band18 array */ Band18_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band18_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band18_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=19: Cloud Mask", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ uchar_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( uchar_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the uchar array */ status = SDreaddata( sds_id, start, stride, edge, uchar_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cloud_mask is band 19 */ got_bands[18] = 1; image_n_bands++; HDF_Data_flag[18] = TRUE; /* Calibration */ range_mins[18] = 0.0; range_maxs[18] = 3.0; range_miss[18] = -128.0; scale_mins[18] = 0; scale_maxs[18] = 3; scale_miss[18] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band19 array */ Band19_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band19_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band19_array */ size = image_line_size * image_element_size; for( i=0; i maxval ) maxval = Band19_array[i]; } } sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server,minval,maxval,misval); M0sxtrce( trace_string ); /* discard the uchar array */ free( uchar_array ); } } } /* Cloud altitude */ else if( strncmp( name, "cld_altitude_acha", 17 ) == 0 ) { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND 20: CLD FLT HGHT SDS", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 20 */ got_bands[19] = 1; image_n_bands++; HDF_Data_flag[19] = TRUE; /* Calibration */ range_mins[19] = 0.0; range_maxs[19] = 100000.0; range_miss[19] = -999.0; scale_mins[19] = -32767; scale_maxs[19] = 32767; scale_miss[19] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band2 array */ Band20_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band20_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band20_array */ size = image_line_size * image_element_size; for( i=0; i maxval ) maxval = Band20_array[i]; } } sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server,minval,maxval,misval); M0sxtrce( trace_string ); /* discard the uchar array */ free( short_array ); } } /* DCOMP: Cloud transmission 0.65 microns */ else if( strncmp( name, "cloud_transmission_0_65um_nom", 29 ) == 0 ) { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND 21: Cloud Transmission", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the char array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 12 */ got_bands[20] = 1; image_n_bands++; HDF_Data_flag[20] = TRUE; /* Calibration */ range_mins[20] = 0.0; range_maxs[20] = 1.0; range_miss[20] = -999.0; scale_mins[20] = -127; scale_maxs[20] = 127; scale_miss[20] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band20 array */ Band21_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band21_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band20_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND 22: CLD FLT BASE SDS", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 20 */ got_bands[21] = 1; image_n_bands++; HDF_Data_flag[21] = TRUE; /* Calibration */ range_mins[21] = 0.0; range_maxs[21] = 100000.0; range_miss[21] = -999.0; scale_mins[21] = -32767; scale_maxs[21] = 32767; scale_miss[21] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band22 array */ Band22_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band22_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band22_array */ size = image_line_size * image_element_size; for( i=0; i maxval ) maxval = Band22_array[i]; } } sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server,minval,maxval,misval); M0sxtrce( trace_string ); /* discard the uchar array */ free( short_array ); } } /* Cloud Cover Layers */ else if( (strncmp( name, "cld_layer", 9) == 0) ) { if( strncmp( name, "cld_layer_", 10 ) == 0 ) { wrong++; } else { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=23: Cloud Cover Layers", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ uchar_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( uchar_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the uchar array */ status = SDreaddata( sds_id, start, stride, edge, uchar_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* cld_layer is band 23 */ got_bands[22] = 1; image_n_bands++; HDF_Data_flag[22] = TRUE; /* Calibration */ range_mins[22] = 0.0; range_maxs[22] = 3.0; range_miss[22] = -128.0; scale_mins[22] = 0; scale_maxs[22] = 3; scale_miss[22] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band23 array */ Band23_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band23_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band23_array */ size = image_line_size * image_element_size; for( i=0; i maxval ) maxval = Band23_array[i]; } } sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server,minval,maxval,misval); M0sxtrce( trace_string ); /* discard the uchar array */ free( uchar_array ); } } /* CLD: Cloud Convective Probability */ } else if( strncmp( name, "conv_cloud_probability", 22 ) == 0 ) { sum = 0; for (i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=24 Convective Cloud Probability", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the char array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 24 */ got_bands[23] = 1; image_n_bands++; HDF_Data_flag[23] = TRUE; /* Calibration */ range_mins[23] = 0.0; range_maxs[23] = 1.0; range_miss[23] = -999.0; scale_mins[23] = -127; scale_maxs[23] = 127; scale_miss[23] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band24 array */ Band24_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band24_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band24_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=25 Sensor Zenith Angle", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; /* reserve memory for the char array */ char_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(char) ); if( char_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the char array */ status = SDreaddata( sds_id, start, stride, edge, char_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 25 */ got_bands[24] = 1; image_n_bands++; HDF_Data_flag[24] = TRUE; /* Calibration */ range_mins[24] = 0.0; range_maxs[24] = 90.0; range_miss[24] = -999.0; scale_mins[24] = -127; scale_maxs[24] = 127; scale_miss[24] = -128; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band24 array */ Band25_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(short) ); if( Band25_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band24_array */ size = image_line_size * image_element_size; for( i=0; i 0 ) { sprintf(trace_string, "%s Found BAND=26 DNB Reflectivity", server); M0sxtrce( trace_string ); /* setup for data read */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = sds_dim_sizes[0]; edge[1] = sds_dim_sizes[1]; sprintf(trace_string, "%s DNB SIZE = %d X %d", server,edge[0],edge[1]); M0sxtrce( trace_string ); /* reserve memory for the short array */ short_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( short_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* read the short array */ status = SDreaddata( sds_id, start, stride, edge, short_array); if( status == FAIL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* mark that we have band 26 */ got_bands[25] = 1; image_n_bands++; HDF_Data_flag[25] = TRUE; /* Calibration */ range_mins[25] = -2.0; range_maxs[25] = 150.0; range_miss[25] = -999.0; scale_mins[25] = -32767; scale_maxs[25] = 32767; scale_miss[25] = -32768; /* set the image line/element sizes */ image_line_size = sds_dim_sizes[0]; image_element_size = sds_dim_sizes[1]; /* reserve memory for the Band25 array */ Band26_array = malloc( (sds_dim_sizes[0]*sds_dim_sizes[1])*sizeof(int16) ); if( Band26_array == NULL ) { requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* copy values into Band26_array */ size = image_line_size * image_element_size; for( i=0; i image_geo_maximum_latitude || request_center_longitude < image_geo_minimum_longitude || request_center_longitude > image_geo_maximum_longitude ) { (void)strcpy(requestBlock.errormsg, "requested Earth location is not contained in the image"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); /* sprintf(trace_string, "%s segment fails lat/lon bounds", server); M0sxtrce( trace_string ); goto SWATH_END_LABEL; */ } /* scan for the closest lat/lon point in geo-fields */ minimum = 999.0; for( i=0; i 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: (void *)sprintf(trace_string,"%s GEO REQUEST",server); M0sxtrce( trace_string ); /* determine the size of the geo request */ read_geo_line_size = read_line_size; read_geo_element_size = read_element_size; /* determine the coordinates of the geo request */ read_geo_starting_line = read_starting_line; read_geo_starting_element = read_starting_element; read_geo_ending_line = read_ending_line; read_geo_ending_element = read_ending_element; (void *)sprintf(trace_string,"%s READ GEO: line size=%d",server,read_geo_line_size); M0sxtrce( trace_string ); (void *)sprintf(trace_string,"%s READ GEO: element size=%d",server,read_geo_element_size); M0sxtrce( trace_string ); (void *)sprintf(trace_string,"%s READ GEO: starting line=%d",server,read_geo_starting_line); M0sxtrce( trace_string ); (void *)sprintf(trace_string,"%s READ GEO: starting element=%d",server,read_geo_starting_element); M0sxtrce( trace_string ); (void *)sprintf(trace_string,"%s READ GEO: ending line=%d",server,read_geo_ending_line); M0sxtrce( trace_string ); (void *)sprintf(trace_string,"%s READ GEO: ending element=%d",server,read_geo_ending_element); M0sxtrce( trace_string ); /* set the line and element sampling rates */ lineSampleRate = request_line_magnification; elemSampleRate = request_element_magnification; /* *************************** Transfer starts here ***************************** */ (void *)sprintf(trace_string,"%s TRANSFER",server); M0sxtrce( trace_string ); /* size of a lat/lon transfer array */ lalo_array_line_size = read_geo_line_size / image_geo_line_magnification; lalo_array_elem_size = read_geo_element_size / image_geo_element_magnification; for( i=0; i<4; i++ ) { LALO_step = pow(2,i); LALO_size = ((((lalo_array_line_size/LALO_step)*(lalo_array_elem_size/LALO_step))*4)*2)+52; if( LALO_size < MAX_AUXBLOCK_SIZE ) break; } lalo_array_line_size = lalo_array_line_size / LALO_step; lalo_array_elem_size = lalo_array_elem_size / LALO_step; lalo_array_size = lalo_array_line_size * lalo_array_elem_size * 4; /* size of the AUX block */ aux_block_size = (LAT_AUX + lalo_array_size ) + (LON_AUX + lalo_array_size ); (void *)sprintf(trace_string,"%s aux_block_size=%d",server,aux_block_size); M0sxtrce( trace_string ); /* size of the line prefix */ if( request_n_bands == 1 ) { psize = 0; } else { psize = request_n_bands / 4; if( (request_n_bands % 4) != 0 ) psize = psize+1; psize = psize * 4; } /* 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 ); (void *)sprintf(trace_string,"%s dat_block_size=%d",server,dat_block_size); M0sxtrce( trace_string ); /* 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); (void *)sprintf(trace_string,"%s total_block_size=%d",server,totalSize); M0sxtrce( trace_string ); requestBlock.reply_length += totalSize; M0swbyt4(&totalSize, 1); rc = M0sxsend(4, &totalSize ); /* ***************** DIRECTORY BLOCK ****************** */ /* initialize the directory block */ for( i=0; i 1 ) { directory[14] = psize; directory[50] = psize; for( i=0; i=0 && i=0 && j sector_max_lat ) sector_max_lat = Latitude_array[k]; } if( Longitude_array[k] != -999.0 ) { if( Longitude_array[k] < sector_min_lon ) sector_min_lon = Longitude_array[k]; if( Longitude_array[k] > sector_max_lon ) sector_max_lon = Longitude_array[k]; } } } } /* initialize the navigation block */ for( i=0; i70 ) { sprintf(trace_string, " NAV BLOCK: nav_block[%d]=%d", i, nav_block[i]); M0sxtrce( trace_string ); } } /* send the navigation */ M0swbyt4( &nav_block[2], NAV_BLOCK_SIZE-2 ); rc = M0sxsend( NAV_BLOCK_SIZE*4, nav_block ); sprintf(trace_string, "%s sent navigation: bytes=%d", server,NAV_BLOCK_SIZE*4); M0sxtrce( trace_string ); /* ***************** NAVIGATION BLOCK ***************** */ /* **************** CALIBRATION BLOCK ***************** */ if( CAL_BLOCK_SIZE > 0 ) { /* initialize the calibration block */ for( i=0; i 0 ) { float_array = malloc( lalo_array_size * sizeof(float) ); if( float_array == NULL ) { (void)strcpy(requestBlock.errormsg, "Failed malloc of lat/lon line array"); requestBlock.returncode = -30; M0sxdone(&requestBlock); return(0); } /* LATITUDE entry */ aux_head[0] = AUX_MAGIC_NUMBER; aux_head[1] = LAT_AUX + lalo_array_size; aux_head[2] = 8; aux_head[3] = lalo_array_size; memcpy( (void *)&aux_head[4], (void *)"LATITUDE", 8); M0swbyt4( aux_head, 6); rc = M0sxsend( 24, aux_head ); /* allow for line magnification */ if( read_geo_starting_line == 0 ) { starting_line = read_geo_starting_line; } else { starting_line = (read_geo_starting_line/image_geo_line_magnification)*image_geo_line_magnification; if( starting_line != read_geo_starting_line ) { starting_line=((read_geo_starting_line/image_geo_line_magnification)+1)*image_geo_line_magnification; } } ending_line = starting_line + ( (lalo_array_line_size-1) * (image_geo_line_magnification*LALO_step) ); /* allow for element magnification */ if( read_geo_starting_element == 0 ) { starting_elem = read_geo_starting_element; } else { starting_elem = (read_geo_starting_element/image_geo_element_magnification)*image_geo_element_magnification; if( starting_elem != read_geo_starting_element ) { starting_elem=((read_geo_starting_element/image_geo_element_magnification)+1)*image_geo_element_magnification; } } ending_elem = starting_elem + ( (lalo_array_elem_size-1) * (image_geo_element_magnification*LALO_step) ); sprintf(trace_string, "%s MAX_AUXBLOCK_SIZE=%d", server,MAX_AUXBLOCK_SIZE); M0sxtrce( trace_string ); sprintf(trace_string, "%s LAT: LINE start=%d end=%d mag=%d", server, starting_line, ending_line, image_geo_line_magnification); M0sxtrce( trace_string ); sprintf(trace_string, "%s LAT: ELEM start=%d end=%d mag=%d", server, starting_elem, ending_elem, image_geo_element_magnification); M0sxtrce( trace_string ); sprintf(trace_string, "%s LAT: SIZE line=%d elem=%d", server, image_geo_line_size, image_geo_element_size); M0sxtrce( trace_string ); sprintf(trace_string, "%s LALO: line=%d elem=%d size=%d", server, lalo_array_line_size, lalo_array_elem_size, lalo_array_size); M0sxtrce( trace_string ); /* sample down the Latitude array */ jj = 0; for ( i=starting_line; i<=ending_line; i=i+(image_geo_line_magnification*LALO_step)){ for ( j=starting_elem; j<=ending_elem; j=j+(image_geo_element_magnification*LALO_step)){ if( (i>=0 && i=0 && j=0 && i=0 && j 1 ) { memcpy( (void *)&uchar_array[0], (void *)&level_map[0], psize ); } } else if( space == 2 ) { ushort_array=malloc(((psize/2)+(request_n_bands*request_element_size))*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 ) { ulong_array=malloc(((psize/4)+(request_n_bands*request_element_size))*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 ); } } sprintf(trace_string, "%s Past input array malloc", server); M0sxtrce( trace_string ); sprintf(trace_string, "%s READ LINE: START=%d END=%d", server, read_starting_line, read_ending_line); M0sxtrce( trace_string ); sprintf(trace_string, "%s READ ELEM: START=%d END=%d", server, read_starting_element, read_ending_element); M0sxtrce( trace_string ); /* LOOP through the data field */ max_value = -1; min_value = 256; mis_value = 0; process = 0; trap = 0; offset = psize/space; for( i=read_starting_line; i<=read_ending_line; i=i+lineSampleRate ) { /* Band loop */ for( band_ptr=0; band_ptr=0 && i=0 && ie RAW */ case 0: value = 0.0; if( band == 1 ) { if( Band1_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band1_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)raw; } else if( band == 2 ) { if( Band2_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band2_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*TEMP_SCALE); } else if( band == 3 ) { if( Band3_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band3_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); /* raw = raw / 1000.;*/ /* This is to keep output in km */ } value = (int)(raw*HGHT_SCALE); /*allows for 0.1km - WCS3, 04052012 */ /* value = (int)raw;*/ } else if( band == 4 ) { if( Band4_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band4_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)raw; } else if( band == 5 ) { if( Band5_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band5_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)raw; } else if( band == 6 ) { if( Band6_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band6_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 7 ) { if( Band7_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band7_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 8 ) { if( Band8_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band8_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 9 ) { if( Band9_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band9_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 10 ) { if( Band10_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band10_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 11 ) { if( Band11_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band11_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 12 ) { if( Band12_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band12_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 13 ) { if( Band13_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band13_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 14 ) { if( Band14_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band14_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 15 ) { if( Band15_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band15_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 16 ) { if( Band16_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band16_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*EMIS_SCALE); } else if( band == 17 ) { if( Band17_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band17_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 18 ) { if( Band18_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band18_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 19 ) { if( Band19_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band19_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)raw; } else if( band == 20 ) { if( Band20_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band20_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)raw; } else if( band == 21 ) { if( Band21_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band21_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 22 ) { if( Band22_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band22_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } } else if( band == 23 ) { if( Band23_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band23_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)raw; } else if( band == 24 ) { if( Band24_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band24_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 25 ) { if( Band25_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band25_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } else if( band == 26 ) { if( Band26_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band26_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } break; /* RAW --> REF */ case 1: process++; if( band == 1 ) { if( Band1_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band1_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); if( raw < 0.0 ) raw = 0.0; } if( NSS_product_type == 4 ) value = (int)(raw*10); } else if( band == 2 ) { if( Band2_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band2_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); if( raw < 0.0 ) raw = 0.0; } if( NSS_product_type == 4 ) value = (int)(raw*10); } else if( band == 3 ) { if( Band3_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band3_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); /* raw = raw / 1000.*/ /* This is to keep output in km */ if( raw < 0.0 ) raw = 0.0; } if( NSS_product_type == 4 ) value = (int)(raw*10); } break; /* RAW --> HGT (Height)*/ case 2: process++; if( band == 3 ) { if( Band3_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band3_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); /* raw = raw / 1000.*/ /* This is to keep output in km */ } value = (int)(raw *HGHT_SCALE); /* WCS3 edit to allow 0.1km increments 04052012*/ } break; /* RAW --> TYPE */ case 3: process++; if( band == 1 ) { if( Band1_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band1_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw); } break; /* RAW --> REFF (Effective Radius) */ case 4: process++; if( band == 6 ) { if( Band6_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band6_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw*100); } break; /* RAW --> PROBability */ case 5: process++; if( band == 1 ) { if( Band1_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band1_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } if( NSS_product_type == 1 ) value = (int)(raw*100.0); } break; /* RAW --> MASS */ case 6: process++; if( band == 2 ) { if( Band2_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band2_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } if( NSS_product_type == 1 ) value = (int)(raw); } break; /* RAW --> PRESsure */ case 7: process++; if( band == 4 ) { if( Band4_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band4_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw); } break; /* RAW --> TEMP */ case 8: process++; if( band == 2 ) { if( Band2_array[j] == scale_miss[band-1] ) { value = 0.0; } else { raw = ((float)(Band2_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*TEMP_SCALE); } } else if( band == 7 ) { if( Band7_array[j] == scale_miss[band-1] ) { value = 0.0; mis_value++; } else { raw = ((float)(Band7_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*TEMP_SCALE); } } else if( band == 8 ) { if( Band8_array[j] == scale_miss[band-1] ) { value = 0.0; mis_value++; } else { raw = ((float)(Band8_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*TEMP_SCALE); } } else if( band == 13 ) { value = 0.0; if( Band13_array[j] != scale_miss[band-1] ) { raw = ((float)(Band13_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*TEMP_SCALE); } } else if( band == 14 ) { value = 0.0; if( Band14_array[j] != scale_miss[band-1] ) { raw = ((float)(Band14_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*TEMP_SCALE); } } else if( band == 15 ) { value = 0.0; if( Band15_array[j] != scale_miss[band-1] ) { raw = ((float)(Band15_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*TEMP_SCALE); } } break; /* RAW --> DPTH */ case 9: if( band == 5 ) { if( Band5_array[j] == scale_miss[band-1] ) { raw = 0.0; } else { raw = ((float)(Band5_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); } value = (int)(raw); } break; /* RAW --> BRIT */ case 10: process++; value = 0.0; if( band == 1 ) { if( Band1_array[j] != scale_miss[band-1] ) { raw = ((float)(Band1_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)((raw+1)*20.0); } } else if( band == 2 ) { if( Band2_array[j] != scale_miss[band-1] ) { raw = ((float)(Band2_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TEMPtoBRIT(raw); } } else if( band == 3 ) { if( Band3_array[j] != scale_miss[band-1] ) { raw = ((float)(Band3_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); /* raw = raw / 1000.*/ /* This is to keep output in km */ value = (int)(raw * HGHT_SCALE); /*allows for 0.1km - WCS3, 04052012 */ /* value = (int)(raw)*10;*/ } } else if( band == 4 ) { if( Band4_array[j] != scale_miss[band-1] ) { raw = ((float)(Band4_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = 255.0-(raw*255.0); value = (int)(raw); } } else if( band == 5 ) { value = 0.0; if( Band5_array[j] != scale_miss[band-1] ) { raw = ((float)(Band5_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); /*value = (int)(raw)*255;*/ value = CODtoBRIT(raw); } } else if( band == 6 ) { value = 0.0; if( Band6_array[j] != scale_miss[band-1] ) { raw = ((float)(Band6_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); /*value = (int)(raw/12.0*255.0);*/ value = REFFtoBRIT(raw); } } else if( band == 7 ) { value = 0.0; if( Band7_array[j] != scale_miss[band-1] ) { raw = ((float)(Band7_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TEMPtoBRIT(raw); } } else if( band == 8 ) { value = 0.0; if( Band8_array[j] != scale_miss[band-1] ) { raw = ((float)(Band8_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TEMPtoBRIT(raw); } } else if( band == 9 ) { value = 0.0; if( Band9_array[j] != scale_miss[band-1] ) { raw = ((float)(Band9_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw+0.5)+100; } } else if( band == 10 ) { value = 0.0; if( Band10_array[j] != scale_miss[band-1] ) { raw = ((float)(Band10_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw+0.5)+100; } } else if( band == 11 ) { value = 0.0; if( Band11_array[j] != scale_miss[band-1] ) { raw = ((float)(Band11_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw+0.5)+100; } } else if( band == 12 ) { value = 0.0; if( Band12_array[j] != scale_miss[band-1] ) { raw = ((float)(Band12_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw+0.5)+100; } } else if( band == 13 ) { value = 0.0; if( Band13_array[j] != scale_miss[band-1] ) { raw = ((float)(Band13_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TEMPtoBRIT(raw); } } else if( band == 14 ) { value = 0.0; if( Band14_array[j] != scale_miss[band-1] ) { raw = ((float)(Band14_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TEMPtoBRIT(raw); } } else if( band == 15 ) { value = 0.0; if( Band15_array[j] != scale_miss[band-1] ) { raw = ((float)(Band15_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TEMPtoBRIT(raw); } } else if( band == 16 ) { value = 0.0; if( Band16_array[j] != scale_miss[band-1] ) { raw = ((float)(Band16_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*255); } } else if( band == 17 ) { /* Cloud Probability */ value = 0.0; if( Band17_array[j] != scale_miss[band-1] ) { raw = ((float)(Band17_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*200); } } else if( band == 18 ) { /*Cloud Fraction */ value = 0.0; if( Band18_array[j] != scale_miss[band-1] ) { raw = ((float)(Band18_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*200); } } else if( band == 19 ) { /*Cloud Mask */ value = 0.0; if( Band19_array[j] != scale_miss[band-1] ) { raw = ((float)(Band19_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)((raw+1)*50); } } else if( band == 20 ) { /*Cloud Altitude */ value = 0.0; if( Band20_array[j] != scale_miss[band-1] ) { raw = ((float)(Band20_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = ALTtoBRIT(raw); } } else if( band == 21 ) { /*Cloud Transmission */ value = 0.0; if( Band21_array[j] != scale_miss[band-1] ) { raw = ((float)(Band21_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = TRANStoBRIT(raw); } } else if( band == 22 ) { /*Cloud Base Altitude */ value = 0.0; if( Band22_array[j] != scale_miss[band-1] ) { raw = ((float)(Band22_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = ALTtoBRIT(raw); } } else if( band == 23 ) { /*Cloud Cover Layers */ value = 0.0; if( Band23_array[j] != scale_miss[band-1] ) { raw = ((float)(Band23_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)((raw+1)*50); } } else if( band == 24 ) { /*Convective Cloud Probability */ value = 0.0; if( Band24_array[j] != scale_miss[band-1] ) { raw = ((float)(Band24_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw*200); } } else if( band == 25 ) { /*Sensor Zenith Angle */ value = 0.0; if( Band25_array[j] != scale_miss[band-1] ) { raw = ((float)(Band25_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = ZENtoBRIT(raw); } } else if( band == 26 ) { /*DNB Reflectivity*/ value = 0.0; if( Band26_array[j] != scale_miss[band-1] ) { raw = ((float)(Band26_array[j] - scale_mins[band-1])) / ((float)(scale_maxs[band-1] - scale_mins[band-1])); raw = range_mins[band-1] + ((range_maxs[band-1] - range_mins[band-1]) * raw ); value = (int)(raw+0.5)+100; } } if( value < 0 ) value = 0; if( value > 255 ) value = 255; if( value > max_value ) max_value = value; if( value < min_value ) min_value = value; break; } } /* WRITE the McIDAS data array */ if( space == 1 ) { uchar_array[jj] = (unsigned char)value; } else if( space == 2 ) { ushort_array[jj] = (unsigned short)value; if( i==9 && ie==0 ) { sprintf(trace_string, "%s VALUE=%d", server,value); M0sxtrce( trace_string ); } } else if( space == 4 ) { ulong_array[jj] = value; } jj = jj+request_n_bands; } } /* correct byte order */ if( space == 4 ) { size = request_n_bands*request_element_size; M0swbyt4( ulong_array+(psize/4), size ); size = size + (psize/4); } if( space == 2 ) { size = request_n_bands*request_element_size; (void)swbyt2_( ushort_array+(psize/2), &size ); size = size + (psize/2); } if( space == 1 ) { size = psize + (request_n_bands*request_element_size); } /* send out the line array */ if( space == 1 ) { rc = M0sxsend( size, uchar_array ); } else if( space == 2 ) { rc = M0sxsend( size*2, ushort_array ); } else if( space == 4 ) { rc = M0sxsend( size*4, ulong_array ); } } sprintf(trace_string, "%s FINISHED!!!", server); M0sxtrce( trace_string ); /* FREE the HDF-EOS array */ if( space == 1 ) free ( uchar_array) ; if( space == 2 ) free ( ushort_array ); if( space == 4 ) free ( ulong_array ); /* ******************* DATA BLOCK ********************* */ sprintf(trace_string, "%s MIN=%d MAX=%d MIS=%d", server, min_value, max_value, mis_value); M0sxtrce( trace_string ); /* termination */ M0sxdone(&requestBlock); sprintf(trace_string, "%s exit\n", server); M0sxtrce( trace_string ); return (0); } /*converts altitude to Tempurature value*/ int TEMPtoBRIT( float temp ) { int brit; float raw; if( temp < 242.0 ) { raw = 418.0 - temp; } else { raw = 660.0-(2*temp); } brit = (int)(raw+.5); if( brit > 255 ) brit = 255; if( brit < 0 ) brit = 0; return (brit); } /*converts REFF to BRIT value*/ int REFFtoBRIT( float raw ) { int brit; /* New CLAVR-x scaling5-30 */ brit = (int)(((raw-5)/25.0)*255); /* old CLAVR-x scaling 0-50 */ /*brit = (int)(((raw)/50.0)*255);*/ if( brit > 255 ) brit = 255; if( brit < 0 ) brit = 0; return (brit); } /*converts COD to BRIT value*/ int CODtoBRIT( float raw ) { int brit; brit = (int)((raw/40.0)*255); if( brit > 255 ) brit = 255; if( brit < 0 ) brit = 0; return (brit); } /*converts altitude to BRIT value*/ int ALTtoBRIT( float raw ) { int brit; /* 0 -> 766201. kft */ brit = (int)((raw*0.00333333)); /* 0 -> 60000. kft */ /* brit = (int)((raw*0.00425));*/ /* 0 -> 60000. kft, 0-60 BRIT */ /* brit = (int)((raw*0.001));*/ if( raw > 60000 ) brit = 255; if( brit < 0 ) brit = 0; return (brit); } /*converts transmission to BRIT value*/ int TRANStoBRIT( float raw ) { int brit; /* 0 -> 1.0 */ brit = (int)((raw*253)+1); if( raw > 1.0 ) brit = 255; if( brit < 0 ) brit = 0; return (brit); } /*converts satzen to BRIT value*/ int ZENtoBRIT( float raw ) { int brit; brit = (int)((raw/35.3)*100.0); if( brit > 255 ) brit = 255; if( brit < 0 ) brit = 0; return (brit); }