OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
alloc_l1.c
Go to the documentation of this file.
1 #include "l1.h"
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 
6 void free_l1(l1str *l1rec) {
7  free((void *) l1rec->data);
8 }
9 
10 /* --------------------------------------------------------- */
11 /* alloc_l1() - allocates 1 level-1b record to hold data for */
12 /* a single scan of "npix" pixels. */
13 
14 /* --------------------------------------------------------- */
15 int32_t alloc_l1(filehandle* l1file, l1str *l1rec) {
16  char *p;
17  int32_t len;
18 
19  l1rec->l1file = l1file;
20 
21  int32_t nbands = l1file->nbands;
22  int32_t nbandsir = NBANDSIR;
23  int32_t npix = l1rec->npix = l1file->npix;
24 
25  /* */
26  /* allocate data block as contiguous bytes */
27  /* */
28  len = 44 * sizeof (float)*npix
29  + 23 * sizeof (float)*npix * nbands
30  + 2 * sizeof (float)*npix * nbandsir
31  + 1 * sizeof (float)*nbands
32  + 4 * sizeof (int32_t) * npix
33  + 2 * sizeof (short)*npix
34  + 15 * sizeof (char)*npix;
35 
36  /* Force to 4-byte increments for good measure */
37  len = (len / 4 + 1)*4;
38 
39  if ((p = (char *) malloc(len)) == NULL) {
40  fprintf(stderr,
41  "-E- %s line %d: Memory allocation failure.\n",
42  __FILE__, __LINE__);
43  return (0);
44  }
45 
46  /* Note: positional allocation is in order of datatype size, to
47  ensure that all 4-byte words start on 4-byte boundaries. Some
48  machines seem to have trouble if this is not done. */
49 
50  l1rec->length = len;
51  l1rec->data = p;
52 
53  // + 44*sizeof(float)*npix
54  l1rec->lon = (float *) p;
55  p += sizeof (float)*npix;
56  l1rec->lat = (float *) p;
57  p += sizeof (float)*npix;
58  l1rec->solz = (float *) p;
59  p += sizeof (float)*npix;
60  l1rec->sola = (float *) p;
61  p += sizeof (float)*npix;
62  l1rec->senz = (float *) p;
63  p += sizeof (float)*npix;
64  l1rec->sena = (float *) p;
65  p += sizeof (float)*npix;
66  l1rec->delphi = (float *) p;
67  p += sizeof (float)*npix;
68  l1rec->csolz = (float *) p;
69  p += sizeof (float)*npix;
70  l1rec->csenz = (float *) p;
71  p += sizeof (float)*npix;
72  l1rec->alpha = (float *) p;
73  p += sizeof (float)*npix;
74  l1rec->scattang = (float *) p;
75  p += sizeof (float)*npix;
76  l1rec->ws = (float *) p;
77  p += sizeof (float)*npix;
78  l1rec->wd = (float *) p;
79  p += sizeof (float)*npix;
80  l1rec->mw = (float *) p;
81  p += sizeof (float)*npix;
82  l1rec->zw = (float *) p;
83  p += sizeof (float)*npix;
84  l1rec->pr = (float *) p;
85  p += sizeof (float)*npix;
86  l1rec->oz = (float *) p;
87  p += sizeof (float)*npix;
88  l1rec->wv = (float *) p;
89  p += sizeof (float)*npix;
90  l1rec->rh = (float *) p;
91  p += sizeof (float)*npix;
92  l1rec->sfcp = (float *) p;
93  p += sizeof (float)*npix;
94  l1rec->sfcrh = (float *) p;
95  p += sizeof (float)*npix;
96  l1rec->sfct = (float *) p;
97  p += sizeof (float)*npix;
98  l1rec->icefr = (float *) p;
99  p += sizeof (float)*npix;
100  l1rec->no2_tropo = (float *) p;
101  p += sizeof (float)*npix;
102  l1rec->no2_strat = (float *) p;
103  p += sizeof (float)*npix;
104  l1rec->no2_frac = (float *) p;
105  p += sizeof (float)*npix;
106  l1rec->ws_unc = (float *) p;
107  p += sizeof (float)*npix;
108  l1rec->wd_unc = (float *) p;
109  p += sizeof (float)*npix;
110  l1rec->mw_unc = (float *) p;
111  p += sizeof (float)*npix;
112  l1rec->zw_unc = (float *) p;
113  p += sizeof (float)*npix;
114  l1rec->pr_unc = (float *) p;
115  p += sizeof (float)*npix;
116  l1rec->oz_unc = (float *) p;
117  p += sizeof (float)*npix;
118  l1rec->wv_unc = (float *) p;
119  p += sizeof (float)*npix;
120  l1rec->rh_unc = (float *) p;
121  p += sizeof (float)*npix;
122  l1rec->no2_tropo_unc = (float *) p;
123  p += sizeof (float)*npix;
124  l1rec->no2_strat_unc = (float *) p;
125  p += sizeof (float)*npix;
126  l1rec->height = (float *) p;
127  p += sizeof (float)*npix;
128  l1rec->dem = (float *) p;
129  p += sizeof (float)*npix;
130  l1rec->glint_coef = (float *) p;
131  p += sizeof (float)*npix;
132  l1rec->cloud_albedo = (float *) p;
133  p += sizeof (float)*npix;
134  l1rec->aerindex = (float *) p;
135  p += sizeof (float)*npix;
136  l1rec->sstref = (float *) p;
137  p += sizeof (float)*npix;
138  l1rec->sssref = (float *) p;
139  p += sizeof (float)*npix;
140  l1rec->rho_cirrus = (float *) p;
141  p += sizeof (float)*npix;
142 
143  // + 23*sizeof(float)*npix*nbands
144  l1rec->Lt = (float *) p;
145  p += sizeof (float)*npix*nbands;
146  l1rec->Lt_unc = (float *) p;
147  p += sizeof (float)*npix*nbands;
148  l1rec->t_h2o = (float *) p;
149  p += sizeof (float)*npix*nbands;
150  l1rec->t_o2 = (float *) p;
151  p += sizeof (float)*npix*nbands;
152  l1rec->tg_sol = (float *) p;
153  p += sizeof (float)*npix*nbands;
154  l1rec->tg_sen = (float *) p;
155  p += sizeof (float)*npix*nbands;
156  l1rec->t_sol = (float *) p;
157  p += sizeof (float)*npix*nbands;
158  l1rec->t_sen = (float *) p;
159  p += sizeof (float)*npix*nbands;
160  l1rec->rhof = (float *) p;
161  p += sizeof (float)*npix*nbands;
162  l1rec->tLf = (float *) p;
163  p += sizeof (float)*npix*nbands;
164  l1rec->Lr = (float *) p;
165  p += sizeof (float)*npix*nbands;
166  l1rec->L_q = (float *) p;
167  p += sizeof (float)*npix*nbands;
168  l1rec->L_u = (float *) p;
169  p += sizeof (float)*npix*nbands;
170  l1rec->polcor = (float *) p;
171  p += sizeof (float)*npix*nbands;
172  l1rec->dpol = (float *) p;
173  p += sizeof (float)*npix*nbands;
174  l1rec->TLg = (float *) p;
175  p += sizeof (float)*npix*nbands;
176  l1rec->rhos = (float *) p;
177  p += sizeof (float)*npix*nbands;
178  l1rec->sw_n = (float *) p;
179  p += sizeof (float)*npix*nbands;
180  l1rec->sw_a = (float *) p;
181  p += sizeof (float)*npix*nbands;
182  l1rec->sw_bb = (float *) p;
183  p += sizeof (float)*npix*nbands;
184  l1rec->sw_a_avg = (float *) p;
185  p += sizeof (float)*npix*nbands;
186  l1rec->sw_bb_avg = (float *) p;
187  p += sizeof (float)*npix*nbands;
188  l1rec->radcor = (float *) p;
189  p += sizeof (float)*npix*nbands;
190 
191  // + 2*sizeof(float)*npix*nbandsir
192  l1rec->Ltir = (float *) p;
193  p += sizeof (float)*npix*nbandsir;
194  l1rec->Bt = (float *) p;
195  p += sizeof (float)*npix*nbandsir;
196 
197  // + 1*sizeof(float)*nbands
198  l1rec->Fo = (float *) p;
199  p += sizeof (float)*nbands;
200 
201  // + 4*sizeof(int32_t)*npix
202  l1rec->nobs = (int32_t*) p;
203  p += sizeof (int32_t) * npix;
204  l1rec->pixnum = (int32_t*) p;
205  p += sizeof (int32_t) * npix;
206  l1rec->flags = (int32_t*) p;
207  p += sizeof (int32_t) * npix;
208  l1rec->pixdet = (int32_t*) p;
209  p += sizeof (int32_t) * npix;
210 
211  // + 2*sizeof(short)*npix
212  l1rec->ancqc = (short *) p;
213  p += sizeof (short)*npix;
214  l1rec->ssttype = (short *) p;
215  p += sizeof (short)*npix;
216 
217  // + 15*sizeof(char )*npix
218  l1rec->mask = (char *) p;
219  p += sizeof (char)*npix;
220  l1rec->hilt = (char *) p;
221  p += sizeof (char)*npix;
222  l1rec->cloud = (char *) p;
223  p += sizeof (char)*npix;
224  l1rec->glint = (char *) p;
225  p += sizeof (char)*npix;
226  l1rec->land = (char *) p;
227  p += sizeof (char)*npix;
228  l1rec->swater = (char *) p;
229  p += sizeof (char)*npix;
230  l1rec->ice = (char *) p;
231  p += sizeof (char)*npix;
232  l1rec->solzmax = (char *) p;
233  p += sizeof (char)*npix;
234  l1rec->senzmax = (char *) p;
235  p += sizeof (char)*npix;
236  l1rec->stlight = (char *) p;
237  p += sizeof (char)*npix;
238  l1rec->absaer = (char *) p;
239  p += sizeof (char)*npix;
240  l1rec->navfail = (char *) p;
241  p += sizeof (char)*npix;
242  l1rec->navwarn = (char *) p;
243  p += sizeof (char)*npix;
244  l1rec->filter = (char *) p;
245  p += sizeof (char)*npix;
246  l1rec->slot = (char *) p;
247  p += sizeof (char)*npix;
248 
249  if ((len - (int32_t) (p - l1rec->data)) < 0) {
250  printf("%s Line %d: bad allocation on L1 record\n", __FILE__, __LINE__);
251  exit(1);
252  }
253 
254  l1rec->private_data = NULL;
255  l1rec->geom_per_band = NULL;
256  l1rec->anc_add = NULL;
257  l1rec->anc_aerosol = NULL;
258  l1rec->cld_dat = NULL;
259 
260  if (want_verbose)
261  printf("Allocated %d bytes in L1 record.\n", (int32_t) (p - l1rec->data));
262 
263  return (1);
264 }
265 
int32 l1file(int32 sdfid, int32 *nsamp, int32 *nscans, int16 *dtynum)
Definition: l1stat_chk.c:586
#define NBANDSIR
Definition: filehandle.h:23
#define NULL
Definition: decode_rs.h:63
read l1rec
int want_verbose
void free_l1(l1str *l1rec)
Definition: alloc_l1.c:6
int32_t nbands
int32_t alloc_l1(filehandle *l1file, l1str *l1rec)
Definition: alloc_l1.c:15
int npix
Definition: get_cmp.c:27
float p[MODELMAX]
Definition: atrem_corl1.h:131