//HDF includes #include #include #include #include // leocat includes #include #include #include "type_kind.h" #include "common_leocat.h" #include "imagerL1_leocat.h" #include "imagerL2_leocat.h" #include "sounderL1_leocat.h" #include "sounderL2_leocat.h" #include "rtm_leocat.h" #include "nwp_leocat.h" #include "radutils_leocat.h" #include "algorithm_interface.h" // MOD35 includes #include "granule.h" #include "pixel.h" #include "thresholds.h" #include "stats.h" #include "sst.h" #define ALG_NUMBER 29 //Prototypes for functions within Alg29.cpp extern "C" void algorithmInformation_29 (void *initializeMe); extern "C" void algorithmImplementation_29 (unsigned char, imagerL1 *, imagerL2 *, sounderL1 *, sounderL2 *, nwp_params, rtm_profiles **, rtm_toa, rad_utils); static void raf_copyDataFromLeocat( imagerL1 *, imagerL2 *, rtm_toa, rad_utils); static void copyResultsToLeocat( imagerL1 *, imagerL2 *); static void copyNDVIbackground_alg29 (imagerL1 *imgr1); extern "C" void modis_cm_main(char *); extern "C" float planck_btemp_aqua (int, float); static void get_Olson_eco_m(imagerL1 *imgr1); extern "C" void getcoord_(double *lt, double *ln, double *drow, double *dcol); static void get_NISE(imagerL1 *imgr1); extern "C" void massage_snowice(int, int, int); extern "C" unsigned char * umd_lmask_grid2pixel(float *, float *, long, unsigned char *); static void get_Reynolds_SST(imagerL1 *imgr1, imagerL2 *imgr2); extern "C" int swapbyte4(void *, int); extern "C" int bilinearInterpSST(int, int, float, float, const SST *, float *); //Declarations static char algorithmName[80] = "MODISCloudmask_MOD35_C6"; static char algorithmKey[80] = "MODISCloudmask"; static char *sds_name[MAX_ALGO_OUTPUT] = {"flag_arr1", "flag_arr2", "surface_temperature", "stats_250m"}; static nwp_params *pointer_to_nwp = NULL; static float DEG2RAD = (3.14159 / 180.0); static int output_cm_stats = 1; static algorithm_interface this_algo_info = { /***********************************************************************************/ /*@29*/ /*The algorithm function name from the prototype list above*/ algorithmImplementation_29, algorithmInformation_29, /*The algorithm number (1:NALGO)*/ 29, /*The number of algorithm outputs*/ 4, /*The generic name of the algorithm*/ algorithmName, /*Algorithm keyword id*/ algorithmKey, /*A string describing a reference or further detail about algorithm*/ "MOD35 Collection 6 Test", /*The name of the HDF SDS's produced by this algorithm*/ {"flag_arr1","flag_arr2","surface_temperature","stats_250m"}, /*Is the default cloud mask needed to run this algorithm (YES or NO)*/ NO, /*Is the default cloud type needed to run this algorithm (YES or NO)*/ NO, /*Is the default aerosol mask needed to run this algorithm (YES or NO)*/ NO, /*Are nwp data needed to run this algorithm (YES or NO)*/ YES, /*Is the RTM needed to run this algorithm (YES or NO)*/ NO, /*The MODIS channels used in the algorithm, 0=not used, 1=used*/ /*1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22*/ {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 , 1, /*23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36*/ 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0} }; static void raf_copyDataFromLeocat( imagerL1 *imgr1, imagerL2 *imgr2, rtm_toa rclr, rad_utils rutil) { long int idx; int row; int col; int indx00 = 0; int indx01 = 0; int indx10 = 0; int indx11 = 0; float t00 = 0.0; float t01 = 0.0; float t10 = 0.0; float t11 = 0.0; float tx = 0.0; float ty = 0.0; float t = 0.0; // Place MODIS data into MOD35 data structures. g_rad[0] = imgr1->ref1; g_rad[1] = imgr1->ref2; g_rad[2] = imgr1->ref3; g_rad[3] = imgr1->ref4; g_rad[4] = imgr1->ref5; g_rad[5] = imgr1->ref6; g_rad[6] = imgr1->ref7; g_rad[7] = imgr1->ref8; g_rad[8] = imgr1->ref9; g_rad[9] = NULL; g_rad[10] = NULL; g_rad[11] = NULL; g_rad[12] = NULL; g_rad[13] = NULL; g_rad[14] = NULL; g_rad[15] = NULL; g_rad[16] = imgr1->ref17; g_rad[17] = imgr1->ref18; g_rad[18] = imgr1->ref19; g_rad[19] = imgr1->bt20; g_rad[20] = imgr1->bt21; g_rad[21] = imgr1->bt22; g_rad[22] = NULL; g_rad[23] = NULL; g_rad[24] = NULL; g_rad[25] = imgr1->ref26; g_rad[26] = imgr1->bt27; g_rad[27] = imgr1->bt28; g_rad[28] = imgr1->bt29; g_rad[29] = NULL; g_rad[30] = imgr1->bt31; g_rad[31] = imgr1->bt32; g_rad[32] = imgr1->bt33; g_rad[33] = NULL; g_rad[34] = imgr1->bt35; g_rad[35] = NULL; proc_qkm = imgr1->proc_250; if(proc_qkm) { g_qkm1 = imgr1->qkm_ref1; g_qkm2 = imgr1->qkm_ref2; g_qkm_ncol = imgr1->qkm_ncol; } // Satellite ID if(imgr1->satid == TERRA) { sid_terra = 1; sid_aqua = 0; } else if (imgr1->satid == AQUA) { sid_terra = 0; sid_aqua = 1; } // Number scans in granule nscans = imgr1->nrow; // Assume number pixels is always 1354. neles = 1354; // Get angular data from input geolocation data. g_lat = imgr1->lat; g_lon = imgr1->lon; g_vza = imgr1->satzen; g_sza = imgr1->solzen; g_raz = imgr1->relaz; // Get MODIS land/sea flag (from MODIS geolocation file). g_lsf = imgr1->landmask; // Get surface elevation. g_elev = imgr1->zsfc; if ( (pointer_to_nwp != NULL) ) { profile_params *nwp_map; nwp_params *nwp_map2; nwp_map = pointer_to_nwp->map; nwp_map2 = pointer_to_nwp; float *granule_sfctmp; granule_sfctmp = (float *)malloc(neles*nscans*sizeof(float)); int *granule_sfct_flag; granule_sfct_flag = (int *)malloc(neles*nscans*sizeof(int)); float *granule_tpw; granule_tpw = (float *)malloc(neles*nscans*sizeof(float)); float lst_sum; idx = 0; for ( row=0; rowindex_nwp[idx]].t_sfc; granule_sfct_flag[idx] = 0; imgr2->sfctmp[idx] = nwp_map[imgr1->index_nwp[idx]].t_sfc; // Get bilinearly interpolated surface temperature (set-up in nwp_grid2pixel of LEOCAT/src/utils.c). if(imgr1->py[idx] <= 1.00 && imgr1->px[idx] <= 1.00) { t = nwp_map[imgr1->index_nwp[idx]].t_sfc; granule_sfctmp[idx] = t; indx00 = (imgr1->j1[idx] * pointer_to_nwp->nlon) + imgr1->i1[idx]; indx01 = (imgr1->j1[idx] * pointer_to_nwp->nlon) + imgr1->i2[idx]; indx10 = (imgr1->j2[idx] * pointer_to_nwp->nlon) + imgr1->i1[idx]; indx11 = (imgr1->j2[idx] * pointer_to_nwp->nlon) + imgr1->i2[idx]; // Interpolate only if region contains only land or water. lst_sum = nwp_map[indx00].land + nwp_map[indx01].land + nwp_map[indx10].land + nwp_map[indx11].land; if( (lst_sum == 0 && (imgr1->landmask[idx] == 0 || imgr1->landmask[idx] > 2)) || (lst_sum > 1 && (imgr1->landmask[idx] == 1 || imgr1->landmask[idx] == 2)) ) { t00 = nwp_map[indx00].t_sfc; t01 = nwp_map[indx01].t_sfc; tx = ((1.0 - imgr1->px[idx]) * t00) + (imgr1->px[idx] * t01); t10 = nwp_map[indx10].t_sfc; t11 = nwp_map[indx11].t_sfc; ty = ((1.0 - imgr1->px[idx]) * t10) + (imgr1->px[idx] * t11); t = ((1.0 - imgr1->py[idx]) * tx) + (imgr1->py[idx] * ty); } else { // If coastal region, and 1-km LST is water, set flag. granule_sfct_flag[idx] = 1; } granule_sfctmp[idx] = t; imgr2->sfctmp[idx] = t; if( idx < 10) printf("SFCT: %ld %f %f %f\n", idx, imgr1->lat[idx], imgr1->lon[idx], granule_sfctmp[idx]); } else { printf("trouble with spatial interp: %d %f %f \n", imgr1->j1[idx], imgr1->px[idx], imgr1->py[idx]); } // Get precipitable water values. granule_tpw[idx] = nwp_map[imgr1->index_nwp[idx]].tpw / 10.0; idx++; } } g_sfctmp = granule_sfctmp; g_sfct_flag = granule_sfct_flag; g_tpw = granule_tpw; } } static void get_Olson_eco_m(imagerL1 *imgr1) { FILE *eco_file_ptr; size_t bytes_read; unsigned char eco_index; unsigned char *granule_ecotype; char eco_file[69]; int row, col, numberRows; int32 idx, irow, icol, byte_loc; double lt, ln, ltt, lnn; double drow; double dcol; // extern long int lround(double); granule_ecotype = (unsigned char *)malloc(neles*nscans*sizeof(unsigned char)); int32 max_row = 17347; int32 max_col = 40031; numberRows = imgr1->nrow; /* Get file name */ (void) strcpy(eco_file, imgr1->sfc_dir_name); (void) strcat(eco_file, "/goge1_2_img.v1"); printf("ecosystem file: %s \n", eco_file); /* Open file */ eco_file_ptr = fopen(eco_file, "r"); if(eco_file_ptr == NULL) { printf("Cannot open ecosystem file %s \n", eco_file); } idx = 0; for ( row=0; row<(numberRows); ++row) { for ( col=0; collat[idx]; ln = (double) imgr1->lon[idx]; ltt = lt; lnn = ln; // Get row/col of data grid corresponding to lat/lon. (void) getcoord_(<, &ln, &drow, &dcol); irow = lround(drow); if(irow > max_row) irow = max_row; if(irow < 1) irow = 1; icol = lround(dcol); if(icol > max_col) icol = max_col; if(icol < 1) icol = 1; byte_loc = ( ((irow-1) * max_col) + icol) - 1; // Read file fseek(eco_file_ptr, byte_loc, SEEK_SET); bytes_read = fread((char *) &eco_index, sizeof(eco_index), 1, eco_file_ptr); granule_ecotype[idx] = eco_index; if(idx < 10) printf("Olson ecosystem index: %d %d\n", idx, eco_index); ++idx; } } /* Close file */ (void) fclose(eco_file_ptr); g_eco = granule_ecotype; } extern "C" char sst_file[]; static void get_Reynolds_SST (imagerL1 *imgr1, imagerL2 *imgr2) { /* number of points around a latitude circle */ int32 npoints_x = 360; /* number of grid points along a meridian */ int32 npoints_y = 180; /* the 2 possible sizes of an SST file (formatted/unformatted) */ int32 unfSize = 583264; char reynSSTFile[200]; char fileFormat[4] = "unk"; int32 fileSize; FILE * sst_file_ptr; size_t bytes_read; int i, j, xindx, yindx; int32 indx; int ok; float xlon, ytemp; float * sstInterp; float tempVal; SST sstGrid; (void) strcpy(reynSSTFile, sst_file); printf("Reynolds SST file: %s \n", reynSSTFile); /* Open file */ sst_file_ptr = fopen(reynSSTFile, "rb"); if(sst_file_ptr == NULL) { printf("Cannot open Reynolds SST file %s\n", reynSSTFile); } /* Get the file size */ fseek(sst_file_ptr, 0, SEEK_END); fileSize = ftell(sst_file_ptr); fseek(sst_file_ptr, 0, SEEK_SET); /* read if file is unformatted only */ if ( fileSize == unfSize ) { strcpy(fileFormat,"unf"); bytes_read = fread (&sstGrid,sizeof(sstGrid),1,sst_file_ptr); (void) swapbyte4(&sstGrid, 12 + npoints_x * npoints_y); } else { /* Close file */ (void) fclose(sst_file_ptr); return; } /* Close file */ (void) fclose(sst_file_ptr); sstInterp = (float *)malloc(imgr1->ncol*imgr1->nrow*sizeof(float)); indx = 0; for ( i=0; i < imgr1->nrow; ++i) { for ( j=0; j < imgr1->ncol; ++j) { if(imgr1->landmask[indx] != 1) { if (imgr1->lon[indx] < 0.0) xlon = imgr1->lon[indx] + 360.0; else xlon = imgr1->lon[indx]; xindx = (int) fmin(fmax(xlon,0.0),359.99); ytemp = fmin(fmax(imgr1->lat[indx],-89.99), 89.99); yindx = (int) (ytemp + 90.0); ok = bilinearInterpSST(xindx,yindx,imgr1->lat[indx],xlon,&sstGrid,&tempVal); if (ok == 0) { sstInterp[indx] = tempVal + 273.15; imgr2->sfctmp[indx] = sstInterp[indx]; } if(ok != 0) printf("Bad SST interpolation: %d %d %d %d %d %d %f\n", indx, i, j, xindx, yindx, ok, sstInterp[indx]); } if(indx < 10) printf("SSTs: %d %d %d %d %d %f\n", indx, imgr1->landmask[indx], xindx, yindx, ok, sstInterp[indx]); indx++; } } g_reynSST = sstInterp; } extern "C" char nise_file[]; static void get_NISE (imagerL1 *imgr1) { /* Get snow/ice data from NISE ancillary file */ int row, col, numberRows; long int idx; float32 lt, ln, r0, s0, r, s, phi, lam, rg, rho; float32 pi; char NISE_file[200]; unsigned char *nise_north; unsigned char *nise_south; unsigned char *granule_nise; int32 idgd, status, grid_id, start[2], stride[2], edge[2], nise_val; int32 xsize, ysize; int32 i, j, k; float64 upleft[2]; float64 loright[2]; numberRows = imgr1->nrow; /* Get file name */ (void) strcpy(NISE_file, nise_file); printf("NISE file: %s \n", NISE_file); /* Open file and access Northern Hemisphere grid */ idgd = GDopen(NISE_file, DFACC_READ); grid_id = GDattach(idgd, "Northern Hemisphere"); // printf("grid_id: %d \n", grid_id); status = GDgridinfo(grid_id, &xsize, &ysize, upleft, loright); // printf("grid info: %d %d %d %d %f %f \n", status, grid_id, xsize, ysize, upleft[1], loright[1]); start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[0] = xsize; edge[1] = ysize; /* Get NH data */ nise_north = (unsigned char *) malloc(xsize * ysize); status = GDreadfield(grid_id, "Extent", start, stride, edge, nise_north); // printf("grid read NH: %d %d %d \n", status, *(nise_north+0), *(nise_north+1000)); status = GDdetach(grid_id); /* Access and get SH data */ grid_id = GDattach(idgd, "Southern Hemisphere"); nise_south = (unsigned char *) malloc(xsize * ysize); status = GDreadfield(grid_id, "Extent", start, stride, edge, nise_south); // printf("grid read SH: %d %d %d \n", status, *(nise_south+0), *(nise_south+1000)); status = GDdetach(grid_id); status = GDclose(idgd); g_nisenorth = nise_north; g_nisesouth = nise_south; (void) massage_snowice(1, xsize, ysize); (void) massage_snowice(2, xsize, ysize); // Allocate memory for granule-sized NISE data. granule_nise = (unsigned char *)malloc(neles*nscans*sizeof(unsigned char)); /* Assign values to granule lat/lon positions. */ pi = 3.14159; idx = 0; for ( row=0; rowlat[idx]; ln = imgr1->lon[idx]; r0 = (ysize-1) / 2.0; s0 = (xsize-1) / 2.0; phi = lt * DEG2RAD; lam = ln * DEG2RAD; rg = 6371.228 / 25.067525; if(lt >= 0.0) { rho = 2 * rg * sin(pi/4.0 - phi/2.0); r = r0 + rho * sin(lam); s = s0 + rho * cos(lam); /* This code adapted from 1-based FORTRAN; adjust to 0-based data structures. */ i = lroundf(r) - 1; j = lroundf(s) - 1; k = (j * xsize) + i; nise_val = *(nise_north+k); } else { rho = 2 * rg * cos(pi/4.0 - phi/2.0); r = r0 + rho * sin(lam); s = s0 - rho * cos(lam); /* This code adapted from 1-based FORTRAN; adjust to 0-based data structures. */ i = lroundf(r) - 1; j = lroundf(s) - 1; k = (j * xsize) + i; nise_val = *(nise_south+k); } granule_nise[idx] = nise_val; if(idx < 10) printf("NISE proc: %f %f %f %f %f %d %d %d \n", lt, ln, rho, r, s, i, j, nise_val); idx++; } } g_nise = granule_nise; } static void copyNDVIbackground_alg29 (imagerL1 *imgr1) { /* Get background NDVIs for land day processing */ int jd, idx, xerr, yerr, row, col, numberRows; int32 ii, jj, id; int32 start[2], stride[2], edge[2], sds_index, sds_id, irt, xindex, yindex, indx; float map_res, wm_lon, nm_lat; float *ndvi_background; char NDVI_data[23][80]; char *NDVI_file; int16 *ndvi_arr; char SDS_name[10]; int32 nncols = 21600; int32 nnrows = 10800; ndvi_arr = (int16*) malloc(21600 * 10800 * 2); int fnday[23] = {1, 17, 33, 49, 65, 81, 97, 113, 129, 145, 161, 177, 193, 209, 225, 241, 257, 273, 289, 305, 321, 337, 353}; char * ndvi_sub="/NDVI/"; /* Static files containing 5-year (2000-2004) mean for each 16-day period in a year */ for ( ii = 0; ii < 23; ii++ ) { (void) sprintf(NDVI_data[ii],"NDVI.FM.c004.v2.0.WS.00-04.%03d.hdf",fnday[ii]); } /* (void) sprintf(NDVI_data[0],"%s/NDVI.FM.c004.v2.0.WS.00-04.001.hdf",ndvi_sub); (void) sprintf(NDVI_data[1],"%s/NDVI.FM.c004.v2.0.WS.00-04.017.hdf",ndvi_sub); (void) sprintf(NDVI_data[2],"%s/NDVI.FM.c004.v2.0.WS.00-04.033.hdf",ndvi_sub); (void) sprintf(NDVI_data[3],"%s/NDVI.FM.c004.v2.0.WS.00-04.049.hdf",ndvi_sub); (void) sprintf(NDVI_data[4],"%s/NDVI.FM.c004.v2.0.WS.00-04.065.hdf",ndvi_sub); (void) sprintf(NDVI_data[5],"%s/NDVI.FM.c004.v2.0.WS.00-04.081.hdf",ndvi_sub); (void) sprintf(NDVI_data[6],"%s/NDVI.FM.c004.v2.0.WS.00-04.097.hdf",ndvi_sub); (void) sprintf(NDVI_data[7],"%s/NDVI.FM.c004.v2.0.WS.00-04.113.hdf",ndvi_sub); (void) sprintf(NDVI_data[8],"%s/NDVI.FM.c004.v2.0.WS.00-04.129.hdf",ndvi_sub); (void) sprintf(NDVI_data[9],"%s/NDVI.FM.c004.v2.0.WS.00-04.145.hdf",ndvi_sub); (void) sprintf(NDVI_data[10],"%s/NDVI.FM.c004.v2.0.WS.00-04.161.hdf",ndvi_sub); (void) sprintf(NDVI_data[11],"%s/NDVI.FM.c004.v2.0.WS.00-04.177.hdf",ndvi_sub); (void) sprintf(NDVI_data[12],"%s/NDVI.FM.c004.v2.0.WS.00-04.193.hdf",ndvi_sub); (void) sprintf(NDVI_data[13],"%s/NDVI.FM.c004.v2.0.WS.00-04.209.hdf",ndvi_sub); (void) sprintf(NDVI_data[14],"%s/NDVI.FM.c004.v2.0.WS.00-04.225.hdf",ndvi_sub); (void) sprintf(NDVI_data[15],"%s/NDVI.FM.c004.v2.0.WS.00-04.241.hdf",ndvi_sub); (void) sprintf(NDVI_data[16],"%s/NDVI.FM.c004.v2.0.WS.00-04.257.hdf",ndvi_sub); (void) sprintf(NDVI_data[17],"%s/NDVI.FM.c004.v2.0.WS.00-04.273.hdf",ndvi_sub); (void) sprintf(NDVI_data[18],"%s/NDVI.FM.c004.v2.0.WS.00-04.289.hdf",ndvi_sub); (void) sprintf(NDVI_data[19],"%s/NDVI.FM.c004.v2.0.WS.00-04.305.hdf",ndvi_sub); (void) sprintf(NDVI_data[20],"%s/NDVI.FM.c004.v2.0.WS.00-04.321.hdf",ndvi_sub); (void) sprintf(NDVI_data[21],"%s/NDVI.FM.c004.v2.0.WS.00-04.337.hdf",ndvi_sub); (void) sprintf(NDVI_data[22],"%s/NDVI.FM.c004.v2.0.WS.00-04.353.hdf",ndvi_sub); */ /* Find file that matches input data date */ jd = 22; for ( jj = 1; jj < 23; ++jj) { if (imgr1->jday < fnday[jj]) { jd = jj - 1; goto found; } } found:; /* Construct file name */ NDVI_file = (char *)calloc(strlen(imgr1->sfc_dir_name) + strlen(NDVI_data[jd]) + 10, sizeof(char)); (void) strcpy(NDVI_file, imgr1->sfc_dir_name); (void) strcat(NDVI_file, ndvi_sub); (void) strcat(NDVI_file, NDVI_data[jd]); (void) strcpy(g_ndviFile, NDVI_data[jd]); // printf("sfc_dir_name %s \n", imgr1->sfc_dir_name); printf("NDVI file: %d %s\n", jd, NDVI_file); /* Open file. */ id = SDstart(NDVI_file, DFACC_READ); if (id <= 0) { printf("Could not open NDVI file %s\n",NDVI_file); exit (-1); } /* Select proper SDS and read the data */ start[0] = 0; start[1] = 0; stride[0] = 1; stride[1] = 1; edge[1] = nncols; edge[0] = nnrows; (void) strcpy(SDS_name, "NDVI"); sds_index = SDnametoindex(id, SDS_name); sds_id = SDselect(id, sds_index); irt = SDreaddata(sds_id, start, stride, edge, ndvi_arr); /* Close NDVI file. */ id = SDend(id); map_res = 360.0 / float(nncols); wm_lon = (map_res / 2.0) - 180.0; nm_lat = 90.0 - (map_res / 2.0); /* Loop through current data and assign NDVI value for each pixel. */ ndvi_background = (float *)malloc(neles*nscans*sizeof(float)); idx = 0; numberRows = imgr1->nrow; for ( row=0;row<(numberRows );++row) { for ( col=0;collon[idx] - wm_lon) / map_res); yindex = int32((nm_lat - imgr1->lat[idx]) / map_res); if(xindex < 0 || xindex> nncols) { xerr = 1; printf("xindex out of bounds on NDVI map! \n"); // exit (-1); } if(yindex < 0 || yindex> nnrows) { yerr = 1; printf("yindex out of bounds on NDVI map! \n"); // exit (-1); } if(xerr == 0 && yerr == 0) { indx = (yindex*nncols) + xindex; ndvi_background[idx] = *(ndvi_arr + indx) * 0.001; if (idx < 10) { printf("ndvi %d %d %d %d %d %f %f %d %f \n", row, col, xindex, yindex, indx, imgr1->lat[idx], imgr1->lon[idx], *(ndvi_arr + indx), ndvi_background[idx]); } } idx++; } } free (ndvi_arr); g_ndvibk = ndvi_background; } static void copyResultsToLeocat( imagerL1 *imgr1, imagerL2 *imgr2) { long int idx; long int pixel; int numberRows = imgr1->nrow; int row; int col; int byte; int i; int num_250m_stats = 4; int out_indx; unsigned char *flagBuffer; float *statBuffer; imgr2->numberFlagsArray1Buffers = 6; imgr2->numberFlagsArray2Buffers = 10; for ( pixel=0; pixel<(imgr2->npts); ++pixel) { flagBuffer = imgr2->flag_arr2[pixel]; idx=0; for ( byte=0; bytenumberFlagsArray2Buffers; ++byte) { if(byte <= imgr2->numberFlagsArray1Buffers) { flagBuffer[idx] = g_qa[byte][pixel]; } else { flagBuffer[idx]= 0; } idx++; } } for (byte=0; bytenumberFlagsArray1Buffers; ++byte) { flagBuffer = imgr2->flag_arr1[byte]; idx = 0; for (row=0; rownumberStats250Buffers = 4; for ( pixel=0; pixel<(imgr2->npts); ++pixel) { statBuffer = imgr2->stats_250m[pixel]; idx = 0; for ( out_indx=0; out_indxstats_arr; for (i=0; i < numPSA; i++) { statBuffer[i] = g_stats[i]; } /* copy the NDVI and threshold filenames over */ (void) strcpy(imgr2->ndviFile,g_ndviFile); (void) strcpy(imgr2->threshFile,g_threshFile); /* Set flag to inform LEOCAT to output stats as global attributes in create_level2_output.c. */ //RAF imgr2->output_cm_stats_flag = 1; } } extern "C" void algorithmInformation_29 (void *initializeMe) { sprintf(algorithmName,"Alg%d",ALG_NUMBER); sprintf(algorithmKey,"AlgKey%d",ALG_NUMBER); int i; printf("algorithmInformation for #%d %s %s\n",ALG_NUMBER,algorithmName,algorithmKey); algorithm_interface *leocatCopy=(algorithm_interface *)initializeMe; algorithm_interface *local = &this_algo_info; leocatCopy->algo_num=local->algo_num; leocatCopy->nout=local->nout; leocatCopy->algo_name=local->algo_name; leocatCopy->keyword=local->keyword; for (i=0;isds_name[i]=sds_name[i]; } leocatCopy->cmask_needed=local->cmask_needed; leocatCopy->ctype_needed=local->ctype_needed; leocatCopy->amask_needed=local->amask_needed; leocatCopy->nwp_needed=local->nwp_needed; leocatCopy->rtm_needed=local->rtm_needed; for (i=0;ichflg[i] = local->chflg[i]; } leocatCopy->algo_function_ptr = local->algo_function_ptr; leocatCopy->algo_function_info_ptr = local->algo_function_info_ptr; leocatCopy->reference=local->reference; } extern "C" void algorithmImplementation_29 ( unsigned char verbose, imagerL1 *imgr1, imagerL2 *imgr2, sounderL1 *sndr1, sounderL2 *sndr2, nwp_params nwp, rtm_profiles ** rtm, rtm_toa rclr, rad_utils rutil) { printf("\nalgorithmImplementation \n"); (void)fflush(stdout); pointer_to_nwp = &nwp; printf("\nCalling raf_copyDataFromLeocat \n"); (void)fflush(stdout); raf_copyDataFromLeocat(imgr1, imgr2, rclr, rutil ); printf("\nCalling get_Reynolds_SST\n"); (void)fflush(stdout); get_Reynolds_SST(imgr1, imgr2); printf("\nCalling get_NISE \n"); (void)fflush(stdout); get_NISE(imgr1); printf("\nCalling get_Olson_eco \n"); (void)fflush(stdout); get_Olson_eco_m(imgr1); printf("\nCalling copyNDVIbackground_alg29 \n"); (void)fflush(stdout); copyNDVIbackground_alg29(imgr1); printf("\nCalling modis_cm_main \n"); (void)fflush(stdout); modis_cm_main(imgr1->algData_dir_name); // GPC printf("\nCalling copyResultsToLeocat \n"); (void)fflush(stdout); copyResultsToLeocat(imgr1,imgr2); }