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 
193 /* global storage space for BAND 8 gain value to be used in stray_light */
194 short gain8;
195 
196 #endif /* !NO_SET_HIGHLT1 */
197 
198 #define STRAY_LIGHT_COMPLETE 0
199 #define STRAY_LIGHT_LATE_START 1
200 #define STRAY_LIGHT_EARLY_STOP 2
201 #define STRAY_LIGHT_RANDOM 4
202 #define PIX_SUB_V 4.0
203 #define GAC_STRAY_LIGHT_COEF(v) (ceil(roundingup = v/PIX_SUB_V))
204 #define LAC_STRAY_LIGHT_COEF(v) (v)
205 #define STRAY_LIGHT_COEF(v,dtyp) (strcmp(dtyp,"GAC")?LAC_STRAY_LIGHT_COEF(v):GAC_STRAY_LIGHT_COEF(v))
206 
207 #define NTRY_WARNING 5
208 #define NTRY_LIMIT 20
209 
210 
211 #ifdef L1A_INIT_NEEDED
212 
213 #ifdef PROTOTYPE
214 PRIVATE void init(void)
215 #else
216 
217 PRIVATE void init()
218 #endif
219 {
220  char *FUNC = "l1a_init";
221  int i, j;
222 
223  ON_TIME();
224  /* invalidate all fids */
225  for (i = 0; i < MAX_HDF_L1AGET; i++) {
226  fid[i] = -1;
227  blksize_changed[i] = BLKSIZE_NOT_CHANGED;
228  blksize[i] = DEFAULT_BUFFER_BLKSIZE;
229  /* set to zero, indicate no call to get_l1a_record yet */
230  blksrec[i] = 0;
231  cal_table_file[i] = NULL;
232  stray_light_flag[i] = 0;
233  ltyp_frac_coef[i] = 0.0;
234  out_band_flag[i] = 0;
235  recursive_flag[i] = FALSE;
236  recursive_free = 0;
237  stray_light_calling_flag[i] = STRAY_LIGHT_COMPLETE;
238  stray_light_scan_no[i] = 1;
239  }
240  OFF_TIME();
241 }
242 
243 #endif // L1A_INIT_NEEDED
244 
245 /*------------------------------------------------------------------------------
246 
247  calculate the mean and standard deviation of the 8 bands of
248  dark-restore values for each band
249  W. Robinson, GSC, 18 Mar 98 change dark computation to filter
250  dark values <5, > 35 and then find the median on the remainder
251  Note routines d_stats, i16comp and d_sd are a part of this now
252 
253 ------------------------------------------------------------------------------*/
254 #ifdef PROTOTYPE
255 int dark_rest_stat(int16 *data, int nrec, float *dark_mean, float *dark_std)
256 #else
257 
259 int16 *data; /* 8 bands of dark restore data */
260 int nrec; /* number of scan lines */
261 float *dark_mean; /* 8 bands of dark restore mean values */
262 float *dark_std; /* 8 bands of dark restore std values */
263 #endif
264 {
265  double *ddata;
266  double dmedian;
267  double dark;
268  int32 num_out, i, j;
269  ddata = malloc(nrec * sizeof (double));
270 
271  for (i = 0; i < 8; i++) {
272  for (j = 0; j < nrec; j++) {
273  ddata[j] = (double) *(data + j * 8 + i);
274  }
275  gsl_sort(ddata, 1, nrec);
276  dmedian = gsl_stats_median_from_sorted_data(ddata, 1, nrec);
277  memset(ddata, 0, nrec);
278  num_out = 0;
279  for (j = 0; j < nrec; j++) {
280  dark = (double) *(data + j * 8 + i);
281  if (dark > dmedian * 0.85 && dark < dmedian * 1.15) {
282  ddata[num_out] = (double) *(data + j * 8 + i);
283  num_out++;
284  }
285  }
286  *(dark_mean + i) = (float) gsl_stats_mean(ddata, 1, num_out);
287  *(dark_std + i) = (float) gsl_stats_sd(ddata, 1, num_out);
288  }
289  free(ddata);
290  return 0;
291 
292 }
integer, parameter int16
Definition: cubeio.f90:3
float dark_mean[8]
Definition: l1a_seawifs.c:34
int j
Definition: decode_rs.h:73
#define STRAY_LIGHT_COMPLETE
Definition: l1a.c:198
#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 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:194
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:258
int i
Definition: decode_rs.h:71