/* DISCLAIMER * ========== * * The University of Wisconsin-Madison Space Science and Engineering Center * (SSEC) makes no warranty of any kind with regard to the update_fy3_l1b_calb * software or any accompanying documentation, including but not limited to * the implied warranties of merchantability and fitness for a particular * purpose. SSEC does not indemnify any infringement of copyright, patent, or * trademark through the use or modification of this software. * * There is no expressed or implied warranty made to anyone as to the * suitability of this software for any purpose. All risk of use is assumed by * the user. Users agree not to hold SSEC, the University of * Wisconsin-Madison, or any of its employees or assigns liable for any * consequences resulting from the use of the update_fy3_l1b_calb software. */ #include #include /* Use old version of HDF5: Version 1.6 */ #define H5_USE_16_API 1 #include #define NR_QKM_DS 4 /* Number of QKM datasets */ #define NR_1KM_DS 15 /* Number of 1km datasets */ /* ======================= */ /* String global variables */ /* ======================= */ /* HDF5 data set names */ char qkm_refl_DS_name_str_pp [NR_QKM_DS][20] = {"EV_250_RefSB_b1", "EV_250_RefSB_b2", "EV_250_RefSB_b3", "EV_250_RefSB_b4"}; char km_refl_DS_name_str_pp [2][25] = {"EV_250_Aggr.1KM_RefSB", "EV_1KM_RefSB"}; int km_refl_DS_nr_attr_p [2] = {4, 15}; char cal_coeff_DS_name_str_p [20] = {"VIR_Cal_Coeff"}; /* New attribute names */ char ref_attr_str_p [3][3] = {"k0", "k1", "k2"}; /* Help message string */ char *help_str = " "; /* ============= */ /* Main function */ /* ============= */ int main (int argc, char **argv) { int n_cal_coeff_int, n_km_attr_int, index, r_attr_index; double *attr_arr = NULL, *k0_attr_arr = NULL, *k1_attr_arr = NULL, *k2_attr_arr = NULL; /* These variables will be used accross multiple data sets */ hid_t file_id, attr_type, lc_data_type; /* The following variables are only used when a dataset is opened */ hid_t attr_id, attr_space, data_set; char *l1b_qkm_file_str_p, *l1b_1km_file_str_p; if (argc != 3) { fprintf (stderr, "[ERROR] Invalid number of input arguments.\n"); fprintf (stderr, "\tUsage: %s %s\n", argv [0], help_str); return 1; } l1b_qkm_file_str_p = argv [1]; l1b_1km_file_str_p = argv [2]; /* ------------------------------------- */ /* Update the data sets in the 250m file */ /* ------------------------------------- */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ /* Load VIR_Cal_Coeff in a local array */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ file_id = H5Fopen (l1b_qkm_file_str_p, H5F_ACC_RDWR, H5P_DEFAULT); /* Get the calibration coefficients */ attr_id = H5Aopen_name (file_id, cal_coeff_DS_name_str_p); /* Get data type of attribute */ attr_type = H5Aget_type (attr_id); lc_data_type = H5Tcopy (H5T_NATIVE_DOUBLE); attr_space = H5Aget_space (attr_id); n_cal_coeff_int = (int) H5Sget_simple_extent_npoints (attr_space); attr_arr = (double *)malloc (sizeof (double) * n_cal_coeff_int); H5Aread (attr_id, lc_data_type, attr_arr); /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ /* Release attribute resources of 250m file */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ H5Sclose (attr_space); H5Aclose (attr_id); /* Scale the attribute values */ for (index = 0; index < n_cal_coeff_int; ++index) { attr_arr [index] = attr_arr [index]; } /* Create new attributes for each 250m reflectance dataset */ for (index = 0; index < NR_QKM_DS; ++index) { /* Open the dataset */ data_set = H5Dopen (file_id, qkm_refl_DS_name_str_pp [index]); /* Create data space for attribute */ attr_space = H5Screate (H5S_SIMPLE); /* Set the charaterstics of the data space of the attribute */ { hsize_t attr_space_size [1] = {1}; H5Sset_extent_simple (attr_space, 1, attr_space_size, NULL); } /* Create the k0 attribute */ /*attr_id = H5Acreate (data_set, ref_k0_attr_str_p, attr_type, attr_space, H5P_DEFAULT);*/ /* Every third element in the VIR_Cal_Coeff array has the intercept value */ /*H5Awrite (attr_id, lc_data_type, &(attr_arr [index * 3])); H5Aclose (attr_id);*/ /* Create the k1 attribute */ /*attr_id = H5Acreate (data_set, ref_k1_attr_str_p, attr_type, attr_space, H5P_DEFAULT);*/ /* Every third element in the VIR_Cal_Coeff array has the slope value */ /*H5Awrite (attr_id, lc_data_type, &(attr_arr [(index * 3) + 1])); H5Aclose (attr_id);*/ for (r_attr_index = 0; r_attr_index < 3; ++r_attr_index) { attr_id = H5Acreate (data_set, ref_attr_str_p [r_attr_index], attr_type, attr_space, H5P_DEFAULT); H5Awrite (attr_id, lc_data_type, &(attr_arr [(index * 3) + r_attr_index])); } H5Sclose (attr_space); H5Dclose (data_set); } /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ /* Release resources for 250m file */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ H5Tclose (attr_type); H5Tclose (lc_data_type); if (attr_arr != NULL) { free (attr_arr); attr_arr = NULL; } /* -------------------------------------- */ /* Update the data sets in the 1000m file */ /* -------------------------------------- */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ /* Load VIR_Cal_Coeff in a local array */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ file_id = H5Fopen (l1b_1km_file_str_p, H5F_ACC_RDWR, H5P_DEFAULT); /* Get the calibration coefficients */ attr_id = H5Aopen_name (file_id, cal_coeff_DS_name_str_p); /* Get data type of attribute */ attr_type = H5Aget_type (attr_id); lc_data_type = H5Tcopy (H5T_NATIVE_DOUBLE); attr_space = H5Aget_space (attr_id); n_cal_coeff_int = (int) H5Sget_simple_extent_npoints (attr_space); attr_arr = (double *)malloc (sizeof (double) * n_cal_coeff_int); H5Aread (attr_id, lc_data_type, attr_arr); n_km_attr_int = (n_cal_coeff_int / 3); /* Seperate the intercept and close values */ k0_attr_arr = (double *)malloc (sizeof (double) * n_km_attr_int); k1_attr_arr = (double *)malloc (sizeof (double) * n_km_attr_int); k2_attr_arr = (double *)malloc (sizeof (double) * n_km_attr_int); for (index = 0; index < n_km_attr_int; ++index) { k0_attr_arr [index] = attr_arr [ index * 3]; k1_attr_arr [index] = attr_arr [(index * 3) + 1]; k2_attr_arr [index] = attr_arr [(index * 3) + 2]; } for (index = 0; index < 2; ++index) { /* Open 1km data set */ data_set = H5Dopen (file_id, km_refl_DS_name_str_pp [index]); /* Create data space for the attributes */ attr_space = H5Screate (H5S_SIMPLE); /* Set charaterstics of the data space of the attribute */ { hsize_t attr_space_size [1] = {km_refl_DS_nr_attr_p [index]}; H5Sset_extent_simple (attr_space, 1, attr_space_size, NULL); } /* Create the k0 attribute */ attr_id = H5Acreate (data_set, ref_attr_str_p [0], attr_type, attr_space, H5P_DEFAULT); H5Awrite (attr_id, lc_data_type, &(k0_attr_arr [index * 4])); H5Aclose (attr_id); /* Create the k1 attribute */ attr_id = H5Acreate (data_set, ref_attr_str_p [1], attr_type, attr_space, H5P_DEFAULT); H5Awrite (attr_id, lc_data_type, &(k1_attr_arr [index * 4])); H5Aclose (attr_id); /* Create the k2 attribute */ attr_id = H5Acreate (data_set, ref_attr_str_p [2], attr_type, attr_space, H5P_DEFAULT); H5Awrite (attr_id, lc_data_type, &(k2_attr_arr [index * 4])); H5Aclose (attr_id); H5Sclose (attr_space); H5Dclose (data_set); } /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ /* Release resources for 1000m file */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ H5Tclose (attr_type); H5Tclose (lc_data_type); if (attr_arr != NULL) { free (attr_arr); } if (k0_attr_arr != NULL) { free (k0_attr_arr); } if (k1_attr_arr != NULL) { free (k1_attr_arr); } if (k2_attr_arr != NULL) { free (k2_attr_arr); } /* -------------------------- */ /* Release resources for file */ /* -------------------------- */ H5Fclose (file_id); return 0; }