23 static char *invalidlutfile =
24 "This is most likely due to an invalid LUT file.";
25 static PGSt_SMF_status Read_LUT_Tables
123 char *location =
"Read_Lookup_Tables";
136 "Read_Emiss_Tables", 0,
NULL,
True);
150 if (strcmp(
tables->refl.MCST_Version,
151 tables->QA.common_QA_tables.MCST_Version))
155 "MCST version in reflective LUT file does "
156 "not match that in QA LUT file.",
158 "LUT files are invalid. All must have the "
159 "same MCST version.",
163 if (strcmp(
tables->emiss.MCST_Version,
164 tables->QA.common_QA_tables.MCST_Version))
168 "MCST version in emissive LUT file does not "
169 "match that in QA LUT file.",
171 "LUT files are invalid. All must have the "
172 "same MCST version.",
183 tables->QA.common_QA_tables.MCST_Version))
187 "MCST version in PCF file does not match that in LUT files.",
189 "LUT files must have the same MCST version as "
190 "specified in the PCF file.",
211 #define ASSIGN_DATA_PTR(luts,lutname,dataptr) \
213 while (luts[i].name) \
215 if (!strcmp(lutname,luts[i].name)) \
222 sprintf(errmsg, "LUT name %s not found in LUTs array.", lutname); \
223 returnStatus = MODIS_F_NOK; \
224 L1BErrorMsg(location, returnStatus, errmsg, NULL, \
225 lun, "*** CODE BUG ***", True); \
226 return returnStatus; \
228 luts[i].data = (VOIDP) dataptr;
371 char *location =
"Read_Refl_Tables";
465 &
tables->DN_obc_avg_first_frame_to_use);
469 &
tables->DN_obc_avg_number_of_frames_to_use);
497 tables->RSB_specified_uncertainty);
501 tables->RSB_UI_scaling_factor);
509 &
tables->RSB_SV_DN_moon_include_frames);
521 &
tables->B26_B5_Corr_Switch);
525 tables->B26_B5_Frame_Offset);
555 returnStatus = Read_LUT_Tables(L1A_Gran,
582 "Band to use for SWIR OOB Correction is out of range.",
587 if (
tables->DN_obc_avg_first_frame_to_use < 0 ||
592 "DN_OBC first frame to use is out of range.",
597 if (
tables->DN_obc_avg_number_of_frames_to_use <= 0 ||
598 (
tables->DN_obc_avg_first_frame_to_use +
603 "DN_OBC number of frames to use is out of range "
604 "or is inconsistent\n"
605 "with the value of DN_OBC first frame to use.",
620 "Bad m1 LUT (Zero values detected).",
627 if (
fabs((
double)
tables->E_sun_over_pi[det])
632 "Bad E_sun_over_pi LUT (Zero values detected).",
647 "Bad RSB_specified_uncertainty LUT "
648 "(Zero or negative values detected).",
654 if ((
RFLAG & 1) == 1) {
655 tables->dn_star_Max[0] = 32767;
656 tables->dn_star_Max[1] = 32767;
660 if ((
RFLAG & 2) == 2) {
661 tables->dn_star_Max[2] = 32767;
662 tables->dn_star_Max[3] = 32767;
746 char *location =
"Read_Emiss_Tables";
779 tables->delta_T_bb_delta);
791 tables->RVS_BB_SV_Frame_No);
803 tables->NUM_RSR_vs_Lambda);
841 tables->T_ins_function_flag);
853 tables->T_cav_function_flag);
861 tables->T_mir_function_flag);
873 &
tables->BB_DN_first_frame_to_use);
877 &
tables->BB_DN_number_of_frames_to_use);
881 &
tables->SV_DN_first_frame_to_use);
885 &
tables->SV_DN_number_of_frames_to_use);
889 &
tables->SV_DN_moon_include_frames);
893 &
tables->PCX_correction_switch);
897 &
tables->num_overlap_scans_b1);
913 tables->TEB_specified_uncertainty);
917 tables->TEB_UI_scaling_factor);
921 &
tables->BB_T_sat_switch_aqua);
929 tables->BB_T_sat_default_b1_baseline_aqua);
933 tables->BB_T_sat_default_b1_c1_aqua);
937 &
tables->BB_T_sat_default_b1_Tlwir_baseline_aqua);
953 tables->sigma_epsilon_BB);
957 tables->sigma_epsilon_CAV);
987 returnStatus = Read_LUT_Tables(L1A_Gran,
1010 for (
i = 0;
i < 2;
i++)
1012 if (
tables->RVS_BB_SV_Frame_No[
i] < 0 ||
1017 "Value(s) of Frame to use for BB or SV RVS "
1018 " correction is out of range.",
1020 return returnStatus;
1032 for (
j = 0;
j <
tables->NUM_RSR_vs_Lambda[
i];
j++)
1038 "Value(s) of input RSR wavelength are zero.",
1040 return returnStatus;
1050 if (
tables->BB_DN_first_frame_to_use < 0 ||
1055 "BB DN first frame to use is out of range.",
1057 return returnStatus;
1060 if (
tables->BB_DN_number_of_frames_to_use <= 0 ||
1061 (
tables->BB_DN_first_frame_to_use +
1066 "BB DN number of frames to use is out of "
1067 "range or is inconsistent\n"
1068 "with the value of DN_OBC first frame to use.",
1070 return returnStatus;
1073 if (
tables->SV_DN_first_frame_to_use < 0 ||
1078 "SV DN first frame to use is out of range.",
1080 return returnStatus;
1083 if (
tables->SV_DN_number_of_frames_to_use <= 0 ||
1084 (
tables->SV_DN_first_frame_to_use +
1089 "SV DN number of frames to use is out of range or "
1091 "with the value of DN_OBC first frame to use.",
1093 return returnStatus;
1106 "Bad TEB_specified_uncertainty LUT (Zero "
1107 "or negative values detected).",
1109 return returnStatus;
1170 int16 D_490,
R, B, D, S_520, subsamp;
1172 char *location =
"Read_QA_Tables";
1272 emiss_QA_LUT->
NEdL);
1294 returnStatus = Read_LUT_Tables(L1A_Gran,
1301 return returnStatus;
1378 for (subsamp = 0; subsamp <
i; subsamp++, S_520++)
1394 for (
i = 0;
i < 12;
i++)
1399 "Table \"var_T_bb\" is zero or negative.",
1401 return returnStatus;
1408 "Table \"var_T_bb_avg\" is zero or negative.",
1410 return returnStatus;
1416 "Table \"var_T_lwir\" is zero or negative.",
1418 return returnStatus;
1425 "Table \"var_T_mwir\" is zero or negative.",
1427 return returnStatus;
1434 "Table \"var_T_mir1\" is zero or negative.",
1436 return returnStatus;
1443 "Table \"var_T_mir2\" is zero or negative.",
1445 return returnStatus;
1452 "Table \"var_T_mir_avg\" is zero or negative.",
1454 return returnStatus;
1461 "Table \"var_T_ins\" is zero or negative.",
1463 return returnStatus;
1470 "Table \"var_T_cav\" is zero or negative.",
1472 return returnStatus;
1480 "Table \"NEdL\" is zero or negative.",
1482 return returnStatus;
1490 "Table \"a1\" is zero or negative.",
1492 return returnStatus;
1511 "*** WRONG LUTS ARE INSTALLED ***\n"
1512 "Satellite instrument in the LUTs is inconsistent "
1514 "inside the middle L1A granule (lun 500001).",
1516 "This is probably due to improper installation of "
1517 "LUT files.",
True);
1518 return returnStatus;
1568 char file_name[PGSd_PC_FILE_PATH_MAX];
1572 char *location =
"Read_LUT_Tables";
1583 #ifdef ENABLE_LUT_VALID_RANGE_CHECKING
1592 returnStatus = PGS_PC_GetReference (lun, &
version, file_name);
1593 if (returnStatus != PGS_S_SUCCESS)
1597 "Could not retrieve file name from PCF.",
1598 "PGS_PC_GetReference", lun,
NULL,
True);
1599 return returnStatus;
1601 file_id = SDstart(file_name, DFACC_RDONLY);
1602 if (file_id ==
FAIL)
1606 "Could not open file for SD read access.",
1608 "The file may be missing, corrupted or "
1609 "not an HDF-4 file.",
True);
1610 return returnStatus;
1624 for (
i = 0;
i < nluts;
i++)
1628 char errmsg[PGS_SMF_MAX_MSGBUF_SIZE];
1630 sprintf(errmsg,
"\"data\" member not assigned for LUT %s",
1633 NULL, lun,
"*** CODE BUG ***",
True);
1634 return returnStatus;
1644 "read_attribute", lun,
NULL,
True);
1645 return returnStatus;
1656 dims_ptr =
luts[
i].dims;
1680 "Read_L1B_SDS_LUT", lun,
NULL,
True);
1681 return returnStatus;
1690 void *data_new =
NULL;
1698 return returnStatus;
1700 memcpy(
luts[
i].
data, data_new, n_bytes);
1715 char msg[PGS_SMF_MAX_MSGBUF_SIZE];
1717 sprintf(
msg,
"PGE version in the file (%s) does not "
1718 "match the code value of %s",
1721 "The LUT file is incompatible with this "
1722 "version of the L1B code.",
1724 return returnStatus;
1729 #ifdef ENABLE_LUT_VALID_RANGE_CHECKING
1742 "Check_Valid_Range", lun,
NULL,
True);
1743 return returnStatus;
1752 if (SDend(file_id) ==
FAIL)
1756 "Could not close access to the HDF file.",
1758 return returnStatus;
1801 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1802 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1803 NULL,
True,
"-0.1",
"0.1",
"-999" },
1809 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1810 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1811 NULL,
True,
"-0.1",
"0.1",
"-999" },
1817 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1818 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1819 NULL,
True,
"0.0",
"1.0",
"-999" },
1825 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1826 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1827 NULL,
True,
"1.0E-20",
"1.0",
"-999" },
1833 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1834 "NUM_MIRROR_SIDES",
"NUM_RSB_RVS_COEFFS",
NULL},
1835 NULL,
True,
"-4.0E-4",
"2.4",
"-999" },
1903 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1913 "swir_oob_correction_switch_table.asc",
1915 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1919 "swir_oob_sending_band_table.asc",
1921 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1925 "swir_oob_sending_detector_table.asc",
1935 {
"NUM_SWIR_BANDS",
"MAX_DETECTORS_PER_SWIR_BAND",
1936 "MAX_NUM_SWIR_SUBSAMPLES",
"NUM_MIRROR_SIDES",
NULL},
1937 NULL,
True,
"-100",
"100",
"-999" },
1943 {
"NUM_SWIR_BANDS",
"MAX_DETECTORS_PER_SWIR_BAND",
1944 "MAX_NUM_SWIR_SUBSAMPLES",
"NUM_MIRROR_SIDES",
NULL},
1945 NULL,
True,
"-100",
"100",
"-999" },
1951 {
"NUM_SWIR_BANDS",
"MAX_DETECTORS_PER_SWIR_BAND",
1952 "MAX_NUM_SWIR_SUBSAMPLES",
"NUM_MIRROR_SIDES",
NULL},
1953 NULL,
True,
"-100",
"100",
"-999" },
1956 "dn_obc_avg_first_frame_to_use_table.asc",
1958 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1962 "dn_obc_avg_number_of_frames_to_use_table.asc",
1964 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1981 "rsb_specified_uncertainty_table.asc",
1988 "rsb_ui_scaling_factor_table.asc",
2001 "rsb_sv_dn_moon_include_frames_table.asc",
2003 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2010 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
2011 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
2036 {
"NUM_REFLECTIVE_DETECTORS",
NULL,
2044 {
"NUM_REFLECTIVE_DETECTORS",
2045 "NUM_MIRROR_SIDES",
"NUM_U2_FRAME",
NULL,
NULL},
2052 {
"NUM_REFLECTIVE_DETECTORS",
2060 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
2061 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
"NUM_2ND_ORDER_COEFFS"},
2130 {
"NUM_PC_XT_BANDS",
"DETECTORS_PER_1KM_BAND",
2131 "NUM_PC_XT_PARAMETERS",
NULL,
NULL},
2137 {
"NUM_EMISSIVE_DETECTORS",
"MAX_NUM_RSR_vs_LAMBDA",
2139 NULL,
True,
"0.01",
"1.0",
"0.0" },
2144 {
"NUM_EMISSIVE_DETECTORS",
"MAX_NUM_RSR_vs_LAMBDA",
2146 NULL,
True,
"3.0",
"15.5",
"-999." },
2158 {
"NUM_a0_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2159 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2166 {
"NUM_a2_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2167 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2211 "bb_dn_first_frame_to_use_table.asc",
2213 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2217 "bb_dn_number_of_frames_to_use_table.asc",
2219 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2223 "sv_dn_first_frame_to_use_table.asc",
2225 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2229 "sv_dn_number_of_frames_to_use_table.asc",
2231 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2235 "sv_dn_moon_include_frames_table.asc",
2237 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2242 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2246 "pcx_correction_switch_table.asc",
2248 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2252 "t_ins_function_flag_table.asc",
2260 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2270 "t_cav_function_flag_table.asc",
2277 "t_mir_function_flag_table.asc",
2284 "t_cav_default_table.asc",
2286 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2291 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2304 {
"NUM_EMISSIVE_BANDS",
"DETECTORS_PER_1KM_BAND",
2305 "NUM_MIRROR_SIDES",
"NUM_2ND_ORDER_COEFFS",
NULL},
2306 NULL,
True,
"-2.0E-4",
"1.2",
"-999" },
2317 {
"DETECTORS_PER_1KM_BAND",
"NUM_MIRROR_SIDES",
NULL,
NULL,
NULL},
2333 "teb_specified_uncertainty_table.asc",
2340 "teb_ui_scaling_factor_table.asc",
2347 "bb_t_sat_switch_aqua_table.asc",
2349 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2353 "bb_t_sat_aqua_table.asc",
2360 "bb_t_sat_default_b1_baseline_aqua_table.asc",
2364 {
"NUM_AQUA_BB_SAT_BANDS",
"DETECTORS_PER_1KM_BAND",
2369 "bb_t_sat_default_b1_c1_aqua_table.asc",
2373 {
"NUM_AQUA_BB_SAT_BANDS",
"DETECTORS_PER_1KM_BAND",
2378 "bb_t_sat_default_b1_Tlwir_baseline_aqua_table.asc",
2385 "sigma_a0_table.asc",
2389 {
"NUM_a0_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2390 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2394 "sigma_a2_table.asc",
2398 {
"NUM_a2_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2399 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2403 "sigma_RVS_ev_table.asc",
2407 {
"NUM_EMISSIVE_BANDS",
"DETECTORS_PER_1KM_BAND",
2408 "NUM_MIRROR_SIDES",
"NUM_2ND_ORDER_COEFFS",
NULL},
2412 "sigma_epsilon_bb_table.asc",
2419 "sigma_epsilon_cav_table.asc",
2426 "sigma_L_lambda_table.asc",
2429 {
"NUM_EMISSIVE_BANDS",
"NUM_1ST_ORDER_COEFFS",
NULL,
NULL,
NULL},
2433 "sigma_L_Tbb_table.asc",
2440 "sigma_L_Tsm_table.asc",
2447 "sigma_L_Tcav_table.asc",
2454 "sigma_b1_B21_table.asc",
2457 {
"DETECTORS_PER_1KM_BAND",
"NUM_MIRROR_SIDES",
NULL,
NULL,
NULL},
2461 "pcx_ui_factor_table.asc",
2494 "associatedplatformshortname_table.asc",
2501 "algorithmpackageacceptancedate_table.asc",
2508 "algorithmpackagematuritycode_table.asc",
2515 "detector_quality_flag_values_table.asc",
2518 {
"NUM_DETECTORS",
"NUM_BITS_IN_UINT8",
NULL,
NULL,
NULL},
2522 "detector_quality_flag2_values_table.asc",
2525 {
"NUM_HIGH_RESOLUTION_DETECTORS",
"NUM_BITS_IN_UINT8",
NULL,
NULL,
NULL},
2541 "visual_fpa_base_variance_table.asc",
2543 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2547 "nir_fpa_base_variance_table.asc",
2549 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2559 "bb_average_temperature_variance_table.asc",
2561 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2565 "lwir_fpa_temperature_variance_table.asc",
2567 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2571 "mwir_fpa_temperature_variance_table.asc",
2573 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2577 "mirrorside_1_temperature_variance_table.asc",
2579 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2583 "mirrorside_2_temperature_variance_table.asc",
2585 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2589 "mirror_average_temperature_variance_table.asc",
2591 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2595 "instrument_temperature_variance_table.asc",
2597 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2601 "cavity_temperature_variance_table.asc",
2603 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2621 {
"NUM_BANDS",
"NUM_MOON_OFFSET_LIMITS",
NULL,
NULL,
NULL},
2651 float64 data_collection_TAI_time,
2697 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2698 char *location =
"Read_L1B_SDS_LUT";
2703 !dims || !
data || data_collection_TAI_time <= 0)
2707 "One or more input parameters are invalid.\n",
2709 return returnStatus;
2733 data_collection_TAI_time,
2738 "TDLUT_ReadStepFunction", 0,
NULL,
False);
2745 data_collection_TAI_time,
2750 "TDLUT_ReadPiecewiseLinearFunction", 0,
NULL,
False);
2758 "The algorithm flag is invalid for LUT \"%s\".",
2763 return returnStatus;
2804 int32 algorithm_flag;
2805 int32 sds_id =
FAIL;
2814 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2816 char *location =
"TDLUT_GetAlgorithm";
2823 "Input parameter sd_id is -1 or name is NULL\n",
2830 sds_index = SDnametoindex(sd_id,
name);
2831 if (sds_index ==
FAIL)
2834 "Could not find SDS \"%s\" in the file.",
name);
2842 sds_id = SDselect (sd_id, sds_index);
2846 "Could not open access to SDS \"%s\".",
name);
2854 hdf_return = SDgetinfo(sds_id,
2860 if (hdf_return ==
FAIL)
2864 "Could not get information about SDS \"%s\".",
name);
2867 goto TDLUT_GetAlgorithm_exit;
2877 goto TDLUT_GetAlgorithm_exit;
2885 for (attr_index = 0; attr_index < nattrs; attr_index++)
2887 hdf_return = SDattrinfo(sds_id,
2892 if (hdf_return ==
FAIL)
2896 "Could not get information of an attribute of SDS \"%s\""
2897 "with a valid index.",
name);
2900 goto TDLUT_GetAlgorithm_exit;
2908 "The data type or the count is not correct for the"
2913 goto TDLUT_GetAlgorithm_exit;
2917 hdf_return = SDreadattr(sds_id, attr_index, &algorithm_flag);
2918 if (hdf_return ==
FAIL)
2922 "Failed to read attribute \"%s\" of SDS \"%s\".",
2926 goto TDLUT_GetAlgorithm_exit;
2933 TDLUT_GetAlgorithm_exit:
2935 if (sds_id !=
FAIL) SDendaccess(sds_id);
2937 return algorithm_flag;
2945 float64 data_collection_TAI_time,
3003 #define TDLUT_STEPFUNCTION_MAX_TIMES 1000
3005 int32 sds_id =
FAIL;
3014 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
3020 char *location =
"TDLUT_ReadStepFunction";
3025 !dims || !
data || data_collection_TAI_time <= 0)
3029 "One or more input parameters are invalid.\n",
3031 return returnStatus;
3036 sds_index = SDnametoindex(sd_id,
name);
3037 if (sds_index ==
FAIL)
3041 "Could not find SDS \"%s\" in the file.",
name);
3042 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDnametoindex", 0,
3044 goto TDLUT_ReadStepFunction_exit;
3049 sds_id = SDselect (sd_id, sds_index);
3054 "Could not open access to SDS \"%s\".",
name);
3055 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDselect", 0,
3057 goto TDLUT_ReadStepFunction_exit;
3062 hdf_return = SDgetinfo(sds_id, buffer, &f_rank, full_dims,
3063 &f_data_type, &nattrs);
3064 if (hdf_return ==
FAIL)
3068 "Could not get information about SDS \"%s\".",
name);
3069 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDgetinfo", 0,
3071 goto TDLUT_ReadStepFunction_exit;
3073 if (data_type != f_data_type)
3077 "SDS \"%s\" has data type mismatch.\n"
3078 "File data type = %ld, expected type = %ld\n",
3079 name, (
long)f_data_type, (
long)data_type);
3082 goto TDLUT_ReadStepFunction_exit;
3086 if ((
rank + 1) != f_rank)
3090 "SDS \"%s\" has a rank mismatch.\n"
3091 "HDF File rank = %ld, expected rank = %ld\n",
3092 name, (
long)f_rank, (
long)(
rank + 1));
3095 goto TDLUT_ReadStepFunction_exit;
3107 "The number of attributes for the step function LUT"
3108 " \"%s\" is 0.",
name);
3111 goto TDLUT_ReadStepFunction_exit;
3117 if (attr_index ==
FAIL)
3121 "Step function lut \"%s\" does not have attribute \"%s\".",
3123 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDfindattr", 0,
3125 goto TDLUT_ReadStepFunction_exit;
3130 hdf_return = SDattrinfo(sds_id, attr_index, buffer, &f_data_type, &
count);
3131 if (hdf_return ==
FAIL)
3135 "Could not get info of the attribute \"%s\" of SDS \"%s\".",
3137 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDattrinfo", 0,
3139 goto TDLUT_ReadStepFunction_exit;
3150 if (f_data_type != DFNT_FLOAT64 ||
3155 "Either the data type is not float64 or the number of\n"
3156 "values are too large (>500) for the "
3157 "attribute\n \"%s\" of SDS \"%s\".",
3160 goto TDLUT_ReadStepFunction_exit;
3165 hdf_return = SDreadattr(sds_id, attr_index, times);
3166 if (hdf_return ==
FAIL)
3170 "Failed to read attribute \"%s\" of SDS \"%s\".",
3174 goto TDLUT_ReadStepFunction_exit;
3182 if (data_collection_TAI_time < times[0])
3184 else if (data_collection_TAI_time >= times[
count - 1])
3190 if (data_collection_TAI_time >= times[
i] &&
3191 data_collection_TAI_time < times[
i + 1])
3207 edge[
i] = dims[
i - 1];
3215 if (hdf_return ==
FAIL)
3219 "Could not read data from SDS \"%s\".",
name);
3220 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDreaddata", 0,
3222 goto TDLUT_ReadStepFunction_exit;
3225 TDLUT_ReadStepFunction_exit:
3227 if (sds_id !=
FAIL) SDendaccess(sds_id);
3229 return returnStatus;
3241 float64 data_collection_TAI_time,
3304 #define TDLUT_PIECEWISE_LINEAR_MAX_TIMES 1000
3307 int32 sds_id =
FAIL;
3311 int32 num_lut_copies;
3316 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
3322 float64 data_coll_time;
3323 float64 lut_data_time;
3324 float64 next_lut_data_time;
3325 float64 slope_denom;
3326 float64 xproportion;
3327 int32 num_lut_elements;
3328 char *location =
"TDLUT_ReadPiecewiseLinearFunction";
3330 int32 pw_size =
sizeof(float32);
3336 !dims || !
data || data_collection_TAI_time <= 0)
3340 "One or more input parameters are invalid.\n",
3342 return returnStatus;
3350 "\"%s\" must have data type float32 to be Piecewise Linear.",
name) ;
3352 return returnStatus;
3357 sds_index = SDnametoindex(sd_id,
name);
3358 if (sds_index ==
FAIL)
3362 "Could not find SDS \"%s\" in the file.",
name);
3363 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDnametoindex", 0,
3365 return returnStatus;
3370 sds_id = SDselect (sd_id, sds_index);
3375 "Could not open access to SDS \"%s\".",
name);
3376 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDselect", 0,
3378 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3383 hdf_return = SDgetinfo(sds_id, buffer, &f_rank, full_dims,
3384 &f_data_type, &nattrs);
3385 if (hdf_return ==
FAIL)
3389 "Could not get information about SDS \"%s\".",
name);
3390 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDgetinfo", 0,
3392 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3397 if (data_type != f_data_type)
3401 "SDS \"%s\" has data type mismatch.\n"
3402 "HDF File data type = %ld, expected type = %ld\n",
3403 name, (
long)f_data_type, (
long)data_type);
3406 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3410 if ((
rank + 1) != f_rank)
3414 "SDS \"%s\" has a rank mismatch.\n"
3415 "HDF File rank = %ld, expected rank = %ld\n",
3416 name, (
long)f_rank, (
long)(
rank + 1));
3419 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3431 "There must be at least 2 attributes for a Piecewise Linear LUT but"
3432 " \"%s\" has %ld.",
name, (
long)nattrs);
3435 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3441 if (attr_index ==
FAIL)
3445 "Piecewise linear function LUT \"%s\" does not have attribute \"%s\".",
3447 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDfindattr", 0,
3449 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3454 hdf_return = SDattrinfo(sds_id,
3459 if (hdf_return ==
FAIL)
3463 "Could not get info of the attribute \"%s\" of SDS \"%s\".",
3465 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDattrinfo", 0,
3467 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3475 if (f_data_type != DFNT_FLOAT64 ||
3480 "Either the data type is not float64 or the number of\n"
3481 "values are too large (>500) for the "
3482 "attribute\n \"%s\" of SDS \"%s\".",
3485 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3490 hdf_return = SDreadattr(sds_id, attr_index, times);
3491 if (hdf_return ==
FAIL)
3495 "Failed to read attribute \"%s\" of SDS \"%s\".",
3499 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3509 if (num_lut_copies == 1)
3515 else if (data_collection_TAI_time < times[0])
3521 else if (data_collection_TAI_time >= times[num_lut_copies-1])
3523 start[0] = num_lut_copies - 2;
3524 next_start[0] = num_lut_copies - 1;
3529 for (
i = 0;
i < num_lut_copies - 1;
i++)
3531 if (data_collection_TAI_time >= times[
i] &&
3532 data_collection_TAI_time < times[
i+1])
3535 next_start[0] =
i+1;
3549 edge[
i] = dims[
i - 1];
3555 if (hdf_return ==
FAIL)
3559 "Could not read first set of data from"
3560 " SDS \"%s\".",
name);
3561 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDreaddata", 0,
3563 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3568 if (num_lut_copies == 1)
return returnStatus;
3572 data_coll_time = data_collection_TAI_time;
3573 lut_data_time = times[
start[0]];
3574 next_lut_data_time = times[next_start[0]];
3575 slope_denom = (next_lut_data_time - lut_data_time);
3581 if (slope_denom <= 0)
3585 "LUT associated with \"%s\" has times out of order.",
3588 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3592 xproportion = (data_coll_time - lut_data_time)/slope_denom;
3595 for (num_lut_elements = 1,
i = 0;
i <
rank;
i++)
3596 num_lut_elements *= dims[
i];
3600 data2 = malloc((
unsigned) num_lut_elements*pw_size);
3605 "Could not allocate memory for second LUT associated "
3606 "with \"%s\".",
name);
3608 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3611 hdf_return = SDreaddata(sds_id, next_start,
NULL, edge, data2);
3612 if (hdf_return ==
FAIL)
3616 "Could not read second set of data from"
3617 " SDS \"%s\"." ,
name);
3618 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDreaddata", 0,
3620 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3627 float32 first_val, second_val, interp_val;
3628 float32 *first_data = (float32 *)
data;
3629 float32 *next_data = (float32 *) data2;
3631 for (
i = 0;
i < num_lut_elements;
i++)
3633 first_val = *first_data;
3634 second_val = *next_data;
3635 interp_val = first_val + xproportion*(second_val - first_val);
3636 *first_data = interp_val;
3645 TDLUT_ReadPiecewiseLinearFunction_exit:
3651 if (sds_id !=
FAIL) SDendaccess(sds_id);
3653 return returnStatus;
3708 UINT16,
INT32, UINT32,
3712 int32 all_data_types[NUM_DATA_TYPES] = {
3717 int32 data_var_size[NUM_DATA_TYPES] = {
3718 sizeof(int8),
sizeof(uint8),
sizeof(
int16),
3719 sizeof(uint16),
sizeof(int32),
sizeof(uint32),
3720 sizeof(float32),
sizeof(float64)
3724 float64 fill_64 = -999.0;
3731 int32
i, i_type, arrsize;
3732 int32 i_T, i_B, i_D, i_S, i_M;
3734 char *location =
"Expand_BDSM_LUT";
3738 #define INSERT_LUT_VALUES \
3741 for (i_T = 0; i_T < dims[0]; i_T++) \
3748 for (i_B = 0; i_B < NUM_250M_BANDS; i_B++) \
3749 for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3750 for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3751 for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3752 {data_temp[i] = *data_orig++; \
3761 for (i_B = 0; i_B < NUM_500M_BANDS; i_B++) \
3762 for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3763 for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3764 for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3765 {if ((i_D < DETECTORS_PER_500M_BAND) && \
3766 (i_S < NUM_500M_SUBSAMP)) \
3767 data_temp[i] = *data_orig++; \
3776 for (i_B = 0; i_B < NUM_1000M_REFL_BANDS; i_B++) \
3777 for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3778 for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3779 for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3780 {if ((i_D < DETECTORS_PER_1KM_BAND) && \
3781 (i_S < NUM_1KM_SUBSAMP)) \
3782 data_temp[i] = *data_orig++; \
3793 for (arrsize = 1,
i = 0;
i <
rank+1;
i++)
3798 for (i_type = 0; i_type < NUM_DATA_TYPES; i_type++) {
3799 if (all_data_types[i_type] == data_type)
break;
3801 if (i_type == NUM_DATA_TYPES)
3804 L1BErrorMsg(location, returnStatus,
"Invalid data type",
3806 return returnStatus;
3808 *n_bytes = arrsize * data_var_size[i_type];
3812 datap = malloc((
unsigned) (*n_bytes));
3816 L1BErrorMsg(location, returnStatus,
"Could not allocate memory",
3818 return returnStatus;
3823 if (data_type == DFNT_INT8)
3825 int8 *data_orig = (int8 *)
data;
3826 int8 *data_temp = (int8 *)datap;
3827 int8 fill_value = (int8)fill_64;
3828 for (
i = 0;
i < arrsize;
i++)
3829 data_temp[
i] = fill_value;
3831 *data_new = (
void *) data_temp;
3838 for (
i = 0;
i < arrsize;
i++)
3839 data_temp[
i] = fill_value;
3841 *data_new = (
void *) data_temp;
3845 int32 *data_orig = (int32 *)
data;
3846 int32 *data_temp = (int32 *)datap;
3847 int32 fill_value = (int32)fill_64;
3848 for (
i = 0;
i < arrsize;
i++)
3849 data_temp[
i] = fill_value;
3851 *data_new = (
void *) data_temp;
3855 float32 *data_orig = (float32 *)
data;
3856 float32 *data_temp = (float32 *)datap;
3857 float32 fill_value = (float32)fill_64;
3858 for (
i = 0;
i < arrsize;
i++)
3859 data_temp[
i] = fill_value;
3861 *data_new = (
void *) data_temp;
3863 else if (data_type == DFNT_FLOAT64)
3865 float64 *data_orig = (float64 *)
data;
3866 float64 *data_temp = (float64 *)datap;
3867 float64 fill_value = fill_64;
3868 for (
i = 0;
i < arrsize;
i++)
3869 data_temp[
i] = fill_value;
3871 *data_new = (
void *) data_temp;
3875 return returnStatus;
3916 int32 returnStatus = -1;
3925 return returnStatus;
3933 for (i_lut = 0; i_lut < nluts; i_lut++)
3936 if (!strcmp (ascii_file,
refl_luts[i_lut].ascii_file))
3941 return returnStatus;
3947 return returnStatus;
3953 if (strcmp (dimnames[0],
"NUM_REFLECTIVE_BANDS") ||
3954 strcmp (dimnames[1],
"MAX_DETECTORS_PER_BAND") ||
3955 strcmp (dimnames[2],
"MAX_SAMPLES_PER_BAND") ||
3956 strcmp (dimnames[3],
"NUM_MIRROR_SIDES"))
3957 return returnStatus;
3963 return returnStatus = i_lut;