/* Name- copyMirsIMGToOutputFile.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 "uthash.h" #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 copyMirsIMGToOutputFile(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; int num_channels; short short_value, short_in_fill, short_out_fill; short *short_array; float float_value, float_in_fill, float_out_fill, scaling_factor; float *float_array; size_t output_index[1]; size_t input_2d_index[2], input_2d_count[2]; size_t input_3d_index[3], input_3d_count[3]; size_t output_2d_index[2], output_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); if (retval == NC_NOERR) { // Loop through the collocations for (coll=0; coll 0) && (strcmp(collocations[coll].closest_img_granule, file_name) == 0)) { //num_collocations_copied++; //input_index[1] = collocations[coll].closest_footprint; // Copy the granule name and footprint retval = nc_inq_varid(out_id, "collocated_img_granule_name", &out_var_id); copyGranuleName(collocations[coll].closest_img_granule, out_id, coll, out_var_id); // Copy the granule name and footprint retval = nc_inq_varid(out_id, "collocated_img_granule_name", &out_var_id); copyGranuleName(collocations[coll].closest_img_granule, out_id, coll, out_var_id); // Copy the cloud liquid water retval = nc_inq_varid(in_id, "CLW", &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, "CLW", &out_var_id); retval = nc_put_var1_float(out_id, out_var_id, output_index, &float_value); } // Channel selection short_array = (short*)malloc(num_channels*sizeof(short)); input_3d_index[0] = scan_line; input_3d_index[1] = fov; input_3d_index[2] = 0; input_3d_count[0] = 1; input_3d_count[1] = 1; input_3d_count[2] = num_channels; retval = nc_inq_varid(in_id, "ChanSel", &in_var_id); retval = nc_get_vara_short(in_id, in_var_id, input_3d_index, input_3d_count, short_array); retval = nc_get_att_short(in_id, in_var_id, "_FillValue", &short_in_fill); retval = nc_inq_varid(out_id, "ChanSel", &out_var_id); retval = nc_get_att_short(out_id, out_var_id, "_FillValue", &short_out_fill); for (n=0; n