OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_cal.c
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------
2  File: get_cal.c
3 
4  Contents:
5  get_cal - opens the given calibration HDF file, retrieves
6  the sensor calibration data, calculates knee counts
7  and radiances, closes the file and returns status
8 
9  Other relevant files:
10  get_cal.h - various #defined constants, and also includes hdf.h
11  getcal_proto.h - prototypes for get_cal functions
12  get_cal_misc.c - a lower layer of calibration input functions
13 
14  Notes:
15  o A test program appears at the end of this file. It reads the
16  given calibration file. The input calibration file name is hard
17  coded. To test the code, uncomment the TESTCODE section
18  and compile with -DTESTCODE on the compile line.
19  To get debug output include, "-DDEBUG" on the compile line.
20 
21  Modification history:
22  Programmer Organization Date Description of change
23  -------------- ------------ -------- ---------------------
24  Lakshmi Kumar Hughes STX 03/11/94 Original development
25  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1
26  interface spcifications
27  Lakshmi Kumar Hughes STX 11/15/94 Modified comments
28  Lakshmi Kumar Hughes STX 05/22/96 Modified to read revised
29  calibration table
30  Removed time_factor
31  Added output arguments
32  reference year, day,
33  min, t_const, t_linear,
34  t_quadratic & cal_offs.
35  Ref. V5.0 I/O specs.
36  Lakshmi Kumar Hughes STX 11/01/96 fixed output parameters
37  of get_ref_time call.
38  Lakshmi Kumar Hughes STX 03/17/97 Chnaged idoffs[8][4] to
39  idoffs[8][16] and non-
40  prototype declarations
41  have been removed
42 ------------------------------------------------------------------------------*/
43 
44 #include "get_cal.h"
45 #include "getcal_proto.h"
46 #include <mfhdf.h>
47 
48 /*-----------------------------------------------------------------------------
49  Function: get_cal
50 
51  Returns: int32 (status)
52  Returns a status code of 0 when successful. Otherwise returns
53  -1 - to indicate file open/close error
54  -2 - to indicate read error
55  -3 - to indicate time error (if the given time cannot be found)
56  -4 - to indicate insufficient memory error
57 
58  Description:
59  The function get_cal reads given HDF file, determines the detector
60  combination to be used, calculates knee counts and radiances.
61 
62  Arguments: (in calling order)
63  Type Name I/O Description
64  ---- ---- --- -----------
65  char * cal_path I calibration file path
66  int16 syear I year of data start time
67  int16 sday I day of year for data start time
68  int16 eday I day of year for data end time
69  int32 msec I milliseconds of the day
70  char * dtype I data type flag
71  int16 * tdi I input TDI for all 8 bands
72  int16 * cal_year O the year the calibration table entry
73  was make
74  int16 * cal_day O the day of year the calibration table
75  entry was made
76  float32 fp_temps[256][8] O focal plane temperatures
77  float32 scan_mod[2][1285] O scan modulation correction factors
78  float64 t_const[8] O time correction constant term
79  float64 t_linear[8] O time correction linear term
80  float64 t_exponential[8] O time correction exponential term
81  float64 cal_offs[8] O calibration offset term
82  float64 inst_tcorr[8] O instrument temperature correction term
83  float64 fp_tcorr[8] O fp temperature correction term
84  float64 ms1_const[8] O mirror side1 constant term
85  float64 ms2_const[8] O mirror side2 constant term
86  float64 ms1_linear[8] O mirror side1 linear term
87  float64 ms2_linear[8] O mirror side2 linear term
88  float32 counts[8][4][5] O Digital cnts corresponding to eh knee
89  float32 rads[8][4][5] O Radiances corresponding to each knee
90 
91  Notes:
92 
93  Modification history:
94  Programmer Organization Date Description of change
95  -------------- ------------ -------- ---------------------
96  Lakshmi Kumar Hughes STX 03/11/94 Original development
97  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.0
98  interface spcifications
99  Lakshmi Kumar Hughes STX 02/07/95 Added output arguments
100  cal_year and cal_day
101  (ref. I/O specs v4.2)
102  Lakshmi Kumar Hughes STX 05/22/96 Modified to read revised
103  calibration table
104  Lakshmi Kumar Hughes STX 11/01/96 removed '&' sign from
105  ref_year, ref_day & ref_
106  minute variables.
107  Joel Gales Futuretech 10/02/00 Pass npix, nsta, & ninc
108  to setup_scanmod
109  Gene Eplee SAIC GSC 12/07/00 Update time correction and
110  mirror correction terms
111  Gene Eplee SAIC 03/09/04 Convert time correction and
112  mirror correction terms
113  to simultaneous exponentials.
114  Gene Eplee SAIC 07/26/06 Add focal plane
115  temperatures and
116  instrument electronics
117  temperature corrections
118  Gene Eplee SAIC 06/27/2007 Added focal plane and
119  instrument electronics
120  reference temperatures
121 ------------------------------------------------------------------------------*/
122 
123 int32_t get_cal(char *cal_path, int16_t syear, int16_t sday, int16_t eday, int32_t msec,
124  int32_t npix, int32_t nsta, int32_t ninc,
125  char *dtype, int16_t *tdi, int16_t *cal_year, int16_t *cal_day,
126  int16_t *ref_year, int16_t *ref_day, int16_t *ref_min,
127  float fp_temps[256][BANDS], float scan_mod[2][1285],
128  double *t_const, double *t_linear_1, double *t_exponential_1,
129  double *t_linear_2, double *t_exponential_2,
130  double *cal_offs, double *inst_tcorr, double *inst_tref,
131  double *fp_tcorr, double *fp_tref, double *ms1_const,
132  double *ms1_linear_1, double *ms1_exponential_1,
133  double *ms1_linear_2, double *ms1_exponential_2,
134  double *ms2_const, double *ms2_linear_1,
135  double *ms2_exponential_1, double *ms2_linear_2,
136  double *ms2_exponential_2, float counts[BANDS][4][5],
137  float rads[BANDS][4][5]) {
138  int16 tdi_list[256][4];
139  int32 fid, sdfid, status = 0, index = 0;
140  int32 idoffs[BANDS][16];
141  float32 gains[BANDS][16];
142 
143 
144  /* open given HDF file */
145  if ((fid = Hopen(cal_path, DFACC_RDONLY, 0)) < 0)
146  return FAIL;
147  sdfid = SDstart(cal_path, DFACC_RDONLY);
148  Vstart(fid);
149 
150  /*
151  * Read global attributes Reference Year, Reference Day and Reference Minute
152  * from calibration data file
153  */
154 
155  if ((status = get_ref_time(sdfid, ref_year, ref_day, ref_min)) < 0)
156  return status;
157 
158  if ((index = get_tindex(fid, syear, sday, eday, msec, cal_year, cal_day)) < 0)
159  return index;
160 
161  if ((status = read_parm_data(fid, sdfid, index, idoffs, gains, fp_temps,
167  tdi_list)) < 0)
168  return status;
169 
170  calc_knees(tdi, tdi_list, idoffs, gains, counts, rads);
171 
173 
174  /* close the given HDF file */
175  Vend(fid);
176  if ((Hclose(fid)) < 0)
177  return FAIL;
178  if ((SDend(sdfid)) < 0)
179  return FAIL;
180  return SUCCEED;
181 }
182 
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
integer, parameter int16
Definition: cubeio.f90:3
float rads[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
Definition: l1a_seawifs.c:47
double fp_tcorr[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:57
int16 eday
Definition: l1_czcs_hdf.c:17
double t_const[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:49
int status
Definition: l1_czcs_hdf.c:32
double ms2_const[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:64
int32 get_ref_time(int32 sdfid, int16 *ref_year, int16 *ref_day, int16 *ref_min)
#define FAIL
Definition: ObpgReadGrid.h:18
int32 * msec
Definition: l1_czcs_hdf.c:31
uint8 * counts
Definition: l1_czcs_hdf.c:30
int32 read_parm_data(int32 fid, int32 sdfid, int32 index, int32 idoffs[8][16], float32 gains[8][16], float32 temps[256][8], float32 scan_mod[2][1285], float64 *tfactor_const, float64 *tfactor_linear, float64 *tfactor_quadratic, float32 *cal_offset, float32 mirror[2][8], int16 tdi_list[256][4])
double fp_tref[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:58
int syear
Definition: l1_czcs_hdf.c:15
int32_t get_cal(char *cal_path, int16_t syear, int16_t sday, int16_t eday, int32_t msec, int32_t npix, int32_t nsta, int32_t ninc, char *dtype, int16_t *tdi, int16_t *cal_year, int16_t *cal_day, int16_t *ref_year, int16_t *ref_day, int16_t *ref_min, float fp_temps[256][BANDS], float scan_mod[2][1285], double *t_const, double *t_linear_1, double *t_exponential_1, double *t_linear_2, double *t_exponential_2, double *cal_offs, double *inst_tcorr, double *inst_tref, double *fp_tcorr, double *fp_tref, double *ms1_const, double *ms1_linear_1, double *ms1_exponential_1, double *ms1_linear_2, double *ms1_exponential_2, double *ms2_const, double *ms2_linear_1, double *ms2_exponential_1, double *ms2_linear_2, double *ms2_exponential_2, float counts[BANDS][4][5], float rads[BANDS][4][5])
Definition: get_cal.c:123
double ms2_linear_2[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:67
double t_linear_1[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:50
int sday
Definition: l1_czcs_hdf.c:15
int32 nsta
Definition: l1_czcs_hdf.c:27
double t_exponential_1[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:51
double cal_offs[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:54
double t_linear_2[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:52
int32_t get_tindex(int32_t fid, int16_t syear, int16_t sday, int16_t eday, int32_t msec, int16_t *cal_year, int16_t *cal_day)
Definition: get_cal_misc.c:130
double ms2_exponential_2[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:68
int32 ninc
Definition: l1_czcs_hdf.c:28
double inst_tcorr[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:55
int16_t tdi[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:37
int16_t ref_day
Definition: l1a_seawifs.c:42
float fp_temps[256][BANDS_DIMS_1A]
Definition: l1a_seawifs.c:44
double inst_tref[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:56
double ms1_linear_1[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:60
double ms1_const[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:59
dtype
Definition: DDataset.hpp:31
double ms2_linear_1[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:65
double ms2_exponential_1[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:66
int16_t ref_year
Definition: l1a_seawifs.c:41
float scan_mod[2][1285]
Definition: l1a_seawifs.c:45
double ms1_exponential_2[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:63
void setup_scanmod(char *dtype, float32 scan_mod[2][1285])
double ms1_linear_2[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:62
double t_exponential_2[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:53
int npix
Definition: get_cmp.c:27
#define BANDS
void calc_knees(int16 *tdi, int16 tdi_list[256][4], int32 idoffs[8][16], float32 gains[8][16], float32 counts[8][4][5], float32 rads[8][4][5])
double ms1_exponential_1[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:61