OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
alloc_target.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "target_struc.h"
5 #include "l12_parms.h"
6 
7 /* --------------------------------------------------------- */
8 /* alloc_target() - allocates 1 target record to hold data */
9 /* for a single scan of "npix" pixels. */
10 
11 /* --------------------------------------------------------- */
12 int alloc_target(int32_t npix, int32_t nbands, tgstr *rec) {
13  char *p;
14  int32_t len = 3 * sizeof (int32_t) /* time */
15  + sizeof (float)*npix /* solz */
16  + 2 * nbands * sizeof (float)*npix; /* lw,nLw */
17 
18  if ((p = (char *) malloc(len)) == NULL) {
19  fprintf(stderr,
20  "-E- %s line %d: Memory allocation failure.\n",
21  __FILE__, __LINE__);
22  return (0);
23  }
24  memset(p, '\0', len);
25 
26  rec->length = len;
27  rec->npix = npix;
28  rec->data = p;
29 
30  rec->year = (int32_t *) p;
31  p += sizeof (int32_t);
32  rec->day = (int32_t *) p;
33  p += sizeof (int32_t);
34  rec->msec = (int32_t *) p;
35  p += sizeof (int32_t);
36  rec->solz = (float *) p;
37  p += sizeof (float)*npix;
38  rec->Lw = (float *) p;
39  p += sizeof (float)*npix*nbands;
40  rec->nLw = (float *) p;
41  p += sizeof (float)*npix*nbands;
42 
43  return (len);
44 }
#define NULL
Definition: decode_rs.h:63
int alloc_target(int32_t npix, int32_t nbands, tgstr *rec)
Definition: alloc_target.c:12
int32_t nbands
int npix
Definition: get_cmp.c:27
float p[MODELMAX]
Definition: atrem_corl1.h:131