OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1a.c
Go to the documentation of this file.
1 /*
2 
3 $Header: /app/shared/RCS/irix-5.2/seawifsd/src/hdfio/L1A.V4.5/l1a.c,v 4.18 1996/01/17 16:53:52 seawifsd Exp seawifsd $
4 $Log: l1a.c,v $
5 Revision 4.18 1996/01/17 16:53:52 seawifsd
6 added ON_TIME()/OFF_TIME() to report execution elapse time.
7 
8 Revision 4.17 1995/12/19 14:51:04 seawifsd
9 fixed bug in testing main program. The bug only occurs when
10 L1B HDF file was not created(specified). Fixes are done to
11 use the fid of L1A HDF file instead of that of L1B.
12 
13 Revision 4.16 1995/12/07 19:21:01 seawifsd
14 dded support to compile with calibration and straylight correction routines.
15 added snode,enode,startclat,startclon,endclat,endclon and
16 made it IO_SPEC_V4.4 and PROD_SPEC_V2.8 compliant.
17 added l2_flags, checked and set HIGHLT1 flag. Created additional
18 SDS to store L1B data in the test main program.
19 
20 Revision 4.15 1995/05/12 13:53:00 seawifsd
21 1. code conformed to specifications IO_SPEC_V43, PROD_SPEC_V27,
22 and NONPROD_SPEC_V12(no funtionality changes, just eliminate
23 code related to versions before IO_SPEC_V42)
24 
25 Revision 4.14 1995/05/04 15:28:24 seawifsd
26 changed all references to 'exist.h' to 'generic.h'.
27 
28 Revision 4.13 1995/04/03 16:06:36 seawifsd
29 modified testing part of the l1a.c for more consistent and accurate output.
30 
31 Revision 4.12 1995/02/15 18:51:23 seawifsd
32 added additional code to implement the objects 'scsol_z', 'entry_year',
33 'entry_day', and 'csol_z'.
34 renamed macro LAKSHMI to EXTRA_FOR_BROWSE.
35 specifically declared the datatype of fid[] and fid2[].
36 added an optional third command parameter <skip> in the testing
37 main program to indicate number of scan line to skip in displaying
38 l1a science data. Corresponding print statements were revised to
39 add this support and the support of TRANSPOSE_IMAGE macro.
40 
41 Revision 4.11 1995/01/27 18:20:33 seawifsd
42 changed the order of mirror from mirror[bands][sides] to mirror[sides][bands]
43 
44 Revision 4.10 1995/01/17 20:03:18 seawifsd
45 Jan. 17, 1994 V4.1
46 
47 Revision 4.2 1995/01/17 14:34:50 seawifsd
48 added calling FORTRAN cdata_() before geonav_() because the changes
49 in MOPS geonav.f code.
50 
51 Revision 4.1 1995/01/17 14:15:37 seawifsd
52 Jan. 9, 1994, 4.0
53 
54 Revision 3.6 1994/12/15 16:06:42 seawifsd
55 code conformed to IO_SPEC_V41, PROD_SPEC_V24 and NONPROD_SPEC_V10(no
56 changes were needed from IO_SPEC_V40)
57 
58 Revision 3.5 1994/12/15 16:04:57 seawifsd
59 made sure that the pointers passed into the i/o routines in the test
60 main program are all null by declaring as static.
61 
62 Revision 3.4 1994/12/06 19:31:41 seawifsd
63 made the code comformed to IO_SPEC_V40 and PROD_SPEC_V24.
64 elliminated all references to IO_SPEC_V10 and related features under that
65 version.
66 made the L1A image data to be pixel interlaced(to fit the spec.) instead
67 of the original band interlaced.(by define TRANSPOSE_IMAGE in wifs_conf.h)
68 
69 Revision 3.3 1994/11/08 18:45:55 seawifsd
70 Nov. 8, 1994, 3.3a3
71 
72 Revision 3.3 1994/11/08 15:03:53 seawifsd
73 Nov. 8, 1994, 3.3a2
74 
75 Revision 1.1.1.5 1994/11/03 20:24:00 frank
76 renamed MIN macro to MINV.
77 
78 Revision 1.1.1.4 1994/11/01 16:02:28 frank
79 added processing of 'meta_l1a.infiles' because of the new requirement
80 from L1A Browse routines.
81 
82 Revision 1.1.1.3 1994/10/21 19:43:51 frank
83 turned off some message printing by using PRINTF instead of printf.
84 
85 Revision 1.1.1.2 1994/10/05 20:14:01 frank
86 1. updated L1A source code to fit the specification of the
87 "SeaWiFS OPERATIONAL ARCHIVE PRODUCT SPECIFICATIONS" v 1.0, 07/22/94,
88 and the "INTERFACE SPECIFICATIONS FOR SeaWiFS OPERATIONAL PRODUCT
89 INPUT, OUTPUT, AND SENSOR CALIBRATION SOFTWARE" v 3.3 07/12/94
90 
91 Revision 1.1.1.1 1994/05/23 19:04:43 frank
92 variables ptr_orb_vec, ptr_l_vert, ptr_sun_ref, ptr_att_ang, ptr_sen_mat,
93 ptr_scan_ell, ptr_nflag, nsta, ninc, and npix are declared as PRIVATE(static)
94 'int32_t *longptr' was added in get_l1a_record() routine and used as the
95 lhs to nav.nflag so that to match the prototype.
96 
97 Revision 1.2 1994/05/10 18:44:37 seawifst
98 May 6, 1994 version 1.2
99 
100 Revision 1.1 1994/04/19 13:23:38 seawifst
101 Initial revision
102 
103 Removed all code that was only compiled when GENERAL, USE_STRUCT,
104 or TESTCODE were defined. (687 lines of code removed.)
105 Norman Kuring 6-Nov-1996
106 
107 Added code to handle "Calibration" Vgroup data.
108 Norman Kuring 6-Nov-1996
109 
110 Removed all code that was only compiled when EVERYTHING was defined.
111 Removed non-prototype style function definitions.
112 Norman Kuring 7-Nov-1996
113 
114 Put back all of the GENERAL and EVERYTHING code. Heavy sigh.
115 Norman Kuring 25-Nov-1996
116 
117 fix values of l1a_data and geoloc when stray light processing is done.
118 W. Robinson 3-Apr-1997
119 
120 W. Robinson , GSC, 20 Mar 98 update the dark restore calculation to filter
121 unreasonable values and to take the median
122  */
123 
124 
125 #include <stdio.h>
126 #include <string.h>
127 #include <stdlib.h>
128 /* for ceil used in STRAY_LIGHT_COEF macro */
129 #include <math.h>
130 
131 // why reinvent the wheel
132 #include <gsl/gsl_sort.h>
133 #include <gsl/gsl_statistics.h>
134 
135 #include "hdf.h"
136 //#include "hdfhdr.h"
137 //#include "hdfmac.h"
138 //#include "usrhdr.h"
139 #include "usrmac.h"
140 
141 //#include "generic.h"
142 
143 #include "ffm.h"
144 #include "cdl_object.h"
145 #include "hdf_object.h"
146 #include "SeaWiFS.h"
147 #include "navigation.h"
148 #include "l1a.h"
149 #include "level_1a_index.h"
150 
151 #include "datatype.h"
152 #include "tlm.h"
153 #include "l1a_proto.h"
154 
155 /* prototype for get_WIFSinfo() */
156 #include "WIFSHDF.h"
157 
158 /* stray light */
159 #include "st_lt.h"
160 #include "cal_l1a.h"
161 #include "get_cal.h"
162 #ifndef NO_SET_HIGHLT1
163 #include "l2_flags_sw.h"
164 #endif /* !NO_SET_HIGHLT1 */
165 
166 /* cpp_processing_start_here_please_do_not_delete_this_line */
167 
168 /* Make following as default in all future release(040194) */
169 
170 
171 #define FIRST_GET_L1A_OPEN 1
172 
173 #ifndef DEFAULT_BUFFER_BLKSIZE
174 #define DEFAULT_BUFFER_BLKSIZE 10
175 #endif
176 
177 #define BLKSIZE_NOT_CHANGED 0
178 #define BLKSIZE_CHANGED 1
179 
180 /*
181  Following are for get_l1a_record routine to keep track of:
182  1. current access record number
183  2. total record number
184  */
185 
186 #define CLEAR 0
187 #define INIT 1
188 #define RECORDS 2
189 
190 #ifndef NO_SET_HIGHLT1
191 #define FIRST_KNEE 1
192 /* this global variable is in the code with calibrate_l1a() */
195 
196 /* global storage space for BAND 8 gain value to be used in stray_light */
197 short gain8;
198 
199 #endif /* !NO_SET_HIGHLT1 */
200 
201 #define STRAY_LIGHT_COMPLETE 0
202 #define STRAY_LIGHT_LATE_START 1
203 #define STRAY_LIGHT_EARLY_STOP 2
204 #define STRAY_LIGHT_RANDOM 4
205 #define PIX_SUB_V 4.0
206 #define GAC_STRAY_LIGHT_COEF(v) (ceil(roundingup = v/PIX_SUB_V))
207 #define LAC_STRAY_LIGHT_COEF(v) (v)
208 #define STRAY_LIGHT_COEF(v,dtyp) (strcmp(dtyp,"GAC")?LAC_STRAY_LIGHT_COEF(v):GAC_STRAY_LIGHT_COEF(v))
209 
210 #define NTRY_WARNING 5
211 #define NTRY_LIMIT 20
212 
213 
214 #ifdef L1A_INIT_NEEDED
215 
216 #ifdef PROTOTYPE
217 PRIVATE void init(void)
218 #else
219 
220 PRIVATE void init()
221 #endif
222 {
223  char *FUNC = "l1a_init";
224  int i, j;
225 
226  ON_TIME();
227  /* invalidate all fids */
228  for (i = 0; i < MAX_HDF_L1AGET; i++) {
229  fid[i] = -1;
230  blksize_changed[i] = BLKSIZE_NOT_CHANGED;
231  blksize[i] = DEFAULT_BUFFER_BLKSIZE;
232  /* set to zero, indicate no call to get_l1a_record yet */
233  blksrec[i] = 0;
234  cal_table_file[i] = NULL;
235  stray_light_flag[i] = 0;
236  ltyp_frac_coef[i] = 0.0;
237  out_band_flag[i] = 0;
238  recursive_flag[i] = FALSE;
239  recursive_free = 0;
240  stray_light_calling_flag[i] = STRAY_LIGHT_COMPLETE;
241  stray_light_scan_no[i] = 1;
242  }
243  OFF_TIME();
244 }
245 
246 #endif // L1A_INIT_NEEDED
247 
248 /*------------------------------------------------------------------------------
249 
250  calculate the mean and standard deviation of the 8 bands of
251  dark-restore values for each band
252  W. Robinson, GSC, 18 Mar 98 change dark computation to filter
253  dark values <5, > 35 and then find the median on the remainder
254  Note routines d_stats, i16comp and d_sd are a part of this now
255 
256 ------------------------------------------------------------------------------*/
257 #ifdef PROTOTYPE
258 int dark_rest_stat(int16 *data, int nrec, float *dark_mean, float *dark_std)
259 #else
260 
262 int16 *data; /* 8 bands of dark restore data */
263 int nrec; /* number of scan lines */
264 float *dark_mean; /* 8 bands of dark restore mean values */
265 float *dark_std; /* 8 bands of dark restore std values */
266 #endif
267 {
268  double *ddata;
269  double dmedian;
270  double dark;
271  int32 num_out, i, j;
272  ddata = malloc(nrec * sizeof (double));
273 
274  for (i = 0; i < 8; i++) {
275  for (j = 0; j < nrec; j++) {
276  ddata[j] = (double) *(data + j * 8 + i);
277  }
278  gsl_sort(ddata, 1, nrec);
279  dmedian = gsl_stats_median_from_sorted_data(ddata, 1, nrec);
280  memset(ddata, 0, nrec);
281  num_out = 0;
282  for (j = 0; j < nrec; j++) {
283  dark = (double) *(data + j * 8 + i);
284  if (dark > dmedian * 0.85 && dark < dmedian * 1.15) {
285  ddata[num_out] = (double) *(data + j * 8 + i);
286  num_out++;
287  }
288  }
289  *(dark_mean + i) = (float) gsl_stats_mean(ddata, 1, num_out);
290  *(dark_std + i) = (float) gsl_stats_sd(ddata, 1, num_out);
291  }
292  free(ddata);
293  return 0;
294 
295 }
integer, parameter int16
Definition: cubeio.f90:3
float dark_mean[8]
Definition: l1a_seawifs.c:34
int j
Definition: decode_rs.h:73
#define GAINS_DIMS_1A
#define STRAY_LIGHT_COMPLETE
Definition: l1a.c:201
#define FALSE
Definition: rice.h:164
#define NULL
Definition: decode_rs.h:63
int init(int32_t ipr, int32_t jpr, char *efile, char *pfile)
Definition: proj_report.c:51
#define BANDS_DIMS_1A
Definition: level_1a_index.h:8
#define DEFAULT_BUFFER_BLKSIZE
Definition: l1a.c:174
#define OFF_TIME()
Definition: usrmac.h:163
#define ON_TIME()
Definition: usrmac.h:162
#define MAX_HDF_L1AGET
Definition: calib_l1a.h:91
#define BLKSIZE_NOT_CHANGED
Definition: l1a.c:177
short gain8
Definition: l1a.c:197
integer, parameter double
float dark_std[8]
Definition: l1a_seawifs.c:35
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
#define PRIVATE
Definition: usrmac.h:85
int dark_rest_stat(int16 *data, int nrec, float *dark_mean, float *dark_std)
Definition: l1a.c:261
float32 cal_rads[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]
#define KNEES_DIMS_1A
int i
Definition: decode_rs.h:71
float32 cal_counts[BANDS_DIMS_1A][GAINS_DIMS_1A][KNEES_DIMS_1A]