/** * Name: * subDataRemapping. * Purpose: * Remaps the 3km fire emission to 9km. * Inputs: * - column and row indexes of the 3km and 9km grids. * - 3km grid fire emission. * - 3km grid fire emission quality. * Output: * - 9km grid fire emission. * Procedure: * Aggregate the fire emission of the 3km grids with valid value and * medium or high quality. * * @param remappingindexfile The input file that contains column and row indexes * for 3km and 9km grids. * @param var3 The input array that contains the 3km grid fire emission. * @param qaf The input array that contains the 3km grid quality. * @param var9 The output array that stores the remapped 9km fire emission * types. * */ int subDataRemapping(char *remappingindexfile, float var3[], short int qaf3[], float var9[]) { // Declare variables. FILE *fp; char buffer[MAX_LEN]; int i, m; long int k; int nps, npp; char *token; int i9, j9; // column index (i9) and row index (j9) for 9km data. int i3, j3; // column index (i3) and row index (j3) for 3km data. // Initialize var9. for (i = 0; i < LAST_HOURS * grid_xt_9km * grid_yt_9km; i++) var13[i] = 0.0; // Open the grid index file. fp = fopen(remappingindexfile, "r"); if (fp == NULL) { perror("Failed: "); return 1; } // To execute a while-loop grid by grid. while (fgets(buffer, MAX_LEN, fp)) // read a line from a given grid and stores it a string. { // Remove trailing newline characters from end of string and replace it // with '\0'. buffer[strcspn(buffer, "\n")] = 0; // Extract 9km grid column and row indexes. token = strtok(buffer, ","); // break the string into a series of tokens. i9 = atoi(token); token = strtok(NULL, ","); j9 = grid_yt_9km - 1 - atoi(token); m = j9 * LAST_HOURS * grid_xt_9km + i9; // Extract the number of 3km grids centered at a given 9km grid. token = strtok(NULL, ","); nps = atoi(token); // Read lats/lons of four angle points for a given 9km grid. for (i = 0; i < 4; i++) fgets(buffer, MAX_LEN, fp); // Initialize. npp = 0; // Loop execution to get 13km grid emissions. for (i = 0; i < nps; i++) { // Extract 3km grid column and row indexes. fgets(buffer, MAX_LEN, fp); token = strtok(buffer, ","); token = strtok(NULL, ","); i3 = atoi(token); token = strtok(NULL, ","); j3 = atoi(token); k = j3 * LAST_HOURS * grid_xt_3km + i3; /* Aggregate 3km grid emissions for the grid with medium or high quality and emission value greater than 0.0. */ if ((qaf3[k] == 2 || qaf3[k] == 3) && var3[k] > 0.0) { var9[m] = var9[m] + var3[k]; npp = npp + 1; } } // Assign 9km emissions to '-1.0' for the grids with low quality or no // valid values. if (npp == 0) var13[m] = -1.0; } // Close the open file stream. fclose(fp); return 0; }