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;
367 char *location =
"Read_Refl_Tables";
461 &
tables->DN_obc_avg_first_frame_to_use);
465 &
tables->DN_obc_avg_number_of_frames_to_use);
493 tables->RSB_specified_uncertainty);
497 tables->RSB_UI_scaling_factor);
505 &
tables->RSB_SV_DN_moon_include_frames);
517 &
tables->B26_B5_Corr_Switch);
521 tables->B26_B5_Frame_Offset);
551 returnStatus = Read_LUT_Tables(L1A_Gran,
578 "Band to use for SWIR OOB Correction is out of range.",
583 if (
tables->DN_obc_avg_first_frame_to_use < 0 ||
588 "DN_OBC first frame to use is out of range.",
593 if (
tables->DN_obc_avg_number_of_frames_to_use <= 0 ||
594 (
tables->DN_obc_avg_first_frame_to_use +
599 "DN_OBC number of frames to use is out of range "
600 "or is inconsistent\n"
601 "with the value of DN_OBC first frame to use.",
616 "Bad m1 LUT (Zero values detected).",
623 if (
fabs((
double)
tables->E_sun_over_pi[det])
628 "Bad E_sun_over_pi LUT (Zero values detected).",
643 "Bad RSB_specified_uncertainty LUT "
644 "(Zero or negative values detected).",
650 if ((
RFLAG & 1) == 1) {
651 tables->dn_star_Max[0] = 32767;
652 tables->dn_star_Max[1] = 32767;
656 if ((
RFLAG & 2) == 2) {
657 tables->dn_star_Max[2] = 32767;
658 tables->dn_star_Max[3] = 32767;
742 char *location =
"Read_Emiss_Tables";
775 tables->delta_T_bb_delta);
787 tables->RVS_BB_SV_Frame_No);
799 tables->NUM_RSR_vs_Lambda);
836 tables->T_ins_function_flag);
848 tables->T_cav_function_flag);
856 tables->T_mir_function_flag);
868 &
tables->BB_DN_first_frame_to_use);
872 &
tables->BB_DN_number_of_frames_to_use);
876 &
tables->SV_DN_first_frame_to_use);
880 &
tables->SV_DN_number_of_frames_to_use);
884 &
tables->SV_DN_moon_include_frames);
888 &
tables->PCX_correction_switch);
892 &
tables->num_overlap_scans_b1);
908 tables->TEB_specified_uncertainty);
912 tables->TEB_UI_scaling_factor);
928 tables->sigma_epsilon_BB);
932 tables->sigma_epsilon_CAV);
966 returnStatus = Read_LUT_Tables(L1A_Gran,
989 for (
i = 0;
i < 2;
i++)
991 if (
tables->RVS_BB_SV_Frame_No[
i] < 0 ||
996 "Value(s) of Frame to use for BB or SV RVS "
997 " correction is out of range.",
1011 for (
j = 0;
j <
tables->NUM_RSR_vs_Lambda[
i];
j++)
1017 "Value(s) of input RSR wavelength are zero.",
1019 return returnStatus;
1029 if (
tables->BB_DN_first_frame_to_use < 0 ||
1034 "BB DN first frame to use is out of range.",
1036 return returnStatus;
1039 if (
tables->BB_DN_number_of_frames_to_use <= 0 ||
1040 (
tables->BB_DN_first_frame_to_use +
1045 "BB DN number of frames to use is out of "
1046 "range or is inconsistent\n"
1047 "with the value of DN_OBC first frame to use.",
1049 return returnStatus;
1052 if (
tables->SV_DN_first_frame_to_use < 0 ||
1057 "SV DN first frame to use is out of range.",
1059 return returnStatus;
1062 if (
tables->SV_DN_number_of_frames_to_use <= 0 ||
1063 (
tables->SV_DN_first_frame_to_use +
1068 "SV DN number of frames to use is out of range or "
1070 "with the value of DN_OBC first frame to use.",
1072 return returnStatus;
1085 "Bad TEB_specified_uncertainty LUT (Zero "
1086 "or negative values detected).",
1088 return returnStatus;
1148 int16 D_490,
R, B, D, S_520, subsamp;
1150 char *location =
"Read_QA_Tables";
1250 emiss_QA_LUT->
NEdL);
1272 returnStatus = Read_LUT_Tables(L1A_Gran,
1279 return returnStatus;
1356 for (subsamp = 0; subsamp <
i; subsamp++, S_520++)
1372 for (
i = 0;
i < 12;
i++)
1377 "Table \"var_T_bb\" is zero or negative.",
1379 return returnStatus;
1386 "Table \"var_T_bb_avg\" is zero or negative.",
1388 return returnStatus;
1394 "Table \"var_T_lwir\" is zero or negative.",
1396 return returnStatus;
1403 "Table \"var_T_mwir\" is zero or negative.",
1405 return returnStatus;
1412 "Table \"var_T_mir1\" is zero or negative.",
1414 return returnStatus;
1421 "Table \"var_T_mir2\" is zero or negative.",
1423 return returnStatus;
1430 "Table \"var_T_mir_avg\" is zero or negative.",
1432 return returnStatus;
1439 "Table \"var_T_ins\" is zero or negative.",
1441 return returnStatus;
1448 "Table \"var_T_cav\" is zero or negative.",
1450 return returnStatus;
1458 "Table \"NEdL\" is zero or negative.",
1460 return returnStatus;
1468 "Table \"a1\" is zero or negative.",
1470 return returnStatus;
1489 "*** WRONG LUTS ARE INSTALLED ***\n"
1490 "Satellite instrument in the LUTs is inconsistent "
1492 "inside the middle L1A granule (lun 500001).",
1494 "This is probably due to improper installation of "
1495 "LUT files.",
True);
1496 return returnStatus;
1546 char file_name[PGSd_PC_FILE_PATH_MAX];
1550 char *location =
"Read_LUT_Tables";
1561 #ifdef ENABLE_LUT_VALID_RANGE_CHECKING
1570 returnStatus = PGS_PC_GetReference (lun, &
version, file_name);
1571 if (returnStatus != PGS_S_SUCCESS)
1575 "Could not retrieve file name from PCF.",
1576 "PGS_PC_GetReference", lun,
NULL,
True);
1577 return returnStatus;
1579 file_id = SDstart(file_name, DFACC_RDONLY);
1580 if (file_id ==
FAIL)
1584 "Could not open file for SD read access.",
1586 "The file may be missing, corrupted or "
1587 "not an HDF-4 file.",
True);
1588 return returnStatus;
1602 for (
i = 0;
i < nluts;
i++)
1606 char errmsg[PGS_SMF_MAX_MSGBUF_SIZE];
1608 sprintf(errmsg,
"\"data\" member not assigned for LUT %s",
1611 NULL, lun,
"*** CODE BUG ***",
True);
1612 return returnStatus;
1622 "read_attribute", lun,
NULL,
True);
1623 return returnStatus;
1634 dims_ptr =
luts[
i].dims;
1658 "Read_L1B_SDS_LUT", lun,
NULL,
True);
1659 return returnStatus;
1668 void *data_new =
NULL;
1676 return returnStatus;
1678 memcpy(
luts[
i].
data, data_new, n_bytes);
1693 char msg[PGS_SMF_MAX_MSGBUF_SIZE];
1695 sprintf(
msg,
"PGE version in the file (%s) does not "
1696 "match the code value of %s",
1699 "The LUT file is incompatible with this "
1700 "version of the L1B code.",
1702 return returnStatus;
1707 #ifdef ENABLE_LUT_VALID_RANGE_CHECKING
1720 "Check_Valid_Range", lun,
NULL,
True);
1721 return returnStatus;
1730 if (SDend(file_id) ==
FAIL)
1734 "Could not close access to the HDF file.",
1736 return returnStatus;
1779 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1780 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1781 NULL,
True,
"-0.1",
"0.1",
"-999" },
1787 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1788 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1789 NULL,
True,
"-0.1",
"0.1",
"-999" },
1795 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1796 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1797 NULL,
True,
"0.0",
"1.0",
"-999" },
1803 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1804 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
1805 NULL,
True,
"1.0E-20",
"1.0",
"-999" },
1811 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1812 "NUM_MIRROR_SIDES",
"NUM_RSB_RVS_COEFFS",
NULL},
1813 NULL,
True,
"-4.0E-4",
"2.4",
"-999" },
1881 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1891 "swir_oob_correction_switch_table.asc",
1893 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1897 "swir_oob_sending_band_table.asc",
1899 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1903 "swir_oob_sending_detector_table.asc",
1913 {
"NUM_SWIR_BANDS",
"MAX_DETECTORS_PER_SWIR_BAND",
1914 "MAX_NUM_SWIR_SUBSAMPLES",
"NUM_MIRROR_SIDES",
NULL},
1915 NULL,
True,
"-100",
"100",
"-999" },
1921 {
"NUM_SWIR_BANDS",
"MAX_DETECTORS_PER_SWIR_BAND",
1922 "MAX_NUM_SWIR_SUBSAMPLES",
"NUM_MIRROR_SIDES",
NULL},
1923 NULL,
True,
"-100",
"100",
"-999" },
1929 {
"NUM_SWIR_BANDS",
"MAX_DETECTORS_PER_SWIR_BAND",
1930 "MAX_NUM_SWIR_SUBSAMPLES",
"NUM_MIRROR_SIDES",
NULL},
1931 NULL,
True,
"-100",
"100",
"-999" },
1934 "dn_obc_avg_first_frame_to_use_table.asc",
1936 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1940 "dn_obc_avg_number_of_frames_to_use_table.asc",
1942 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1959 "rsb_specified_uncertainty_table.asc",
1966 "rsb_ui_scaling_factor_table.asc",
1979 "rsb_sv_dn_moon_include_frames_table.asc",
1981 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
1988 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
1989 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
NULL},
2014 {
"NUM_REFLECTIVE_DETECTORS",
NULL,
2022 {
"NUM_REFLECTIVE_DETECTORS",
2023 "NUM_MIRROR_SIDES",
"NUM_U2_FRAME",
NULL,
NULL},
2030 {
"NUM_REFLECTIVE_DETECTORS",
2038 {
"NUM_REFLECTIVE_BANDS",
"MAX_DETECTORS_PER_BAND",
2039 "MAX_SAMPLES_PER_BAND",
"NUM_MIRROR_SIDES",
"NUM_2ND_ORDER_COEFFS"},
2109 {
"NUM_PC_XT_BANDS",
"DETECTORS_PER_1KM_BAND",
2110 "NUM_PC_XT_PARAMETERS",
NULL,
NULL},
2116 {
"NUM_EMISSIVE_DETECTORS",
"MAX_NUM_RSR_vs_LAMBDA",
2118 NULL,
True,
"0.01",
"1.0",
"0.0" },
2123 {
"NUM_EMISSIVE_DETECTORS",
"MAX_NUM_RSR_vs_LAMBDA",
2125 NULL,
True,
"3.0",
"15.0",
"-999." },
2137 {
"NUM_a0_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2138 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2145 {
"NUM_a2_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2146 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2190 "bb_dn_first_frame_to_use_table.asc",
2192 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2196 "bb_dn_number_of_frames_to_use_table.asc",
2198 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2202 "sv_dn_first_frame_to_use_table.asc",
2204 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2208 "sv_dn_number_of_frames_to_use_table.asc",
2210 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2214 "sv_dn_moon_include_frames_table.asc",
2216 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2221 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2225 "pcx_correction_switch_table.asc",
2227 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2231 "t_ins_function_flag_table.asc",
2239 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2249 "t_cav_function_flag_table.asc",
2256 "t_mir_function_flag_table.asc",
2263 "t_cav_default_table.asc",
2265 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2270 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2283 {
"NUM_EMISSIVE_BANDS",
"DETECTORS_PER_1KM_BAND",
2284 "NUM_MIRROR_SIDES",
"NUM_2ND_ORDER_COEFFS",
NULL},
2285 NULL,
True,
"-2.0E-4",
"1.2",
"-999" },
2296 {
"DETECTORS_PER_1KM_BAND",
"NUM_MIRROR_SIDES",
NULL,
NULL,
NULL},
2312 "teb_specified_uncertainty_table.asc",
2319 "teb_ui_scaling_factor_table.asc",
2326 "sigma_a0_table.asc",
2330 {
"NUM_a0_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2331 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2335 "sigma_a2_table.asc",
2339 {
"NUM_a2_vs_T_inst_COEFF",
"NUM_MIRROR_SIDES",
2340 "NUM_EMISSIVE_DETECTORS",
NULL,
NULL},
2344 "sigma_RVS_ev_table.asc",
2348 {
"NUM_EMISSIVE_BANDS",
"DETECTORS_PER_1KM_BAND",
2349 "NUM_MIRROR_SIDES",
"NUM_2ND_ORDER_COEFFS",
NULL},
2353 "sigma_epsilon_bb_table.asc",
2360 "sigma_epsilon_cav_table.asc",
2367 "sigma_L_lambda_table.asc",
2370 {
"NUM_EMISSIVE_BANDS",
"NUM_1ST_ORDER_COEFFS",
NULL,
NULL,
NULL},
2374 "sigma_L_Tbb_table.asc",
2381 "sigma_L_Tsm_table.asc",
2388 "sigma_L_Tcav_table.asc",
2395 "sigma_b1_B21_table.asc",
2398 {
"DETECTORS_PER_1KM_BAND",
"NUM_MIRROR_SIDES",
NULL,
NULL,
NULL},
2402 "xt_ui_factor_table.asc",
2405 {
"NUM_EMISSIVE_BANDS",
"DETECTORS_PER_1KM_BAND",
NULL,
NULL,
NULL},
2409 "pvlw_xt_coeff_table.asc",
2412 {
"NUM_PVLW_XT_RECEIVING_BANDS",
"DETECTORS_PER_1KM_BAND",
"NUM_PVLW_XT_SENDING_BANDS",
"DETECTORS_PER_1KM_BAND",
"NUM_PVLW_XT_COEFF"},
2442 "associatedplatformshortname_table.asc",
2449 "algorithmpackageacceptancedate_table.asc",
2456 "algorithmpackagematuritycode_table.asc",
2463 "detector_quality_flag_values_table.asc",
2466 {
"NUM_DETECTORS",
"NUM_BITS_IN_UINT8",
NULL,
NULL,
NULL},
2470 "detector_quality_flag2_values_table.asc",
2473 {
"NUM_HIGH_RESOLUTION_DETECTORS",
"NUM_BITS_IN_UINT8",
NULL,
NULL,
NULL},
2489 "visual_fpa_base_variance_table.asc",
2491 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2495 "nir_fpa_base_variance_table.asc",
2497 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2507 "bb_average_temperature_variance_table.asc",
2509 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2513 "lwir_fpa_temperature_variance_table.asc",
2515 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2519 "mwir_fpa_temperature_variance_table.asc",
2521 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2525 "mirrorside_1_temperature_variance_table.asc",
2527 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2531 "mirrorside_2_temperature_variance_table.asc",
2533 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2537 "mirror_average_temperature_variance_table.asc",
2539 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2543 "instrument_temperature_variance_table.asc",
2545 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2549 "cavity_temperature_variance_table.asc",
2551 {1, 0, 0, 0, 0}, {
"1",
NULL,
NULL,
NULL,
NULL},
2569 {
"NUM_BANDS",
"NUM_MOON_OFFSET_LIMITS",
NULL,
NULL,
NULL},
2599 float64 data_collection_TAI_time,
2645 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2646 char *location =
"Read_L1B_SDS_LUT";
2651 !dims || !
data || data_collection_TAI_time <= 0)
2655 "One or more input parameters are invalid.\n",
2657 return returnStatus;
2681 data_collection_TAI_time,
2686 "TDLUT_ReadStepFunction", 0,
NULL,
False);
2693 data_collection_TAI_time,
2698 "TDLUT_ReadPiecewiseLinearFunction", 0,
NULL,
False);
2706 "The algorithm flag is invalid for LUT \"%s\".",
2711 return returnStatus;
2752 int32 algorithm_flag;
2753 int32 sds_id =
FAIL;
2762 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2764 char *location =
"TDLUT_GetAlgorithm";
2771 "Input parameter sd_id is -1 or name is NULL\n",
2778 sds_index = SDnametoindex(sd_id,
name);
2779 if (sds_index ==
FAIL)
2782 "Could not find SDS \"%s\" in the file.",
name);
2790 sds_id = SDselect (sd_id, sds_index);
2794 "Could not open access to SDS \"%s\".",
name);
2802 hdf_return = SDgetinfo(sds_id,
2808 if (hdf_return ==
FAIL)
2812 "Could not get information about SDS \"%s\".",
name);
2815 goto TDLUT_GetAlgorithm_exit;
2825 goto TDLUT_GetAlgorithm_exit;
2833 for (attr_index = 0; attr_index < nattrs; attr_index++)
2835 hdf_return = SDattrinfo(sds_id,
2840 if (hdf_return ==
FAIL)
2844 "Could not get information of an attribute of SDS \"%s\""
2845 "with a valid index.",
name);
2848 goto TDLUT_GetAlgorithm_exit;
2856 "The data type or the count is not correct for the"
2861 goto TDLUT_GetAlgorithm_exit;
2865 hdf_return = SDreadattr(sds_id, attr_index, &algorithm_flag);
2866 if (hdf_return ==
FAIL)
2870 "Failed to read attribute \"%s\" of SDS \"%s\".",
2874 goto TDLUT_GetAlgorithm_exit;
2881 TDLUT_GetAlgorithm_exit:
2883 if (sds_id !=
FAIL) SDendaccess(sds_id);
2885 return algorithm_flag;
2893 float64 data_collection_TAI_time,
2952 #define TDLUT_STEPFUNCTION_MAX_TIMES 500
2954 int32 sds_id =
FAIL;
2963 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
2969 char *location =
"TDLUT_ReadStepFunction";
2974 !dims || !
data || data_collection_TAI_time <= 0)
2978 "One or more input parameters are invalid.\n",
2980 return returnStatus;
2985 sds_index = SDnametoindex(sd_id,
name);
2986 if (sds_index ==
FAIL)
2990 "Could not find SDS \"%s\" in the file.",
name);
2991 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDnametoindex", 0,
2993 goto TDLUT_ReadStepFunction_exit;
2998 sds_id = SDselect (sd_id, sds_index);
3003 "Could not open access to SDS \"%s\".",
name);
3004 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDselect", 0,
3006 goto TDLUT_ReadStepFunction_exit;
3011 hdf_return = SDgetinfo(sds_id, buffer, &f_rank, full_dims,
3012 &f_data_type, &nattrs);
3013 if (hdf_return ==
FAIL)
3017 "Could not get information about SDS \"%s\".",
name);
3018 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDgetinfo", 0,
3020 goto TDLUT_ReadStepFunction_exit;
3022 if (data_type != f_data_type)
3026 "SDS \"%s\" has data type mismatch.\n"
3027 "File data type = %ld, expected type = %ld\n",
3028 name, (
long)f_data_type, (
long)data_type);
3031 goto TDLUT_ReadStepFunction_exit;
3035 if ((
rank + 1) != f_rank)
3039 "SDS \"%s\" has a rank mismatch.\n"
3040 "HDF File rank = %ld, expected rank = %ld\n",
3041 name, (
long)f_rank, (
long)(
rank + 1));
3044 goto TDLUT_ReadStepFunction_exit;
3056 "The number of attributes for the step function LUT"
3057 " \"%s\" is 0.",
name);
3060 goto TDLUT_ReadStepFunction_exit;
3066 if (attr_index ==
FAIL)
3070 "Step function lut \"%s\" does not have attribute \"%s\".",
3072 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDfindattr", 0,
3074 goto TDLUT_ReadStepFunction_exit;
3079 hdf_return = SDattrinfo(sds_id, attr_index, buffer, &f_data_type, &
count);
3080 if (hdf_return ==
FAIL)
3084 "Could not get info of the attribute \"%s\" of SDS \"%s\".",
3086 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDattrinfo", 0,
3088 goto TDLUT_ReadStepFunction_exit;
3099 if (f_data_type != DFNT_FLOAT64 ||
3104 "Either the data type is not float64 or the number of\n"
3105 "values are too large (>500) for the "
3106 "attribute\n \"%s\" of SDS \"%s\".",
3109 goto TDLUT_ReadStepFunction_exit;
3114 hdf_return = SDreadattr(sds_id, attr_index, times);
3115 if (hdf_return ==
FAIL)
3119 "Failed to read attribute \"%s\" of SDS \"%s\".",
3123 goto TDLUT_ReadStepFunction_exit;
3131 if (data_collection_TAI_time < times[0])
3133 else if (data_collection_TAI_time >= times[
count - 1])
3139 if (data_collection_TAI_time >= times[
i] &&
3140 data_collection_TAI_time < times[
i + 1])
3156 edge[
i] = dims[
i - 1];
3164 if (hdf_return ==
FAIL)
3168 "Could not read data from SDS \"%s\".",
name);
3169 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDreaddata", 0,
3171 goto TDLUT_ReadStepFunction_exit;
3174 TDLUT_ReadStepFunction_exit:
3176 if (sds_id !=
FAIL) SDendaccess(sds_id);
3178 return returnStatus;
3190 float64 data_collection_TAI_time,
3253 #define TDLUT_PIECEWISE_LINEAR_MAX_TIMES 1000
3256 int32 sds_id =
FAIL;
3260 int32 num_lut_copies;
3265 char errmsgbuf[PGS_SMF_MAX_MSGBUF_SIZE];
3271 float64 data_coll_time;
3272 float64 lut_data_time;
3273 float64 next_lut_data_time;
3274 float64 slope_denom;
3275 float64 xproportion;
3276 int32 num_lut_elements;
3277 char *location =
"TDLUT_ReadPiecewiseLinearFunction";
3279 int32 pw_size =
sizeof(float32);
3285 !dims || !
data || data_collection_TAI_time <= 0)
3289 "One or more input parameters are invalid.\n",
3291 return returnStatus;
3299 "\"%s\" must have data type float32 to be Piecewise Linear.",
name) ;
3301 return returnStatus;
3306 sds_index = SDnametoindex(sd_id,
name);
3307 if (sds_index ==
FAIL)
3311 "Could not find SDS \"%s\" in the file.",
name);
3312 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDnametoindex", 0,
3314 return returnStatus;
3319 sds_id = SDselect (sd_id, sds_index);
3324 "Could not open access to SDS \"%s\".",
name);
3325 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDselect", 0,
3327 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3332 hdf_return = SDgetinfo(sds_id, buffer, &f_rank, full_dims,
3333 &f_data_type, &nattrs);
3334 if (hdf_return ==
FAIL)
3338 "Could not get information about SDS \"%s\".",
name);
3339 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDgetinfo", 0,
3341 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3346 if (data_type != f_data_type)
3350 "SDS \"%s\" has data type mismatch.\n"
3351 "HDF File data type = %ld, expected type = %ld\n",
3352 name, (
long)f_data_type, (
long)data_type);
3355 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3359 if ((
rank + 1) != f_rank)
3363 "SDS \"%s\" has a rank mismatch.\n"
3364 "HDF File rank = %ld, expected rank = %ld\n",
3365 name, (
long)f_rank, (
long)(
rank + 1));
3368 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3380 "There must be at least 2 attributes for a Piecewise Linear LUT but"
3381 " \"%s\" has %ld.",
name, (
long)nattrs);
3384 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3390 if (attr_index ==
FAIL)
3394 "Piecewise linear function LUT \"%s\" does not have attribute \"%s\".",
3396 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDfindattr", 0,
3398 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3403 hdf_return = SDattrinfo(sds_id,
3408 if (hdf_return ==
FAIL)
3412 "Could not get info of the attribute \"%s\" of SDS \"%s\".",
3414 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDattrinfo", 0,
3416 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3424 if (f_data_type != DFNT_FLOAT64 ||
3429 "Either the data type is not float64 or the number of\n"
3430 "values are too large (>500) for the "
3431 "attribute\n \"%s\" of SDS \"%s\".",
3434 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3439 hdf_return = SDreadattr(sds_id, attr_index, times);
3440 if (hdf_return ==
FAIL)
3444 "Failed to read attribute \"%s\" of SDS \"%s\".",
3448 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3458 if (num_lut_copies == 1)
3464 else if (data_collection_TAI_time < times[0])
3470 else if (data_collection_TAI_time >= times[num_lut_copies-1])
3472 start[0] = num_lut_copies - 2;
3473 next_start[0] = num_lut_copies - 1;
3478 for (
i = 0;
i < num_lut_copies - 1;
i++)
3480 if (data_collection_TAI_time >= times[
i] &&
3481 data_collection_TAI_time < times[
i+1])
3484 next_start[0] =
i+1;
3498 edge[
i] = dims[
i - 1];
3504 if (hdf_return ==
FAIL)
3508 "Could not read first set of data from"
3509 " SDS \"%s\".",
name);
3510 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDreaddata", 0,
3512 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3517 if (num_lut_copies == 1)
return returnStatus;
3521 data_coll_time = data_collection_TAI_time;
3522 lut_data_time = times[
start[0]];
3523 next_lut_data_time = times[next_start[0]];
3524 slope_denom = (next_lut_data_time - lut_data_time);
3530 if (slope_denom <= 0)
3534 "LUT associated with \"%s\" has times out of order.",
3537 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3541 xproportion = (data_coll_time - lut_data_time)/slope_denom;
3544 for (num_lut_elements = 1,
i = 0;
i <
rank;
i++)
3545 num_lut_elements *= dims[
i];
3549 data2 = malloc((
unsigned) num_lut_elements*pw_size);
3554 "Could not allocate memory for second LUT associated "
3555 "with \"%s\".",
name);
3557 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3560 hdf_return = SDreaddata(sds_id, next_start,
NULL, edge, data2);
3561 if (hdf_return ==
FAIL)
3565 "Could not read second set of data from"
3566 " SDS \"%s\"." ,
name);
3567 L1BErrorMsg(location, returnStatus, errmsgbuf,
"SDreaddata", 0,
3569 goto TDLUT_ReadPiecewiseLinearFunction_exit;
3576 float32 first_val, second_val, interp_val;
3577 float32 *first_data = (float32 *)
data;
3578 float32 *next_data = (float32 *) data2;
3580 for (
i = 0;
i < num_lut_elements;
i++)
3582 first_val = *first_data;
3583 second_val = *next_data;
3584 interp_val = first_val + xproportion*(second_val - first_val);
3585 *first_data = interp_val;
3594 TDLUT_ReadPiecewiseLinearFunction_exit:
3600 if (sds_id !=
FAIL) SDendaccess(sds_id);
3602 return returnStatus;
3657 UINT16,
INT32, UINT32,
3661 int32 all_data_types[NUM_DATA_TYPES] = {
3666 int32 data_var_size[NUM_DATA_TYPES] = {
3667 sizeof(int8),
sizeof(uint8),
sizeof(
int16),
3668 sizeof(uint16),
sizeof(int32),
sizeof(uint32),
3669 sizeof(float32),
sizeof(float64)
3673 float64 fill_64 = -999.0;
3680 int32
i, i_type, arrsize;
3681 int32 i_T, i_B, i_D, i_S, i_M;
3683 char *location =
"Expand_BDSM_LUT";
3687 #define INSERT_LUT_VALUES \
3690 for (i_T = 0; i_T < dims[0]; i_T++) \
3697 for (i_B = 0; i_B < NUM_250M_BANDS; i_B++) \
3698 for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3699 for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3700 for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3701 {data_temp[i] = *data_orig++; \
3710 for (i_B = 0; i_B < NUM_500M_BANDS; i_B++) \
3711 for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3712 for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3713 for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3714 {if ((i_D < DETECTORS_PER_500M_BAND) && \
3715 (i_S < NUM_500M_SUBSAMP)) \
3716 data_temp[i] = *data_orig++; \
3725 for (i_B = 0; i_B < NUM_1000M_REFL_BANDS; i_B++) \
3726 for (i_D = 0; i_D < MAX_DETECTORS_PER_BAND; i_D++) \
3727 for (i_S = 0; i_S < MAX_SAMPLES_PER_BAND; i_S++) \
3728 for (i_M = 0; i_M < NUM_MIRROR_SIDES; i_M++) \
3729 {if ((i_D < DETECTORS_PER_1KM_BAND) && \
3730 (i_S < NUM_1KM_SUBSAMP)) \
3731 data_temp[i] = *data_orig++; \
3742 for (arrsize = 1,
i = 0;
i <
rank+1;
i++)
3747 for (i_type = 0; i_type < NUM_DATA_TYPES; i_type++) {
3748 if (all_data_types[i_type] == data_type)
break;
3750 if (i_type == NUM_DATA_TYPES)
3753 L1BErrorMsg(location, returnStatus,
"Invalid data type",
3755 return returnStatus;
3757 *n_bytes = arrsize * data_var_size[i_type];
3761 datap = malloc((
unsigned) (*n_bytes));
3765 L1BErrorMsg(location, returnStatus,
"Could not allocate memory",
3767 return returnStatus;
3772 if (data_type == DFNT_INT8)
3774 int8 *data_orig = (int8 *)
data;
3775 int8 *data_temp = (int8 *)datap;
3776 int8 fill_value = (int8)fill_64;
3777 for (
i = 0;
i < arrsize;
i++)
3778 data_temp[
i] = fill_value;
3780 *data_new = (
void *) data_temp;
3787 for (
i = 0;
i < arrsize;
i++)
3788 data_temp[
i] = fill_value;
3790 *data_new = (
void *) data_temp;
3794 int32 *data_orig = (int32 *)
data;
3795 int32 *data_temp = (int32 *)datap;
3796 int32 fill_value = (int32)fill_64;
3797 for (
i = 0;
i < arrsize;
i++)
3798 data_temp[
i] = fill_value;
3800 *data_new = (
void *) data_temp;
3804 float32 *data_orig = (float32 *)
data;
3805 float32 *data_temp = (float32 *)datap;
3806 float32 fill_value = (float32)fill_64;
3807 for (
i = 0;
i < arrsize;
i++)
3808 data_temp[
i] = fill_value;
3810 *data_new = (
void *) data_temp;
3812 else if (data_type == DFNT_FLOAT64)
3814 float64 *data_orig = (float64 *)
data;
3815 float64 *data_temp = (float64 *)datap;
3816 float64 fill_value = fill_64;
3817 for (
i = 0;
i < arrsize;
i++)
3818 data_temp[
i] = fill_value;
3820 *data_new = (
void *) data_temp;
3824 return returnStatus;
3865 int32 returnStatus = -1;
3874 return returnStatus;
3882 for (i_lut = 0; i_lut < nluts; i_lut++)
3885 if (!strcmp (ascii_file,
refl_luts[i_lut].ascii_file))
3890 return returnStatus;
3896 return returnStatus;
3902 if (strcmp (dimnames[0],
"NUM_REFLECTIVE_BANDS") ||
3903 strcmp (dimnames[1],
"MAX_DETECTORS_PER_BAND") ||
3904 strcmp (dimnames[2],
"MAX_SAMPLES_PER_BAND") ||
3905 strcmp (dimnames[3],
"NUM_MIRROR_SIDES"))
3906 return returnStatus;
3912 return returnStatus = i_lut;