OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
get_cal_misc_osmi.c
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------
2  File : get_cal_misc.c
3 
4  Contents:
5  get_index - reads time vdata and returns appropriate index to
6  access data
7  read_parm_data - reads parameter data
8 
9  Other relevant files:
10  cal.h - various #defined constants, TDI table, and also
11  includes hdf.h
12  getcal_proto.h - prototypes for get_cal functions
13  get_cal.c - a higher layer of calibration input functions
14 
15  Notes:
16 
17  Modification history:
18  Programmer Organization Date Description of change
19  -------------- ------------ -------- ---------------------
20  Lakshmi Kumar Hughes STX 03/11/94 Original development
21  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1
22  interface spcifications
23  Lakshmi Kumar Hughes STX 03/21/96 Corrected non-prototype
24  declarations
25  Lakshmi Kumar Hughes STX 03/17/97 Removed non-ANSI proto
26  declarations. In-detector
27  offsets are redefined as
28  idoffs[8][16].
29 ------------------------------------------------------------------------------*/
30 
31 #include "get_cal_osmi.h"
32 #include "getcal_proto_osmi.h"
33 #include <hdf4utils.h>
34 
35 #include <hdf.h>
36 #include <mfhdf.h>
37 
38 
39 /*-----------------------------------------------------------------------------
40  Function: get_index
41 
42  Returns: int32 (index)
43  On successful it returns the index of the given time entry and if
44  time entry not found, returns -3.
45 
46  Description:
47  The function get_index reads time vdata and searches for the
48  given time entry. If the given time found, it rerurns the entry
49  number to access related information from slopes and parameter vdatas.
50 
51  Arguments: (in calling order)
52  Type Name I/O Description
53  ---- ---- --- -----------
54  int32 fid I file ID
55  int16 syear I year of data start time
56  int16 sday I day-of-year for data start time
57  int16 eday I day-of-year for data end time
58  int32 smsec I milliseconds-of-day for data start time
59  int16 *cal_year O year the cal entry was made
60  int16 *cal_day O day of the year the cal entry was made
61 
62  Notes:
63 
64  Modification history:
65  Programmer Organization Date Description of change
66  -------------- ------------ -------- ---------------------
67  Lakshmi Kumar Hughes STX 03/11/94 Original development
68  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1
69  interface spcifications
70  Lakshmi Kumar Hughes STX 02/07/94 Added code to return
71  cal entry year and day
72  (ref to I/O specs v4.2)
73 ------------------------------------------------------------------------------*/
74 
75 int32_t get_index_osmi(int32_t fid, int16_t syear, int16_t sday, int16_t eday, int32_t msec,
76  int16_t *cal_year, int16_t *cal_day, int32_t *cal_msec) {
77 
78  int16_t dyear, dday, *cal_syear, *cal_sday, *cal_eyear, *cal_eday;
79  int16_t *entry_year, *entry_day;
80  int32_t i, *cal_smsec, *cal_emsec, vsid, elts;
81 
82 
83  if ((vsid = attach_vdata(fid, TIME)) < 0)
84  return RDERR;
85 
86  if ((elts = VSelts(vsid)) < 0)
87  return RDERR;
88  if ((cal_syear = (int16 *) malloc(elts * sizeof (int16))) == NULL)
89  return BUFERR;
90 
91  if ((cal_eyear = (int16 *) malloc(elts * sizeof (int16))) == NULL)
92  return BUFERR;
93 
94  if ((cal_sday = (int16 *) malloc(elts * sizeof (int16))) == NULL)
95  return BUFERR;
96 
97  if ((cal_eday = (int16 *) malloc(elts * sizeof (int16))) == NULL)
98  return BUFERR;
99 
100  if ((cal_smsec = (int32_t *) malloc(elts * sizeof (int32_t))) == NULL)
101  return BUFERR;
102 
103  if ((cal_emsec = (int32_t *) malloc(elts * sizeof (int32_t))) == NULL)
104  return BUFERR;
105 
106  if ((entry_year = (int16 *) malloc(elts * sizeof (int16))) == NULL)
107  return BUFERR;
108 
109  if ((entry_day = (int16 *) malloc(elts * sizeof (int16))) == NULL)
110  return BUFERR;
111 
112  rdvdata(vsid, SYEAR, 0, elts, (unsigned char *) cal_syear);
113  rdvdata(vsid, SDAY, 0, elts, (unsigned char *) cal_sday);
114  rdvdata(vsid, SMSEC, 0, elts, (unsigned char *) cal_smsec);
115 
116  rdvdata(vsid, EYEAR, 0, elts, (unsigned char *) cal_eyear);
117  rdvdata(vsid, EDAY, 0, elts, (unsigned char *) cal_eday);
118  rdvdata(vsid, EMSEC, 0, elts, (unsigned char *) cal_emsec);
119 
120  rdvdata(vsid, ENTRY_YEAR, 0, elts, (unsigned char *) entry_year);
121  rdvdata(vsid, ENTRY_DAY, 0, elts, (unsigned char *) entry_day);
122 
123  dyear = syear;
124  dday = sday;
125  if (sday != eday && msec < 43200000)
126  dday = eday;
127  if (dday < sday)
128  dyear += 1;
129 
130  for (i = elts - 1; i >= 0; i--) {
131  if (cal_eyear[i] == 0) { /* onwards rec */
132  if (dyear > cal_syear[i])
133  break;
134  if (dyear == cal_syear[i] && dday > cal_sday[i])
135  break;
136  if (dyear == cal_syear[i] && dday == cal_sday[i] &&
137  msec >= cal_smsec[i])
138  break;
139  } else { /* not an onwards rec */
140  if (dyear > cal_syear[i]) {
141  if (dyear < cal_eyear[i])
142  break;
143  if (dyear == cal_eyear[i]) {
144  if (dday < cal_eday[i])
145  break;
146  if (dday == cal_eday[i] && msec <= cal_emsec[i])
147  break;
148  }
149  } else
150  if (dyear == cal_syear[i]) {
151  if (dyear < cal_eyear[i])
152  break;
153  if (dyear == cal_eyear[i]) {
154  if (dday >= cal_sday[i] && dday < cal_eday[i])
155  break;
156  if (dday >= cal_sday[i] && dday == cal_eday[i] &&
157  msec <= cal_emsec[i])
158  break;
159  }
160  }
161  }
162  }
163 
164  *cal_year = cal_syear[i];
165  *cal_day = cal_sday[i];
166  *cal_msec = cal_smsec[i];
167 
168  VSdetach(vsid);
169  free(cal_syear);
170  free(cal_sday);
171  free(cal_smsec);
172  free(cal_eyear);
173  free(cal_eday);
174  free(cal_emsec);
175  free(entry_year);
176  free(entry_day);
177 
178  if (i < 0)
179  return TMERR;
180  else
181  return i;
182 }
183 
184 /*-----------------------------------------------------------------------------
185  Function: read_parm_data
186 
187  Returns: int32 (Status)
188  On success returns 0, otherwise returns -2 indicating read error.
189  Description:
190  The function attaches to the requested vdata
191 
192  Arguments: (in calling order)
193  Type Name I/O Description
194  ---- ---- --- -----------
195  int32 fid I HDF file ID
196  int32 sdfid I HDF SD file ID
197  int32 index I element number
198  int32 idoffs[8][16] O detector zero offset counts
199  float32 gains[8][16] O slopes (band*detector*gains)
200  float32 temps[256][2]O temp and ref temp correction factors
201  float32 scan_mod[2][1285]O scan-modulation buffer
202  float32 mirror[8][2] O mirror side1 and side2 for all bands
203  int16 tdi_list[256][4] O TDI values for all 8 bands
204 
205  Notes:
206 
207  Modification history:
208  Programmer Organization Date Description of change
209  -------------- ------------ -------- ---------------------
210  Lakshmi Kumar Hughes STX 03/11/94 Original development
211  Lakshmi Kumar Hughes STX 06/07/94 Updated to reflect v3.1
212  interface spcifications
213 ------------------------------------------------------------------------------*/
214 int32_t read_parm_data_osmi(int32_t fid, int32_t sdfid, int32_t index, float *eoffset,
215  float *egain, float *temp, float *mirror,
216  float *t_const, float *t_linear, float *t_quadratic,
217  float *slope, float *dc, float *sm) {
218 
219  int32_t i, slpid;
220  float32 egain_buf[9];
221  if ((slpid = attach_vdata(fid, "Electronics")) < 0)
222  return RDERR;
223  if ((rdvdata(slpid, gain_flds, index, 1, (unsigned char *) egain_buf)) < 0)
224  return RDERR;
225  VSdetach(slpid);
226  for (i = 0; i < 8; i++)
227  egain[i] = egain_buf[i];
228  *eoffset = egain_buf[8];
229  if ((slpid = attach_vdata(fid, "Mirror")) < 0)
230  return RDERR;
231  if ((rdvdata(slpid, mirror_flds, index, 1, (unsigned char *) mirror)) < 0)
232  return RDERR;
233  VSdetach(slpid);
234 
235  if ((slpid = attach_vdata(fid, "Longterm")) < 0)
236  return RDERR;
237  if ((rdvdata(slpid, t_const_flds, index, 1, (unsigned char *) t_const)) < 0)
238  return RDERR;
239  if ((rdvdata(slpid, t_linear_flds, index, 1, (unsigned char *) t_linear)) < 0)
240  return RDERR;
241  if ((rdvdata(slpid, t_quadratic_flds, index, 1, (unsigned char *) t_quadratic)) < 0)
242  return RDERR;
243  VSdetach(slpid);
244  if ((slpid = attach_vdata(fid, "TempCorr")) < 0)
245  return RDERR;
246  if ((rdvdata(slpid, temp_flds, index, 1, (unsigned char *) temp)) < 0)
247  return RDERR;
248  VSdetach(slpid);
249  if ((slpid = attach_vdata(fid, "Slopes")) < 0)
250  return RDERR;
251  if ((rdvdata(slpid, slope_flds, index, 1, (unsigned char *) slope)) < 0)
252  return RDERR;
253  VSdetach(slpid);
254  if ((slpid = attach_vdata(fid, "DCs")) < 0)
255  return RDERR;
256  if ((rdvdata(slpid, dc_flds, index, 1, (unsigned char *) dc)) < 0)
257  return RDERR;
258  VSdetach(slpid);
259  if ((slpid = attach_vdata(fid, "ScanMod")) < 0)
260  return RDERR;
261  if ((rdvdata(slpid, sm_flds, index, 1, (unsigned char *) sm)) < 0)
262  return RDERR;
263  VSdetach(slpid);
264 
265  return SUCCEED;
266 }
267 
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
int16 eday
Definition: l1_czcs_hdf.c:17
double t_const[BANDS_DIMS_1A]
Definition: l1a_seawifs.c:49
#define EYEAR
Definition: regen.h:37
#define SYEAR
Definition: regen.h:34
#define NULL
Definition: decode_rs.h:63
#define SDAY
Definition: regen.h:35
int16_t entry_year
Definition: l1a_seawifs.c:39
int attach_vdata(int32_t fid, const char *sname)
int32 * msec
Definition: l1_czcs_hdf.c:31
int syear
Definition: l1_czcs_hdf.c:15
int16_t entry_day
Definition: l1a_seawifs.c:40
int sday
Definition: l1_czcs_hdf.c:15
#define EMSEC
Definition: regen.h:39
float32 slope[]
Definition: l2lists.h:30
#define SMSEC
Definition: regen.h:36
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)
int rdvdata(int32_t vskey, const char *fields, int32_t start, int32_t nelt, unsigned char *databuf)
#define EDAY
Definition: regen.h:38
#define ENTRY_YEAR
Definition: calib_get_cal.h:24
#define ENTRY_DAY
Definition: calib_get_cal.h:25
#define TIME
Definition: calib_get_cal.h:12
#define TMERR
Definition: calib_get_cal.h:14
int i
Definition: decode_rs.h:71
#define BUFERR
Definition: calib_get_cal.h:15
#define RDERR
Definition: l2brsgen.h:22