82 "EV_250m",
"EV_500m",
"EV_1km_day",
"EV_1km_night"
108 "EV_250_RefSB",
"EV_250_RefSB_Uncert_Indexes",
109 "EV_500_RefSB",
"EV_500_RefSB_Uncert_Indexes",
110 "EV_1KM_RefSB",
"EV_1KM_RefSB_Uncert_Indexes",
111 "EV_1KM_Emissive",
"EV_1KM_Emissive_Uncert_Indexes",
112 "EV_250_Aggr500_RefSB",
"EV_250_Aggr500_RefSB_Uncert_Indexes",
113 "EV_250_Aggr500_RefSB_Samples_Used",
114 "EV_250_Aggr1km_RefSB",
"EV_250_Aggr1km_RefSB_Uncert_Indexes",
115 "EV_250_Aggr1km_RefSB_Samples_Used",
116 "EV_500_Aggr1km_RefSB",
"EV_500_Aggr1km_RefSB_Uncert_Indexes",
117 "EV_500_Aggr1km_RefSB_Samples_Used"
122 "Earth View 250M Reflective Solar Bands Scaled Integers",
123 "Earth View 250M Reflective Solar Bands Uncertainty Indexes",
124 "Earth View 500M Reflective Solar Bands Scaled Integers",
125 "Earth View 500M Reflective Solar Bands Uncertainty Indexes",
126 "Earth View 1KM Reflective Solar Bands Scaled Integers",
127 "Earth View 1KM Reflective Solar Bands Uncertainty Indexes",
128 "Earth View 1KM Emissive Bands Scaled Integers",
129 "Earth View 1KM Emissive Bands Uncertainty Indexes",
130 "Earth View 250M Aggregated 500M Reflective Solar Bands "
132 "Earth View 250M Aggregated 500M Reflective Solar Bands "
133 "Uncertainty Indexes",
134 "Earth View 250M Aggregated 500M Reflective Solar Bands "
135 "Number of Samples Used in Aggregation",
136 "Earth View 250M Aggregated 1km Reflective Solar Bands "
138 "Earth View 250M Aggregated 1km Reflective Solar Bands "
139 "Uncertainty Indexes",
140 "Earth View 250M Aggregated 1km Reflective Solar Bands "
141 "Number of Samples Used in Aggregation",
142 "Earth View 500M Aggregated 1km Reflective Solar Bands "
144 "Earth View 500M Aggregated 1km Reflective Solar Bands "
145 "Uncertainty Indexes",
146 "Earth View 500M Aggregated 1km Reflective Solar Bands "
147 "Number of Samples Used in Aggregation"
162 #define L1B_EV_SDS_RANK 3
165 {
"Band_250M",
"40*nscans",
"4*Max_EV_frames"},
166 {
"Band_500M",
"20*nscans",
"2*Max_EV_frames"},
167 {
"Band_1KM_RefSB",
"10*nscans",
"Max_EV_frames"},
168 {
"Band_1KM_Emissive",
"10*nscans",
"Max_EV_frames"}
174 {1, 0}, {0, 0}, {0, 0}, {0, 0}
180 {0.5, 0.0}, {0.5, 0.0}, {0.0, 0.0}, {0.0, 0.0}
194 {-90.,90.} , -999. ,
"3,8" ,
"3,8,13,...", 1.f} ,
196 {-180., 180.} , -999. ,
"3,8" ,
"3,8,13,...", 1.f} ,
197 {
"Height" ,
"Height" ,
DFNT_INT16 ,
"meters" ,
198 {-400,10000} , -32767 ,
"3,8" ,
"3,8,13,...", 1.f} ,
199 {
"SensorZenith" ,
"SensorZenith" ,
DFNT_INT16 ,
"degrees" ,
200 {0,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
201 {
"SensorAzimuth",
"SensorAzimuth",
DFNT_INT16 ,
"degrees" ,
202 {-18000,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
203 {
"Range" ,
"Range" , DFNT_UINT16 ,
"meters" ,
204 {27000.,65535.}, 0 ,
"3,8" ,
"3,8,13,...", 25.f} ,
205 {
"SolarZenith" ,
"SolarZenith" ,
DFNT_INT16 ,
"degrees" ,
206 {0,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
207 {
"SolarAzimuth" ,
"SolarAzimuth" ,
DFNT_INT16 ,
"degrees" ,
208 {-18000,18000} , -32767 ,
"3,8" ,
"3,8,13,...", 0.01f},
209 {
"gflags" ,
"gflags" , DFNT_UINT8 ,
"" ,
210 {0.,0.} , 255 ,
"" ,
"" , 1.}
225 boolean skip_night_hi_res)
323 char *location =
"L1B_Setup";
325 &
tables->refl.SWIR_correction_tables;
343 "Band to use for SWIR OOB Correction is out of range.",
345 "This is most likely due to an invalid LUT file.",
True);
358 SMF_ERROR(returnStatus,
"Open_L1A_EV_SDS() in L1B_Setup");
364 "Calculate_Earth_Sun_Distance",
371 SMF_ERROR(returnStatus,
"Calculate_RSB_Cal_Coeff() in L1B_Setup");
377 SMF_ERROR(returnStatus,
"Init_L1B_ScaleOffset() in L1B_Setup");
386 (
tables->refl.B26_B5_Corr,
392 "Calculate_B26_B5_Correction() in L1B_Setup");
397 SMF_ERROR(returnStatus,
"Open_W_L1B_Granule() in L1B_Setup");
399 returnStatus =
Copy_Geo_SDS (L1B_Gran, skip_night_hi_res);
401 SMF_ERROR(returnStatus,
"Copy_Geo_SDS() in L1B_Setup");
404 L1A_Gran, L1B_Gran, L1B_Scan_Meta, QA);
406 SMF_ERROR(returnStatus,
"Scan_Meta_Cal() in L1B_Setup");
410 SMF_ERROR(returnStatus,
"Calculate_DCR_Change() in Gran_Meta_Cal()");
414 SMF_ERROR(returnStatus,
"Init_QA_Parameters() in L1B_Setup");
469 char *location =
"Open_L1A_EV_SDS";
476 if ((
RFLAG & (1 <<
R)) != 0)
continue;
479 if (sds_index ==
FAIL)
481 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
489 L1A_Scan->
sds_id[
R] = SDselect (L1A_Gran->
sd_id, sds_index);
492 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
505 float32 *Earth_Sun_Dist)
573 char *location =
"Calculate_Earth_Sun_Distance";
578 if (L1A_Gran ==
NULL || Earth_Sun_Dist ==
NULL)
580 "Input parameter is NULL pointer.",
NULL, 0,
NULL,
True);
600 EMA = -2.15802 + 0.0000114074107 * TAItime -
601 1.56645046e-23 * TAItime * TAItime;
609 *Earth_Sun_Dist = 1.0001396 - 0.0167068 * cos((
double)(EMA *
PGS_PI/180.0))
610 - 0.0001396 * cos((
double)(2 * EMA *
PGS_PI/180.0));
667 {40, 40, 20, 20, 20, 20, 20, 10,
668 10, 10, 10, 10, 10, 10, 10, 10,
669 10, 10, 10, 10, 10, 10};
672 {4, 4, 2, 2, 2, 2, 2, 1, 1, 1, 1,
673 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
701 for ( det = 0; det < num_detectors[
band]; det++, det_490++ )
703 for ( sample = 0; sample < num_subsamps[
band]; sample++ )
707 m1 =
tables->refl.m1[
band][det][sample][mirr_side];
709 m1 * E_S_Dist * E_S_Dist;
711 if (
tables->QA.common_QA_tables.dead_detector[det_490] != 1)
713 work[n] = RSB_Cal_Coeff->
m1_des_sq[
band][det][sample][mirr_side];
722 for (
i = 0;
i < n;
i++)
728 "invalid m1 maximum value in Calculate_RSB_Cal_Coeff()");
733 return (returnStatus);
822 "LUT dn_star_Max <= dn_star_Min, Init_L1B_ScaleOffset");
832 (
tables->emiss.L_Max[B_emiss] -
836 (
tables->emiss.L_Max[B_emiss] -
837 tables->emiss.L_Min[B_emiss]);
848 E_sun_over_pi_B[B] = 0;
850 E_sun_over_pi_B[B] +=
tables->refl.E_sun_over_pi[D_330];
855 E_sun_over_pi_B[B] = 0;
857 E_sun_over_pi_B[B] +=
tables->refl.E_sun_over_pi[D_330];
862 E_sun_over_pi_B[B] = 0;
864 E_sun_over_pi_B[B] +=
tables->refl.E_sun_over_pi[D_330];
884 (E_sun_over_pi_B[B] / (E_S_Dist * E_S_Dist))
897 boolean skip_night_hi_res)
971 PGSt_PC_Logical logical_id = 0;
973 char fname[PGSd_PC_FILE_PATH_MAX];
975 char *location =
"Open_W_L1B_Granule";
983 if (skip_night_hi_res ==
True)
998 if (PGS_PC_GetReference(logical_id, &
version, fname) != PGS_S_SUCCESS)
1002 "Could not retrieve file name from PCF.",
1003 "PGS_PC_GetReference", logical_id,
NULL,
True);
1004 return returnStatus;
1007 if ((L1B_Gran->
sw_f_id[
f] = SWopen(fname, DFACC_CREATE)) ==
FAIL)
1011 "Could not create output granule.",
1013 return returnStatus;
1021 "Create_L1B_Swath", 0,
NULL,
True);
1022 return returnStatus;
1032 return returnStatus;
1042 "Set_L1B_EV_SDS_Attrs", 0,
NULL,
True);
1043 return returnStatus;
1051 "Create_Band_Subsetting_SDS", 0,
NULL,
True);
1052 return returnStatus;
1060 boolean skip_night_hi_res)
1133 PGSt_SMF_status returnStatus;
1134 char *location =
"Create_L1B_Swath";
1135 int16 file_index = 0;
1138 int32 track_dim = 0;
1139 int32 frame_dim = 0;
1143 intn hdf_return = 0;
1150 #define MAX_ATTR_NAME_SIZE2 72
1154 #define SW_DEF_EV_SDS(SI_name, UI_name, str) \
1155 if (SWdefdatafield(sw_id[file_index], SI_name, str, DFNT_UINT16, \
1156 HDFE_NOMERGE) == FAIL) \
1158 returnStatus = MODIS_F_HDF_ERROR; \
1159 L1BErrorMsg(location, returnStatus, SI_name, \
1160 "SWdefdatafield", evfile_luns[file_index], NULL, True); \
1161 return returnStatus; \
1163 if (SWdefdatafield(sw_id[file_index], UI_name, str, DFNT_UINT8, \
1164 HDFE_NOMERGE) == FAIL) \
1166 returnStatus = MODIS_F_HDF_ERROR; \
1167 L1BErrorMsg(location, returnStatus, UI_name, \
1168 "SWdefdatafield", evfile_luns[file_index], NULL, True); \
1169 return returnStatus; \
1172 #define SW_DEF_EV_Aggr_SDS(SI_name, UI_name, SU_name, str) \
1173 SW_DEF_EV_SDS(SI_name,UI_name,str); \
1174 if (SWdefdatafield(sw_id[file_index], SU_name, str, DFNT_INT8, \
1175 HDFE_NOMERGE) == FAIL) \
1177 returnStatus = MODIS_F_HDF_ERROR; \
1178 L1BErrorMsg(location, returnStatus, SU_name, \
1179 "SWdefdatafield", evfile_luns[file_index], NULL, True); \
1180 return returnStatus; \
1189 if (skip_night_hi_res ==
True)
1195 for (file_index = start_output_res;
1201 sw_id[file_index] = SWcreate(L1B_Gran->
sw_f_id[file_index],
1202 "MODIS_SWATH_Type_L1B");
1203 if (sw_id[file_index] ==
FAIL)
1207 "SWcreate", evfile_luns[file_index],
NULL,
True);
1208 return returnStatus;
1213 if (EHidinfo(L1B_Gran->
sw_f_id[file_index],
1214 &L1B_Gran->
v_id[file_index],
1219 "EHidinfo", evfile_luns[file_index],
NULL,
True);
1220 return returnStatus;
1225 num_BGs = file_index + 1;
1228 for (BG_index = 0; BG_index < num_BGs; BG_index++)
1233 if (hdf_return ==
FAIL)
1237 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1238 return returnStatus;
1252 sprintf(attr_name_buffer,
1253 "HDFEOS_FractionalOffset_%s_MODIS_SWATH_Type_L1B",
1256 if(SDsetattr(L1B_Gran->
sd_id[file_index],
1261 "Could not write L1B EV file dimensional attribute.",
1262 "SDsetattr", evfile_luns[file_index],
NULL,
True);
1265 sprintf(attr_name_buffer,
1266 "HDFEOS_FractionalOffset_%s_MODIS_SWATH_Type_L1B",
1269 if(SDsetattr(L1B_Gran->
sd_id[file_index],
1274 "Could not write L1B EV file dimensional attribute.",
1275 "SDsetattr", evfile_luns[file_index],
NULL,
True);
1290 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1291 return returnStatus;
1299 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1300 return returnStatus;
1307 if (SWdefdim(sw_id[file_index],
"2*nscans",
1312 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1313 return returnStatus;
1316 if (SWdefdim(sw_id[file_index],
"1KM_geo_dim",
1320 L1BErrorMsg(location, returnStatus,
"1KM_geo_dim",
1321 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1322 return returnStatus;
1325 if (SWdefgeofield(sw_id[file_index],
"Latitude",
1327 HDFE_NOMERGE) ==
FAIL)
1331 "SWdefgeofield", evfile_luns[file_index],
1333 return returnStatus;
1336 if (SWdefgeofield(sw_id[file_index],
"Longitude",
1338 HDFE_NOMERGE) ==
FAIL)
1342 "SWdefgeofield", evfile_luns[file_index],
1344 return returnStatus;
1349 "Band_1KM_RefSB,10*nscans,Max_EV_frames");
1353 "Band_1KM_Emissive,10*nscans,Max_EV_frames");
1358 "Band_250M,10*nscans,Max_EV_frames");
1363 "Band_500M,10*nscans,Max_EV_frames");
1367 if (SWdefdatafield(sw_id[file_index],
GEO_SDS[isds].
name,
1368 "2*nscans,1KM_geo_dim",
1373 "SWdefdatafield", evfile_luns[file_index],
NULL,
True);
1374 return returnStatus;
1378 if (SWdefdimmap(sw_id[file_index],
"2*nscans",
"10*nscans",
1382 L1BErrorMsg(location, returnStatus,
"2*nscans to 10*nscans",
1383 "SWdefdimmap", evfile_luns[file_index],
NULL,
True);
1384 return returnStatus;
1387 if (SWdefdimmap(sw_id[file_index],
"1KM_geo_dim",
"Max_EV_frames",
1391 L1BErrorMsg(location, returnStatus,
"1KM_geo_dim to Max_EV_frames",
1392 "SWdefdimmap", evfile_luns[file_index],
NULL,
True);
1393 return returnStatus;
1399 for (
R = 0;
R < 4;
R++) {
1400 if (SWdefdatafield(sw_id[file_index],
1407 "SWdefdatafield", evfile_luns[file_index],
NULL,
True);
1408 return returnStatus;
1415 if (SWdefdim(sw_id[file_index],
"10*nscans",
1420 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1421 return returnStatus;
1424 if (SWdefdim(sw_id[file_index],
"Max_EV_frames",
1428 L1BErrorMsg(location, returnStatus,
"Max_EV_frames",
1429 "SWdefdim", evfile_luns[file_index],
NULL,
True);
1430 return returnStatus;
1433 if (SWdefgeofield(sw_id[file_index],
"Latitude",
1435 HDFE_NOMERGE) ==
FAIL)
1439 "SWdefgeofield", evfile_luns[file_index],
NULL,
True);
1440 return returnStatus;
1443 if (SWdefgeofield(sw_id[file_index],
"Longitude",
1445 HDFE_NOMERGE) ==
FAIL)
1449 "SWdefgeofield", evfile_luns[file_index],
NULL,
True);
1450 return returnStatus;
1458 "Band_250M,40*nscans,4*Max_EV_frames");
1460 if (SWdefdatafield(sw_id[file_index],
1469 evfile_luns[file_index],
NULL,
True);
1470 return returnStatus;
1478 "Band_500M,20*nscans,2*Max_EV_frames");
1483 "Band_250M,20*nscans,2*Max_EV_frames");
1485 for (
R = 0;
R < 2;
R++) {
1486 if (SWdefdatafield(sw_id[file_index],
1495 evfile_luns[file_index],
NULL,
True);
1496 return returnStatus;
1504 if (SWdefdimmap(sw_id[file_index],
1511 "L1B_EV_DIM_NAME[R][1] to 10*nscans",
1513 evfile_luns[file_index],
NULL,
True);
1514 return returnStatus;
1517 if (SWdefdimmap(sw_id[file_index],
1524 "L1B_EV_DIM_NAME[R][2] to 10*nscans",
1526 evfile_luns[file_index],
NULL,
True);
1527 return returnStatus;
1532 #ifdef WRITE_BAND_26_SDS
1542 "10*nscans,Max_EV_frames");
1549 for (file_index = start_output_res;
1557 if (SWdetach(sw_id[file_index]) ==
FAIL)
1561 "SWdetach", evfile_luns[file_index],
NULL,
True);
1562 return returnStatus;
1572 "Write_Swath_Band_Number",
1573 evfile_luns[file_index],
NULL,
True);
1574 return returnStatus;
1616 char *location =
"Write_Swath_Band_Number";
1619 float32 data_250m[2] = {1, 2};
1620 float32 data_500m[5] = {3, 4, 5, 6, 7};
1621 float32 data_1km_refl[15] =
1622 {8, 9, 10, 11, 12, 13, 13.5, 14, 14.5,
1623 15, 16, 17, 18, 19, 26};
1624 float32 data_1km_emiss[16] =
1625 {20, 21, 22, 23, 24, 25, 27, 28, 29,
1626 30, 31, 32, 33, 34, 35, 36};
1634 swId = SWattach(L1B_Gran->
sw_f_id[file_index],
"MODIS_SWATH_Type_L1B");
1639 "SWattach", evfile_luns[file_index],
NULL,
True);
1640 return returnStatus;
1646 if (SWwritefield(swId,
"Band_250M", (int32*)
NULL, (int32*)
NULL,
1647 (int32*)
NULL, (VOIDP)data_250m) ==
FAIL)
1651 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1652 return returnStatus;
1655 if (SWwritefield(swId,
"Band_500M", (int32*)
NULL, (int32*)
NULL,
1656 (int32*)
NULL, (VOIDP)data_500m) ==
FAIL)
1660 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1661 return returnStatus;
1664 if (SWwritefield(swId,
"Band_1KM_RefSB", (int32*)
NULL, (int32*)
NULL,
1665 (int32*)
NULL, (VOIDP)data_1km_refl)==
FAIL)
1668 L1BErrorMsg(location, returnStatus,
"Band_1KM_RefSB",
1669 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1670 return returnStatus;
1673 if (SWwritefield(swId,
"Band_1KM_Emissive", (int32*)
NULL, (int32*)
NULL,
1674 (int32*)
NULL, (VOIDP)data_1km_emiss)==
FAIL)
1677 L1BErrorMsg(location, returnStatus,
"Band_1KM_Emissive",
1678 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1679 return returnStatus;
1684 if (SWwritefield(swId,
"Band_250M", (int32*)
NULL, (int32*)
NULL,
1685 (int32*)
NULL, (VOIDP)data_250m) ==
FAIL)
1689 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1690 return returnStatus;
1693 if (SWwritefield(swId,
"Band_500M", (int32*)
NULL, (int32*)
NULL,
1694 (int32*)
NULL, (VOIDP)data_500m) ==
FAIL)
1698 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1699 return returnStatus;
1704 if (SWwritefield(swId,
"Band_250M", (int32*)
NULL, (int32*)
NULL,
1705 (int32*)
NULL, (VOIDP)data_250m) ==
FAIL)
1709 "SWwritefield", evfile_luns[file_index],
NULL,
True);
1710 return returnStatus;
1715 if (SWdetach(swId) ==
FAIL)
1719 "SWdetach", evfile_luns[file_index],
NULL,
True);
1720 return returnStatus;
1728 boolean skip_night_hi_res)
1801 PGSt_SMF_status returnStatus;
1802 char *location =
"Open_L1B_EV_SDS";
1803 int32 sds_index = 0;
1804 int16 file_index = 0;
1811 int32 scaled_250[2] = {13,16};
1812 int32 scaled_500[2] = {10,12};
1822 #define CREATE_EV_SDS(sd_id, SI_name, UI_name, SI_longName, UI_longName, \
1824 if((sds_index = SDnametoindex(sd_id, SI_name)) == FAIL) \
1826 returnStatus = MODIS_F_HDF_ERROR; \
1827 L1BErrorMsg(location, returnStatus, SI_name, \
1828 "SDnametoindex", evfile_luns[file_index], NULL, True); \
1829 return returnStatus; \
1831 if((SI_id = SDselect(sd_id, sds_index)) == FAIL) \
1833 returnStatus = MODIS_F_HDF_ERROR; \
1834 L1BErrorMsg(location, returnStatus, SI_name, \
1835 "SDselect", evfile_luns[file_index], NULL, True); \
1836 return returnStatus; \
1838 if(SDsetattr(SI_id, "long_name", DFNT_CHAR8,(int32)strlen(SI_longName), \
1839 SI_longName) == FAIL) \
1841 returnStatus = MODIS_F_HDF_ERROR; \
1842 L1BErrorMsg(location, returnStatus, SI_name, \
1843 "SDsetattr", evfile_luns[file_index], "long_name", True); \
1844 return returnStatus; \
1846 if((sds_index = SDnametoindex(sd_id, UI_name)) == FAIL) \
1848 returnStatus = MODIS_F_HDF_ERROR; \
1849 L1BErrorMsg(location, returnStatus, UI_name, \
1850 "SDnametoindex", evfile_luns[file_index], NULL, True); \
1851 return returnStatus; \
1853 if((UI_id = SDselect(sd_id, sds_index)) == FAIL) \
1855 returnStatus = MODIS_F_HDF_ERROR; \
1856 L1BErrorMsg(location, returnStatus, UI_name, \
1857 "SDselect", evfile_luns[file_index], NULL, True); \
1858 return returnStatus; \
1860 if(SDsetattr(UI_id, "long_name", DFNT_CHAR8,(int32)strlen(UI_longName), \
1861 UI_longName) == FAIL) \
1863 returnStatus = MODIS_F_HDF_ERROR; \
1864 L1BErrorMsg(location, returnStatus, UI_name, \
1865 "SDsetattr", evfile_luns[file_index], "long_name", True); \
1866 return returnStatus; \
1877 #define CREATE_EV_Aggr_SDS(sd_id, SI_name, UI_name, SU_name, SI_LName, \
1878 UI_LName, SU_LName, SI_id, UI_id, SU_id) \
1879 CREATE_EV_SDS(sd_id, SI_name, UI_name, SI_LName, UI_LName, SI_id, UI_id); \
1880 if((sds_index = SDnametoindex(sd_id, SU_name)) == FAIL) \
1882 returnStatus = MODIS_F_HDF_ERROR; \
1883 L1BErrorMsg(location, returnStatus, SU_name, \
1884 "SDnametoindex", evfile_luns[file_index], NULL, True); \
1885 return returnStatus; \
1887 if((SU_id = SDselect(sd_id, sds_index)) == FAIL) \
1889 returnStatus = MODIS_F_HDF_ERROR; \
1890 L1BErrorMsg(location, returnStatus, SU_name, \
1891 "SDselect", evfile_luns[file_index], NULL, True); \
1892 return returnStatus; \
1894 if(SDsetattr(SU_id, "long_name", DFNT_CHAR8,(int32)strlen(SU_LName), \
1895 SU_LName) == FAIL) \
1897 returnStatus = MODIS_F_HDF_ERROR; \
1898 L1BErrorMsg(location, returnStatus, SU_name, \
1899 "SDsetattr", evfile_luns[file_index], "long_name", True); \
1900 return returnStatus; \
1906 if (skip_night_hi_res ==
False)
1985 1, &scaled_250[0]) ==
FAIL)
1988 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean R",
1990 return returnStatus;
1998 1, &scaled_250[1]) ==
FAIL)
2001 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean NIR",
2003 return returnStatus;
2011 1, &scaled_500[0]) ==
FAIL)
2014 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean B",
2016 return returnStatus;
2024 1, &scaled_500[1]) ==
FAIL)
2027 L1BErrorMsg(location, returnStatus,
"Rescaled Ocean G",
2029 return returnStatus;
2034 #ifdef WRITE_BAND_26_SDS
2058 boolean skip_night_hi_res)
2131 PGSt_SMF_status returnStatus;
2132 char *location =
"Set_L1B_EV_SDS_Attrs";
2136 int32 sds_ids[4] = {0, 0, 0, 0};
2143 } ScaleOffset_Kind_t;
2150 "8,9,10,11,12,13lo,13hi,14lo,14hi,15,16,17,18,19,26",
2151 "20,21,22,23,24,25,27,28,29,30,31,32,33,34,35,36"
2153 char *rad_units =
"Watts/m^2/micrometer/steradian";
2154 char *refl_units =
"none";
2155 char *counts_units =
"counts";
2168 "Set_Unit_Range_Fillvalue", 0,
NULL,
True);
2169 return returnStatus;
2182 "Set_UI_ConvertToPercent_Attrs", 0,
NULL,
True);
2183 return returnStatus;
2251 if ((
RFLAG & 1) == 1) {
2261 if ((
RFLAG & 2) == 2) {
2273 if (skip_night_hi_res ==
True)
2280 returnStatus =
Get_SDS_id(
f, L1B_Scan, &num_sds, sds_ids);
2285 "Get_SDS_id", evfile_luns[
f],
NULL,
True);
2286 return returnStatus;
2300 "Set_SDS_Attributes", evfile_luns[
f],
NULL,
True);
2301 return returnStatus;
2307 #ifdef WRITE_BAND_26_SDS
2322 "Could not write Band 26 SI SDS "
2324 "\"radiance_scales\".",
2325 "SDsetattr", evfile_luns[
f],
NULL,
True);
2326 return returnStatus;
2335 "Could not write Band 26 SI SDS "
2337 "\"radiance_offsets\".",
2338 "SDsetattr", evfile_luns[
f],
NULL,
True);
2339 return returnStatus;
2344 (int32)strlen(rad_units), rad_units) ==
FAIL)
2348 "Could not write Band 26 SI SDS "
2350 "\"radiance_units\".",
2351 "SDsetattr", evfile_luns[
f],
NULL,
True);
2352 return returnStatus;
2361 "Could not write Band 26 SI SDS "
2363 "\"reflectance_scales\".",
2364 "SDsetattr", evfile_luns[
f],
NULL,
True);
2365 return returnStatus;
2374 "Could not write Band 26 SI SDS "
2376 "\"reflectance_offsets\".",
2377 "SDsetattr", evfile_luns[
f],
NULL,
True);
2378 return returnStatus;
2383 (int32)strlen(refl_units), refl_units) ==
FAIL)
2387 "Could not write Band 26 SI SDS "
2389 "\"reflectance_units\".",
2390 "SDsetattr", evfile_luns[
f],
NULL,
True);
2391 return returnStatus;
2400 "Could not write Band 26 SI SDS "
2402 "\"corrected_counts_scales\".",
2403 "SDsetattr", evfile_luns[
f],
NULL,
True);
2404 return returnStatus;
2413 "Could not write Band 26 SI SDS "
2415 "\"corrected_counts_offsets\".",
2416 "SDsetattr", evfile_luns[
f],
NULL,
True);
2417 return returnStatus;
2422 (int32)strlen(counts_units), counts_units) ==
FAIL)
2426 "Could not write Band 26 SI SDS "
2428 "\"corrected_counts_units\".",
2429 "SDsetattr", evfile_luns[
f],
NULL,
True);
2430 return returnStatus;
2440 boolean skip_night_hi_res)
2492 char *location =
"Set_Unit_Range_Fillvalue";
2494 char *errmsgfmt =
"Could not write attribute \"%s\", "
2495 "type[%ld], sds_number[%ld].";
2502 typedef enum { RefSB_250_Data,
2506 Aggr_250_500_RefSB_Data,
2507 Aggr_250_1km_RefSB_Data,
2508 Aggr_500_1km_RefSB_Data,
2511 typedef enum { Aggr_250_500_RefSB_Samples,
2512 Aggr_250_1km_RefSB_Samples,
2513 Aggr_500_1km_RefSB_Samples,
2515 } ev_Aggr_Samples_t;
2518 int32 num_sds_ids[Num_Data_types] = {7, 7, 3};
2520 char *
units =
"none";
2521 uint16 SI_valid_range[2] = {0, 32767};
2522 uint8 UI_valid_range[2] = {0, 15};
2523 int8 SU_valid_range_X2[2] = {0, 6};
2524 int8 SU_valid_range_X4[2] = {0, 28};
2525 int8 *SU_valid_range[3];
2526 uint16 SI_fillvalue = 65535;
2527 uint8 UI_fillvalue = 255;
2528 int8 SU_fillvalue = -1;
2529 int32 SI_sds_ids[7];
2530 int32 UI_sds_ids[7];
2531 int32 SU_sds_ids[3];
2532 int32 *sds_ids[Num_Data_types];
2537 SU_valid_range[Aggr_250_500_RefSB_Samples] = SU_valid_range_X2;
2539 SU_valid_range[Aggr_250_1km_RefSB_Samples] = SU_valid_range_X4;
2541 SU_valid_range[Aggr_500_1km_RefSB_Samples] = SU_valid_range_X2;
2543 sds_ids[0] = SI_sds_ids;
2544 sds_ids[1] = UI_sds_ids;
2545 sds_ids[2] = SU_sds_ids;
2553 SI_sds_ids[Aggr_250_500_RefSB_Data] =
2555 SI_sds_ids[Aggr_250_1km_RefSB_Data] =
2557 SI_sds_ids[Aggr_500_1km_RefSB_Data] =
2560 UI_sds_ids[Aggr_250_500_RefSB_Data] =
2562 UI_sds_ids[Aggr_250_1km_RefSB_Data] =
2564 UI_sds_ids[Aggr_500_1km_RefSB_Data] =
2567 SU_sds_ids[Aggr_250_500_RefSB_Samples] =
2569 SU_sds_ids[Aggr_250_1km_RefSB_Samples] =
2571 SU_sds_ids[Aggr_500_1km_RefSB_Samples] =
2602 if (
type < SU && skip_night_hi_res ==
True)
2607 for (sds_number = start_output_res;
2608 sds_number < num_sds_ids[
type]; sds_number++)
2611 if (skip_night_hi_res ==
True)
2612 if ((
type < SU && sds_number == Aggr_250_500_RefSB_Data) ||
2613 (
type == SU && sds_number == Aggr_250_500_RefSB_Samples))
2616 if (SDsetattr(sds_ids[
type][sds_number],
"units",
2619 sprintf(errmsg, errmsgfmt,
"units", (
long)
type, (
long)sds_number);
2623 return returnStatus;
2630 if (SDsetattr(sds_ids[
type][sds_number],
"valid_range",
2631 DFNT_UINT16, 2, (VOIDP)SI_valid_range) ==
FAIL)
2633 sprintf(errmsg, errmsgfmt,
"valid_range", (
long)
type, (
long)sds_number);
2637 return returnStatus;
2640 if (SDsetattr(sds_ids[
type][sds_number],
"_FillValue",
2641 DFNT_UINT16, 1,(VOIDP)&SI_fillvalue) ==
FAIL)
2643 sprintf(errmsg, errmsgfmt,
"_FillValue", (
long)
type, (
long)sds_number);
2647 return returnStatus;
2653 if (SDsetattr(sds_ids[
type][sds_number],
"valid_range",
2654 DFNT_UINT8, 2, (VOIDP)UI_valid_range) ==
FAIL)
2656 sprintf(errmsg, errmsgfmt,
"valid_range", (
long)
type, (
long)sds_number);
2660 return returnStatus;
2663 if (SDsetattr(sds_ids[
type][sds_number],
"_FillValue",
2664 DFNT_UINT8, 1,(VOIDP)&UI_fillvalue) ==
FAIL)
2666 sprintf(errmsg, errmsgfmt,
"_FillValue", (
long)
type, (
long)sds_number);
2670 return returnStatus;
2676 if (SDsetattr(sds_ids[
type][sds_number],
"valid_range",
2678 (VOIDP)SU_valid_range[sds_number]) ==
FAIL)
2680 sprintf(errmsg, errmsgfmt,
"valid_range", (
long)
type, (
long)sds_number);
2684 return returnStatus;
2687 if (SDsetattr(sds_ids[
type][sds_number],
"_FillValue",
2688 DFNT_INT8, 1,(VOIDP)&SU_fillvalue) ==
FAIL)
2690 sprintf(errmsg, errmsgfmt,
"_FillValue", (
long)
type, (
long)sds_number);
2694 return returnStatus;
2701 "Invalid \"type\" ... must be code bug.",
2703 return returnStatus;
2710 #ifdef WRITE_BAND_26_SDS
2720 strcpy(errmsg,
"Could not write Band 26 SI SDS "
2721 "attribute \"units\".");
2725 return returnStatus;
2728 DFNT_UINT16, 2, (VOIDP)SI_valid_range) ==
FAIL)
2730 strcpy(errmsg,
"Could not write Band 26 SI SDS "
2731 "attribute \"valid_range\".");
2735 return returnStatus;
2738 DFNT_UINT16, 1,(VOIDP)&SI_fillvalue) ==
FAIL)
2740 strcpy(errmsg,
"Could not write Band 26 SI SDS "
2741 "attribute \"_FillValue\".");
2745 return returnStatus;
2753 strcpy(errmsg,
"Could not write Band 26 UI SDS "
2754 "attribute \"units\".");
2758 return returnStatus;
2761 DFNT_UINT8, 2, (VOIDP)UI_valid_range) ==
FAIL)
2763 strcpy(errmsg,
"Could not write Band 26 UI SDS "
2764 "attribute \"valid_range\".");
2768 return returnStatus;
2771 DFNT_UINT8, 1,(VOIDP)&UI_fillvalue) ==
FAIL)
2773 strcpy(errmsg,
"Could not write Band 26 UI SDS "
2774 "attribute \"_FillValue\".");
2778 return returnStatus;
2929 char *location =
"Set_SDS_Attributes";
2930 char *errmsgfmt =
"Could not write attribute \"%s\" for R = %ld";
2938 } ScaleOffset_Kind_t;
2941 int32 dim_size[4] = {2, 5, 15, 16};
2943 for (
R = 0;
R < num_sds;
R++)
2945 if (SDsetattr(sds_id[
R],
"band_names",DFNT_CHAR8,
2946 (int32)strlen(BandNames[
R]), BandNames[
R]) ==
FAIL)
2949 sprintf(errmsg, errmsgfmt,
"band_names", (
long)
R);
2952 return returnStatus;
2956 dim_size[
R],
scale[radiance * sds_dim +
R]) ==
FAIL)
2959 sprintf(errmsg, errmsgfmt,
"radiance_scales", (
long)
R);
2962 return returnStatus;
2969 sprintf(errmsg, errmsgfmt,
"radiance_offsets", (
long)
R);
2972 return returnStatus;
2975 if (SDsetattr(sds_id[
R],
"radiance_units",DFNT_CHAR8,
2976 (int32)strlen(rad_units), rad_units) ==
FAIL)
2979 sprintf(errmsg, errmsgfmt,
"radiance_units", (
long)
R);
2982 return returnStatus;
2988 dim_size[
R],
scale[reflectance * sds_dim +
R])
2992 sprintf(errmsg, errmsgfmt,
"reflectance_scales", (
long)
R);
2995 return returnStatus;
2999 dim_size[
R],
offset[reflectance * sds_dim +
R])
3003 sprintf(errmsg, errmsgfmt,
"reflectance_offsets", (
long)
R);
3006 return returnStatus;
3009 if (SDsetattr(sds_id[
R],
"reflectance_units",DFNT_CHAR8,
3010 (int32)strlen(refl_units),refl_units) ==
FAIL)
3013 sprintf(errmsg, errmsgfmt,
"reflectance_units", (
long)
R);
3016 return returnStatus;
3019 if (SDsetattr(sds_id[
R],
"corrected_counts_scales",
DFNT_FLOAT32,
3023 sprintf(errmsg, errmsgfmt,
"corrected_counts_scales", (
long)
R);
3026 return returnStatus;
3029 if (SDsetattr(sds_id[
R],
"corrected_counts_offsets",
DFNT_FLOAT32,
3033 sprintf(errmsg, errmsgfmt,
"corrected_counts_offsets", (
long)
R);
3036 return returnStatus;
3039 if (SDsetattr(sds_id[
R],
"corrected_counts_units",DFNT_CHAR8,
3040 (int32)strlen(counts_units),counts_units) ==
FAIL)
3043 sprintf(errmsg, errmsgfmt,
"corrected_counts_units", (
long)
R);
3046 return returnStatus;
3056 boolean skip_night_hi_res)
3124 PGSt_SMF_status returnStatus;
3125 char *location =
"Create_Band_Subsetting_SDS";
3133 float32 data_250m[2] = {1, 2};
3134 float32 data_500m[5] = {3, 4, 5, 6, 7};
3135 float32 data_1km_refl[15] = {8, 9, 10, 11, 12, 13, 13.5, 14, 14.5, 15,
3136 16, 17, 18, 19, 26};
3137 float32 data_1km_emiss[16] = {20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31,
3138 32, 33, 34, 35, 36};
3142 "250M Band Numbers for Subsetting",
3143 "500M Band Numbers for Subsetting",
3144 "1KM Reflective Solar Band Numbers for Subsetting",
3145 "1KM Emissive Band Numbers for Subsetting"
3155 data[0] = data_250m;
3156 data[1] = data_500m;
3157 data[2] = data_1km_refl;
3158 data[3] = data_1km_emiss;
3165 if (skip_night_hi_res ==
True)
3177 for (
R = 0;
R < num_sds;
R++)
3183 "float32",
data[
R]);
3187 "write_sds_rank1", evfile_luns[
f],
NULL,
True);
3188 return returnStatus;
3191 sds_index = SDnametoindex(L1B_Gran->
sd_id[
f],
3193 if(sds_index ==
FAIL)
3195 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3199 "SDnametoindex", evfile_luns[
f],
NULL,
True);
3200 return returnStatus;
3203 sds_id = SDselect(L1B_Gran->
sd_id[
f], sds_index);
3206 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3210 "SDselect", evfile_luns[
f],
NULL,
True);
3211 return returnStatus;
3214 if(SDsetattr(sds_id,
"long_name", DFNT_CHAR8,
3215 (int32)strlen(SDS_LongName[
R]),
3216 (VOIDP)SDS_LongName[
R]) ==
FAIL)
3219 "Could not write long_name attribute for SDS \"%s\".",
3223 "SDsetattr", evfile_luns[
f],
NULL,
True);
3224 return returnStatus;
3227 hdf_return = SDendaccess(sds_id);
3228 if (hdf_return ==
FAIL)
3230 sprintf(errmsg,
"Could not end access to SDS \"%s\".",
3234 "SDendaccess", evfile_luns[
f],
NULL,
True);
3235 return returnStatus;
3244 boolean skip_night_hi_res)
3321 char *location =
"Copy_Geo_SDS";
3324 int32 geo_sd_id = 0;
3327 int32 geo_sds_index = 0;
3328 int32 geo_sds_id = 0;
3329 int32 geo_attr_index = 0;
3330 int32 L1B_sds_index = 0;
3331 int32 L1B_sds_id = 0;
3334 int32
start[2] = {0, 0};
3335 int32 edge[2] = {0, 0};
3336 intn hdf_return =
FAIL;
3345 char *attr_name =
NULL;
3346 char *attr_value =
NULL;
3348 #define MAX_ATTR_NAME_SIZE 26
3349 #define MAX_ATTR_BUFFER_SIZE 72
3354 int32 attr_data_type = 0;
3355 int32 attr_count = 0;
3362 #define COPY_ATTR(attr_name) \
3363 geo_attr_index = SDfindattr(geo_sds_id, attr_name); \
3364 if (geo_attr_index == FAIL) \
3366 sprintf(errmsg, "Could not get attribute index for \"%s\".", \
3368 returnStatus = MODIS_F_READ_ERROR; \
3369 L1BErrorMsg(location, returnStatus, errmsg, \
3370 "SDfindattr", GEOLOCATION_FILE, NULL, True); \
3371 return returnStatus; \
3373 hdf_return = SDattrinfo(geo_sds_id, geo_attr_index, attr_name_buffer, \
3374 &attr_data_type, &attr_count); \
3375 if (hdf_return == FAIL) \
3377 sprintf(errmsg, "Could not get attribute info for \"%s\".", \
3379 returnStatus = MODIS_F_HDF_ERROR; \
3380 L1BErrorMsg(location, returnStatus, errmsg, \
3381 "SDattrinfo", GEOLOCATION_FILE, NULL, True); \
3382 return returnStatus; \
3384 hdf_return = SDreadattr(geo_sds_id, geo_attr_index, \
3385 (void *)attr_buffer); \
3386 if (hdf_return == FAIL) \
3388 sprintf(errmsg, "Could not read attribute \"%s\".", attr_name); \
3389 returnStatus = MODIS_F_READ_ERROR; \
3390 L1BErrorMsg(location, returnStatus, errmsg, \
3391 "SDreadattr", GEOLOCATION_FILE, NULL, True); \
3392 return returnStatus; \
3394 hdf_return = SDsetattr(L1B_sds_id, attr_name, attr_data_type, \
3395 attr_count, (void *)attr_buffer); \
3396 if (hdf_return == FAIL) \
3398 sprintf(errmsg, "Could not write attribute \"%s\".", attr_name); \
3399 returnStatus = MODIS_F_WRITE_ERROR; \
3400 L1BErrorMsg(location, returnStatus, errmsg, \
3401 "SDsetattr", evfile_luns[i], NULL, True); \
3402 return returnStatus; \
3413 "Could not retrieve file name from PCF.",
3415 return returnStatus;
3420 geo_sd_id = SDstart(fname, DFACC_RDONLY);
3421 if (geo_sd_id ==
FAIL)
3425 "Could not open file for SD read access.",
3427 "The file may be missing, corrupted or "
3428 "not an HDF-4 file.",
True);
3429 return returnStatus;
3437 if (skip_night_hi_res ==
False)
3444 geo_sds_index = SDnametoindex(geo_sd_id,
GEO_SDS[isds].src_name);
3445 if (geo_sds_index ==
FAIL)
3447 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3452 return returnStatus;
3455 geo_sds_id = SDselect(geo_sd_id, geo_sds_index);
3456 if (geo_sds_id ==
FAIL)
3458 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3463 return returnStatus;
3466 hdf_return = SDreaddata(geo_sds_id,
start,
NULL, edge,
3468 if (hdf_return ==
FAIL)
3470 sprintf(errmsg,
"Could not read data for SDS \"%s\".",
3475 return returnStatus;
3480 L1B_sds_index = SDnametoindex(L1B_Gran->
sd_id[
i],
3482 if (L1B_sds_index ==
FAIL)
3484 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3488 "SDnametoindex", evfile_luns[
i],
NULL,
True);
3489 return returnStatus;
3492 L1B_sds_id = SDselect(L1B_Gran->
sd_id[
i], L1B_sds_index);
3493 if (L1B_sds_id ==
FAIL)
3495 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3499 "SDselect", evfile_luns[
i],
NULL,
True);
3500 return returnStatus;
3503 hdf_return = SDwritedata(L1B_sds_id,
start,
3504 NULL, edge, (
void *)buffer);
3505 if (hdf_return ==
FAIL)
3507 sprintf(errmsg,
"Could not write SDS \"%s\".",
3511 "SDwritedata", evfile_luns[
i],
NULL,
True);
3512 return returnStatus;
3521 hdf_return = SDendaccess(L1B_sds_id);
3522 if (hdf_return ==
FAIL)
3524 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3528 "SDendaccess", evfile_luns[
i],
NULL,
True);
3529 return returnStatus;
3536 hdf_return = SDendaccess(geo_sds_id);
3537 if (hdf_return ==
FAIL)
3539 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3544 return returnStatus;
3561 geo_sds_index = SDnametoindex(geo_sd_id,
GEO_SDS[isds].src_name);
3562 if (geo_sds_index ==
FAIL)
3564 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3569 return returnStatus;
3572 geo_sds_id = SDselect(geo_sd_id, geo_sds_index);
3573 if (geo_sds_id ==
FAIL)
3575 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3580 return returnStatus;
3587 if (L1B_sds_index ==
FAIL)
3589 sprintf(errmsg,
"Could not get SDS index of \"%s\".",
3594 return returnStatus;
3598 if (L1B_sds_id ==
FAIL)
3600 sprintf(errmsg,
"Could not get SDS ID for \"%s\".",
3605 return returnStatus;
3610 hdf_return = SDreaddata(geo_sds_id, geo_start, geo_stride,
3611 edge, (
void *)buffer);
3612 if (hdf_return ==
FAIL)
3614 sprintf(errmsg,
"Could not read data for SDS \"%s\".",
3619 return returnStatus;
3624 hdf_return = SDwritedata(L1B_sds_id,
start,
NULL, edge, (
void *)buffer);
3625 if (hdf_return ==
FAIL)
3627 sprintf(errmsg,
"Could not write SDS \"%s\".",
GEO_SDS[isds].
name);
3631 return returnStatus;
3654 hdf_return = SDsetattr(L1B_sds_id,
"line_numbers", DFNT_CHAR8,
3655 (int32)strlen(
"3,8"), (VOIDP)
"3,8");
3656 if (hdf_return ==
FAIL)
3658 sprintf(errmsg,
"Could not write attribute \"line_numbers\" "
3664 return returnStatus;
3667 hdf_return = SDsetattr(L1B_sds_id,
"frame_numbers", DFNT_CHAR8,
3668 (int32)strlen(
"3,8,13,..."),
3669 (VOIDP)
"3,8,13,...");
3670 if (hdf_return ==
FAIL)
3672 sprintf(errmsg,
"Could not write attribute \"frame_numbers\" "
3679 return returnStatus;
3686 for (
i = 0;
i < 5;
i++)
3690 case 0: attr_name =
"Bit 7(MSB)";
3691 attr_value =
"1 = invalid input data";
3693 case 1: attr_name =
"Bit 6";
3694 attr_value =
"1 = no ellipsoid intersection";
3696 case 2: attr_name =
"Bit 5";
3697 attr_value =
"1 = no valid terrain data";
3699 case 3: attr_name =
"Bit 4";
3700 attr_value =
"1 = DEM missing or of inferior quality";
3702 case 4: attr_name =
"Bit 3";
3703 attr_value =
"1 = invalid sensor range";
3705 hdf_return = SDsetattr(L1B_sds_id, attr_name, DFNT_CHAR8,
3706 (int32)strlen(attr_value), attr_value);
3707 if (hdf_return ==
FAIL)
3710 "Could not write attribute \"%s\" to SDS \"%s\".",
3715 return returnStatus;
3722 hdf_return = SDendaccess(geo_sds_id);
3723 if (hdf_return ==
FAIL)
3725 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3730 return returnStatus;
3735 hdf_return = SDendaccess(L1B_sds_id);
3736 if (hdf_return ==
FAIL)
3738 sprintf(errmsg,
"Could not end access for SDS \"%s\".",
3743 return returnStatus;
3750 hdf_return = SDend(geo_sd_id);
3751 if (hdf_return ==
FAIL)
3756 "Memory or the disk file must have become corrupted.",
3758 return returnStatus;
3851 PGSt_SMF_status returnStatus;
3862 float32 *f32_buffer;
3864 int32 buf_index = 0;
3865 float32 *SD_Sun_zenith;
3866 SD_Sun_zenith = (float32*) malloc(
MAX_NUM_SCANS *
sizeof(float32));
3867 float32 *SD_Sun_Azimuth;
3868 SD_Sun_Azimuth = (float32*) malloc(
MAX_NUM_SCANS *
sizeof(float32));
3870 char *location =
"Scan_Meta_Cal";
3871 char upper_bound_str[20];
3873 Attitude_Angles_t *Attitude_Angles;
3874 Attitude_Angles = (Attitude_Angles_t*) malloc(
MAX_NUM_SCANS *
sizeof(Attitude_Angles_t));
3875 float32 rtod = 180.0/
PGS_PI;
3879 SCAN_SECTOR_ROTATION,
3911 } temp[NUM_FIELD] = {
3917 {
"Command Parameters",
"SET_FR_ENC_DELTA", {0} },
3918 {
"Telemetry Major Cycle 4A of 7",
"CR_PCLWA_ECAL_ON", {0} },
3919 {
"Telemetry Major Cycle 4A of 7",
"CR_PCLWB_ECAL_ON", {0} },
3920 {
"Telemetry Major Cycle 4B of 7",
"CR_PVVISA_ECALON", {0} },
3921 {
"Telemetry Major Cycle 4B of 7",
"CR_PVVISB_ECALON", {0} },
3922 {
"Telemetry Major Cycle 4B of 7",
"CR_PVNIRA_ECALON", {0} },
3923 {
"Telemetry Major Cycle 4B of 7",
"CR_PVNIRB_ECALON", {0} },
3924 {
"Telemetry Major Cycle 4B of 7",
"CR_PVSMA_ECAL_ON", {0} },
3925 {
"Telemetry Major Cycle 4B of 7",
"CR_PVSMB_ECAL_ON", {0} },
3926 {
"Telemetry Major Cycle 4A of 7",
"CR_PVLWA_ECAL_ON", {0} },
3927 {
"Telemetry Major Cycle 4A of 7",
"CR_PVLWB_ECAL_ON", {0} },
3928 {
"Telemetry Major Cycle 5B of 7",
"CR_SM_SDSM_A_ON", {0} },
3929 {
"Telemetry Major Cycle 5B of 7",
"CR_SM_SDSM_B_ON", {0} },
3930 {
"Telemetry Major Cycle 5A of 7",
"CR_RC_CSHTR_ON", {0} },
3931 {
"Telemetry Major Cycle 5A of 7",
"CR_RC_ISHTR_ON", {0} },
3932 {
"Telemetry Major Cycle 5A of 7",
"CR_RC_OSHTR_ON", {0} },
3933 {
"Telemetry Major Cycle 0 of 7",
"CR_BB_A_PWR_ON", {0} },
3934 {
"Telemetry Major Cycle 0 of 7",
"CR_BB_B_PWR_ON", {0} },
3935 {
"Telemetry Major Cycle 3A of 7",
"CR_DR_SDD_OPEN", {0} },
3936 {
"Telemetry Major Cycle 3A of 7",
"CR_DR_SDS_OPEN", {0} },
3937 {
"Telemetry Major Cycle 1 of 7",
"SS_FR_SCIABNORM", {0} },
3938 {
"Telemetry Major Cycle 3A of 7",
"CR_DR_NAD_CLSD", {0} },
3939 {
"Telemetry Major Cycle All Part 3",
"SS_CP_MACRO_ID", {0} },
3940 {
"Telemetry Major Cycle 4A of 7" ,
"CR_PCLW_A_ON", {0} },
3941 {
"Telemetry Major Cycle 4A of 7" ,
"CR_PCLW_B_ON", {0} }
3956 #define NADIR_FRAME_GEO_VALS(geoname,var,scalefactor,buf) \
3957 returnStatus = read_sds_rank2(geo_sd_id, geoname, \
3958 10 * L1A_Gran->num_scans, \
3959 EV_1km_FRAMES, buf); \
3960 if (returnStatus != MODIS_S_OK) \
3962 L1BErrorMsg(location, returnStatus, NULL, \
3963 "read_sds_rank2", GEOLOCATION_FILE, NULL, True); \
3964 return returnStatus; \
3966 for (S = 0; S < L1A_Gran->num_scans; S++) { \
3967 buf_index = (S * 10 + 4) * EV_1km_FRAMES + NADIR_1km_FRAME_NUM - 1; \
3968 var[S] = buf[buf_index] * scalefactor; \
3971 for (
i = SCAN_SECTOR_ROTATION;
i < NUM_FIELD;
i++)
3978 (VOIDP)temp[
i].buffer);
3983 return returnStatus;
3987 strcpy(upper_bound_str,
"31");
3988 else if (
i == SCAN_SECTOR_ROTATION)
3989 strcpy(upper_bound_str,
"16383");
3991 strcpy(upper_bound_str,
"1");
3996 (
void *) temp[
i].buffer);
4001 return returnStatus;
4016 for (S = 0; S < L1A_Gran->
num_scans; S++)
4018 if (temp[MACRO_ID].buffer[S] == 15 ||
4019 temp[MACRO_ID].buffer[S] == 16 ||
4020 temp[MACRO_ID].buffer[S] == 17)
4022 else if (temp[MACRO_ID].buffer[S] == 18 ||
4023 temp[MACRO_ID].buffer[S] == 19 ||
4024 temp[MACRO_ID].buffer[S] == 20 ||
4025 temp[MACRO_ID].buffer[S] == 21)
4027 else if (temp[MACRO_ID].buffer[S] == 22 ||
4028 temp[MACRO_ID].buffer[S] == 23 ||
4029 temp[MACRO_ID].buffer[S] == 24)
4042 "Could not retrieve file name from PCF.",
4044 return returnStatus;
4049 geo_sd_id = SDstart(fname, DFACC_RDONLY);
4050 if (geo_sd_id ==
FAIL)
4054 "Could not open file for SD read access.",
4056 "The file may be missing, corrupted or "
4057 "not an HDF-4 file.",
True);
4058 return returnStatus;
4069 return returnStatus;
4072 for (S = 0; S < L1A_Gran->
num_scans; S++)
4086 if (
fabs((
double) (Attitude_Angles[S][0]))*rtod >
4087 tables->QA.common_QA_tables.roll_threshold_angle ||
4088 fabs((
double) (Attitude_Angles[S][1]))*rtod >
4089 tables->QA.common_QA_tables.pitch_threshold_angle ||
4090 fabs((
double) (Attitude_Angles[S][2]))*rtod >
4091 tables->QA.common_QA_tables.yaw_threshold_angle )
4096 if ( temp[SCAN_SECTOR_ROTATION].buffer[S])
4105 if ( temp[PCLW_ADC_PRI].buffer[S] == 1 && temp[PCLW_ADC_RED].buffer[S] == 1)
4117 if (temp[PC_LW_A].buffer[S] || temp[PC_LW_B].buffer[S])
4122 if (temp[PV_VIS_A].buffer[S] || temp[PV_VIS_B].buffer[S]
4123 || temp[PV_NIR_A].buffer[S] || temp[PV_NIR_B].buffer[S]
4124 || temp[PV_SW_A].buffer[S] || temp[PV_SW_B].buffer[S]
4125 || temp[PV_LW_A].buffer[S] || temp[PV_LW_B].buffer[S])
4130 if (temp[SD_DOOR].buffer[S] == 1)
4135 if (temp[SD_SCREEN].buffer[S] == 0)
4143 if (temp[NAD_DOOR].buffer[S] == 0)
4156 if (temp[SDSM_A].buffer[S] || temp[SDSM_B].buffer[S])
4161 if (temp[RC_CSH].buffer[S] || temp[RC_ISH].buffer[S]
4162 || temp[RC_OSH].buffer[S])
4180 if (temp[BB_HEATER_A].buffer[S] || temp[BB_HEATER_B].buffer[S])
4195 if (SRCA_mode[S] == 2 || SRCA_mode[S] == 3 || SRCA_mode[S] == -1)
4197 if (SRCA_mode[S] == 1 || SRCA_mode[S] == 3 || SRCA_mode[S] == -1)
4232 if (temp[SCI_ABNORM].buffer[S] == 0)
4247 for (S = 0; S < L1A_Gran->
num_scans; S++)
4265 return returnStatus;
4274 return returnStatus;
4291 for (S = 0; S < L1A_Gran->
num_scans; S++)
4293 Z_MODIS = - 0.34582 * sin((
double)SD_Sun_zenith[S]) *
4294 cos((
double)SD_Sun_Azimuth[S]) +
4295 0.923830 * cos((
double)SD_Sun_zenith[S]);
4299 if (Z_MODIS > 0 && strcmp(L1A_Gran->
ScanType[S],
"Day") == 0)
4319 if (SDend(geo_sd_id) ==
FAIL)
4324 "Memory or the disk file must have become corrupted.",
4326 return returnStatus;
4332 free(SD_Sun_zenith);
4333 free(SD_Sun_Azimuth);
4334 free(Attitude_Angles);
4388 PGSt_SMF_status returnStatus;
4389 int32 S, B, B_emiss, D, D_1km, num_scans;
4395 DCR_offset_t *DCR_offset;
4396 DCR_offset = (DCR_offset_t*) malloc(
MAX_NUM_SCANS *
sizeof(DCR_offset_t));
4398 XDCR_offset_t *XDCR_offset;
4399 XDCR_offset = (XDCR_offset_t*) malloc((
MAX_NUM_SCANS + 1) *
sizeof(XDCR_offset_t));
4401 char file_name[PGSd_PC_FILE_PATH_MAX];
4402 char *location =
"Calculate_DCR_Change";
4409 if (returnStatus != PGS_S_SUCCESS)
4413 "Could not retrieve file name from PCF.",
4415 return returnStatus;
4420 file_id = SDstart(file_name, DFACC_RDONLY);
4421 if (file_id ==
FAIL)
4425 "Could not open file for SD read access.",
4427 "The file may be missing, corrupted or "
4428 "not an HDF-4 file.",
True);
4429 return returnStatus;
4437 "Could not read Number of Scans.",
4440 return returnStatus;
4449 Leading_DCR_offset);
4453 "Could not read fpa_dcr_offset.",
4456 return returnStatus;
4459 if (SDend(file_id) ==
FAIL)
4464 "Memory or the disk file must have become "
4465 "corrupted.",
True);
4466 return returnStatus;
4479 "Could not read fpa_dcr_offset.",
4482 return returnStatus;
4492 XDCR_offset[0][DCR_550] = Leading_DCR_offset[DCR_550];
4496 XDCR_offset[0][DCR_550] = DCR_offset[0][DCR_550];
4499 for(S = 0; S < L1A_Gran->
num_scans; S++) {
4501 XDCR_offset[S+1][DCR_550] = DCR_offset[S][DCR_550];
4504 for(S = 0; S < L1A_Gran->
num_scans; S++)
4515 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4531 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4545 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4563 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4577 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550])
4590 if(XDCR_offset[S+1][DCR_550] == XDCR_offset[S][DCR_550] &&
4591 XDCR_offset[S+1][DCR_550 + 1] == XDCR_offset[S][DCR_550 + 1])
4614 return(returnStatus);
4729 #ifdef WRITE_BAND_26_SDS
4760 for (S = 0; S < L1B_Gran->
num_scans; S++)
4779 #ifdef WRITE_BAND_26_SDS
4813 boolean skip_night_hi_res)
4889 char *location =
"Write_L1B_ScanMeta";
4894 int16 num_fields = 14;
4898 int32 scan_number = 0;
4899 int32 complete_scan_flag = 0;
4900 char8 scan_type[4] = {
' ',
' ',
' ',
' '};
4901 int32 mirror_side = 0;
4902 int32 EV_frames = 0;
4903 int32 nadir_frame = 0;
4904 float32 nadir_frame_latitude = 0;
4905 float32 nadir_frame_longitude = 0;
4906 float32 nadir_frame_solar_azimuth = 0;
4907 float32 nadir_frame_solar_zenith = 0;
4908 int32 BB_thermistor_outliers = 0;
4909 uint32 bit_QA_flags = 0;
4911 float32 sector_rotation_angle;
4916 char file_name[512];
4917 struct {
char *
name; int32
type; int32 order; } vd_field[14] =
4921 {
"Scan Type" , DFNT_CHAR8 , 4},
4923 {
"EV Sector Start Time" , DFNT_FLOAT64, 1},
4930 {
"No. OBC BB thermistor outliers" ,
DFNT_INT32 , 1},
4931 {
"Bit QA Flags" , DFNT_UINT32 , 1},
4942 #define PACK_MEMBER(member, buffer_ptr) \
4943 memcpy(buffer_ptr, (void *)&member, sizeof(member)); \
4944 buffer_ptr += sizeof(member)
4946 if (skip_night_hi_res ==
True)
4956 if ((vd_id = VSattach(L1B_Scan_Meta->
v_id[
f],-1,
"w")) ==
FAIL)
4960 "Could not attach to vdata for writing Level "
4961 "1B Swath Metadata",
4962 "VSattach", evfile_luns[
f],
NULL,
True);
4963 return returnStatus;
4968 if (VSsetname(vd_id,
"Level 1B Swath Metadata") ==
FAIL)
4972 "Could not create vdata name for writing "
4973 "Level 1B Swath Metadata",
4974 "VSsetname", evfile_luns[
f],
NULL,
True);
4975 return returnStatus;
4981 for (
i = 0;
i < num_fields;
i++)
4983 if (VSfdefine(vd_id,
4986 vd_field[
i].order) ==
FAIL)
4989 if (vd_field[
i].
name)
4991 "Could not define vdata field for \"%s\".",
4994 strcpy(errmsg,
"Could not define vdata field -- name is NULL.");
4997 "VSfdefine", evfile_luns[
f],
NULL,
True);
4998 return returnStatus;
5002 list_len += strlen(vd_field[
i].
name);
5006 list = (
char *)malloc((list_len + num_fields + 1) *
sizeof(char));
5011 return returnStatus;
5020 for (
i = 0;
i < num_fields - 1;
i++)
5032 if (VSsetfields(vd_id,
list) ==
FAIL)
5036 "VSsetfields", evfile_luns[
f],
NULL,
True);
5037 return returnStatus;
5067 "Command Parameters",
5069 (VOIDP)sector_rotation_dn);
5074 return returnStatus;
5082 (
void *) sector_rotation_dn);
5088 return returnStatus;
5091 for (S = 0; S < L1B_Scan_Meta->
num_scans; S++)
5093 buffer_ptr = buffer;
5095 scan_number = S + 1;
5099 complete_scan_flag = 0;
5101 complete_scan_flag = 1;
5108 else if (strcmp(L1B_Scan_Meta->
ScanType[S],
"Night") ==
SAME)
5112 memcpy(buffer_ptr, (
void *)scan_type,
sizeof(scan_type));
5113 buffer_ptr +=
sizeof(scan_type);
5129 nadir_frame_latitude =
5133 nadir_frame_longitude =
5137 nadir_frame_solar_azimuth =
5139 PACK_MEMBER(nadir_frame_solar_azimuth, buffer_ptr);
5141 nadir_frame_solar_zenith =
5143 PACK_MEMBER(nadir_frame_solar_zenith, buffer_ptr);
5145 BB_thermistor_outliers =
5153 sector_rotation_angle =
5154 (180.0/8192.0)*(float32)sector_rotation_dn[S];
5158 (
unsigned char *)buffer,
5160 FULL_INTERLACE) ==
FAIL)
5165 return returnStatus;
5181 if (returnStatus != PGS_S_SUCCESS)
5185 "Could not retrieve file name from PCF.",
5187 return returnStatus;
5195 obc_file_id = SDstart (file_name, DFACC_RDWR);
5196 if (obc_file_id ==
FAIL)
5200 "Could not open file for SD read/write access.",
5202 "The file may be missing, corrupted or "
5203 "not an HDF-4 file.",
True);
5204 return returnStatus;
5221 return returnStatus;
5228 hdf_return = SDend(obc_file_id);
5229 if (hdf_return ==
FAIL)
5233 "Memory or the disk file must have become corrupted.",
5235 return returnStatus;
5288 char *location =
"Determine_Other_Missing_Scans";
5300 "Determine_Split_Scans", 0,
NULL,
True);
5304 for (S = 0; S < L1A_Gran->
num_scans; S++)
5305 split_scan[S] =
False;
5314 for (S = 0; S < L1A_Gran->
num_scans; S++) {
5320 bad_scan_quality[S] =
True;
5322 bad_scan_quality[S] =
False;
5327 for (S = 0; S < L1A_Gran->
num_scans; S++)
5328 bad_scan_quality[S] =
False;
5335 for (S = 0; S < L1A_Gran->
num_scans; S++)
5337 if (split_scan[S] || bad_scan_quality[S])
5351 for (S = 0; S < L1A_Gran->
num_scans; S++)
5362 boolean *split_scan)
5440 #define SCAN_INTERVAL 1.4771
5441 PGSt_SMF_status returnStatus;
5447 char *location =
"Determine_Split_Scans";
5458 (
void *)SD_start_time);
5462 "Could not read SD start time.",
5465 return returnStatus;
5499 "Get_Split_Scan_Indexes", 0,
NULL,
False);
5503 if (S_split_1 >= 0 && S_split_1 < L1A_Gran->num_scans)
5504 split_scan[S_split_1] =
True;
5505 if (S_split_2 >= 0 && S_split_2 < L1A_Gran->num_scans)
5506 split_scan[S_split_2] =
True;
5517 int16 mirror_side[],
5518 int32 scan_quality[]
5569 int32 S, S_begin, S_end;
5570 int32 num_invalid_ms, n, max_n;
5571 char *location =
"Get_Split_Scan_Indexes";
5577 if (S1 < 0 || S1 >= num_scans || num_scans <= 0)
5581 "Input error in S1 or num_scans:\nS1 = %ld\nnum_scans = %ld\n",
5582 (
long)S1, (
long)num_scans);
5602 if (S_begin < 0) S_begin = 0;
5604 if (S_end >= num_scans) S_end = num_scans - 1;
5611 for (S = S_begin; S <= S_end; S++) {
5612 if (!(mirror_side[S] == 0 || mirror_side[S] == 1))
5622 if (num_invalid_ms == 0) {
5623 for (S = S_begin; S < S_end; S++) {
5624 if (mirror_side[S] == mirror_side[S+1]) {
5633 for (S = S_begin; S < S_end; S++) {
5635 if (scan_quality[S][1] > 0)
5636 n+= scan_quality[S][1];
5637 if (scan_quality[S+1][1] > 0)
5638 n+= scan_quality[S+1][1];
5641 if (scan_quality[S][0] == 0) {
5645 else if (scan_quality[S+1][0] == 0) {
5668 boolean skip_night_hi_res)
5724 PGSt_SMF_status returnStatus;
5725 char *units_attr_value =
"percent";
5726 char *location =
"Set_UI_ConvertToPercent_Attrs";
5728 #define REFL_250M_START_INDEX 0
5729 #define REFL_500M_START_INDEX 2
5730 #define REFL_1000M_START_INDEX 7
5731 #define REFL_BAND26_START_INDEX 21
5740 #define SET_UI_SDS_CONV_ATTRS(sds_id, spec_uncert, scale_factor, indx, \
5742 if (SDsetattr(sds_id, "specified_uncertainty", DFNT_FLOAT32, \
5743 numval, &(spec_uncert[indx])) == FAIL) { \
5744 returnStatus = MODIS_F_WRITE_ERROR; \
5745 L1BErrorMsg(location, returnStatus, \
5746 "Could not write UI SDS attribute" \
5747 "\"specified_uncertainty\".", \
5748 "SDsetattr", lun, NULL, True); \
5749 return returnStatus; \
5751 if (SDsetattr(sds_id, "scaling_factor", DFNT_FLOAT32, \
5752 numval, &(scale_factor[indx])) == FAIL) { \
5753 returnStatus = MODIS_F_WRITE_ERROR; \
5754 L1BErrorMsg(location, returnStatus, \
5755 "Could not write UI SDS attribute \"scaling_factor\".", \
5756 "SDsetattr", lun, NULL, True); \
5757 return returnStatus; \
5759 if (SDsetattr(sds_id, "uncertainty_units", DFNT_CHAR8, \
5760 (int32)strlen(units_attr_value), units_attr_value) == FAIL) { \
5761 returnStatus = MODIS_F_WRITE_ERROR; \
5762 L1BErrorMsg(location, returnStatus, \
5763 "Could not write UI SDS attribute \"uncertainty_units\".", \
5764 "SDsetattr", lun, NULL, True); \
5765 return returnStatus; \
5768 if (skip_night_hi_res ==
False)
5771 tables->refl.RSB_specified_uncertainty,
5772 tables->refl.RSB_UI_scaling_factor,
5777 tables->refl.RSB_specified_uncertainty,
5778 tables->refl.RSB_UI_scaling_factor,
5783 tables->refl.RSB_specified_uncertainty,
5784 tables->refl.RSB_UI_scaling_factor,
5790 tables->refl.RSB_specified_uncertainty,
5791 tables->refl.RSB_UI_scaling_factor,
5796 tables->emiss.TEB_specified_uncertainty,
5797 tables->emiss.TEB_UI_scaling_factor,
5802 tables->refl.RSB_specified_uncertainty,
5803 tables->refl.RSB_UI_scaling_factor,
5808 tables->refl.RSB_specified_uncertainty,
5809 tables->refl.RSB_UI_scaling_factor,
5814 #ifdef WRITE_BAND_26_SDS
5817 tables->refl.RSB_specified_uncertainty,
5818 tables->refl.RSB_UI_scaling_factor,
5829 (float32 *original_correction,
5830 float32 *scaled_correction,
5872 float32 scale_factor = 1.;
5878 scaled_correction[D] = scale_factor*original_correction[D];
5880 return returnStatus;