OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_cal_osmi.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_osmi.h"
45 #include "getcal_proto_osmi.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 temps[256][8] O temperature correction coefficients
77  float32 scan_mod[2][1285] O scan modulation correction factors
78  float32 mirror[2][8] O mirror side-0 & 1 correction factors
79  float32 counts[8][4][5] O Digital cnts corresponding to eh knee
80  float32 rads[8][4][5] O Radiances corresponding to each knee
81 
82  Notes:
83 
84  Modification history:
85  Programmer Organization Date Description of change
86  -------------- ------------ -------- ---------------------
87  Lakshmi Kumar Hughes STX 03/11/94 Original development
88  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.0
89  interface spcifications
90  Lakshmi Kumar Hughes STX 02/07/95 Added output arguments
91  cal_year and cal_day
92  (ref. I/O specs v4.2)
93  Lakshmi Kumar Hughes STX 05/22/96 Modified to read revised
94  calibration table
95  Lakshmi Kumar Hughes STX 11/01/96 removed '&' sign from
96  ref_year, ref_day & ref_
97  minute variables.
98 ------------------------------------------------------------------------------*/
99 int32_t get_cal_osmi(char *cal_path, int16_t syear, int16_t sday, int16_t eday, int32_t msec,
100  int16_t *cal_year, int16_t *cal_day, int32_t *cal_msec,
101  float *eoffset, float *egain, float *temp,
102  float *mirror, float *t_const,
103  float *t_linear, float *t_quadratic,
104  float *slope, float *dc,
105  float *sm) {
106  int32 fid, sdfid, status = 0, index = 0;
107 
108 
109  /* open given HDF file */
110  if ((fid = Hopen(cal_path, DFACC_RDONLY, 0)) < 0)
111  return FAIL;
112 
113  sdfid = SDstart(cal_path, DFACC_RDONLY);
114  Vstart(fid);
115  /*
116  * Read global attributes Reference Year, Reference Day and Reference Minute
117  * from calibration data file
118  */
119 
120 
121  if ((index = get_index_osmi(fid, syear, sday, eday, msec, cal_year, cal_day, cal_msec)) < 0)
122  return index;
123 
124  if ((status = read_parm_data_osmi(fid, sdfid, index, eoffset, egain, temp, mirror,
125  t_const, t_linear, t_quadratic,
126  slope, dc, sm)) < 0)
127  return status;
128 
129  /* close the given HDF file */
130  Vend(fid);
131  if ((Hclose(fid)) < 0)
132  return FAIL;
133  if ((SDend(sdfid)) < 0)
134  return FAIL;
135  return SUCCEED;
136 }
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
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
#define FAIL
Definition: ObpgReadGrid.h:18
int32 * msec
Definition: l1_czcs_hdf.c:31
int syear
Definition: l1_czcs_hdf.c:15
int sday
Definition: l1_czcs_hdf.c:15
int32_t get_cal_osmi(char *cal_path, int16_t syear, int16_t sday, int16_t eday, int32_t msec, int16_t *cal_year, int16_t *cal_day, int32_t *cal_msec, float *eoffset, float *egain, float *temp, float *mirror, float *t_const, float *t_linear, float *t_quadratic, float *slope, float *dc, float *sm)
Definition: get_cal_osmi.c:99
float32 slope[]
Definition: l2lists.h:30
int32_t get_index_osmi(int32_t fid, int16_t syear, int16_t sday, int16_t eday, int32_t msec, int16_t *cal_year, int16_t *cal_day, int32_t *cal_msec)
int32_t read_parm_data_osmi(int32_t fid, int32_t sdfid, int32_t index, float *eoffset, float *egain, float *temp, float *mirror, float *t_const, float *t_linear, float *t_quadratic, float *slope, float *dc, float *sm)