/* Name- copyMirsSFRToOutputFile.c Language- C Type- MAIN Version- 1.0 Date- 2/28/2026 Programmer- Mike Pettey (STC) Function- This program extracts data from NUCAPS granules and collocates the data to selected collocations times and locations. */ #include #include #include #include #include #include #include #include #include "mirs_collocator.h" void copyGranuleName(char *granule_name, int out_id, int out_index, int out_var_id); int fileStartsWith(char *file_name, char *token); int fileEndsWith(char *file_name, char *token); int copyMirsSFRToOutputFile(struct collocation_data *collocations, int num_collocations, char *file_name, size_t file_size, void* nc_buffer, int out_id) { int num_collocations_copied; int n, i, j, coll, level, in_footprint, scan_line, fov; int retval, in_id, in_var_id, out_var_id, out_dim_id; short short_value, short_in_fill, short_out_fill; float float_value, float_in_fill, float_out_fill, scaling_factor; size_t output_index[1]; size_t input_2d_index[2], input_2d_count[2]; num_collocations_copied = 0; scan_line = collocations[coll].closest_scanline; fov = collocations[coll].closest_fov; input_2d_index[0] = scan_line; input_2d_index[1] = fov; input_2d_count[0] = 1; input_2d_count[1] = 1; // Open the input file retval = nc_open_mem(file_name, NC_NOWRITE, file_size, nc_buffer, &in_id); //printf(" File opened: %d\n", retval); if (retval == NC_NOERR) { // Loop through the collocations for (coll=0; coll 0) && (strcmp(collocations[coll].closest_snow_granule, file_name) == 0)) { // Copy the granule name and footprint retval = nc_inq_varid(out_id, "collocated_sfr_granule_name", &out_var_id); copyGranuleName(collocations[coll].closest_snow_granule, out_id, coll, out_var_id); // Snow detection retval = nc_inq_varid(in_id, "SD", &in_var_id); retval = nc_get_var1_short(in_id, in_var_id, input_2d_index, &short_value); retval = nc_get_att_short(in_id, in_var_id, "_FillValue", &short_in_fill); if (short_value != short_in_fill) { retval = nc_inq_varid(out_id, "SD", &out_var_id); retval = nc_put_var1_short(out_id, out_var_id, output_index, &short_value); } // Snowfall rate retval = nc_inq_varid(in_id, "SFR", &in_var_id); retval = nc_get_var1_float(in_id, in_var_id, input_2d_index, &float_value); retval = nc_get_att_float(in_id, in_var_id, "_FillValue", &float_in_fill); if (float_value != float_in_fill) { retval = nc_inq_varid(out_id, "SFR", &out_var_id); retval = nc_put_var1_float(out_id, out_var_id, output_index, &float_value); } } // if (strlen(collocations[coll].closest_snd_granule... } // for (coll=0... nc_close(in_id); } // if (retval nc_mem_open... return num_collocations_copied; } // end of file