OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
cz_dat_alloc.c
Go to the documentation of this file.
1 #include "l1czcs.h"
2 
3 int cz_dat_alloc(int nscans, int n_ctl_pt, int r_mode,
4  l1_data_struc *l1_data)
5 /*******************************************************************
6 
7  cz_dat_alloc
8 
9  purpose: allocate the data storage in the czcs data structure
10 
11  Returns type: int - 0 - no problems
12 
13  Parameters: (in calling order)
14  Type Name I/O Description
15  ---- ---- --- -----------
16  int nscans I # scan lines of data
17  int n_ctl_pt I # pixel control points
18  int r_mode I read mode for how much of the
19  data arrays to allocate:
20  0 - allocate all data arrays
21  1 - allocate time and qual only
22  l1_data_struc * l1_data I/O data arrays
23 
24  Modification history:
25  Programmer Date Description of change
26  ---------- ---- ---------------------
27  W. Robinson, SAIC 10 Aug 2004 Original development
28  W. Robinson, SAIC 19 Dec 2005 add the pos_err position error array
29  allocation
30 
31  *******************************************************************/
32  {
33  int j;
34 
35  l1_data->msec = (int *) malloc(nscans * sizeof ( int));
36  l1_data->cal_sum =
37  (unsigned char *) malloc(nscans * 5 * sizeof ( unsigned char));
38  l1_data->cal_scan =
39  (unsigned char *) malloc(nscans * 6 * sizeof ( unsigned char));
40  /*
41  * for the rest, only allocate if mode 0
42  */
43  if (r_mode == 0) {
44  for (j = 0; j < 6; j++)
45  l1_data->counts[j] = (unsigned char *)
46  malloc(nscans * NCZCS_PIX * sizeof ( unsigned char));
47  l1_data->tilt = (float *) malloc(nscans * sizeof ( float));
48  l1_data->slat = (float *) malloc(nscans * sizeof ( float));
49  l1_data->slon = (float *) malloc(nscans * sizeof ( float));
50  l1_data->clat = (float *) malloc(nscans * sizeof ( float));
51  l1_data->clon = (float *) malloc(nscans * sizeof ( float));
52  l1_data->elat = (float *) malloc(nscans * sizeof ( float));
53  l1_data->elon = (float *) malloc(nscans * sizeof ( float));
54  l1_data->orb_vec =
55  (float *) malloc(nscans * 3 * sizeof ( float));
56  l1_data->att_ang =
57  (float *) malloc(nscans * 3 * sizeof ( float));
58  l1_data->pos_err = (float *) malloc(nscans * sizeof ( float));
59  l1_data->slope =
60  (float *) malloc(nscans * 6 * sizeof ( float));
61  l1_data->intercept =
62  (float *) malloc(nscans * 6 * sizeof ( float));
63  l1_data->gain = (short *) malloc(nscans * sizeof ( short));
64  l1_data->ctl_pt_rows = (int *) malloc(nscans * sizeof ( int));
65  l1_data->ctl_pt_cols = (int *) malloc(n_ctl_pt * sizeof (int));
66  l1_data->ctl_pt_lat =
67  (float *) malloc(nscans * n_ctl_pt * sizeof ( float));
68  l1_data->ctl_pt_lon =
69  (float *) malloc(nscans * n_ctl_pt * sizeof ( float));
70  /*
71  * for extra outputs of geometry and calibrated radiance data
72  */
73 #ifdef GEOM_CAL
74  l1_data->sen_zen =
75  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
76  l1_data->sen_az =
77  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
78  l1_data->sol_zen =
79  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
80  l1_data->sol_az =
81  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
82  l1_data->all_lat =
83  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
84  l1_data->all_lon =
85  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
86  l1_data->Lt_443 =
87  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
88  l1_data->Lt_520 =
89  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
90  l1_data->Lt_550 =
91  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
92  l1_data->Lt_670 =
93  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
94  l1_data->Lt_750 =
95  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
96  l1_data->Lt_11500 =
97  (float *) malloc(nscans * NCZCS_PIX * sizeof ( float));
98 #endif
99  }
100  /*
101  * and return
102  */
103  return 0;
104 }
105 
106 void cz_dat_free(l1_data_struc *l1_data, int r_mode)
107 /*******************************************************************
108 
109  cz_dat_free
110 
111  purpose: easy way to fre up all the array space for the SDSes
112 
113  Parameters: (in calling order)
114  Type Name I/O Description
115  ---- ---- --- -----------
116  l1_data_struc * l1_data I structure for czcs data
117  int r_mode I read mode, as above
118 
119  Modification history:
120  Programmer Date Description of change
121  ---------- ---- ---------------------
122  W. Robinson, SAIC 6 Aug 2004 Original development
123 
124  *******************************************************************/
125  {
126  int i;
127  /*
128  * just free the allocated arrays
129  */
130  free(l1_data->msec);
131  free(l1_data->cal_sum);
132  free(l1_data->cal_scan);
133  if (r_mode == 0) {
134  for (i = 0; i < 6; i++)
135  free(l1_data->counts[i]);
136  free(l1_data->tilt);
137  free(l1_data->slat);
138  free(l1_data->slon);
139  free(l1_data->clat);
140  free(l1_data->clon);
141  free(l1_data->elat);
142  free(l1_data->elon);
143  free(l1_data->orb_vec);
144  free(l1_data->att_ang);
145  free(l1_data->pos_err);
146  free(l1_data->slope);
147  free(l1_data->intercept);
148  free(l1_data->gain);
149  free(l1_data->ctl_pt_rows);
150  free(l1_data->ctl_pt_cols);
151  free(l1_data->ctl_pt_lat);
152  free(l1_data->ctl_pt_lon);
153  /*
154  * The extra values of satellite view, full navigation and calibrated
155  * radiances need not be accounted for as they are for test only
156  */
157  }
158  return;
159 }
int j
Definition: decode_rs.h:73
int cz_dat_alloc(int nscans, int n_ctl_pt, int r_mode, l1_data_struc *l1_data)
Definition: cz_dat_alloc.c:3
void cz_dat_free(l1_data_struc *l1_data, int r_mode)
Definition: cz_dat_alloc.c:106
int i
Definition: decode_rs.h:71
#define NCZCS_PIX
Definition: l1czcs.h:23