OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
alloc_l2.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "l2_struc.h"
5 #include "l12_parms.h"
6 
7 void free_l2(l2str *l2rec) {
8  free((void *) l2rec->data);
9 }
10 
11 
12 /* --------------------------------------------------------- */
13 /* alloc_l2() - allocates 1 level-2 record to hold data for */
14 /* a single scan of "npix" pixels. */
15 
16 /* --------------------------------------------------------- */
17 int alloc_l2(l1str *l1rec, l2str *l2rec) {
18  l2rec->l1rec = l1rec;
19 
20  int32_t npix = l1rec->npix;
21  int32_t nbands = l1rec->l1file->nbands;
22  char *p;
23  int32_t len = 5 * sizeof(int32_t)*npix
24  + 5 * sizeof(float)*npix
25  + 11 * sizeof(float)*npix*nbands;
26 
27  if (len % 4 != 0)
28  len = len / 4 * 4 + 4;
29 
30  if ((p = (char *) malloc(len)) == NULL) {
31  fprintf(stderr,
32  "-E- %s line %d: Memory allocation failure.\n",
33  __FILE__, __LINE__);
34  return (0);
35  }
36 
37  l2rec->length = len;
38  l2rec->data = p;
39 
40  // var[npix]
41  l2rec->num_iter = (int32_t *) p;
42  p += sizeof(int32_t)*npix;
43  l2rec->aermodmin = (int32_t *) p;
44  p += sizeof(int32_t)*npix;
45  l2rec->aermodmax = (int32_t *) p;
46  p += sizeof(int32_t)*npix;
47  l2rec->aermodmin2 = (int32_t *) p;
48  p += sizeof(int32_t)*npix;
49  l2rec->aermodmax2 = (int32_t *) p;
50  p += sizeof(int32_t)*npix;
51 
52  l2rec->chl = (float *) p;
53  p += sizeof(float)*npix;
54  l2rec->eps = (float *) p;
55  p += sizeof(float)*npix;
56  l2rec->aerratio = (float *) p;
57  p += sizeof(float)*npix;
58  l2rec->aerratio2 = (float *) p;
59  p += sizeof(float)*npix;
60  l2rec->aerindex = (float *) p;
61  p += sizeof(float)*npix;
62 
63  // var[npix][nbands]
64  l2rec->taua = (float *) p;
65  p += sizeof(float)*npix*nbands;
66  l2rec->La = (float *) p;
67  p += sizeof(float)*npix*nbands;
68  l2rec->Lw = (float *) p;
69  p += sizeof(float)*npix*nbands;
70  l2rec->nLw = (float *) p;
71  p += sizeof(float)*npix*nbands;
72  l2rec->nLw_unc = (float *) p;
73  p += sizeof(float)*npix*nbands;
74  l2rec->brdf = (float *) p;
75  p += sizeof(float)*npix*nbands;
76  l2rec->Rrs = (float *) p;
77  p += sizeof(float)*npix*nbands;
78  l2rec->Rrs_unc = (float *) p;
79  p += sizeof(float)*npix*nbands;
80  l2rec->outband_correction = (float *) p;
81  p += sizeof(float)*npix*nbands;
82  l2rec->a = (float *) p;
83  p += sizeof(float)*npix*nbands;
84  l2rec->bb = (float *) p;
85  p += sizeof(float)*npix*nbands;
86 
87  if ((len - (int32_t) (p - l2rec->data)) < 0) {
88  printf("%s Line %d: bad allocation on L2 record\n", __FILE__, __LINE__);
89  exit(1);
90  }
91 
92  // init to NULL
93  l2rec->bindx = NULL;
94  l2rec->sst = NULL;
95  l2rec->Rrs_raman = NULL;
96  l2rec->tgrec = NULL;
97 
98  printf("Allocated %d bytes in L2 record.\n", (int) (p - l2rec->data));
99 
100  return (len);
101 }
void free_l2(l2str *l2rec)
Definition: alloc_l2.c:7
#define NULL
Definition: decode_rs.h:63
read l1rec
int alloc_l2(l1str *l1rec, l2str *l2rec)
Definition: alloc_l2.c:17
int32_t nbands
int npix
Definition: get_cmp.c:27
float p[MODELMAX]
Definition: atrem_corl1.h:131