/* * Copyright(c) 2007, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt */ /**** $Id: imgbowtie.c,v 1.6 2007/06/29 19:14:06 russd Tst $ ****/ /* *? IMGBOWTIE -- BowTie correction for MODIS L1b images *? IMGBOWTIE sdataset ddataset ndataset *? Parameters: *? sdataset | source ADDE dataset name and position; specify as *? alias.position or group/descriptor.position; to use default *? position, either enter "0" or omit .position portion *? (no def for alias or group/descriptor, def=0 for position) *? ddataset | destination ADDE dataset name and absolute position; *? specify as alias.position or group/descriptor.position; *? only positive integers are valid for the position number *? ndataset | source ADDE navigation dataset name; specify as alias *? group/descriptor; *? Keywords: *? ********************* Image Selection Keywords ************************* *? DAY= | selects from sdataset images with the specified day (def=current) *? TIMe=btime etime | selects from sdataset images within the specified *? time range (def=current) *? *************************** Output Keywords **************************** *? BANd= | image band to correct (def=1) *? LATlon= clat clon | center latitude and longitude for ddataset *? (def=center latitude and longitude of sdataset) *? PRO=LAMB slat1 slat2 slon | Lambert Conformal, standard latitude *? and standard longitude (slat1 def=30, *? slat2 def=50, slon def=center longitude) *? =MERC slat | Mercator projection and standard latitude (slat def=0) *? =MOLL slon | Mollweide projection and standard longitude (slon def=0) *? =PS slat slon | Polar Stereographic projection, standard latitude *? and standard longitude *? (slat def=60, slon def=center longitude) *? =RECT | Rectilinear projection *? =SIN | Sinusoidal Equal Area projection *? =TANC slat slon | Tangent Cone projection (def), standard latitude and *? standard longitude (slat def=30 if center latitude *? is in northern hemisphere, -30 if center latitude *? in southern hemisphere; slon def=center longitude) *? RES= | resolution of ddataset in km; (def=1.0) *? SIZe=line ele | number of lines and elements in ddataset; the 'ele' *? value must be a multiple of 4; (def=1000 1000) *? ---------- */ #include #include #include #include"mcidas.h" #include"mcidasp.h" #include"m0glue.h" #include"m0panel.h" int main(int argc, char **argv) { static char sorts[2000]; char DOT[] = "."; const char *is_pos; char *cALL; char *sdataset; char *sdataset_nam; char *sdataset_pos; char *ddataset; char *ddataset_nam; char *ddataset_pos; char *ndataset; char *projectionType; char *bDay; char *eDay; char *bTime; char *eTime; char time[40]; char unit[5]; char poleName[5]; char projectionName[4]; const format[4]; double standardLatitude1; double standardLatitude2; double standardLongitude; double defaultStandard; double resolution; unsigned short int mcidas_min; unsigned short int mcidas_max; unsigned short int modis_min; unsigned short int modis_max; unsigned short int * * modis; unsigned short int * * mcidas; int MAX_BYTE = 40000; int MSG_FLAG = 1; int ok; int nsort; int handle; int lat_handle; int lon_handle; int request_lsize; int request_esize; int first_image_line; int first_image_elem; int band; int trce; int sdirectory[64]; int ndirectory[64]; int ddirectory[64]; int one, two, LL; int hour, min, sec; int lat_ind; int lon_ind; int len; int nzero; int len_sort; int len_time; int len_unit; int len_format; int len_sdataset; int len_sdataset_nam; int len_sdataset_pos; int len_ddataset; int len_ddataset_nam; int len_ddataset_pos; int len_ndataset; int len_projectionName; int len_poleName; int projectionNum; int nd_min =3; int ndiv =3; int nd_scn =9; int nd_fov =7; int max_rad =10; int iFOV; int iscan; int sour_numImgScan; int sour_numImgFOV; int sour_cenImgScan; int sour_cenImgFOV; int sour_numNavScan; int sour_numNavFOV; int dest_numImgScan; int dest_numImgFOV; int w1; int w2; int chan_1; int chan_2; int chan_k; int temp1; int temp2; int dist; int dist_i; int dist_j; int i_start; int i_end; int i; int ii; int j; int k; int * * ilalo; float f_value; float maximum_lat; float minimum_lat; float maximum_lon; float minimum_lon; float request_central_lat; float request_central_lon; float request_resolution; float xlin; float xele; float dum1; float dum2; float slope; float intercept; float f1; float f2; float lat_tmp1; float lat_tmp2; float lon_tmp1; float lon_tmp2; float lat_k; float lon_k; float * * flat; float * * flon; float * * lat_km; float * * lon_km; Fdouble parms[6]; Fdouble request; Fint navigation[128]; Fint calibration[128]; Fint geoRes; enum {MERC,MOLL,PS,LAMB,TANC,RECT,SIN,DEST}; /* get command line parameters and keywords */ ok = Mcinit (argc, argv); if (ok != 0) { Mceprintf("FAILED - init McIDAS environment\n"); Mccodeset(1); return 1; } Mcdprintf( " ***** Start IMGBOWTIE V1.0 ***** \n" ); /* source dataset name */ ok = Mccmdstr ("", 1, "", (const char **) &sdataset); if( ok<0 || strcmp(sdataset,"")==0 ) { Mceprintf("FAILED - No source dataset name specified\n"); return 1; } else { len_sdataset = strlen( sdataset ); is_pos = strchr( sdataset, '.'); if( is_pos != NULL ) { sdataset_nam = strtok( sdataset, DOT ); len_sdataset_nam = strlen( sdataset_nam ); sdataset_pos = strtok( NULL, DOT ); len_sdataset_pos = strlen( sdataset_pos ); } else { strcpy( &sdataset_nam, &sdataset ); len_sdataset_nam = strlen( sdataset_nam ); sdataset_pos = " "; len_sdataset_pos = strlen( sdataset_pos ); } Mcdprintf("Source Dataset: %s Len = %d\n",sdataset,len_sdataset); Mcdprintf(" Name = '%s' Len = '%d'\n", sdataset_nam, len_sdataset_nam); Mcdprintf(" Pos = '%s' Len = '%d'\n", sdataset_pos, len_sdataset_pos); } /* destination dataset name */ ok = Mccmdstr ("", 2, "", (const char **) &ddataset); if( ok<0 || strcmp(ddataset,"")==0 ) { Mceprintf("FAILED - No destination dataset name specified\n"); return 1; } else { len_ddataset = strlen( ddataset ); is_pos = strchr( ddataset, '.'); if( is_pos != NULL ) { ddataset_nam = strtok( ddataset, DOT ); len_ddataset_nam = strlen( ddataset_nam ); ddataset_pos = strtok( NULL, DOT ); len_ddataset_pos = strlen( ddataset_pos ); } else { strcpy( &ddataset_nam, &ddataset ); len_ddataset_nam = strlen( ddataset_nam ); ddataset_pos = " "; len_ddataset_pos = strlen( ddataset_pos ); } Mcdprintf("Destination Dataset: %s Len = %d\n",ddataset, len_ddataset); Mcdprintf(" Name = '%s' Len = '%d'\n", ddataset_nam, len_ddataset_nam); Mcdprintf(" Pos = '%s' Len = '%d'\n", ddataset_pos, len_ddataset_pos); } /* navigation dataset name */ ok = Mccmdstr ("", 3, "", (const char **) &ndataset); if( ok<0 || strcmp(ndataset,"")==0 ) { Mceprintf("FAILED - No navigation dataset name specified\n"); return 1; } len_ndataset = strlen( ndataset ); Mcdprintf("Navigation Dataset:\n"); Mcdprintf(" Name = '%s' Len = '%d'\n", ndataset, len_ndataset); /* DAY keyword */ ok = Mccmdstr("DAY",1," ", (const char**)&bDay ); ok = Mccmdstr("DAY",2," ", (const char**)&eDay ); Mcdprintf(" Source Day: Beg=%s End=%s\n", bDay, eDay); /* TIMe keyword */ ok = Mccmdstr("TIM.E",1," ", (const char**)&bTime ); ok = Mccmdstr("TIM.E",2," ", (const char**)&eTime ); Mcdprintf(" Source Time: Beg=%s End=%s\n", bTime, eTime); /* PROJection keyword */ ok = Mccmdstr("PRO.J", 1, "TANC", (const char**)&projectionType); if( ok<0 ) { Mceprintf("FAILED - Invalid Projection name\n"); return 1; } else { /* Projection = MERC */ if( strncmp(projectionType,"MERC",4)==0 ) { projectionNum=MERC; } else if (strncmp(projectionType,"MOLL",4)==0) { projectionNum=MOLL; } else if (strncmp(projectionType,"PS",2)==0) { projectionNum=PS; strcat(projectionName," "); } else if (strncmp(projectionType,"LAMB",4)==0) { projectionNum=LAMB; } else if (strncmp(projectionType,"TANC",4)==0) { projectionNum=TANC; } else if (strncmp(projectionType,"RECT",4)==0) { projectionNum=RECT; } else if (strncmp(projectionType,"SIN",3)==0) { projectionNum=SIN; strcat(projectionName," "); } else { Mceprintf("FAILED - Invalid projection type!\n"); return 1; } } Mcdprintf("Projection name = %s\n",projectionType); /* LATLON keyword */ ok = Mccmdnum("LAT.LON"); if( ok>0 ) { ok = Mccmddll ("LAT.LON", 1, "Latitude", -99.0, -90.0, 90.0, &request); if( ok<0 ) { Mceprintf("FAILED - Invalid Latitude specified = %f\n", request); return 1; } request_central_lat = request; ok = Mccmddll ("LAT.LON", 2, "Longitude", -999.0, -180.0, 180.0, &request); if( ok<0 ) { Mceprintf("FAILED - Invalid Longitude specified = %f\n", request); return 1; } request_central_lon = request; } else { request_central_lat = -999.0; request_central_lon = -999.0; } /* SIZE Keyword */ ok = Mccmdint("SIZ.E", 1,"Line Size",1000,1,-1, &request_lsize); if( ok<0 ) { Mceprintf("FAILED - Invalid Line Size specified"); return 1; } ok = Mccmdint("SIZ.E", 2,"Element Size",1000,1,-1, &request_esize); if( ok<0 ) { Mceprintf("FAILED - Invalid Element Size specified"); return 1; } /* RESolution Keyword */ ok = Mccmddbl("RES", 1,"Resolution",1.0,0.1,100.0, &request); if( ok<0 ) { Mceprintf("FAILED - Invalid Resolution specified"); return 1; } else { request_resolution = (float) request; } /* Construct the ADDE transaction request for the Source dataset. This application requires the entire source image. */ /* SIZE sort clause */ nsort = 0; sprintf(&sorts[0], "SIZE 99999 99999"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* MAGnification sort clause */ sprintf(&sorts[40], "MAG 1 1"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* BAND sort clause */ ok = Mccmdstr("BAN.D", 1, "", (const char**)&cALL); if( ok<0 ) { Mceprintf("FAILED - Invalid BAND specified"); return 1; } else { if( strncmp( cALL, "ALL",3 ) == 0 ) { Mceprintf("FAILED - BAND=ALL correction is not allowed"); return 1; } else { ok = Mccmdint("BAN.D", 1,"Band Number",1,1,37, &band); if( ok<0 ) { Mceprintf("FAILED - Invalid BAND specified"); return 1; } } } sprintf(&sorts[80], "BAND %d", band); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* AUX sort clause */ sprintf(&sorts[120], "AUX YES"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* POSition sort clause */ sprintf(&sorts[160], "POS %s", sdataset_pos); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* DAY sort clause */ sprintf(&sorts[200], "DAY %s %s", bDay, eDay); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* TIME sort clause */ sprintf(&sorts[240], "TIME %s %s", bTime, eTime); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* TRACE sort clause */ ok = Mccmdint("TRA.CE", 1,"Trace",0,0,1, &trce); sprintf(&sorts[280], "TRACE=%d",trce); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); Mcdprintf("SORTS %s",sorts); /* source unit */ sprintf(unit,"RAW "); /* source format */ sprintf(format,"I2"); len_sort = 40; len_unit = 4; len_format = 2; Mcdprintf("START - Open ADDE transaction\n"); /* open a connection to the source image */ ok = mcaget_( sdataset_nam, &nsort, sorts, unit, format, &MAX_BYTE, &MSG_FLAG, sdirectory, &handle, len_sdataset_nam, len_sort, len_unit, len_format ); if( ok<0 ) { Mceprintf("FAILED - Open ADDE transaction"); return 1; } Mcdprintf("SUCCESS - Open ADDE transaction"); /* read the source calibration */ ok = mcacal_( &handle, calibration ); if( ok<0 ) { Mceprintf("FAILED - Reading source calibration"); return 1; } Mceprintf("SUCCESS - Reading source calibration"); /* size of the source image */ sour_numImgScan = sdirectory[8]; sour_numImgFOV = sdirectory[9]; if( sdirectory[11] == 1 ) { geoRes = 4; resolution = 1.0; } else if( sdirectory[11] == 2 ) { geoRes = 2; resolution = 2.0; } else if( sdirectory[11] == 4 ) { geoRes = 1; resolution = 4.0; } Mcdprintf("Source Image: GEORES=%d SIZE = %d X %d \n",geoRes,sour_numImgScan, sour_numImgFOV ); /* allocate memory to hold the image data */ modis= (short int * *) malloc(sour_numImgScan*sizeof(short int *)); if(modis==NULL) { Mceprintf("FAILED - Memory allocation for source image\n"); return 1; } else { for( iscan=0; iscan modis_max ) modis_max = modis[iscan][iFOV]; } } Mcdprintf("MODIS: MIN=%d MAX=%d\n",modis_min,modis_max); /* We now have the source dataset. Next we need to request the Latitude and Longitude arrays from the Geo Reference dataset. Again, these are the entire array of data. Later we will need to interpolate the QKM and HKM lat/lon arrays to make them match the source data dimensions. */ /* Clear the sort array */ nsort = 0; memset(&sorts[0], ' ', 2000 ); /* SIZE sort clause */ sprintf(&sorts[0], "SIZE 99999 99999"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* DAY sort clause */ sprintf(&sorts[40], "DAY %d %d", sdirectory[3], sdirectory[3] ); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* TIME sort clause */ hour = sdirectory[4]/10000; min = (sdirectory[4]-(hour*10000)) / 100; sec = sdirectory[4]-(hour*10000+min*100); sprintf(&time[0],"%02d:%02d:%02d",hour,min,sec); len_time = strlen( time ); memset(&time[len_time], ' ', (40-len_time) ); sprintf(&sorts[80], "TIME %s %s I", time, time); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* TRACE sort clause */ sprintf(&sorts[120], "TRACE=%d",trce); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* AUX sort clause */ sprintf(&sorts[160], "AUX YES"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* DOC sort clause */ sprintf(&sorts[200], "DOC NO"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* BAND sort clause */ sprintf(&sorts[240], "BAND 1"); nsort++; len_sort = strlen( sorts ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); /* source unit */ sprintf(unit,"X"); /* source format */ sprintf(format," "); /* length of strings (because the mcaget function is FORTRAN) */ len_sort = 40; len_unit = 1; len_format = 1; /* open a connection to the Latitude array */ Mcdprintf("Open ADDE NAV transaction\n"); ok = mcaget_( ndataset, &nsort, sorts, unit, format, &MAX_BYTE, &MSG_FLAG, ndirectory, &lat_handle, len_ndataset, len_sort, len_unit, len_format ); if( ok<0 ) { Mceprintf("FAILED - Open ADDE transaction\n"); return -1; } Mcdprintf("SUCCESS - Open ADDE transaction\n"); /* size of the source naviagtion */ sour_numNavScan = ndirectory[8]; sour_numNavFOV = ndirectory[9]; Mcdprintf("NAV Image Size = %d %d \n",sour_numNavScan, sour_numNavFOV ); /* allocate memory to hold the GEO data */ ilalo = (int * *) malloc(sour_numNavScan*sizeof(int *)); if( ilalo==NULL) { Mceprintf("FAILED - Memory allocation for latlon array \n"); return 1; } else { for( iscan=0; iscan maximum_lon && lon_km[iscan][iFOV] != -999.0 ) maximum_lon = ceil( lon_km[iscan][iFOV] ); if( lat_km[iscan][iFOV] > maximum_lat && lat_km[iscan][iFOV] != -999.0 ) maximum_lat= ceil( lat_km[iscan][iFOV] ); if( lat_km[iscan][iFOV] < minimum_lat && lat_km[iscan][iFOV] != -999.0 ) minimum_lat= floor( lat_km[iscan][iFOV] ); } } Mcdprintf("SUCCESS - Latitude/Longitude Extents \n"); Mcdprintf(" Latitude Max=%f Min=%f \n", maximum_lat, minimum_lat); Mcdprintf(" Longitude Max=%f Min=%f \n", maximum_lon, minimum_lon); /* set central lat/lon if it wasn't specified */ if( request_central_lat == -999.0 ) { sour_cenImgScan = sour_numImgScan/2; sour_cenImgFOV = sour_numImgFOV/2; request_central_lat = lat_km[sour_cenImgScan][sour_cenImgFOV]; } if( request_central_lon == -999.0 ) { sour_cenImgScan = sour_numImgScan/2; sour_cenImgFOV = sour_numImgFOV/2; request_central_lon = lon_km[sour_cenImgScan][sour_cenImgFOV]; } /* We now have the image data, and the latitude/longitude (from the MOD03 data file). Next step is to create a McIDAS navigation for the destination image. */ Mcdprintf("DESTINATION IMAGE:\n"); /* Create a McIDAS navigation */ LL =lit_("LL ",4); one =1; two =2; dum1 = 0.0; dum2 = 0.0; for(i=0; i<6; i++) parms[i] = 0.0; /* based on the specified projection, construct the necessary array of parameters */ Mcdprintf("START - Construct destination navigation\n"); switch (projectionNum) { case MERC: ok = Mccmddll("PRO.J",2,"Standard Latitude: 1",0,-90,90,&standardLatitude1); if( ok<0 ) return 1; ok = Mccmddll("PRO.J",3,"Standard Longitude",-maximum_lon,-180,180,&standardLongitude); if( ok<0 ) return 1; parms[0]=dest_numImgScan; parms[1]=dest_numImgFOV; parms[2]=standardLatitude1; parms[3]=standardLongitude; parms[4]=request_resolution; sprintf(projectionName,"MERC"); break; case MOLL: ok = Mccmddll("PRO.J",2,"Standard Longitude",minimum_lon,-180,180,&standardLongitude); if( ok<0 ) return 1; parms[0]=dest_numImgScan/2; parms[1]=dest_numImgFOV/2; parms[2]=request_resolution; parms[3]=standardLongitude; sprintf(projectionName,"MOLL"); break; case PS: if( maximum_lat<0 ) { defaultStandard = -60; } else { defaultStandard = 60; } ok = Mccmddll("PRO.J",2,"Standard Latitude: 1",defaultStandard,-90,90,&standardLatitude1); if( ok<0 ) return 1; ok = Mccmddll("PRO.J",3,"Standard Longitude",minimum_lon,-180,180,&standardLongitude); if( ok<0 ) return 1; parms[0]=1.0; parms[1]=dest_numImgFOV/2; parms[2]=standardLatitude1; parms[3]=request_resolution; parms[4]=standardLongitude; sprintf(projectionName,"PS"); break; case LAMB: if( maximum_lat<0) { defaultStandard = -30; } else { defaultStandard = 30; } ok = Mccmddll("PRO.J",2,"Standard Latitude: 1",defaultStandard,-90,90,&standardLatitude1); if( ok<0 ) return 1; if( standardLatitude1>=0 ) { if( standardLatitude1<89 ) { defaultStandard=standardLatitude1 + 20; } else { defaultStandard=89; } } else { if( standardLatitude1>-89 ) { defaultStandard=standardLatitude1 - 20; } else { defaultStandard=-89; } } ok = Mccmddll("PRO.J",3,"Standard Latitude: 2",defaultStandard,-90,90,&standardLatitude2); if( ok<0 ) return 1; ok = Mccmddll("PRO.J",4,"Standard Longitude",minimum_lon,-180,180,&standardLongitude); if( ok<0 ) return 1; parms[0]=1; parms[1]=dest_numImgFOV/2; parms[2]=standardLatitude1; parms[3]=standardLatitude2; parms[4]=request_resolution; parms[5]=standardLongitude; sprintf(projectionName,"LAMB"); break; case TANC: if( maximum_lat<0 ) { defaultStandard = -30; } else { defaultStandard = 30; } ok = Mccmddll( "PRO.J", 2, "Standard Latitude: 1", defaultStandard, -90,90, &standardLatitude1 ); if( ok<0 ) return 1; ok = Mccmddll( "PRO.J", 3, "Standard Longitude", request_central_lon, -180,180, &standardLongitude ); if( ok<0 ) return 1; parms[0]=1.0; parms[1]=10000.0; parms[2]=request_resolution; parms[3]=standardLatitude1; parms[4]=standardLongitude; sprintf(projectionName,"TANC"); break; case RECT: parms[0]=1.0; parms[1]=maximum_lat; parms[2]=1.0; parms[3]=minimum_lon; parms[4]=request_resolution; sprintf(projectionName,"RECT"); break; case SIN: parms[0]=dest_numImgScan/2; parms[1]=dest_numImgFOV/2; parms[2]=maximum_lat; parms[3]=minimum_lon; parms[4]=request_resolution; sprintf(projectionName,"SIN"); break; default: break; } /* set the reference pole (north or south) */ if( standardLatitude1<0 ) { sprintf(poleName,"SOUTH "); } else { sprintf(poleName,"NORTH "); } Mcdprintf(" POLE s %s\n",poleName); /* Create the destination Navigation Block */ Mcdprintf(" START - Generate_a_navigation Block\n"); len_projectionName = 4; len_poleName = 5; for( i=0; i<128; i++ ) navigation[i] = 0; gennavblk_( &projectionName, &poleName, &parms, &request_resolution, &navigation, len_projectionName, len_poleName ); /* initialize the McIDAS destination navigation */ ok = nvprep_( &one, &navigation ); if( ok<0 ) { Mceprintf(" FAILED - Preparing the McIDAS transform\n"); return 1; } ok = nv1ini_(&two,&LL); if( ok<0 ) { Mceprintf(" FAILED - Initializing the McIDAS transform\n"); return 1; } Mcdprintf(" SUCCESS - Initializing the McIDAS transform\n"); /* Calculate the first line and element of the destination image based on the navigation that was just created. We have the size of the image (in lines and elements). We use the center lat/lon to get a satellite line and element. Based on that we can determine the starting satellite lien and element. */ lat_k = request_central_lat; lon_k = request_central_lon; dum1 = 0.0; ok = nv1eas_(&lat_k,&lon_k,&dum1,&xlin,&xele,&dum2); first_image_line = (int) xlin - ((dest_numImgScan/2)); first_image_elem = (int) xele - ((dest_numImgFOV/2)); /* Finally, we can start moving the data from the original projection into the new projection. Along the way we are getting rid of the bowtie and filling in the missing pixels */ Mcprintf(" START - Along Track Gridding\n"); /* STEP 1: Along track gridding */ for(ii=0; ii<3; ii++) { /* slope and intercept for each 3rd of a swipe of data */ switch(ii) { case 0: i_start = 0; i_end = sour_numImgFOV/3; slope =-3.0*(nd_scn - nd_min)/sour_numImgFOV; intercept = nd_scn; break; case 1: i_start = sour_numImgFOV/3; i_end = sour_numImgFOV - sour_numImgFOV/3 ; slope = 0.0; intercept = nd_min; break; case 2: i_start = sour_numImgFOV - sour_numImgFOV/3; i_end = sour_numImgFOV - 1; slope = 3.0*(nd_scn - nd_min)/sour_numImgFOV; intercept = 3.0*nd_min+ - 2.*nd_scn; break; } for( iscan=0; iscan 0 && lat_ind >= 0 && lon_ind >= 0 && lat_ind < dest_numImgScan && lon_ind < dest_numImgFOV ) { if( mcidas[lat_ind][lon_ind]==0 ) mcidas[lat_ind][lon_ind] = chan_k; } } } } } for( ii=0; ii<2; ii++ ) { switch ( ii ) { case 0: i_start = 0; i_end = sour_numImgFOV/3 -1; slope = -3.0*(nd_fov - nd_min)/sour_numImgFOV; intercept = nd_fov; break; case 1: i_start = sour_numImgFOV - sour_numImgFOV/3 +1; i_end = sour_numImgFOV; slope = 3.0*(nd_fov - nd_min)/sour_numImgFOV; intercept = 3.0*nd_min+ - 2.*nd_scn; break; } for( iscan = 0; iscan < sour_numImgScan-1; iscan++ ) { for( iFOV = i_start; iFOV < i_end; iFOV++ ) { lat_tmp1 = lat_km[iscan][iFOV]; lon_tmp1 = lon_km[iscan][iFOV]; chan_1 = modis[iscan][iFOV]; lat_tmp2 = lat_km[iscan+1][iFOV]; lon_tmp2 = lon_km[iscan+1][iFOV]; chan_2 = modis[iscan+1][iFOV]; if( lat_tmp1 > minimum_lat && lat_tmp1 < maximum_lat && lon_tmp1 > minimum_lon && lon_tmp1 < maximum_lon && lat_tmp2 > minimum_lat && lat_tmp2 < maximum_lat && lon_tmp2 > minimum_lon && lon_tmp2 < maximum_lon ) { for( k=0; k 0 && lat_ind > 0 && lon_ind > 0 && lat_ind < dest_numImgScan && lon_ind < dest_numImgFOV ) { if( mcidas[lat_ind][lon_ind]==0 ) mcidas[lat_ind][lon_ind] = chan_k; } } } } } } Mcprintf(" SUCCESS - Along Track Gridding\n"); /* Fill missing values over the pass using the nearest neighbor */ Mcdprintf(" START - Fill in missing values\n"); for( j=0; j < dest_numImgScan; j++ ) { for( i=0; i < dest_numImgFOV; i++ ) { if( mcidas[j][i] == 0 ) { dist_i = 0; dist_j = 0; for( dist = 1; dist < max_rad; dist ++) { if( i-dist < 0 || i+dist > dest_numImgFOV || j-dist < 0 || j+dist > dest_numImgScan ) continue; if( mcidas[j][i-dist]>0 && mcidas[j][i+dist]>0 ) { dist_i = dist; } else if( mcidas[j-dist][i] > 0 && mcidas[j+dist][i] > 0 ) { dist_j = dist; } if( dist_i !=0 || dist_j != 0 ) { temp1 = mcidas[j-dist_j][i-dist_i]; temp2 = mcidas[j+dist_j][i+dist_i]; mcidas[j][i] = (temp1 + temp2)/2; dist=max_rad; } } } } } mcidas_min = 65000; mcidas_max = -65000; for( iscan=0; iscan mcidas_max ) mcidas_max = mcidas[iscan][iFOV]; } } Mcdprintf(" SUCCESS - Fill in missing values\n"); Mcdprintf("MCIDAS: MIN=%d MAX=%d\n",mcidas_min,mcidas_max); /* Remapping is complete ... the only thing that remains is to write the resulting image object to the destination dataset */ /* construct the destination directory */ for( i=0; i<64; i++ ) ddirectory[i] = sdirectory[i]; ddirectory[5] = first_image_line; ddirectory[6] = first_image_elem; ddirectory[8] = dest_numImgScan; ddirectory[9] = dest_numImgFOV; ddirectory[11] = 1; ddirectory[12] = 1; ddirectory[13] = 1; ddirectory[14] = 0; /* Put the input file name into memo block */ memcpy( (void *)&ddirectory[24], "MODIS Corrected L1B Data", 4*8); ddirectory[33] = 1280; ddirectory[34] = 256; ddirectory[59] = 0; ddirectory[60] = 0; ddirectory[62] = 768; ddirectory[63] = 0; /* Clear the sort array */ nsort = 0; memset(&sorts[0], ' ', 2000 ); /* Make the SIZE sort clause */ sprintf(&sorts[0], "POS %s",ddataset_pos); nsort++; len_sort = strlen( sorts ); Mceprintf(" PUT: sort length = %d\n",len_sort ); memset(&sorts[len_sort], ' ', (2000-len_sort) ); len_sort = 40; /* open an ADDE image put transaction */ Mcdprintf("START - ADDE PUT transaction\n"); ok = mcaput_( ddataset_nam, &nsort, sorts, ddirectory, navigation, calibration, len_ddataset_nam, len_sort ); if( ok<0 ) { Mceprintf("FAILED - Open ADDE PUT transaction\n"); return 1; } Mcdprintf("SUCCESS - Open ADDE PUT transaction\n"); /* write the image object */ Mcdprintf("START - writing destination Image\n"); for( iscan=0; iscan