OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
cz_l1_read.c
Go to the documentation of this file.
1 #include "l1czcs.h"
2 #include "hdfio.h"
3 
4 int cz_l1_read(char *file, int r_mode, gattr_struc *cz_attr,
5  l1_data_struc *cz_dat)
6 /*******************************************************************
7 
8  cz_l1_read
9 
10  purpose: read the attributes and data from a CZCS L1 file
11 
12  Returns type: int - return status: 0 is good
13 
14  Parameters: (in calling order)
15  Type Name I/O Description
16  ---- ---- --- -----------
17  char * file I name of file to open
18  int r_mode I read mode: 0 - read all the
19  data into the structures
20  1 - read time and quality data
21  only
22  gattr_struc * cz_attr O structure of global attributes
23  l1_data_struc * cz_dat O structure of SDS data
24 
25  Modification history:
26  Programmer Date Description of change
27  ---------- ---- ---------------------
28  W. Robinson, SAIC 6 Aug 2004 Original development
29  W. Robinson, SAIC 20 Dec 2005 add the pos_err or position error
30  sds to the reading
31 
32  *******************************************************************/
33  {
34  hdfio_struc hdfid;
35  int nscan, n_ctl_pt;
36  unsigned char *tmp_ptr;
37  /*
38  * open the file
39  */
40  if (hdfio_open(file, &hdfid) != 0) return -1;
41  /*
42  * read the basic attributes first
43  * # scans
44  */
45  if (hdfio_rd_gattr(hdfid, "Number of Scan Lines", DFNT_INT32,
46  1, (void *) &cz_attr->scan_lines) != 0) return -1;
47  nscan = cz_attr->scan_lines;
48 
49  /* parm presence */
50  if (hdfio_rd_gattr(hdfid, "Parameter Presence Code", DFNT_UINT8, 1,
51  (void *) &cz_attr->parm_presence) != 0) return -1;
52 
53  /* # pixel ctl points */
54  if (hdfio_rd_gattr(hdfid, "Number of Pixel Control Points", DFNT_INT32,
55  1, (void *) &cz_attr->n_ctl_pt) != 0) return -1;
56  n_ctl_pt = cz_attr->n_ctl_pt;
57 
58  /* start day */
59  if (hdfio_rd_gattr(hdfid, "Start Day", DFNT_INT16,
60  1, (void *) &cz_attr->start_day) != 0) return -1;
61 
62  /*
63  * set up the data storage
64  */
65  cz_dat_alloc(nscan, n_ctl_pt, r_mode, cz_dat);
66  /*
67  * read in the arrays
68  */
69  if (hdfio_rd_sd(hdfid, "msec", (void *) cz_dat->msec) != 0) return -1;
70  if (hdfio_rd_sd(hdfid, "cal_sum", (void *) cz_dat->cal_sum) != 0)
71  return -1;
72  if (hdfio_rd_sd(hdfid, "cal_scan", (void *) cz_dat->cal_scan) != 0)
73  return -1;
74  /*
75  * if mode is set for reading all the data, read the rest
76  */
77  if (r_mode == 0) {
78  /*
79  * first, read the rest of the attributes
80  */
81  if (hdfio_rd_gattr(hdfid, "Product Name", DFNT_CHAR,
82  40, (void *) cz_attr->prod_name) != 0) return -1;
83 
84  if (hdfio_rd_gattr(hdfid, "Title", DFNT_CHAR,
85  40, (void *) cz_attr->f_title) != 0) return -1;
86 
87  if (hdfio_rd_gattr(hdfid, "Data Center", DFNT_CHAR,
88  256, (void *) cz_attr->datacenter) != 0) return -1;
89 
90  if (hdfio_rd_gattr(hdfid, "Station Name", DFNT_CHAR,
91  256, (void *) cz_attr->stn_name) != 0) return -1;
92 
93  if (hdfio_rd_gattr(hdfid, "Station Latitude", DFNT_FLOAT32,
94  1, (void *) &cz_attr->stn_lat) != 0) return -1;
95 
96  if (hdfio_rd_gattr(hdfid, "Station Longitude", DFNT_FLOAT32,
97  1, (void *) &cz_attr->stn_lon) != 0) return -1;
98 
99  if (hdfio_rd_gattr(hdfid, "Mission", DFNT_CHAR,
100  40, (void *) cz_attr->mission) != 0) return -1;
101 
102  if (hdfio_rd_gattr(hdfid, "Mission Characteristics", DFNT_CHAR,
103  256, (void *) cz_attr->mission_char) != 0) return -1;
104 
105  if (hdfio_rd_gattr(hdfid, "Sensor", DFNT_CHAR,
106  40, (void *) cz_attr->sensor) != 0) return -1;
107 
108  if (hdfio_rd_gattr(hdfid, "Sensor Characteristics", DFNT_CHAR,
109  256, (void *) cz_attr->sensor_char) != 0) return -1;
110 
111  if (hdfio_rd_gattr(hdfid, "Data Type", DFNT_CHAR,
112  16, (void *) cz_attr->datatype) != 0) return -1;
113 
114  if (hdfio_rd_gattr(hdfid, "Replacement Flag", DFNT_CHAR,
115  40, (void *) cz_attr->repl_flg) != 0) return -1;
116 
117  if (hdfio_rd_gattr(hdfid, "Software ID", DFNT_CHAR,
118  128, (void *) cz_attr->soft_id) != 0) return -1;
119 
120  if (hdfio_rd_gattr(hdfid, "Processing Time", DFNT_CHAR,
121  17, (void *) cz_attr->process_time) != 0) return -1;
122 
123  if (hdfio_rd_gattr(hdfid, "Input Files", DFNT_CHAR,
124  1280, (void *) cz_attr->input_files) != 0) return -1;
125 
126  if (hdfio_rd_gattr(hdfid, "Processing Control", DFNT_CHAR,
127  1024, (void *) cz_attr->proc_ctl) != 0) return -1;
128 
129  if (hdfio_rd_gattr(hdfid, "Start Time", DFNT_CHAR,
130  17, (void *) cz_attr->start_time) != 0) return -1;
131 
132  if (hdfio_rd_gattr(hdfid, "End Time", DFNT_CHAR,
133  17, (void *) cz_attr->end_time) != 0) return -1;
134 
135  if (hdfio_rd_gattr(hdfid, "Scene Center Time", DFNT_CHAR,
136  17, (void *) cz_attr->center_time) != 0) return -1;
137 
138  if (hdfio_rd_gattr(hdfid, "Start Year", DFNT_INT16,
139  1, (void *) &cz_attr->start_year) != 0) return -1;
140 
141  if (hdfio_rd_gattr(hdfid, "Start Millisec", DFNT_INT32,
142  1, (void *) &cz_attr->start_msec) != 0) return -1;
143 
144  if (hdfio_rd_gattr(hdfid, "End Year", DFNT_INT16,
145  1, (void *) &cz_attr->end_year) != 0) return -1;
146 
147  if (hdfio_rd_gattr(hdfid, "End Day", DFNT_INT16,
148  1, (void *) &cz_attr->end_day) != 0) return -1;
149 
150  if (hdfio_rd_gattr(hdfid, "End Millisec", DFNT_INT32,
151  1, (void *) &cz_attr->end_msec) != 0) return -1;
152 
153  if (hdfio_rd_gattr(hdfid, "Start Node", DFNT_CHAR,
154  11, (void *) cz_attr->start_node) != 0) return -1;
155 
156  if (hdfio_rd_gattr(hdfid, "End Node", DFNT_CHAR,
157  11, (void *) cz_attr->end_node) != 0) return -1;
158 
159  if (hdfio_rd_gattr(hdfid, "Orbit Number", DFNT_INT32,
160  1, (void *) &cz_attr->orbit) != 0) return -1;
161 
162  if (hdfio_rd_gattr(hdfid, "Pixels per Scan Line", DFNT_INT32,
163  1, (void *) &cz_attr->pix_per_scan) != 0) return -1;
164 
165  if (hdfio_rd_gattr(hdfid, "Number of Scan Lines", DFNT_INT32,
166  1, (void *) &cz_attr->scan_lines) != 0) return -1;
167 
168  if (hdfio_rd_gattr(hdfid, "Number of Scan Control Points", DFNT_INT32,
169  1, (void *) &cz_attr->n_ctl_lin) != 0) return -1;
170 
171  if (hdfio_rd_gattr(hdfid, "LAC Pixel Start Number", DFNT_INT32,
172  1, (void *) &cz_attr->lac_pixl_start_no) != 0) return -1;
173 
174  if (hdfio_rd_gattr(hdfid, "LAC Pixel Subsampling", DFNT_INT32,
175  1, (void *) &cz_attr->lac_pixl_subsample) != 0) return -1;
176 
177  if (hdfio_rd_gattr(hdfid, "Scene Center Scan Line", DFNT_INT32,
178  1, (void *) &cz_attr->cntr_scn_line) != 0) return -1;
179 
180  if (hdfio_rd_gattr(hdfid, "Filled Scan Lines", DFNT_INT32,
181  1, (void *) &cz_attr->filled_lines) != 0) return -1;
182 
183  if (hdfio_rd_gattr(hdfid, "Sensor Tilt", DFNT_FLOAT32,
184  1, (void *) &cz_attr->tilt) != 0) return -1;
185 
186  if (hdfio_rd_gattr(hdfid, "Scene Gain", DFNT_INT32,
187  1, (void *) &cz_attr->gain) != 0) return -1;
188 
189  if (hdfio_rd_gattr(hdfid, "Thresh", DFNT_INT32,
190  1, (void *) &cz_attr->thresh) != 0) return -1;
191 
192  if (hdfio_rd_gattr(hdfid, "Calibration Slope", DFNT_FLOAT32,
193  6, (void *) cz_attr->slope) != 0) return -1;
194 
195  if (hdfio_rd_gattr(hdfid, "Calibration Intercept", DFNT_FLOAT32,
196  6, (void *) cz_attr->intercept) != 0) return -1;
197 
198  if (hdfio_rd_gattr(hdfid, "Center Roll", DFNT_FLOAT32,
199  1, (void *) &cz_attr->roll) != 0) return -1;
200 
201  if (hdfio_rd_gattr(hdfid, "Center Pitch", DFNT_FLOAT32,
202  1, (void *) &cz_attr->pitch) != 0) return -1;
203 
204  if (hdfio_rd_gattr(hdfid, "Center Yaw", DFNT_FLOAT32,
205  1, (void *) &cz_attr->yaw) != 0) return -1;
206 
207  if (hdfio_rd_gattr(hdfid, "ILT Flags", DFNT_UINT8,
208  1, (void *) &cz_attr->ilt_flags) != 0) return -1;
209 
210  if (hdfio_rd_gattr(hdfid, "Number of Missing Scan Lines", DFNT_INT16,
211  1, (void *) &cz_attr->n_miss_scans) != 0) return -1;
212 
213  if (hdfio_rd_gattr(hdfid, "Number of Scans with Missing Channels",
214  DFNT_INT16,
215  6, (void *) cz_attr->n_scan_mis_chan) != 0) return -1;
216 
217  if (hdfio_rd_gattr(hdfid, "Number of HDT Sync Losses", DFNT_INT16,
218  1, (void *) &cz_attr->n_hdt_sync_loss) != 0) return -1;
219 
220  if (hdfio_rd_gattr(hdfid, "Number of HDT Parity Errors", DFNT_INT16,
221  1, (void *) &cz_attr->n_hdt_parity_err) != 0) return -1;
222 
223  if (hdfio_rd_gattr(hdfid, "Number of WBVT Sync Losses", DFNT_INT16,
224  1, (void *) &cz_attr->n_wbvt_sync_loss) != 0) return -1;
225 
226  if (hdfio_rd_gattr(hdfid, "Number of WBVT Slip Occurrences", DFNT_INT16,
227  1, (void *) &cz_attr->n_wbvt_slips) != 0) return -1;
228 
229  if (hdfio_rd_gattr(hdfid, "Latitude Units", DFNT_CHAR,
230  15, (void *) cz_attr->lat_unit) != 0) return -1;
231 
232  if (hdfio_rd_gattr(hdfid, "Longitude Units", DFNT_CHAR,
233  15, (void *) cz_attr->lon_unit) != 0) return -1;
234 
235  if (hdfio_rd_gattr(hdfid, "Scene Center Latitude", DFNT_FLOAT32,
236  1, (void *) &cz_attr->center_lat) != 0) return -1;
237 
238  if (hdfio_rd_gattr(hdfid, "Scene Center Longitude", DFNT_FLOAT32,
239  1, (void *) &cz_attr->center_lon) != 0) return -1;
240 
241  if (hdfio_rd_gattr(hdfid, "Scene Center Solar Zenith", DFNT_FLOAT32,
242  1, (void *) &cz_attr->cntr_sol_zen) != 0) return -1;
243 
244  if (hdfio_rd_gattr(hdfid, "Upper Left Latitude", DFNT_FLOAT32,
245  1, (void *) &cz_attr->up_lft_lat) != 0) return -1;
246 
247  if (hdfio_rd_gattr(hdfid, "Upper Left Longitude", DFNT_FLOAT32,
248  1, (void *) &cz_attr->up_lft_lon) != 0) return -1;
249 
250  if (hdfio_rd_gattr(hdfid, "Upper Right Latitude", DFNT_FLOAT32,
251  1, (void *) &cz_attr->up_rgt_lat) != 0) return -1;
252 
253  if (hdfio_rd_gattr(hdfid, "Upper Right Longitude", DFNT_FLOAT32,
254  1, (void *) &cz_attr->up_rgt_lon) != 0) return -1;
255 
256  if (hdfio_rd_gattr(hdfid, "Lower Left Latitude", DFNT_FLOAT32,
257  1, (void *) &cz_attr->lo_lft_lat) != 0) return -1;
258 
259  if (hdfio_rd_gattr(hdfid, "Lower Left Longitude", DFNT_FLOAT32,
260  1, (void *) &cz_attr->lo_lft_lon) != 0) return -1;
261 
262  if (hdfio_rd_gattr(hdfid, "Lower Right Latitude", DFNT_FLOAT32,
263  1, (void *) &cz_attr->lo_rgt_lat) != 0) return -1;
264 
265  if (hdfio_rd_gattr(hdfid, "Lower Right Longitude", DFNT_FLOAT32,
266  1, (void *) &cz_attr->lo_rgt_lon) != 0) return -1;
267 
268  if (hdfio_rd_gattr(hdfid, "Northernmost Latitude", DFNT_FLOAT32,
269  1, (void *) cz_attr->limits) != 0) return -1;
270 
271  if (hdfio_rd_gattr(hdfid, "Southernmost Latitude", DFNT_FLOAT32,
272  1, (void *) cz_attr->limits + 1) != 0) return -1;
273 
274  if (hdfio_rd_gattr(hdfid, "Westernmost Longitude", DFNT_FLOAT32,
275  1, (void *) cz_attr->limits + 2) != 0) return -1;
276 
277  if (hdfio_rd_gattr(hdfid, "Easternmost Longitude", DFNT_FLOAT32,
278  1, (void *) cz_attr->limits + 3) != 0) return -1;
279 
280  if (hdfio_rd_gattr(hdfid, "Start Center Latitude", DFNT_FLOAT32,
281  1, (void *) &cz_attr->start_cntr_lat) != 0) return -1;
282 
283  if (hdfio_rd_gattr(hdfid, "Start Center Longitude", DFNT_FLOAT32,
284  1, (void *) &cz_attr->start_cntr_lon) != 0) return -1;
285 
286  if (hdfio_rd_gattr(hdfid, "End Center Latitude", DFNT_FLOAT32,
287  1, (void *) &cz_attr->end_cntr_lat) != 0) return -1;
288 
289  if (hdfio_rd_gattr(hdfid, "End Center Longitude", DFNT_FLOAT32,
290  1, (void *) &cz_attr->end_cntr_lon) != 0) return -1;
291 
292  /*
293  * read in the SDSes
294  */
295  if (hdfio_rd_sd(hdfid, "slat", (void *) cz_dat->slat) != 0)
296  return -1;
297 
298  if (hdfio_rd_sd(hdfid, "slon", (void *) cz_dat->slon) != 0)
299  return -1;
300 
301  if (hdfio_rd_sd(hdfid, "clat", (void *) cz_dat->clat) != 0)
302  return -1;
303 
304  if (hdfio_rd_sd(hdfid, "clon", (void *) cz_dat->clon) != 0)
305  return -1;
306 
307  if (hdfio_rd_sd(hdfid, "elat", (void *) cz_dat->elat) != 0)
308  return -1;
309 
310  if (hdfio_rd_sd(hdfid, "elon", (void *) cz_dat->elon) != 0)
311  return -1;
312 
313  if (hdfio_rd_sd(hdfid, "tilt", (void *) cz_dat->tilt) != 0)
314  return -1;
315 
316  tmp_ptr = (unsigned char *) (cz_dat->counts[0]);
317  if (hdfio_rd_sd(hdfid, "band1", (void *) tmp_ptr) != 0)
318  return -1;
319 
320  tmp_ptr = (unsigned char *) (cz_dat->counts[1]);
321  if (hdfio_rd_sd(hdfid, "band2", (void *) tmp_ptr) != 0)
322  return -1;
323 
324  tmp_ptr = (unsigned char *) (cz_dat->counts[2]);
325  if (hdfio_rd_sd(hdfid, "band3", (void *) tmp_ptr) != 0)
326  return -1;
327 
328  tmp_ptr = (unsigned char *) (cz_dat->counts[3]);
329  if (hdfio_rd_sd(hdfid, "band4", (void *) tmp_ptr) != 0)
330  return -1;
331 
332  tmp_ptr = (unsigned char *) (cz_dat->counts[4]);
333  if (hdfio_rd_sd(hdfid, "band5", (void *) tmp_ptr) != 0)
334  return -1;
335 
336  tmp_ptr = (unsigned char *) (cz_dat->counts[5]);
337  if (hdfio_rd_sd(hdfid, "band6", (void *) tmp_ptr) != 0)
338  return -1;
339 
340  if (hdfio_rd_sd(hdfid, "orb_vec", (void *) cz_dat->orb_vec) != 0)
341  return -1;
342 
343  if (hdfio_rd_sd(hdfid, "att_ang", (void *) cz_dat->att_ang) != 0)
344  return -1;
345 
346  if (hdfio_rd_sd(hdfid, "pos_err", (void *) cz_dat->pos_err) != 0)
347  return -1;
348 
349  if (hdfio_rd_sd(hdfid, "cntl_pt_cols", (void *) cz_dat->ctl_pt_cols)
350  != 0)
351  return -1;
352 
353  if (hdfio_rd_sd(hdfid, "cntl_pt_rows", (void *) cz_dat->ctl_pt_rows)
354  != 0)
355  return -1;
356 
357  if (hdfio_rd_sd(hdfid, "latitude", (void *) cz_dat->ctl_pt_lat) != 0)
358  return -1;
359 
360  if (hdfio_rd_sd(hdfid, "longitude", (void *) cz_dat->ctl_pt_lon) != 0)
361  return -1;
362 
363  if (hdfio_rd_sd(hdfid, "gain", (void *) cz_dat->gain) != 0)
364  return -1;
365 
366  if (hdfio_rd_sd(hdfid, "slope", (void *) cz_dat->slope) != 0)
367  return -1;
368 
369  if (hdfio_rd_sd(hdfid, "intercept", (void *) cz_dat->intercept) != 0)
370  return -1;
371 
372  }
373  /*
374  * close the file and end
375  */
376  hdfio_close(hdfid);
377 
378  return 0;
379 }
int cz_l1_read(char *file, int r_mode, gattr_struc *cz_attr, l1_data_struc *cz_dat)
Definition: cz_l1_read.c:4
float32 intercept
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 hdfio_close(hdfio_struc hdfinfo)
Definition: hdfio.c:223
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
int32 nscan
Definition: l1_czcs_hdf.c:19
int hdfio_rd_gattr(hdfio_struc hdfinfo, char *name, int32 n_type, int32 count, void *data)
Definition: hdfio.c:62
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
int hdfio_open(char *fname, hdfio_struc *hdfinfo)
Definition: hdfio.c:16
float32 slope
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT16
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
int hdfio_rd_sd(hdfio_struc hdfinfo, char *arr_name, void *array)
Definition: hdfio.c:142