OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
calib_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 "calib_get_cal.h"
45 #include "calib_getcal_proto.h"
46 
47 /*-----------------------------------------------------------------------------
48  Function: get_cal
49 
50  Returns: int32 (status)
51  Returns a status code of 0 when successful. Otherwise returns
52  -1 - to indicate file open/close error
53  -2 - to indicate read error
54  -3 - to indicate time error (if the given time cannot be found)
55  -4 - to indicate insufficient memory error
56 
57  Description:
58  The function get_cal reads given HDF file, determines the detector
59  combination to be used, calculates knee counts and radiances.
60 
61  Arguments: (in calling order)
62  Type Name I/O Description
63  ---- ---- --- -----------
64  char * cal_path I calibration file path
65  int16 syear I year of data start time
66  int16 sday I day of year for data start time
67  int16 eday I day of year for data end time
68  int32 msec I milliseconds of the day
69  char * dtype I data type flag
70  int16 * tdi I input TDI for all 8 bands
71  int16 * cal_year O the year the calibration table entry
72  was make
73  int16 * cal_day O the day of year the calibration table
74  entry was made
75  float32 temps[256][8] O temperature correction coefficients
76  float32 scan_mod[2][1285] O scan modulation correction factors
77  float32 mirror[2][8] O mirror side-0 & 1 correction factors
78  float32 counts[8][4][5] O Digital cnts corresponding to eh knee
79  float32 rads[8][4][5] O Radiances corresponding to each knee
80 
81  Notes:
82 
83  Modification history:
84  Programmer Organization Date Description of change
85  -------------- ------------ -------- ---------------------
86  Lakshmi Kumar Hughes STX 03/11/94 Original development
87  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.0
88  interface spcifications
89  Lakshmi Kumar Hughes STX 02/07/95 Added output arguments
90  cal_year and cal_day
91  (ref. I/O specs v4.2)
92  Lakshmi Kumar Hughes STX 05/22/96 Modified to read revised
93  calibration table
94  Lakshmi Kumar Hughes STX 11/01/96 removed '&' sign from
95  ref_year, ref_day & ref_
96  minute variables.
97 ------------------------------------------------------------------------------*/
98 int32 get_cal(char *cal_path, int16 syear, int16 sday, int16 eday, int32 msec,
99  char *dtype, int16 *tdi, int16 *cal_year, int16 *cal_day,
100  int16 *ref_year, int16 *ref_day, int16 *ref_min,
101  float32 temps[256][BANDS], float32 scan_mod[2][1285],
102  float32 mirror[2][BANDS], float64 *t_const,
103  float64 *t_linear, float64 *t_quadratic,
104  float32 *cal_offs, float32 counts[BANDS][4][5],
105  float32 rads[BANDS][4][5]) {
106  int16 tdi_list[256][4];
107  int32 fid, sdfid, status = 0, index = 0;
108  int32 idoffs[BANDS][16];
109  float32 gains[BANDS][16];
110 
111 
112  /* open given HDF file */
113  if ((fid = Hopen(cal_path, DFACC_RDONLY, 0)) < 0)
114  return FAIL;
115  sdfid = SDstart(cal_path, DFACC_RDONLY);
116  Vstart(fid);
117 
118  /*
119  * Read global attributes Reference Year, Reference Day and Reference Minute
120  * from calibration data file
121  */
122 
123  if ((status = get_ref_time(sdfid, ref_year, ref_day, ref_min)) < 0)
124  return status;
125 
126  if ((index = get_index(fid, syear, sday, eday, msec, cal_year, cal_day)) < 0)
127  return index;
128 
129  if ((status = read_parm_data(fid, sdfid, index, idoffs, gains, temps,
130  scan_mod, t_const, t_linear, t_quadratic,
131  cal_offs, mirror, tdi_list)) < 0)
132  return status;
133 
134  calc_knees(tdi, tdi_list, idoffs, gains, counts, rads);
135 
137 
138  /* close the given HDF file */
139  Vend(fid);
140  if ((Hclose(fid)) < 0)
141  return FAIL;
142  if ((SDend(sdfid)) < 0)
143  return FAIL;
144  return SUCCEED;
145 }
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
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
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])
int syear
Definition: l1_czcs_hdf.c:15
int sday
Definition: l1_czcs_hdf.c:15
int32 get_cal(char *cal_path, int16 syear, int16 sday, int16 eday, int32 msec, char *dtype, int16 *tdi, int16 *cal_year, int16 *cal_day, int16 *ref_year, int16 *ref_day, int16 *ref_min, float32 temps[256][BANDS], float32 scan_mod[2][1285], float32 mirror[2][BANDS], float64 *t_const, float64 *t_linear, float64 *t_quadratic, float32 *cal_offs, float32 counts[BANDS][4][5], float32 rads[BANDS][4][5])
Definition: calib_get_cal.c:98
double cal_offs[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:54
int16_t tdi[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:37
int16_t ref_day
Definition: l1a_seawifs.c:42
dtype
Definition: DDataset.hpp:31
int16 get_index(char *Vdata_name)
Definition: get_index.c:6
int16_t ref_year
Definition: l1a_seawifs.c:41
float scan_mod[2][1285]
Definition: l1a_seawifs.c:45
void setup_scanmod(char *dtype, float32 scan_mod[2][1285])
#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])