OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
wrt_czcs_sla.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include "l1czcs.h"
3 #include "hdf.h"
4 #include "mfhdf.h"
5 
6 int wrt_czcs_sla(int32 sdfid, int32 vid, int nlin, l1_data_struc l1_data)
7 /*******************************************************************
8 
9  wrt_czcs_sla
10 
11  purpose: write the CZCS file scan line attributes vgroup
12  including: msec, the line-by-line milliseconds
13  tilt, line-by-line tilt
14  slat, slon, line-by-line start lat, lon
15  clat, clon, line-by-line center lat, lon
16  elat, elon, line-by-line end lat, lon
17 
18  Returns type: int - FAIL if failed, else SUCCEED
19 
20  Parameters: (in calling order)
21  Type Name I/O Description
22  ---- ---- --- -----------
23  int32 sdfid I sd file id from hdf
24  int32 vid I v-group id
25  int nlin I number of lines of data
26  l1_data_struc l1_data I structure of data arrays
27 
28  Modification history:
29  Programmer Date Description of change
30  ---------- ---- ---------------------
31  W. Robinson 14-Apr-2004 Original development
32 
33  *******************************************************************/ {
34 #define MSEC_LNAM "Scan-line time, milliseconds of day"
35 #define MSEC_VRNG "(0, 86399999)"
36 #define MSEC_UNITS "milliseconds"
37 
38 #define TILT_LNAM "Tilt angle for scan line"
39 #define TILT_VRNG "(-20.1,20.1)"
40 #define TILT_UNITS "degrees"
41 
42 #define SLAT_LNAM "Scan start-pixel latitude"
43 #define CLAT_LNAM "Scan center-pixel longitude"
44 #define ELAT_LNAM "Scan end-pixel latitude"
45 #define SLON_LNAM "Scan start-pixel longitude"
46 #define CLON_LNAM "Scan center-pixel latitude"
47 #define ELON_LNAM "Scan end-pixel longitude"
48 #define LAT_RNG "(-90.,90.)"
49 #define LON_RNG "(-180., 180.)"
50 #define NUM_SCN_LN "Number of Scan Lines"
51 #define PIX_PER_SCN "Pixels per Scan Line"
52  int32 create_sds(int32, char *, int32, int32, int32 *, int32, VOIDP *);
53  int32 set_dim_names(int32, char *, char *, char *);
54  int dims[3] = {0, 0, 0}, sdsid, iret;
55 
56  /*
57  * msec
58  */
59  dims[0] = nlin;
60  if ((sdsid = create_sds(sdfid, "msec", DFNT_INT32, 1, (int32 *) dims, vid,
61  (VOIDP) l1_data.msec)) < 0) {
62  fprintf(stderr, "wrt_czcs_sla: create_sds failed on msec\n");
63  return FAIL;
64  }
65  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
66  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on msec\n");
67  return FAIL;
68  }
69  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
70  strlen(MSEC_LNAM) + 1, (VOIDP) MSEC_LNAM)), 0) {
71  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on msec, long_name\n");
72  return FAIL;
73  }
74  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
75  strlen(MSEC_VRNG) + 1, (VOIDP) MSEC_VRNG)), 0) {
76  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on msec, valid_range\n");
77  return FAIL;
78  }
79  if ((iret = SDsetattr(sdsid, "units", DFNT_CHAR,
80  strlen(MSEC_UNITS) + 1, (VOIDP) MSEC_UNITS)), 0) {
81  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on msec, units\n");
82  return FAIL;
83  }
84  /*
85  * tilt
86  */
87  if ((sdsid = create_sds(sdfid, "tilt", DFNT_FLOAT32, 1, (int32 *) dims, vid,
88  (VOIDP) l1_data.tilt)) < 0) {
89  fprintf(stderr, "wrt_czcs_sla: create_sds failed on tilt\n");
90  return FAIL;
91  }
92  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
93  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on tilt\n");
94  return FAIL;
95  }
96  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
97  strlen(TILT_LNAM) + 1, (VOIDP) TILT_LNAM)), 0) {
98  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on tilt, long_name\n");
99  return FAIL;
100  }
101  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
102  strlen(TILT_VRNG) + 1, (VOIDP) TILT_VRNG)), 0) {
103  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on tilt, valid_range\n");
104  return FAIL;
105  }
106  if ((iret = SDsetattr(sdsid, "units", DFNT_CHAR,
107  strlen(TILT_UNITS) + 1, (VOIDP) TILT_UNITS)), 0) {
108  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on tilt, units\n");
109  return FAIL;
110  }
111  /*
112  * slat
113  */
114  if ((sdsid = create_sds(sdfid, "slat", DFNT_FLOAT32, 1, (int32 *) dims, vid,
115  (VOIDP) l1_data.slat)) < 0) {
116  fprintf(stderr, "wrt_czcs_sla: create_sds failed on slat\n");
117  return FAIL;
118  }
119  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
120  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on slat\n");
121  return FAIL;
122  }
123  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
124  strlen(SLAT_LNAM) + 1, (VOIDP) SLAT_LNAM)), 0) {
125  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on slat, long_name\n");
126  return FAIL;
127  }
128  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
129  strlen(LAT_RNG) + 1, (VOIDP) LAT_RNG)), 0) {
130  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on slat, valid_range\n");
131  return FAIL;
132  }
133  /*
134  * slon
135  */
136  if ((sdsid = create_sds(sdfid, "slon", DFNT_FLOAT32, 1, (int32 *) dims, vid,
137  (VOIDP) l1_data.slon)) < 0) {
138  fprintf(stderr, "wrt_czcs_sla: create_sds failed on slon\n");
139  return FAIL;
140  }
141  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
142  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on slon\n");
143  return FAIL;
144  }
145  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
146  strlen(SLAT_LNAM) + 1, (VOIDP) SLON_LNAM)), 0) {
147  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on slon, long_name\n");
148  return FAIL;
149  }
150  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
151  strlen(LON_RNG) + 1, (VOIDP) LON_RNG)), 0) {
152  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on slon, valid_range\n");
153  return FAIL;
154  }
155  /*
156  * clat
157  */
158  if ((sdsid = create_sds(sdfid, "clat", DFNT_FLOAT32, 1, (int32 *) dims, vid,
159  (VOIDP) l1_data.clat)) < 0) {
160  fprintf(stderr, "wrt_czcs_sla: create_sds failed on clat\n");
161  return FAIL;
162  }
163  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
164  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on clat\n");
165  return FAIL;
166  }
167  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
168  strlen(CLAT_LNAM) + 1, (VOIDP) CLAT_LNAM)), 0) {
169  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on clat, long_name\n");
170  return FAIL;
171  }
172  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
173  strlen(LAT_RNG) + 1, (VOIDP) LAT_RNG)), 0) {
174  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on clat, valid_range\n");
175  return FAIL;
176  }
177  /*
178  * clon
179  */
180  if ((sdsid = create_sds(sdfid, "clon", DFNT_FLOAT32, 1, (int32 *) dims, vid,
181  (VOIDP) l1_data.clon)) < 0) {
182  fprintf(stderr, "wrt_czcs_sla: create_sds failed on clon\n");
183  return FAIL;
184  }
185  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
186  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on clon\n");
187  return FAIL;
188  }
189  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
190  strlen(CLON_LNAM) + 1, (VOIDP) CLON_LNAM)), 0) {
191  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on clon, long_name\n");
192  return FAIL;
193  }
194  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
195  strlen(LON_RNG) + 1, (VOIDP) LON_RNG)), 0) {
196  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on clon, valid_range\n");
197  return FAIL;
198  }
199  /*
200  * elat
201  */
202  if ((sdsid = create_sds(sdfid, "elat", DFNT_FLOAT32, 1, (int32 *) dims, vid,
203  (VOIDP) l1_data.elat)) < 0) {
204  fprintf(stderr, "wrt_czcs_sla: create_sds failed on elat\n");
205  return FAIL;
206  }
207  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
208  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on elat\n");
209  return FAIL;
210  }
211  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
212  strlen(ELAT_LNAM) + 1, (VOIDP) ELAT_LNAM)), 0) {
213  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on elat, long_name\n");
214  return FAIL;
215  }
216  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
217  strlen(LAT_RNG) + 1, (VOIDP) LAT_RNG)), 0) {
218  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on elat, valid_range\n");
219  return FAIL;
220  }
221  /*
222  * elon
223  */
224  if ((sdsid = create_sds(sdfid, "elon", DFNT_FLOAT32, 1, (int32 *) dims, vid,
225  (VOIDP) l1_data.elon)) < 0) {
226  fprintf(stderr, "wrt_czcs_sla: create_sds failed on elon\n");
227  return FAIL;
228  }
229  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, NULL, NULL)) < 0) {
230  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on elon\n");
231  return FAIL;
232  }
233  if ((iret = SDsetattr(sdsid, "long_name", DFNT_CHAR,
234  strlen(ELAT_LNAM) + 1, (VOIDP) ELON_LNAM)), 0) {
235  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on elon, long_name\n");
236  return FAIL;
237  }
238  if ((iret = SDsetattr(sdsid, "valid_range", DFNT_CHAR,
239  strlen(LON_RNG) + 1, (VOIDP) LON_RNG)), 0) {
240  fprintf(stderr, "wrt_czcs_sla: SDsetattr failed on elon, valid_range\n");
241  return FAIL;
242  }
243  /*
244  * for extra outputs of geometry and calibrated radiance data
245  */
246 #ifdef GEOM_CAL
247  dims[1] = 1968;
248  if ((sdsid = create_sds(sdfid, "sen_zen", DFNT_FLOAT32, 2,
249  (int32 *) dims, vid, (VOIDP) l1_data.sen_zen)) < 0) {
250  fprintf(stderr, "wrt_czcs_sla: create_sds failed on sen_zen\n");
251  return FAIL;
252  }
253  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
254  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on sen_zen\n");
255  return FAIL;
256  }
257 
258  if ((sdsid = create_sds(sdfid, "sen_az", DFNT_FLOAT32, 2,
259  (int32 *) dims, vid, (VOIDP) l1_data.sen_az)) < 0) {
260  fprintf(stderr, "wrt_czcs_sla: create_sds failed on sen_az\n");
261  return FAIL;
262  }
263  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
264  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on sen_az\n");
265  return FAIL;
266  }
267 
268  if ((sdsid = create_sds(sdfid, "sol_zen", DFNT_FLOAT32, 2,
269  (int32 *) dims, vid, (VOIDP) l1_data.sol_zen)) < 0) {
270  fprintf(stderr, "wrt_czcs_sla: create_sds failed on sol_zen\n");
271  return FAIL;
272  }
273  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
274  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on sol_zen\n");
275  return FAIL;
276  }
277 
278  if ((sdsid = create_sds(sdfid, "sol_az", DFNT_FLOAT32, 2,
279  (int32 *) dims, vid, (VOIDP) l1_data.sol_az)) < 0) {
280  fprintf(stderr, "wrt_czcs_sla: create_sds failed on sol_az\n");
281  return FAIL;
282  }
283  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
284  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on sol_az\n");
285  return FAIL;
286  }
287 
288  if ((sdsid = create_sds(sdfid, "all_lat", DFNT_FLOAT32, 2,
289  (int32 *) dims, vid, (VOIDP) l1_data.all_lat)) < 0) {
290  fprintf(stderr, "wrt_czcs_sla: create_sds failed on all_lat\n");
291  return FAIL;
292  }
293  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
294  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on all_lat\n");
295  return FAIL;
296  }
297 
298  if ((sdsid = create_sds(sdfid, "all_lon", DFNT_FLOAT32, 2,
299  (int32 *) dims, vid, (VOIDP) l1_data.all_lon)) < 0) {
300  fprintf(stderr, "wrt_czcs_sla: create_sds failed on all_lon\n");
301  return FAIL;
302  }
303  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
304  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on all_lon\n");
305  return FAIL;
306  }
307 
308  if ((sdsid = create_sds(sdfid, "Lt_443", DFNT_FLOAT32, 2,
309  (int32 *) dims, vid, (VOIDP) l1_data.Lt_443)) < 0) {
310  fprintf(stderr, "wrt_czcs_sla: create_sds failed on Lt_443\n");
311  return FAIL;
312  }
313  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
314  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on Lt_443\n");
315  return FAIL;
316  }
317 
318  if ((sdsid = create_sds(sdfid, "Lt_520", DFNT_FLOAT32, 2,
319  (int32 *) dims, vid, (VOIDP) l1_data.Lt_520)) < 0) {
320  fprintf(stderr, "wrt_czcs_sla: create_sds failed on Lt_520\n");
321  return FAIL;
322  }
323  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
324  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on Lt_520\n");
325  return FAIL;
326  }
327 
328  if ((sdsid = create_sds(sdfid, "Lt_550", DFNT_FLOAT32, 2,
329  (int32 *) dims, vid, (VOIDP) l1_data.Lt_550)) < 0) {
330  fprintf(stderr, "wrt_czcs_sla: create_sds failed on Lt_550\n");
331  return FAIL;
332  }
333  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
334  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on Lt_550\n");
335  return FAIL;
336  }
337 
338  if ((sdsid = create_sds(sdfid, "Lt_670", DFNT_FLOAT32, 2,
339  (int32 *) dims, vid, (VOIDP) l1_data.Lt_670)) < 0) {
340  fprintf(stderr, "wrt_czcs_sla: create_sds failed on Lt_670\n");
341  return FAIL;
342  }
343  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
344  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on Lt_670\n");
345  return FAIL;
346  }
347 
348  if ((sdsid = create_sds(sdfid, "Lt_750", DFNT_FLOAT32, 2,
349  (int32 *) dims, vid, (VOIDP) l1_data.Lt_750)) < 0) {
350  fprintf(stderr, "wrt_czcs_sla: create_sds failed on Lt_750\n");
351  return FAIL;
352  }
353  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
354  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on Lt_750\n");
355  return FAIL;
356  }
357 
358  if ((sdsid = create_sds(sdfid, "Lt_11500", DFNT_FLOAT32, 2,
359  (int32 *) dims, vid, (VOIDP) l1_data.Lt_11500)) < 0) {
360  fprintf(stderr, "wrt_czcs_sla: create_sds failed on Lt_11500\n");
361  return FAIL;
362  }
363  if ((iret = set_dim_names(sdsid, NUM_SCN_LN, PIX_PER_SCN, NULL)) < 0) {
364  fprintf(stderr, "wrt_czcs_sla: set_dim_names failed on Lt_11500\n");
365  return FAIL;
366  }
367 
368 #endif
369  return SUCCEED;
370 }
#define MSEC_UNITS
#define SLAT_LNAM
#define CLAT_LNAM
#define FAIL
Definition: ObpgReadGrid.h:18
#define NULL
Definition: decode_rs.h:63
#define ELON_LNAM
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_INT32
int32 set_dim_names(int32 sds_id, char *d0, char *d1, char *d2)
Definition: set_dim_names.c:29
int nlin
Definition: get_cmp.c:28
#define MSEC_LNAM
#define SLON_LNAM
int wrt_czcs_sla(int32 sdfid, int32 vid, int nlin, l1_data_struc l1_data)
Definition: wrt_czcs_sla.c:6
#define TILT_LNAM
int32 create_sds(int32 sdfid, char *sdsname, int32 nt, int32 rank, int32 *dims, int32 vid, VOIDP *data)
Definition: create_sds.c:10
#define TILT_UNITS
#define NUM_SCN_LN
#define LAT_RNG
#define LON_RNG
#define CLON_LNAM
HDF4 data type of the output SDS Default is DFNT_FLOAT32 Common types used DFNT_FLOAT32
#define TILT_VRNG
#define ELAT_LNAM
#define PIX_PER_SCN
#define MSEC_VRNG