86 "EV_250m",
"EV_500m",
"EV_1km_day",
"EV_1km_night"
112 "EV_250_RefSB",
"EV_250_RefSB_Uncert_Indexes",
113 "EV_500_RefSB",
"EV_500_RefSB_Uncert_Indexes",
114 "EV_1KM_RefSB",
"EV_1KM_RefSB_Uncert_Indexes",
115 "EV_1KM_Emissive",
"EV_1KM_Emissive_Uncert_Indexes",
116 "EV_250_Aggr500_RefSB",
"EV_250_Aggr500_RefSB_Uncert_Indexes",
117 "EV_250_Aggr500_RefSB_Samples_Used",
118 "EV_250_Aggr1km_RefSB",
"EV_250_Aggr1km_RefSB_Uncert_Indexes",
119 "EV_250_Aggr1km_RefSB_Samples_Used",
120 "EV_500_Aggr1km_RefSB",
"EV_500_Aggr1km_RefSB_Uncert_Indexes",
121 "EV_500_Aggr1km_RefSB_Samples_Used"
126 "Earth View 250M Reflective Solar Bands Scaled Integers",
127 "Earth View 250M Reflective Solar Bands Uncertainty Indexes",
128 "Earth View 500M Reflective Solar Bands Scaled Integers",
129 "Earth View 500M Reflective Solar Bands Uncertainty Indexes",
130 "Earth View 1KM Reflective Solar Bands Scaled Integers",
131 "Earth View 1KM Reflective Solar Bands Uncertainty Indexes",
132 "Earth View 1KM Emissive Bands Scaled Integers",
133 "Earth View 1KM Emissive Bands Uncertainty Indexes",
134 "Earth View 250M Aggregated 500M Reflective Solar Bands "
136 "Earth View 250M Aggregated 500M Reflective Solar Bands "
137 "Uncertainty Indexes",
138 "Earth View 250M Aggregated 500M Reflective Solar Bands "
139 "Number of Samples Used in Aggregation",
140 "Earth View 250M Aggregated 1km Reflective Solar Bands "
142 "Earth View 250M Aggregated 1km Reflective Solar Bands "
143 "Uncertainty Indexes",
144 "Earth View 250M Aggregated 1km Reflective Solar Bands "
145 "Number of Samples Used in Aggregation",
146 "Earth View 500M Aggregated 1km Reflective Solar Bands "
148 "Earth View 500M Aggregated 1km Reflective Solar Bands "
149 "Uncertainty Indexes",
150 "Earth View 500M Aggregated 1km Reflective Solar Bands "
151 "Number of Samples Used in Aggregation"
166 #define L1B_EV_SDS_RANK 3
169 {
"Band_250M",
"40*nscans",
"4*Max_EV_frames"},
170 {
"Band_500M",
"20*nscans",
"2*Max_EV_frames"},
171 {
"Band_1KM_RefSB",
"10*nscans",
"Max_EV_frames"},
172 {
"Band_1KM_Emissive",
"10*nscans",
"Max_EV_frames"}
178 {1, 0}, {0, 0}, {0, 0}, {0, 0}
184 {0.5, 0.0}, {0.5, 0.0}, {0.0, 0.0}, {0.0, 0.0}
199 {-90.,90.} , -999. ,
"3,8" ,
"3,8,13,...", 1.f} ,
201 {-180., 180.} , -999. ,
"3,8" ,
"3,8,13,...", 1.f} ,
202 {
"Height" ,
"Height" ,
DFNT_INT16 ,
"meters" ,
203 {-400,10000} , -32767 ,
"3,8" ,
"3,8,13,...", 1.f} ,
204 {
"SensorZenith" ,
"SensorZenith" ,
DFNT_INT16 ,
"degrees" ,
205 {0,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
206 {
"SensorAzimuth",
"SensorAzimuth",
DFNT_INT16 ,
"degrees" ,
207 {-18000,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
208 {
"Range" ,
"Range" , DFNT_UINT16 ,
"meters" ,
209 {27000.,65535.}, 0 ,
"3,8" ,
"3,8,13,...", 25.f} ,
210 {
"SolarZenith" ,
"SolarZenith" ,
DFNT_INT16 ,
"degrees" ,
211 {0,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
212 {
"SolarAzimuth" ,
"SolarAzimuth" ,
DFNT_INT16 ,
"degrees" ,
213 {-18000,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
214 {
"gflags" ,
"gflags" , DFNT_UINT8 ,
"" ,
215 {0.,0.} , 255 ,
"" ,
"" , 1.}
230 boolean skip_night_hi_res)
328 char *location =
"L1B_Setup";
330 &
tables->refl.SWIR_correction_tables;
348 "Band to use for SWIR OOB Correction is out of range.",
350 "This is most likely due to an invalid LUT file.",
True);
363 SMF_ERROR(returnStatus,
"Open_L1A_EV_SDS() in L1B_Setup");
369 "Calculate_Earth_Sun_Distance",
376 SMF_ERROR(returnStatus,
"Calculate_RSB_Cal_Coeff() in L1B_Setup");
382 SMF_ERROR(returnStatus,
"Init_L1B_ScaleOffset() in L1B_Setup");
391 (
tables->refl.B26_B5_Corr,
397 "Calculate_B26_B5_Correction() in L1B_Setup");
402 SMF_ERROR(returnStatus,
"Open_W_L1B_Granule() in L1B_Setup");
404 returnStatus =
Copy_Geo_SDS (L1B_Gran, skip_night_hi_res);
406 SMF_ERROR(returnStatus,
"Copy_Geo_SDS() in L1B_Setup");
409 L1A_Gran, L1B_Gran, L1B_Scan_Meta, QA);
411 SMF_ERROR(returnStatus,
"Scan_Meta_Cal() in L1B_Setup");
415 SMF_ERROR(returnStatus,
"Calculate_DCR_Change() in Gran_Meta_Cal()");
419 SMF_ERROR(returnStatus,
"Init_QA_Parameters() in L1B_Setup");
474 char *location =
"Open_L1A_EV_SDS";
481 if ((
RFLAG & (1 <<
R)) != 0)
continue;
484 if (sds_index ==
FAIL)
486 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
494 L1A_Scan->
sds_id[
R] = SDselect (L1A_Gran->
sd_id, sds_index);
497 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
510 float32 *Earth_Sun_Dist)
565 char *location =
"Calculate_Earth_Sun_Distance";
570 if (L1A_Gran ==
NULL || Earth_Sun_Dist ==
NULL)
572 "Input parameter is NULL pointer.",
NULL, 0,
NULL,
True);
592 EMA = -2.15802 + 0.0000114074107 * TAItime -
593 1.56645046e-23 * TAItime * TAItime;
601 *Earth_Sun_Dist = 1.0001396 - 0.0167068 * cos((
double)(EMA *
PGS_PI/180.0))
602 - 0.0001396 * cos((
double)(2 * EMA *
PGS_PI/180.0));
659 {40, 40, 20, 20, 20, 20, 20, 10,
660 10, 10, 10, 10, 10, 10, 10, 10,
661 10, 10, 10, 10, 10, 10};
664 {4, 4, 2, 2, 2, 2, 2, 1, 1, 1, 1,
665 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
693 for ( det = 0; det < num_detectors[
band]; det++, det_490++ )
695 for ( sample = 0; sample < num_subsamps[
band]; sample++ )
699 m1 =
tables->refl.m1[
band][det][sample][mirr_side];
701 m1 * E_S_Dist * E_S_Dist;
703 if (
tables->QA.common_QA_tables.dead_detector[det_490] != 1)
705 work[n] = RSB_Cal_Coeff->
m1_des_sq[
band][det][sample][mirr_side];
714 for (
i = 0;
i < n;
i++)
720 "invalid m1 maximum value in Calculate_RSB_Cal_Coeff()");
725 return (returnStatus);
814 "LUT dn_star_Max <= dn_star_Min, Init_L1B_ScaleOffset");
824 (
tables->emiss.L_Max[B_emiss] -
828 (
tables->emiss.L_Max[B_emiss] -
829 tables->emiss.L_Min[B_emiss]);
840 E_sun_over_pi_B[B] = 0;
842 E_sun_over_pi_B[B] +=
tables->refl.E_sun_over_pi[D_330];
847 E_sun_over_pi_B[B] = 0;
849 E_sun_over_pi_B[B] +=
tables->refl.E_sun_over_pi[D_330];
854 E_sun_over_pi_B[B] = 0;
856 E_sun_over_pi_B[B] +=
tables->refl.E_sun_over_pi[D_330];
876 (E_sun_over_pi_B[B] / (E_S_Dist * E_S_Dist))
889 boolean skip_night_hi_res)
963 PGSt_PC_Logical logical_id = 0;
965 char fname[PGSd_PC_FILE_PATH_MAX];
967 char *location =
"Open_W_L1B_Granule";
975 if (skip_night_hi_res ==
True)
990 if (PGS_PC_GetReference(logical_id, &
version, fname) != PGS_S_SUCCESS)
994 "Could not retrieve file name from PCF.",
995 "PGS_PC_GetReference", logical_id,
NULL,
True);
999 if ((L1B_Gran->
sw_f_id[
f] = SWopen(fname, DFACC_CREATE)) ==
FAIL)
1003 "Could not create output granule.",
1005 return returnStatus;
1013 "Create_L1B_Swath", 0,
NULL,
True);
1014 return returnStatus;
1024 return returnStatus;
1034 "Set_L1B_EV_SDS_Attrs", 0,
NULL,
True);
1035 return returnStatus;
1043 "Create_Band_Subsetting_SDS", 0,
NULL,
True);
1044 return returnStatus;
1052 boolean skip_night_hi_res)
1124 PGSt_SMF_status returnStatus;
1125 char *location =
"Create_L1B_Swath";
1126 int16 file_index = 0;
1129 int32 track_dim = 0;
1130 int32 frame_dim = 0;
1134 intn hdf_return = 0;
1141 #define MAX_ATTR_NAME_SIZE2 72
1145 #define SW_DEF_EV_SDS(SI_name, UI_name, str) \
1146 if (SWdefdatafield(sw_id[file_index], SI_name, str, DFNT_UINT16, \
1147 HDFE_NOMERGE) == FAIL) \
1149 returnStatus = MODIS_F_HDF_ERROR; \
1150 L1BErrorMsg(location, returnStatus, SI_name, \
1151 "SWdefdatafield", evfile_luns[file_index], NULL, True); \
1152 return returnStatus; \
1154 if (SWdefdatafield(sw_id[file_index], UI_name, str, DFNT_UINT8, \
1155 HDFE_NOMERGE) == FAIL) \
1157 returnStatus = MODIS_F_HDF_ERROR; \
1158 L1BErrorMsg(location, returnStatus, UI_name, \
1159 "SWdefdatafield", evfile_luns[file_index], NULL, True); \
1160 return returnStatus; \
1163 #define SW_DEF_EV_Aggr_SDS(SI_name, UI_name, SU_name, str) \
1164 SW_DEF_EV_SDS(SI_name,UI_name,str); \
1165 if (SWdefdatafield(sw_id[file_index], SU_name, str, DFNT_INT8, \
1166 HDFE_NOMERGE) == FAIL) \
1168 returnStatus = MODIS_F_HDF_ERROR; \
1169 L1BErrorMsg(location, returnStatus, SU_name, \
1170 "SWdefdatafield", evfile_luns[file_index], NULL, True); \
1171 return returnStatus; \
1180 if (skip_night_hi_res ==
True)
1186 for (file_index = start_output_res;
1192 sw_id[file_index] = SWcreate(L1B_Gran->
sw_f_id[file_index],
1193 "MODIS_SWATH_Type_L1B");
1194 if (sw_id[file_index] ==
FAIL)
1198 "SWcreate", evfile_luns[file_index],
NULL,
True);
1199 return returnStatus;
1204 if (EHidinfo(L1B_Gran->
sw_f_id[file_index],
1205 &L1B_Gran->
v_id[file_index],
1210 "EHidinfo", evfile_luns[file_index],
NULL,
True);
1211 return returnStatus;
1216 num_BGs = file_index + 1;
1219 for (BG_index = 0; BG_index < num_BGs; BG_index++)
1224 if (hdf_return ==
FAIL)
1228 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1229 return returnStatus;
1243 sprintf(attr_name_buffer,
1244 "HDFEOS_FractionalOffset_%s_MODIS_SWATH_Type_L1B",
1247 if(SDsetattr(L1B_Gran->
sd_id[file_index],
1252 "Could not write L1B EV file dimensional attribute.",
1253 "SDsetattr", evfile_luns[file_index],
NULL,
True);
1256 sprintf(attr_name_buffer,
1257 "HDFEOS_FractionalOffset_%s_MODIS_SWATH_Type_L1B",
1260 if(SDsetattr(L1B_Gran->
sd_id[file_index],
1265 "Could not write L1B EV file dimensional attribute.",
1266 "SDsetattr", evfile_luns[file_index],
NULL,
True);
1281 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1282 return returnStatus;
1290 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1291 return returnStatus;
1298 if (SWdefdim(sw_id[file_index],
"2*nscans",
1303 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1304 return returnStatus;
1307 if (SWdefdim(sw_id[file_index],
"1KM_geo_dim",
1311 L1BErrorMsg(location, returnStatus,
"1KM_geo_dim",
1312 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1313 return returnStatus;
1316 if (SWdefgeofield(sw_id[file_index],
"Latitude",
1318 HDFE_NOMERGE) ==
FAIL)
1322 "SWdefgeofield", evfile_luns[file_index],
1324 return returnStatus;
1327 if (SWdefgeofield(sw_id[file_index],
"Longitude",
1329 HDFE_NOMERGE) ==
FAIL)
1333 "SWdefgeofield", evfile_luns[file_index],
1335 return returnStatus;
1340 "Band_1KM_RefSB,10*nscans,Max_EV_frames");
1344 "Band_1KM_Emissive,10*nscans,Max_EV_frames");
1349 "Band_250M,10*nscans,Max_EV_frames");
1354 "Band_500M,10*nscans,Max_EV_frames");
1358 if (SWdefdatafield(sw_id[file_index],
GEO_SDS[isds].
name,
1359 "2*nscans,1KM_geo_dim",
1364 "SWdefdatafield", evfile_luns[file_index],
NULL,
True);
1365 return returnStatus;
1369 if (SWdefdimmap(sw_id[file_index],
"2*nscans",
"10*nscans",
1373 L1BErrorMsg(location, returnStatus,
"2*nscans to 10*nscans",
1374 "SWdefdimmap", evfile_luns[file_index],
NULL,
True);
1375 return returnStatus;
1378 if (SWdefdimmap(sw_id[file_index],
"1KM_geo_dim",
"Max_EV_frames",
1382 L1BErrorMsg(location, returnStatus,
"1KM_geo_dim to Max_EV_frames",
1383 "SWdefdimmap", evfile_luns[file_index],
NULL,
True);
1384 return returnStatus;
1390 for (
R = 0;
R < 4;
R++) {
1391 if (SWdefdatafield(sw_id[file_index],
1398 "SWdefdatafield", evfile_luns[file_index],
NULL,
True);
1399 return returnStatus;
1406 if (SWdefdim(sw_id[file_index],
"10*nscans",
1411 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1412 return returnStatus;
1415 if (SWdefdim(sw_id[file_index],
"Max_EV_frames",
1419 L1BErrorMsg(location, returnStatus,
"Max_EV_frames",
1420 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1421 return returnStatus;
1424 if (SWdefgeofield(sw_id[file_index],
"Latitude",
1426 HDFE_NOMERGE) ==
FAIL)
1430 "SWdefgeofield", evfile_luns[file_index],
NULL,
True);
1431 return returnStatus;
1434 if (SWdefgeofield(sw_id[file_index],
"Longitude",
1436 HDFE_NOMERGE) ==
FAIL)
1440 "SWdefgeofield", evfile_luns[file_index],
NULL,
True);
1441 return returnStatus;
1449 "Band_250M,40*nscans,4*Max_EV_frames");
1451 if (SWdefdatafield(sw_id[file_index],
1460 evfile_luns[file_index],
NULL,
True);
1461 return returnStatus;
1469 "Band_500M,20*nscans,2*Max_EV_frames");
1474 "Band_250M,20*nscans,2*Max_EV_frames");
1476 for (
R = 0;
R < 2;
R++) {
1477 if (SWdefdatafield(sw_id[file_index],
1486 evfile_luns[file_index],
NULL,
True);
1487 return returnStatus;
1495 if (SWdefdimmap(sw_id[file_index],
1502 "L1B_EV_DIM_NAME[R][1] to 10*nscans",
1504 evfile_luns[file_index],
NULL,
True);
1505 return returnStatus;
1508 if (SWdefdimmap(sw_id[file_index],
1515 "L1B_EV_DIM_NAME[R][2] to 10*nscans",
1517 evfile_luns[file_index],
NULL,
True);
1518 return returnStatus;
1523 #ifdef WRITE_BAND_26_SDS
1533 "10*nscans,Max_EV_frames");
1540 for (file_index = start_output_res;
1548 if (SWdetach(sw_id[file_index]) ==
FAIL)
1552 "SWdetach", evfile_luns[file_index],
NULL,
True);
1553 return returnStatus;
1563 "Write_Swath_Band_Number",
1564 evfile_luns[file_index],
NULL,
True);
1565 return returnStatus;
1607 char *location =
"Write_Swath_Band_Number";
1610 float32 data_250m[2] = {1, 2};
1611 float32 data_500m[5] = {3, 4, 5, 6, 7};
1612 float32 data_1km_refl[15] =
1613 {8, 9, 10, 11, 12, 13, 13.5, 14, 14.5,
1614 15, 16, 17, 18, 19, 26};
1615 float32 data_1km_emiss[16] =
1616 {20, 21, 22, 23, 24, 25, 27, 28, 29,
1617 30, 31, 32, 33, 34, 35, 36};
1625 swId = SWattach(L1B_Gran->
sw_f_id[file_index],
"MODIS_SWATH_Type_L1B");
1630 "SWattach", evfile_luns[file_index],
NULL,
True);
1631 return returnStatus;
1637 if (SWwritefield(swId,
"Band_250M", (int32*)
NULL, (int32*)
NULL,
1638 (int32*)
NULL, (VOIDP)data_250m) ==
FAIL)
1642 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1643 return returnStatus;
1646 if (SWwritefield(swId,
"Band_500M", (int32*)
NULL, (int32*)
NULL,
1647 (int32*)
NULL, (VOIDP)data_500m) ==
FAIL)
1651 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1652 return returnStatus;
1655 if (SWwritefield(swId,
"Band_1KM_RefSB", (int32*)
NULL, (int32*)
NULL,
1656 (int32*)
NULL, (VOIDP)data_1km_refl)==
FAIL)
1659 L1BErrorMsg(location, returnStatus,
"Band_1KM_RefSB",
1660 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1661 return returnStatus;
1664 if (SWwritefield(swId,
"Band_1KM_Emissive", (int32*)
NULL, (int32*)
NULL,
1665 (int32*)
NULL, (VOIDP)data_1km_emiss)==
FAIL)
1668 L1BErrorMsg(location, returnStatus,
"Band_1KM_Emissive",
1669 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1670 return returnStatus;
1675 if (SWwritefield(swId,
"Band_250M", (int32*)
NULL, (int32*)
NULL,
1676 (int32*)
NULL, (VOIDP)data_250m) ==
FAIL)
1680 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1681 return returnStatus;
1684 if (SWwritefield(swId,
"Band_500M", (int32*)
NULL, (int32*)
NULL,
1685 (int32*)
NULL, (VOIDP)data_500m) ==
FAIL)
1689 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1690 return returnStatus;
1695 if (SWwritefield(swId,
"Band_250M", (int32*)
NULL, (int32*)
NULL,
1696 (int32*)
NULL, (VOIDP)data_250m) ==
FAIL)
1700 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1701 return returnStatus;
1706 if (SWdetach(swId) ==
FAIL)
1710 "SWdetach", evfile_luns[file_index],
NULL,
True);
1711 return returnStatus;
1719 boolean skip_night_hi_res)
1792 PGSt_SMF_status returnStatus;
1793 char *location =
"Open_L1B_EV_SDS";
1794 int32 sds_index = 0;
1795 int16 file_index = 0;
1802 int32 scaled_250[2] = {13,16};
1803 int32 scaled_500[2] = {10,12};
1813 #define CREATE_EV_SDS(sd_id, SI_name, UI_name, SI_longName, UI_longName, \
1815 if((sds_index = SDnametoindex(sd_id, SI_name)) == FAIL) \
1817 returnStatus = MODIS_F_HDF_ERROR; \
1818 L1BErrorMsg(location, returnStatus, SI_name, \
1819 "SDnametoindex", evfile_luns[file_index], NULL, True); \
1820 return returnStatus; \
1822 if((SI_id = SDselect(sd_id, sds_index)) == FAIL) \
1824 returnStatus = MODIS_F_HDF_ERROR; \
1825 L1BErrorMsg(location, returnStatus, SI_name, \
1826 "SDselect", evfile_luns[file_index], NULL, True); \
1827 return returnStatus; \
1829 if(SDsetattr(SI_id, "long_name", DFNT_CHAR8,(int32)strlen(SI_longName), \
1830 SI_longName) == FAIL) \
1832 returnStatus = MODIS_F_HDF_ERROR; \
1833 L1BErrorMsg(location, returnStatus, SI_name, \
1834 "SDsetattr", evfile_luns[file_index], "long_name", True); \
1835 return returnStatus; \
1837 if((sds_index = SDnametoindex(sd_id, UI_name)) == FAIL) \
1839 returnStatus = MODIS_F_HDF_ERROR; \
1840 L1BErrorMsg(location, returnStatus, UI_name, \
1841 "SDnametoindex", evfile_luns[file_index], NULL, True); \
1842 return returnStatus; \
1844 if((UI_id = SDselect(sd_id, sds_index)) == FAIL) \
1846 returnStatus = MODIS_F_HDF_ERROR; \
1847 L1BErrorMsg(location, returnStatus, UI_name, \
1848 "SDselect", evfile_luns[file_index], NULL, True); \
1849 return returnStatus; \
1851 if(SDsetattr(UI_id, "long_name", DFNT_CHAR8,(int32)strlen(UI_longName), \
1852 UI_longName) == FAIL) \
1854 returnStatus = MODIS_F_HDF_ERROR; \
1855 L1BErrorMsg(location, returnStatus, UI_name, \
1856 "SDsetattr", evfile_luns[file_index], "long_name", True); \
1857 return returnStatus; \
1868 #define CREATE_EV_Aggr_SDS(sd_id, SI_name, UI_name, SU_name, SI_LName, \
1869 UI_LName, SU_LName, SI_id, UI_id, SU_id) \
1870 CREATE_EV_SDS(sd_id, SI_name, UI_name, SI_LName, UI_LName, SI_id, UI_id); \
1871 if((sds_index = SDnametoindex(sd_id, SU_name)) == FAIL) \
1873 returnStatus = MODIS_F_HDF_ERROR; \
1874 L1BErrorMsg(location, returnStatus, SU_name, \
1875 "SDnametoindex", evfile_luns[file_index], NULL, True); \
1876 return returnStatus; \
1878 if((SU_id = SDselect(sd_id, sds_index)) == FAIL) \
1880 returnStatus = MODIS_F_HDF_ERROR; \
1881 L1BErrorMsg(location, returnStatus, SU_name, \
1882 "SDselect", evfile_luns[file_index], NULL, True); \
1883 return returnStatus; \
1885 if(SDsetattr(SU_id, "long_name", DFNT_CHAR8,(int32)strlen(SU_LName), \
1886 SU_LName) == FAIL) \
1888 returnStatus = MODIS_F_HDF_ERROR; \
1889 L1BErrorMsg(location, returnStatus, SU_name, \
1890 "SDsetattr", evfile_luns[file_index], "long_name", True); \
1891 return returnStatus; \
1897 if (skip_night_hi_res ==
False)
1976 1, &scaled_250[0]) ==
FAIL)
1979 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean R",
1981 return returnStatus;
1989 1, &scaled_250[1]) ==
FAIL)
1992 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean NIR",
1994 return returnStatus;
2002 1, &scaled_500[0]) ==
FAIL)
2005 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean B",
2007 return returnStatus;
2015 1, &scaled_500[1]) ==
FAIL)
2018 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean G",
2020 return returnStatus;
2025 #ifdef WRITE_BAND_26_SDS
2049 boolean skip_night_hi_res)
2122 PGSt_SMF_status returnStatus;
2123 char *location =
"Set_L1B_EV_SDS_Attrs";
2127 int32 sds_ids[4] = {0, 0, 0, 0};
2134 } ScaleOffset_Kind_t;
2141 "8,9,10,11,12,13lo,13hi,14lo,14hi,15,16,17,18,19,26",
2142 "20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36"
2144 char *rad_units =
"Watts/m^2/micrometer/steradian";
2145 char *refl_units =
"none";
2146 char *counts_units =
"counts";
2159 "Set_Unit_Range_Fillvalue", 0,
NULL,
True);
2160 return returnStatus;
2173 "Set_UI_ConvertToPercent_Attrs", 0,
NULL,
True);
2174 return returnStatus;
2242 if ((
RFLAG & 1) == 1) {
2252 if ((
RFLAG & 2) == 2) {
2264 if (skip_night_hi_res ==
True)
2271 returnStatus =
Get_SDS_id(
f, L1B_Scan, &num_sds, sds_ids);
2276 "Get_SDS_id", evfile_luns[
f],
NULL,
True);
2277 return returnStatus;
2291 "Set_SDS_Attributes", evfile_luns[
f],
NULL,
True);
2292 return returnStatus;
2298 #ifdef WRITE_BAND_26_SDS
2313 "Could not write Band 26 SI SDS "
2315 "\"radiance_scales\".",
2316 "SDsetattr", evfile_luns[
f],
NULL,
True);
2317 return returnStatus;
2326 "Could not write Band 26 SI SDS "
2328 "\"radiance_offsets\".",
2329 "SDsetattr", evfile_luns[
f],
NULL,
True);
2330 return returnStatus;
2335 (int32)strlen(rad_units), rad_units) ==
FAIL)
2339 "Could not write Band 26 SI SDS "
2341 "\"radiance_units\".",
2342 "SDsetattr", evfile_luns[
f],
NULL,
True);
2343 return returnStatus;
2352 "Could not write Band 26 SI SDS "
2354 "\"reflectance_scales\".",
2355 "SDsetattr", evfile_luns[
f],
NULL,
True);
2356 return returnStatus;
2365 "Could not write Band 26 SI SDS "
2367 "\"reflectance_offsets\".",
2368 "SDsetattr", evfile_luns[
f],
NULL,
True);
2369 return returnStatus;
2374 (int32)strlen(refl_units), refl_units) ==
FAIL)
2378 "Could not write Band 26 SI SDS "
2380 "\"reflectance_units\".",
2381 "SDsetattr", evfile_luns[
f],
NULL,
True);
2382 return returnStatus;
2391 "Could not write Band 26 SI SDS "
2393 "\"corrected_counts_scales\".",
2394 "SDsetattr", evfile_luns[
f],
NULL,
True);
2395 return returnStatus;
2404 "Could not write Band 26 SI SDS "
2406 "\"corrected_counts_offsets\".",
2407 "SDsetattr", evfile_luns[
f],
NULL,
True);
2408 return returnStatus;
2413 (int32)strlen(counts_units), counts_units) ==
FAIL)
2417 "Could not write Band 26 SI SDS "
2419 "\"corrected_counts_units\".",
2420 "SDsetattr", evfile_luns[
f],
NULL,
True);
2421 return returnStatus;
2431 boolean skip_night_hi_res)
2483 char *location =
"Set_Unit_Range_Fillvalue";
2485 char *errmsgfmt =
"Could not write attribute \"%s\", "
2486 "type[%ld], sds_number[%ld].";
2493 typedef enum { RefSB_250_Data,
2497 Aggr_250_500_RefSB_Data,
2498 Aggr_250_1km_RefSB_Data,
2499 Aggr_500_1km_RefSB_Data,
2502 typedef enum { Aggr_250_500_RefSB_Samples,
2503 Aggr_250_1km_RefSB_Samples,
2504 Aggr_500_1km_RefSB_Samples,
2506 } ev_Aggr_Samples_t;
2509 int32 num_sds_ids[Num_Data_types] = {7, 7, 3};
2511 char *
units =
"none";
2512 uint16 SI_valid_range[2] = {0, 32767};
2513 uint8 UI_valid_range[2] = {0, 15};
2514 int8 SU_valid_range_X2[2] = {0, 6};
2515 int8 SU_valid_range_X4[2] = {0, 28};
2516 int8 *SU_valid_range[3];
2517 uint16 SI_fillvalue = 65535;
2518 uint8 UI_fillvalue = 255;
2519 int8 SU_fillvalue = -1;
2520 int32 SI_sds_ids[7];
2521 int32 UI_sds_ids[7];
2522 int32 SU_sds_ids[3];
2523 int32 *sds_ids[Num_Data_types];
2528 SU_valid_range[Aggr_250_500_RefSB_Samples] = SU_valid_range_X2;
2530 SU_valid_range[Aggr_250_1km_RefSB_Samples] = SU_valid_range_X4;
2532 SU_valid_range[Aggr_500_1km_RefSB_Samples] = SU_valid_range_X2;
2534 sds_ids[0] = SI_sds_ids;
2535 sds_ids[1] = UI_sds_ids;
2536 sds_ids[2] = SU_sds_ids;
2544 SI_sds_ids[Aggr_250_500_RefSB_Data] =
2546 SI_sds_ids[Aggr_250_1km_RefSB_Data] =
2548 SI_sds_ids[Aggr_500_1km_RefSB_Data] =
2551 UI_sds_ids[Aggr_250_500_RefSB_Data] =
2553 UI_sds_ids[Aggr_250_1km_RefSB_Data] =
2555 UI_sds_ids[Aggr_500_1km_RefSB_Data] =
2558 SU_sds_ids[Aggr_250_500_RefSB_Samples] =
2560 SU_sds_ids[Aggr_250_1km_RefSB_Samples] =
2562 SU_sds_ids[Aggr_500_1km_RefSB_Samples] =
2593 if (
type < SU && skip_night_hi_res ==
True)
2598 for (sds_number = start_output_res;
2599 sds_number < num_sds_ids[
type]; sds_number++)
2602 if (skip_night_hi_res ==
True)
2603 if ((
type < SU && sds_number == Aggr_250_500_RefSB_Data) ||
2604 (
type == SU && sds_number == Aggr_250_500_RefSB_Samples))
2607 if (SDsetattr(sds_ids[
type][sds_number],
"units",
2610 sprintf(errmsg, errmsgfmt,
"units", (
long)
type, (
long)sds_number);
2614 return returnStatus;
2621 if (SDsetattr(sds_ids[
type][sds_number],
"valid_range",
2622 DFNT_UINT16, 2, (VOIDP)SI_valid_range) ==
FAIL)
2624 sprintf(errmsg, errmsgfmt,
"valid_range", (
long)
type, (
long)sds_number);
2628 return returnStatus;
2631 if (SDsetattr(sds_ids[
type][sds_number],
"_FillValue",
2632 DFNT_UINT16, 1,(VOIDP)&SI_fillvalue) ==
FAIL)
2634 sprintf(errmsg, errmsgfmt,
"_FillValue", (
long)
type, (
long)sds_number);
2638 return returnStatus;
2644 if (SDsetattr(sds_ids[
type][sds_number],
"valid_range",
2645 DFNT_UINT8, 2, (VOIDP)UI_valid_range) ==
FAIL)
2647 sprintf(errmsg, errmsgfmt,
"valid_range", (
long)
type, (
long)sds_number);
2651 return returnStatus;
2654 if (SDsetattr(sds_ids[
type][sds_number],
"_FillValue",
2655 DFNT_UINT8, 1,(VOIDP)&UI_fillvalue) ==
FAIL)
2657 sprintf(errmsg, errmsgfmt,
"_FillValue", (
long)
type, (
long)sds_number);
2661 return returnStatus;
2667 if (SDsetattr(sds_ids[
type][sds_number],
"valid_range",
2669 (VOIDP)SU_valid_range[sds_number]) ==
FAIL)
2671 sprintf(errmsg, errmsgfmt,
"valid_range", (
long)
type, (
long)sds_number);
2675 return returnStatus;
2678 if (SDsetattr(sds_ids[
type][sds_number],
"_FillValue",
2679 DFNT_INT8, 1,(VOIDP)&SU_fillvalue) ==
FAIL)
2681 sprintf(errmsg, errmsgfmt,
"_FillValue", (
long)
type, (
long)sds_number);
2685 return returnStatus;
2692 "Invalid \"type\" ... must be code bug.",
2694 return returnStatus;
2701 #ifdef WRITE_BAND_26_SDS
2711 strcpy(errmsg,
"Could not write Band 26 SI SDS "
2712 "attribute \"units\".");
2716 return returnStatus;
2719 DFNT_UINT16, 2, (VOIDP)SI_valid_range) ==
FAIL)
2721 strcpy(errmsg,
"Could not write Band 26 SI SDS "
2722 "attribute \"valid_range\".");
2726 return returnStatus;
2729 DFNT_UINT16, 1,(VOIDP)&SI_fillvalue) ==
FAIL)
2731 strcpy(errmsg,
"Could not write Band 26 SI SDS "
2732 "attribute \"_FillValue\".");
2736 return returnStatus;
2744 strcpy(errmsg,
"Could not write Band 26 UI SDS "
2745 "attribute \"units\".");
2749 return returnStatus;
2752 DFNT_UINT8, 2, (VOIDP)UI_valid_range) ==
FAIL)
2754 strcpy(errmsg,
"Could not write Band 26 UI SDS "
2755 "attribute \"valid_range\".");
2759 return returnStatus;
2762 DFNT_UINT8, 1,(VOIDP)&UI_fillvalue) ==
FAIL)
2764 strcpy(errmsg,
"Could not write Band 26 UI SDS "
2765 "attribute \"_FillValue\".");
2769 return returnStatus;
2920 char *location =
"Set_SDS_Attributes";
2921 char *errmsgfmt =
"Could not write attribute \"%s\" for R = %ld";
2929 } ScaleOffset_Kind_t;
2932 int32 dim_size[4] = {2, 5, 15, 16};
2934 for (
R = 0;
R < num_sds;
R++)
2936 if (SDsetattr(sds_id[
R],
"band_names",DFNT_CHAR8,
2937 (int32)strlen(BandNames[
R]), BandNames[
R]) ==
FAIL)
2940 sprintf(errmsg, errmsgfmt,
"band_names", (
long)
R);
2943 return returnStatus;
2947 dim_size[
R],
scale[radiance * sds_dim +
R]) ==
FAIL)
2950 sprintf(errmsg, errmsgfmt,
"radiance_scales", (
long)
R);
2953 return returnStatus;
2960 sprintf(errmsg, errmsgfmt,
"radiance_offsets", (
long)
R);
2963 return returnStatus;
2966 if (SDsetattr(sds_id[
R],
"radiance_units",DFNT_CHAR8,
2967 (int32)strlen(rad_units), rad_units) ==
FAIL)
2970 sprintf(errmsg, errmsgfmt,
"radiance_units", (
long)
R);
2973 return returnStatus;
2979 dim_size[
R],
scale[reflectance * sds_dim +
R])
2983 sprintf(errmsg, errmsgfmt,
"reflectance_scales", (
long)
R);
2986 return returnStatus;
2990 dim_size[
R],
offset[reflectance * sds_dim +
R])
2994 sprintf(errmsg, errmsgfmt,
"reflectance_offsets", (
long)
R);
2997 return returnStatus;
3000 if (SDsetattr(sds_id[
R],
"reflectance_units",DFNT_CHAR8,
3001 (int32)strlen(refl_units),refl_units) ==
FAIL)
3004 sprintf(errmsg, errmsgfmt,
"reflectance_units", (
long)
R);
3007 return returnStatus;
3010 if (SDsetattr(sds_id[
R],
"corrected_counts_scales",
DFNT_FLOAT32,
3014 sprintf(errmsg, errmsgfmt,
"corrected_counts_scales", (
long)
R);
3017 return returnStatus;
3020 if (SDsetattr(sds_id[
R],
"corrected_counts_offsets",
DFNT_FLOAT32,
3024 sprintf(errmsg, errmsgfmt,
"corrected_counts_offsets", (
long)
R);
3027 return returnStatus;
3030 if (SDsetattr(sds_id[
R],
"corrected_counts_units",DFNT_CHAR8,
3031 (int32)strlen(counts_units),counts_units) ==
FAIL)
3034 sprintf(errmsg, errmsgfmt,
"corrected_counts_units", (
long)
R);
3037 return returnStatus;
3047 boolean skip_night_hi_res)
3115 PGSt_SMF_status returnStatus;
3116 char *location =
"Create_Band_Subsetting_SDS";
3124 float32 data_250m[2] = {1, 2};
3125 float32 data_500m[5] = {3, 4, 5, 6, 7};
3126 float32 data_1km_refl[15] = {8, 9, 10, 11, 12, 13, 13.5, 14, 14.5, 15,
3127 16, 17, 18, 19, 26};
3128 float32 data_1km_emiss[16] = {20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31,
3129 32, 33, 34, 35, 36};
3133 "250M Band Numbers for Subsetting",
3134 "500M Band Numbers for Subsetting",
3135 "1KM Reflective Solar Band Numbers for Subsetting",
3136 "1KM Emissive Band Numbers for Subsetting"
3146 data[0] = data_250m;
3147 data[1] = data_500m;
3148 data[2] = data_1km_refl;
3149 data[3] = data_1km_emiss;
3156 if (skip_night_hi_res ==
True)
3168 for (
R = 0;
R < num_sds;
R++)
3174 "float32",
data[
R]);
3178 "write_sds_rank1", evfile_luns[
f],
NULL,
True);
3179 return returnStatus;
3182 sds_index = SDnametoindex(L1B_Gran->
sd_id[
f],
3184 if(sds_index ==
FAIL)
3186 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3190 "SDnametoindex", evfile_luns[
f],
NULL,
True);
3191 return returnStatus;
3194 sds_id = SDselect(L1B_Gran->
sd_id[
f], sds_index);
3197 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3201 "SDselect", evfile_luns[
f],
NULL,
True);
3202 return returnStatus;
3205 if(SDsetattr(sds_id,
"long_name", DFNT_CHAR8,
3206 (int32)strlen(SDS_LongName[
R]),
3207 (VOIDP)SDS_LongName[
R]) ==
FAIL)
3210 "Could not write long_name attribute for SDS \"%s\".",
3214 "SDsetattr", evfile_luns[
f],
NULL,
True);
3215 return returnStatus;
3218 hdf_return = SDendaccess(sds_id);
3219 if (hdf_return ==
FAIL)
3221 sprintf(errmsg,
"Could not end access to SDS \"%s\".",
3225 "SDendaccess", evfile_luns[
f],
NULL,
True);
3226 return returnStatus;
3235 boolean skip_night_hi_res)
3312 char *location =
"Copy_Geo_SDS";
3315 int32 geo_sd_id = 0;
3318 int32 geo_sds_index = 0;
3319 int32 geo_sds_id = 0;
3320 int32 geo_attr_index = 0;
3321 int32 L1B_sds_index = 0;
3322 int32 L1B_sds_id = 0;
3325 int32
start[2] = {0, 0};
3326 int32 edge[2] = {0, 0};
3327 intn hdf_return =
FAIL;
3336 char *attr_name =
NULL;
3337 char *attr_value =
NULL;
3339 #define MAX_ATTR_NAME_SIZE 26
3340 #define MAX_ATTR_BUFFER_SIZE 72
3345 int32 attr_data_type = 0;
3346 int32 attr_count = 0;
3353 #define COPY_ATTR(attr_name) \
3354 geo_attr_index = SDfindattr(geo_sds_id, attr_name); \
3355 if (geo_attr_index == FAIL) \
3357 sprintf(errmsg, "Could not get attribute index for \"%s\".", \
3359 returnStatus = MODIS_F_READ_ERROR; \
3360 L1BErrorMsg(location, returnStatus, errmsg, \
3361 "SDfindattr", GEOLOCATION_FILE, NULL, True); \
3362 return returnStatus; \
3364 hdf_return = SDattrinfo(geo_sds_id, geo_attr_index, attr_name_buffer, \
3365 &attr_data_type, &attr_count); \
3366 if (hdf_return == FAIL) \
3368 sprintf(errmsg, "Could not get attribute info for \"%s\".", \
3370 returnStatus = MODIS_F_HDF_ERROR; \
3371 L1BErrorMsg(location, returnStatus, errmsg, \
3372 "SDattrinfo", GEOLOCATION_FILE, NULL, True); \
3373 return returnStatus; \
3375 hdf_return = SDreadattr(geo_sds_id, geo_attr_index, \
3376 (void *)attr_buffer); \
3377 if (hdf_return == FAIL) \
3379 sprintf(errmsg, "Could not read attribute \"%s\".", attr_name); \
3380 returnStatus = MODIS_F_READ_ERROR; \
3381 L1BErrorMsg(location, returnStatus, errmsg, \
3382 "SDreadattr", GEOLOCATION_FILE, NULL, True); \
3383 return returnStatus; \
3385 hdf_return = SDsetattr(L1B_sds_id, attr_name, attr_data_type, \
3386 attr_count, (void *)attr_buffer); \
3387 if (hdf_return == FAIL) \
3389 sprintf(errmsg, "Could not write attribute \"%s\".", attr_name); \
3390 returnStatus = MODIS_F_WRITE_ERROR; \
3391 L1BErrorMsg(location, returnStatus, errmsg, \
3392 "SDsetattr", evfile_luns[i], NULL, True); \
3393 return returnStatus; \
3404 "Could not retrieve file name from PCF.",
3406 return returnStatus;
3411 geo_sd_id = SDstart(fname, DFACC_RDONLY);
3412 if (geo_sd_id ==
FAIL)
3416 "Could not open file for SD read access.",
3418 "The file may be missing, corrupted or "
3419 "not an HDF-4 file.",
True);
3420 return returnStatus;
3428 if (skip_night_hi_res ==
False)
3435 geo_sds_index = SDnametoindex(geo_sd_id,
GEO_SDS[isds].src_name);
3436 if (geo_sds_index ==
FAIL)
3438 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3443 return returnStatus;
3446 geo_sds_id = SDselect(geo_sd_id, geo_sds_index);
3447 if (geo_sds_id ==
FAIL)
3449 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3454 return returnStatus;
3457 hdf_return = SDreaddata(geo_sds_id,
start,
NULL, edge,
3459 if (hdf_return ==
FAIL)
3461 sprintf(errmsg,
"Could not read data for SDS \"%s\".",
3466 return returnStatus;
3471 L1B_sds_index = SDnametoindex(L1B_Gran->
sd_id[
i],
3473 if (L1B_sds_index ==
FAIL)
3475 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3479 "SDnametoindex", evfile_luns[
i],
NULL,
True);
3480 return returnStatus;
3483 L1B_sds_id = SDselect(L1B_Gran->
sd_id[
i], L1B_sds_index);
3484 if (L1B_sds_id ==
FAIL)
3486 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3490 "SDselect", evfile_luns[
i],
NULL,
True);
3491 return returnStatus;
3494 hdf_return = SDwritedata(L1B_sds_id,
start,
3495 NULL, edge, (
void *)buffer);
3496 if (hdf_return ==
FAIL)
3498 sprintf(errmsg,
"Could not write SDS \"%s\".",
3502 "SDwritedata", evfile_luns[
i],
NULL,
True);
3503 return returnStatus;
3512 hdf_return = SDendaccess(L1B_sds_id);
3513 if (hdf_return ==
FAIL)
3515 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3519 "SDendaccess", evfile_luns[
i],
NULL,
True);
3520 return returnStatus;
3527 hdf_return = SDendaccess(geo_sds_id);
3528 if (hdf_return ==
FAIL)
3530 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3535 return returnStatus;
3552 geo_sds_index = SDnametoindex(geo_sd_id,
GEO_SDS[isds].src_name);
3553 if (geo_sds_index ==
FAIL)
3555 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3560 return returnStatus;
3563 geo_sds_id = SDselect(geo_sd_id, geo_sds_index);
3564 if (geo_sds_id ==
FAIL)
3566 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3571 return returnStatus;
3578 if (L1B_sds_index ==
FAIL)
3580 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3585 return returnStatus;
3589 if (L1B_sds_id ==
FAIL)
3591 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3596 return returnStatus;
3601 hdf_return = SDreaddata(geo_sds_id, geo_start, geo_stride,
3602 edge, (
void *)buffer);
3603 if (hdf_return ==
FAIL)
3605 sprintf(errmsg,
"Could not read data for SDS \"%s\".",
3610 return returnStatus;
3615 hdf_return = SDwritedata(L1B_sds_id,
start,
NULL, edge, (
void *)buffer);
3616 if (hdf_return ==
FAIL)
3618 sprintf(errmsg,
"Could not write SDS \"%s\".",
GEO_SDS[isds].
name);
3622 return returnStatus;
3645 hdf_return = SDsetattr(L1B_sds_id,
"line_numbers", DFNT_CHAR8,
3646 (int32)strlen(
"3,8"), (VOIDP)
"3,8");
3647 if (hdf_return ==
FAIL)
3649 sprintf(errmsg,
"Could not write attribute \"line_numbers\" "
3655 return returnStatus;
3658 hdf_return = SDsetattr(L1B_sds_id,
"frame_numbers", DFNT_CHAR8,
3659 (int32)strlen(
"3,8,13,..."),
3660 (VOIDP)
"3,8,13,...");
3661 if (hdf_return ==
FAIL)
3663 sprintf(errmsg,
"Could not write attribute \"frame_numbers\" "
3670 return returnStatus;
3677 for (
i = 0;
i < 5;
i++)
3681 case 0: attr_name =
"Bit 7(MSB)";
3682 attr_value =
"1 = invalid input data";
3684 case 1: attr_name =
"Bit 6";
3685 attr_value =
"1 = no ellipsoid intersection";
3687 case 2: attr_name =
"Bit 5";
3688 attr_value =
"1 = no valid terrain data";
3690 case 3: attr_name =
"Bit 4";
3691 attr_value =
"1 = DEM missing or of inferior quality";
3693 case 4: attr_name =
"Bit 3";
3694 attr_value =
"1 = invalid sensor range";
3696 hdf_return = SDsetattr(L1B_sds_id, attr_name, DFNT_CHAR8,
3697 (int32)strlen(attr_value), attr_value);
3698 if (hdf_return ==
FAIL)
3701 "Could not write attribute \"%s\" to SDS \"%s\".",
3706 return returnStatus;
3713 hdf_return = SDendaccess(geo_sds_id);
3714 if (hdf_return ==
FAIL)
3716 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3721 return returnStatus;
3726 hdf_return = SDendaccess(L1B_sds_id);
3727 if (hdf_return ==
FAIL)
3729 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3734 return returnStatus;
3741 hdf_return = SDend(geo_sd_id);
3742 if (hdf_return ==
FAIL)
3747 "Memory or the disk file must have become corrupted.",
3749 return returnStatus;
3842 PGSt_SMF_status returnStatus;
3853 float32 *f32_buffer;
3855 int32 buf_index = 0;
3856 float32 *SD_Sun_zenith;
3857 SD_Sun_zenith = (float32*) malloc(
MAX_NUM_SCANS *
sizeof(float32));
3858 float32 *SD_Sun_Azimuth;
3859 SD_Sun_Azimuth = (float32*) malloc(
MAX_NUM_SCANS *
sizeof(float32));
3861 char *location =
"Scan_Meta_Cal";
3862 char upper_bound_str[20];
3864 Attitude_Angles_t *Attitude_Angles;
3865 Attitude_Angles = (Attitude_Angles_t*) malloc(
MAX_NUM_SCANS *
sizeof(Attitude_Angles_t));
3866 float32 rtod = 180.0/
PGS_PI;
3870 SCAN_SECTOR_ROTATION,
3902 } temp[NUM_FIELD] = {
3908 {
"Command Parameters",
"SET_FR_ENC_DELTA", {0} },
3909 {
"Telemetry Major Cycle 4A of 7",
"CR_PCLWA_ECAL_ON", {0} },
3910 {
"Telemetry Major Cycle 4A of 7",
"CR_PCLWB_ECAL_ON", {0} },
3911 {
"Telemetry Major Cycle 4B of 7",
"CR_PVVISA_ECALON", {0} },
3912 {
"Telemetry Major Cycle 4B of 7",
"CR_PVVISB_ECALON", {0} },
3913 {
"Telemetry Major Cycle 4B of 7",
"CR_PVNIRA_ECALON", {0} },
3914 {
"Telemetry Major Cycle 4B of 7",
"CR_PVNIRB_ECALON", {0} },
3915 {
"Telemetry Major Cycle 4B of 7",
"CR_PVSMA_ECAL_ON", {0} },
3916 {
"Telemetry Major Cycle 4B of 7",
"CR_PVSMB_ECAL_ON", {0} },
3917 {
"Telemetry Major Cycle 4A of 7",
"CR_PVLWA_ECAL_ON", {0} },
3918 {
"Telemetry Major Cycle 4A of 7",
"CR_PVLWB_ECAL_ON", {0} },
3919 {
"Telemetry Major Cycle 5B of 7",
"CR_SM_SDSM_A_ON", {0} },
3920 {
"Telemetry Major Cycle 5B of 7",
"CR_SM_SDSM_B_ON", {0} },
3921 {
"Telemetry Major Cycle 5A of 7",
"CR_RC_CSHTR_ON", {0} },
3922 {
"Telemetry Major Cycle 5A of 7",
"CR_RC_ISHTR_ON", {0} },
3923 {
"Telemetry Major Cycle 5A of 7",
"CR_RC_OSHTR_ON", {0} },
3924 {
"Telemetry Major Cycle 0 of 7",
"CR_BB_A_PWR_ON", {0} },
3925 {
"Telemetry Major Cycle 0 of 7",
"CR_BB_B_PWR_ON", {0} },
3926 {
"Telemetry Major Cycle 3A of 7",
"CR_DR_SDD_OPEN", {0} },
3927 {
"Telemetry Major Cycle 3A of 7",
"CR_DR_SDS_OPEN", {0} },
3928 {
"Telemetry Major Cycle 1 of 7",
"SS_FR_SCIABNORM", {0} },
3929 {
"Telemetry Major Cycle 3A of 7",
"CR_DR_NAD_CLSD", {0} },
3930 {
"Telemetry Major Cycle All Part 3",
"SS_CP_MACRO_ID", {0} },
3931 {
"Telemetry Major Cycle 4A of 7" ,
"CR_PCLW_A_ON", {0} },
3932 {
"Telemetry Major Cycle 4A of 7" ,
"CR_PCLW_B_ON", {0} }
3947 #define NADIR_FRAME_GEO_VALS(geoname,var,scalefactor,buf) \
3948 returnStatus = read_sds_rank2(geo_sd_id, geoname, \
3949 10 * L1A_Gran->num_scans, \
3950 EV_1km_FRAMES, buf); \
3951 if (returnStatus != MODIS_S_OK) \
3953 L1BErrorMsg(location, returnStatus, NULL, \
3954 "read_sds_rank2", GEOLOCATION_FILE, NULL, True); \
3955 return returnStatus; \
3957 for (S = 0; S < L1A_Gran->num_scans; S++) { \
3958 buf_index = (S * 10 + 4) * EV_1km_FRAMES + NADIR_1km_FRAME_NUM - 1; \
3959 var[S] = buf[buf_index] * scalefactor; \
3962 for (
i = SCAN_SECTOR_ROTATION;
i < NUM_FIELD;
i++)
3969 (VOIDP)temp[
i].buffer);
3974 return returnStatus;
3978 strcpy(upper_bound_str,
"31");
3979 else if (
i == SCAN_SECTOR_ROTATION)
3980 strcpy(upper_bound_str,
"16383");
3982 strcpy(upper_bound_str,
"1");
3987 (
void *) temp[
i].buffer);
3992 return returnStatus;
4007 for (S = 0; S < L1A_Gran->
num_scans; S++)
4009 if (temp[MACRO_ID].buffer[S] == 15 ||
4010 temp[MACRO_ID].buffer[S] == 16 ||
4011 temp[MACRO_ID].buffer[S] == 17)
4013 else if (temp[MACRO_ID].buffer[S] == 18 ||
4014 temp[MACRO_ID].buffer[S] == 19 ||
4015 temp[MACRO_ID].buffer[S] == 20 ||
4016 temp[MACRO_ID].buffer[S] == 21)
4018 else if (temp[MACRO_ID].buffer[S] == 22 ||
4019 temp[MACRO_ID].buffer[S] == 23 ||
4020 temp[MACRO_ID].buffer[S] == 24)
4033 "Could not retrieve file name from PCF.",
4035 return returnStatus;
4040 geo_sd_id = SDstart(fname, DFACC_RDONLY);
4041 if (geo_sd_id ==
FAIL)
4045 "Could not open file for SD read access.",
4047 "The file may be missing, corrupted or "
4048 "not an HDF-4 file.",
True);
4049 return returnStatus;
4060 return returnStatus;
4063 for (S = 0; S < L1A_Gran->
num_scans; S++)
4077 if (
fabs((
double) (Attitude_Angles[S][0]))*rtod >
4078 tables->QA.common_QA_tables.roll_threshold_angle ||
4079 fabs((
double) (Attitude_Angles[S][1]))*rtod >
4080 tables->QA.common_QA_tables.pitch_threshold_angle ||
4081 fabs((
double) (Attitude_Angles[S][2]))*rtod >
4082 tables->QA.common_QA_tables.yaw_threshold_angle )
4088 if ( temp[SCAN_SECTOR_ROTATION].buffer[S])
4097 if ( temp[PCLW_ADC_PRI].buffer[S] == 1 && temp[PCLW_ADC_RED].buffer[S] == 1)
4108 if (temp[PC_LW_A].buffer[S] || temp[PC_LW_B].buffer[S])
4113 if (temp[PV_VIS_A].buffer[S] || temp[PV_VIS_B].buffer[S]
4114 || temp[PV_NIR_A].buffer[S] || temp[PV_NIR_B].buffer[S]
4115 || temp[PV_SW_A].buffer[S] || temp[PV_SW_B].buffer[S]
4116 || temp[PV_LW_A].buffer[S] || temp[PV_LW_B].buffer[S])
4121 if (temp[SD_DOOR].buffer[S] == 1)
4126 if (temp[SD_SCREEN].buffer[S] == 0)
4134 if (temp[NAD_DOOR].buffer[S] == 0)
4147 if (temp[SDSM_A].buffer[S] || temp[SDSM_B].buffer[S])
4152 if (temp[RC_CSH].buffer[S] || temp[RC_ISH].buffer[S]
4153 || temp[RC_OSH].buffer[S])
4171 if (temp[BB_HEATER_A].buffer[S] || temp[BB_HEATER_B].buffer[S])
4186 if (SRCA_mode[S] == 2 || SRCA_mode[S] == 3 || SRCA_mode[S] == -1)
4188 if (SRCA_mode[S] == 1 || SRCA_mode[S] == 3 || SRCA_mode[S] == -1)
4223 if (temp[SCI_ABNORM].buffer[S] == 0)
4238 for (S = 0; S < L1A_Gran->
num_scans; S++)
4256 return returnStatus;
4265 return returnStatus;
4282 for (S = 0; S < L1A_Gran->
num_scans; S++)
4284 Z_MODIS = - 0.34582 * sin((
double)SD_Sun_zenith[S]) *
4285 cos((
double)SD_Sun_Azimuth[S]) +
4286 0.923830 * cos((
double)SD_Sun_zenith[S]);
4290 if (Z_MODIS > 0 && strcmp(L1A_Gran->
ScanType[S],
"Day") == 0)
4310 if (SDend(geo_sd_id) ==
FAIL)
4315 "Memory or the disk file must have become corrupted.",
4317 return returnStatus;
4323 free(SD_Sun_zenith);
4324 free(SD_Sun_Azimuth);
4325 free(Attitude_Angles);
4379 PGSt_SMF_status returnStatus;
4380 int32 S, B, B_emiss, D, D_1km, num_scans;
4386 DCR_offset_t *DCR_offset;
4387 DCR_offset = (DCR_offset_t*) malloc(
MAX_NUM_SCANS *
sizeof(DCR_offset_t));
4389 XDCR_offset_t *XDCR_offset;
4390 XDCR_offset = (XDCR_offset_t*) malloc((
MAX_NUM_SCANS + 1) *
sizeof(XDCR_offset_t));
4392 char file_name[PGSd_PC_FILE_PATH_MAX];
4393 char *location =
"Calculate_DCR_Change";
4400 if (returnStatus != PGS_S_SUCCESS)
4404 "Could not retrieve file name from PCF.",
4406 return returnStatus;
4411 file_id = SDstart(file_name, DFACC_RDONLY);
4412 if (file_id ==
FAIL)
4416 "Could not open file for SD read access.",
4418 "The file may be missing, corrupted or "
4419 "not an HDF-4 file.",
True);
4420 return returnStatus;
4428 "Could not read Number of Scans.",
4431 return returnStatus;
4440 Leading_DCR_offset);
4444 "Could not read fpa_dcr_offset.",
4447 return returnStatus;
4450 if (SDend(file_id) ==
FAIL)
4455 "Memory or the disk file must have become "
4456 "corrupted.",
True);
4457 return returnStatus;
4470 "Could not read fpa_dcr_offset.",
4473 return returnStatus;
4483 XDCR_offset[0][DCR_550] = Leading_DCR_offset[DCR_550];
4487 XDCR_offset[0][DCR_550] = DCR_offset[0][DCR_550];
4490 for(S = 0; S < L1A_Gran->
num_scans; S++) {
4492 XDCR_offset[S+1][DCR_550] = DCR_offset[S][DCR_550];
4495 for(S = 0; S < L1A_Gran->
num_scans; S++)
4506 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4522 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4536 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4554 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4568 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4581 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550] &&
4582 XDCR_offset[S+1][DCR_550 + 1] == XDCR_offset[S][DCR_550 + 1])
4605 return(returnStatus);
4720 #ifdef WRITE_BAND_26_SDS
4751 for (S = 0; S < L1B_Gran->
num_scans; S++)
4770 #ifdef WRITE_BAND_26_SDS
4804 boolean skip_night_hi_res)
4880 char *location =
"Write_L1B_ScanMeta";
4885 int16 num_fields = 14;
4889 int32 scan_number = 0;
4890 int32 complete_scan_flag = 0;
4891 char8 scan_type[4] = {
' ',
' ',
' ',
' '};
4892 int32 mirror_side = 0;
4893 int32 EV_frames = 0;
4894 int32 nadir_frame = 0;
4895 float32 nadir_frame_latitude = 0;
4896 float32 nadir_frame_longitude = 0;
4897 float32 nadir_frame_solar_azimuth = 0;
4898 float32 nadir_frame_solar_zenith = 0;
4899 int32 BB_thermistor_outliers = 0;
4900 uint32 bit_QA_flags = 0;
4902 float32 sector_rotation_angle;
4907 char file_name[512];
4908 struct {
char *
name; int32
type; int32 order; } vd_field[14] =
4912 {
"Scan Type" , DFNT_CHAR8 , 4},
4914 {
"EV Sector Start Time" , DFNT_FLOAT64, 1},
4921 {
"No. OBC BB thermistor outliers" ,
DFNT_INT32 , 1},
4922 {
"Bit QA Flags" , DFNT_UINT32 , 1},
4933 #define PACK_MEMBER(member, buffer_ptr) \
4934 memcpy(buffer_ptr, (void *)&member, sizeof(member)); \
4935 buffer_ptr += sizeof(member)
4937 if (skip_night_hi_res ==
True)
4947 if ((vd_id = VSattach(L1B_Scan_Meta->
v_id[
f],-1,
"w")) ==
FAIL)
4951 "Could not attach to vdata for writing Level "
4952 "1B Swath Metadata",
4953 "VSattach", evfile_luns[
f],
NULL,
True);
4954 return returnStatus;
4959 if (VSsetname(vd_id,
"Level 1B Swath Metadata") ==
FAIL)
4963 "Could not create vdata name for writing "
4964 "Level 1B Swath Metadata",
4965 "VSsetname", evfile_luns[
f],
NULL,
True);
4966 return returnStatus;
4972 for (
i = 0;
i < num_fields;
i++)
4974 if (VSfdefine(vd_id,
4977 vd_field[
i].order) ==
FAIL)
4980 if (vd_field[
i].
name)
4982 "Could not define vdata field for \"%s\".",
4985 strcpy(errmsg,
"Could not define vdata field -- name is NULL.");
4988 "VSfdefine", evfile_luns[
f],
NULL,
True);
4989 return returnStatus;
4993 list_len += strlen(vd_field[
i].
name);
4997 list = (
char *)malloc((list_len + num_fields + 1) *
sizeof(char));
5002 return returnStatus;
5011 for (
i = 0;
i < num_fields - 1;
i++)
5023 if (VSsetfields(vd_id,
list) ==
FAIL)
5027 "VSsetfields", evfile_luns[
f],
NULL,
True);
5028 return returnStatus;
5059 "Command Parameters",
5061 (VOIDP)sector_rotation_dn);
5066 return returnStatus;
5074 (
void *) sector_rotation_dn);
5080 return returnStatus;
5083 for (S = 0; S < L1B_Scan_Meta->
num_scans; S++)
5085 buffer_ptr = buffer;
5087 scan_number = S + 1;
5091 complete_scan_flag = 0;
5093 complete_scan_flag = 1;
5100 else if (strcmp(L1B_Scan_Meta->
ScanType[S],
"Night") ==
SAME)
5104 memcpy(buffer_ptr, (
void *)scan_type,
sizeof(scan_type));
5105 buffer_ptr +=
sizeof(scan_type);
5121 nadir_frame_latitude =
5125 nadir_frame_longitude =
5129 nadir_frame_solar_azimuth =
5131 PACK_MEMBER(nadir_frame_solar_azimuth, buffer_ptr);
5133 nadir_frame_solar_zenith =
5135 PACK_MEMBER(nadir_frame_solar_zenith, buffer_ptr);
5137 BB_thermistor_outliers =
5145 sector_rotation_angle =
5146 (180.0/8192.0)*(float32)sector_rotation_dn[S];
5150 (
unsigned char *)buffer,
5152 FULL_INTERLACE) ==
FAIL)
5157 return returnStatus;
5173 if (returnStatus != PGS_S_SUCCESS)
5177 "Could not retrieve file name from PCF.",
5179 return returnStatus;
5187 obc_file_id = SDstart (file_name, DFACC_RDWR);
5188 if (obc_file_id ==
FAIL)
5192 "Could not open file for SD read/write access.",
5194 "The file may be missing, corrupted or "
5195 "not an HDF-4 file.",
True);
5196 return returnStatus;
5213 return returnStatus;
5220 hdf_return = SDend(obc_file_id);
5221 if (hdf_return ==
FAIL)
5225 "Memory or the disk file must have become corrupted.",
5227 return returnStatus;
5280 char *location =
"Determine_Other_Missing_Scans";
5292 "Determine_Split_Scans", 0,
NULL,
True);
5296 for (S = 0; S < L1A_Gran->
num_scans; S++)
5297 split_scan[S] =
False;
5306 for (S = 0; S < L1A_Gran->
num_scans; S++) {
5312 bad_scan_quality[S] =
True;
5314 bad_scan_quality[S] =
False;
5319 for (S = 0; S < L1A_Gran->
num_scans; S++)
5320 bad_scan_quality[S] =
False;
5327 for (S = 0; S < L1A_Gran->
num_scans; S++)
5329 if (split_scan[S] || bad_scan_quality[S])
5343 for (S = 0; S < L1A_Gran->
num_scans; S++)
5354 boolean *split_scan)
5432 #define SCAN_INTERVAL 1.4771
5433 PGSt_SMF_status returnStatus;
5439 char *location =
"Determine_Split_Scans";
5450 (
void *)SD_start_time);
5454 "Could not read SD start time.",
5457 return returnStatus;
5491 "Get_Split_Scan_Indexes", 0,
NULL,
False);
5495 if (S_split_1 >= 0 && S_split_1 < L1A_Gran->num_scans)
5496 split_scan[S_split_1] =
True;
5497 if (S_split_2 >= 0 && S_split_2 < L1A_Gran->num_scans)
5498 split_scan[S_split_2] =
True;
5509 int16 mirror_side[],
5510 int32 scan_quality[]
5561 int32 S, S_begin, S_end;
5562 int32 num_invalid_ms, n, max_n;
5563 char *location =
"Get_Split_Scan_Indexes";
5569 if (S1 < 0 || S1 >= num_scans || num_scans <= 0)
5573 "Input error in S1 or num_scans:\nS1 = %ld\nnum_scans = %ld\n",
5574 (
long)S1, (
long)num_scans);
5594 if (S_begin < 0) S_begin = 0;
5596 if (S_end >= num_scans) S_end = num_scans - 1;
5603 for (S = S_begin; S <= S_end; S++) {
5604 if (!(mirror_side[S] == 0 || mirror_side[S] == 1))
5614 if (num_invalid_ms == 0) {
5615 for (S = S_begin; S < S_end; S++) {
5616 if (mirror_side[S] == mirror_side[S+1]) {
5625 for (S = S_begin; S < S_end; S++) {
5627 if (scan_quality[S][1] > 0)
5628 n+= scan_quality[S][1];
5629 if (scan_quality[S+1][1] > 0)
5630 n+= scan_quality[S+1][1];
5633 if (scan_quality[S][0] == 0) {
5637 else if (scan_quality[S+1][0] == 0) {
5660 boolean skip_night_hi_res)
5716 PGSt_SMF_status returnStatus;
5717 char *units_attr_value =
"percent";
5718 char *location =
"Set_UI_ConvertToPercent_Attrs";
5720 #define REFL_250M_START_INDEX 0
5721 #define REFL_500M_START_INDEX 2
5722 #define REFL_1000M_START_INDEX 7
5723 #define REFL_BAND26_START_INDEX 21
5732 #define SET_UI_SDS_CONV_ATTRS(sds_id, spec_uncert, scale_factor, indx, \
5734 if (SDsetattr(sds_id, "specified_uncertainty", DFNT_FLOAT32, \
5735 numval, &(spec_uncert[indx])) == FAIL) { \
5736 returnStatus = MODIS_F_WRITE_ERROR; \
5737 L1BErrorMsg(location, returnStatus, \
5738 "Could not write UI SDS attribute" \
5739 "\"specified_uncertainty\".", \
5740 "SDsetattr", lun, NULL, True); \
5741 return returnStatus; \
5743 if (SDsetattr(sds_id, "scaling_factor", DFNT_FLOAT32, \
5744 numval, &(scale_factor[indx])) == FAIL) { \
5745 returnStatus = MODIS_F_WRITE_ERROR; \
5746 L1BErrorMsg(location, returnStatus, \
5747 "Could not write UI SDS attribute \"scaling_factor\".", \
5748 "SDsetattr", lun, NULL, True); \
5749 return returnStatus; \
5751 if (SDsetattr(sds_id, "uncertainty_units", DFNT_CHAR8, \
5752 (int32)strlen(units_attr_value), units_attr_value) == FAIL) { \
5753 returnStatus = MODIS_F_WRITE_ERROR; \
5754 L1BErrorMsg(location, returnStatus, \
5755 "Could not write UI SDS attribute \"uncertainty_units\".", \
5756 "SDsetattr", lun, NULL, True); \
5757 return returnStatus; \
5760 if (skip_night_hi_res ==
False)
5763 tables->refl.RSB_specified_uncertainty,
5764 tables->refl.RSB_UI_scaling_factor,
5769 tables->refl.RSB_specified_uncertainty,
5770 tables->refl.RSB_UI_scaling_factor,
5775 tables->refl.RSB_specified_uncertainty,
5776 tables->refl.RSB_UI_scaling_factor,
5782 tables->refl.RSB_specified_uncertainty,
5783 tables->refl.RSB_UI_scaling_factor,
5788 tables->emiss.TEB_specified_uncertainty,
5789 tables->emiss.TEB_UI_scaling_factor,
5794 tables->refl.RSB_specified_uncertainty,
5795 tables->refl.RSB_UI_scaling_factor,
5800 tables->refl.RSB_specified_uncertainty,
5801 tables->refl.RSB_UI_scaling_factor,
5806 #ifdef WRITE_BAND_26_SDS
5809 tables->refl.RSB_specified_uncertainty,
5810 tables->refl.RSB_UI_scaling_factor,
5821 (float32 *original_correction,
5822 float32 *scaled_correction,
5863 float32 scale_factor = 1.;
5869 scaled_correction[D] = scale_factor*original_correction[D];
5871 return returnStatus;