34 int32 sdfid, fid, raw_vid, nav_vid, sl_attr_vid;
35 int iret, tot_line, tot_pixel;
41 tot_line = gattr.scan_lines;
42 tot_pixel = gattr.pix_per_scan;
47 if ((sdfid = SDstart(
ofile, DFACC_CREATE)) < 0) {
48 fprintf(
stderr,
"[czcs_l1_write] Error: SDstart failed on %s\n",
ofile);
52 if ((fid = Hopen(
ofile, DFACC_RDWR, 0)) < 0) {
53 fprintf(
stderr,
"[czcs_l1_write] Error: Hopen failed on %s\n",
ofile);
66 sl_attr_vid = Vattach(fid, -1,
"w");
67 Vsetname(sl_attr_vid,
"Scan-Line Attributes");
69 raw_vid = Vattach(fid, -1,
"w");
70 Vsetname(raw_vid,
"Raw CZCS Data");
72 nav_vid = Vattach(fid, -1,
"w");
73 Vsetname(nav_vid,
"Navigation");
103 #define TITLE "Title"
104 #define TITLE_VAL "CZCS Level-1A Data"
105 #define SENSOR_VAL "Coastal Zone Color Scanner (CZCS)"
106 #define MISSION "Mission"
107 #define MISSION_VAL "Nimbus CZCS"
108 #define MISSIONCHAR "Mission Characteristics"
109 #define MISSIONCHAR_VAL "Nominal orbit: inclination = 99.3 (Sun-Synchronous); node = 11:52 AM local (ascending); eccentricity =< 0.0009; altitude = 955km; ground speed = 6.4km/sec"
110 #define SENSOR "Sensor"
111 #define SENSOR_VAL "Coastal Zone Color Scanner (CZCS)"
112 #define SENSORCHAR "Sensor Characteristics"
113 #define SENSORCHAR_VAL "Number of bands = 6; number of active bands = 6; wavelengths per band (nm) = 443, 520, 550, 670, 750, 11500; bits per pixel = 8; instantaneous field-of-view = .865 mrad; pixels per scan = 1968; scan rate = 8.08/sec"
114 #define REPL_FLG "ORIGINAL"
119 if ((SDsetattr(sdfid,
"Product Name", DFNT_CHAR, strlen(
file) + 1,
128 if ((SDsetattr(sdfid,
"Data Type", DFNT_CHAR, strlen(gattr.datatype) + 1,
129 (VOIDP) gattr.datatype)) < 0)
132 if ((SDsetattr(sdfid,
"Replacement Flag", DFNT_CHAR, strlen(
REPL_FLG) + 1,
137 if ((SDsetattr(sdfid,
"Data Center", DFNT_CHAR, strlen(gattr.datacenter) + 1,
138 (VOIDP) gattr.datacenter)) < 0)
142 if ((SDsetattr(sdfid,
"Station Name", DFNT_CHAR, strlen(gattr.stn_name) + 1,
143 (VOIDP) gattr.stn_name)) < 0)
146 if ((SDsetattr(sdfid,
"Station Latitude",
DFNT_FLOAT32, 1,
147 (VOIDP) & gattr.stn_lat)) < 0)
150 if ((SDsetattr(sdfid,
"Station Longitude",
DFNT_FLOAT32, 1,
151 (VOIDP) & gattr.stn_lon)) < 0)
174 if ((SDsetattr(sdfid,
"Software ID", DFNT_CHAR,
175 strlen(gattr.soft_id) + 1, (VOIDP) gattr.soft_id)) < 0)
179 if ((SDsetattr(sdfid,
"Processing Time", DFNT_CHAR,
180 strlen(gattr.process_time) + 1, (VOIDP) gattr.process_time)) < 0)
184 if ((SDsetattr(sdfid,
"Input Files", DFNT_CHAR,
185 strlen(gattr.input_files) + 1, (VOIDP) gattr.input_files)) < 0)
189 if ((SDsetattr(sdfid,
"Processing Control", DFNT_CHAR,
190 strlen(gattr.proc_ctl) + 1, (VOIDP) gattr.proc_ctl)) < 0)
193 if ((SDsetattr(sdfid,
"Pixels per Scan Line",
DFNT_INT32, 1,
194 (VOIDP) & gattr.pix_per_scan)) < 0)
197 if ((SDsetattr(sdfid,
"Number of Scan Lines",
DFNT_INT32, 1,
198 &gattr.scan_lines)) < 0)
201 if ((SDsetattr(sdfid,
"Number of Pixel Control Points",
DFNT_INT32, 1,
202 &gattr.n_ctl_pt)) < 0)
205 if ((SDsetattr(sdfid,
"Number of Scan Control Points",
DFNT_INT32, 1,
206 &gattr.scan_lines)) < 0)
209 if ((SDsetattr(sdfid,
"LAC Pixel Start Number",
DFNT_INT32, 1,
210 &gattr.lac_pixl_start_no)) < 0)
213 if ((SDsetattr(sdfid,
"LAC Pixel Subsampling",
DFNT_INT32, 1,
214 &gattr.lac_pixl_subsample)) < 0)
217 cl = gattr.scan_lines / 2 + 1;
218 if ((SDsetattr(sdfid,
"Scene Center Scan Line",
DFNT_INT32, 1, &cl)) < 0)
221 if ((SDsetattr(sdfid,
"Filled Scan Lines",
DFNT_INT32, 1,
222 &gattr.scan_lines)) < 0)
225 if ((SDsetattr(sdfid,
"Start Time", DFNT_CHAR, strlen(gattr.start_time) + 1,
226 &gattr.start_time)) < 0)
229 if ((SDsetattr(sdfid,
"End Time", DFNT_CHAR, strlen(gattr.end_time) + 1,
230 &gattr.end_time)) < 0)
233 if ((SDsetattr(sdfid,
"Scene Center Time", DFNT_CHAR,
234 strlen(gattr.center_time) + 1, &gattr.center_time)) < 0)
237 if ((SDsetattr(sdfid,
"Start Year",
DFNT_INT16, 1,
238 &gattr.start_year)) < 0)
241 if ((SDsetattr(sdfid,
"Start Day",
DFNT_INT16, 1,
242 &gattr.start_day)) < 0)
245 if ((SDsetattr(sdfid,
"Start Millisec",
DFNT_INT32, 1,
246 &gattr.start_msec)) < 0)
249 if ((SDsetattr(sdfid,
"End Year",
DFNT_INT16, 1,
250 &gattr.end_year)) < 0)
253 if ((SDsetattr(sdfid,
"End Day",
DFNT_INT16, 1,
254 &gattr.end_day)) < 0)
257 if ((SDsetattr(sdfid,
"End Millisec",
DFNT_INT32, 1,
258 &gattr.end_msec)) < 0)
261 if ((SDsetattr(sdfid,
"Start Node", DFNT_CHAR,
262 strlen(
"Ascending") + 1,
"Ascending")) < 0)
265 if ((SDsetattr(sdfid,
"End Node", DFNT_CHAR,
266 strlen(
"Ascending") + 1,
"Ascending")) < 0)
269 if ((SDsetattr(sdfid,
"Orbit Number",
DFNT_INT32, 1,
277 if ((SDsetattr(sdfid,
"Scene Gain",
DFNT_INT32, 1,
281 if ((SDsetattr(sdfid,
"Thresh",
DFNT_INT32, 1,
285 if ((SDsetattr(sdfid,
"Latitude Units", DFNT_CHAR,
286 strlen(
"degrees North") + 1,
"degrees North")) < 0)
289 if ((SDsetattr(sdfid,
"Longitude Units", DFNT_CHAR,
290 strlen(
"degrees East") + 1,
"degrees East")) < 0)
293 if ((SDsetattr(sdfid,
"Scene Center Latitude",
297 if ((SDsetattr(sdfid,
"Scene Center Longitude",
301 if ((SDsetattr(sdfid,
"Scene Center Solar Zenith",
305 if ((SDsetattr(sdfid,
"Upper Left Latitude",
309 if ((SDsetattr(sdfid,
"Upper Left Longitude",
313 if ((SDsetattr(sdfid,
"Upper Right Latitude",
317 if ((SDsetattr(sdfid,
"Upper Right Longitude",
321 if ((SDsetattr(sdfid,
"Lower Left Latitude",
325 if ((SDsetattr(sdfid,
"Lower Left Longitude",
329 if ((SDsetattr(sdfid,
"Lower Right Latitude",
333 if ((SDsetattr(sdfid,
"Lower Right Longitude",
337 if ((SDsetattr(sdfid,
"Start Center Latitude",
341 if ((SDsetattr(sdfid,
"Start Center Longitude",
345 if ((SDsetattr(sdfid,
"End Center Latitude",
349 if ((SDsetattr(sdfid,
"End Center Longitude",
353 if ((SDsetattr(sdfid,
"Northernmost Latitude",
DFNT_FLOAT32, 1,
354 (VOIDP) & gattr.limits[0])) < 0)
357 if ((SDsetattr(sdfid,
"Southernmost Latitude",
DFNT_FLOAT32, 1,
358 (VOIDP) & gattr.limits[1])) < 0)
361 if ((SDsetattr(sdfid,
"Westernmost Longitude",
DFNT_FLOAT32, 1,
362 (VOIDP) & gattr.limits[2])) < 0)
365 if ((SDsetattr(sdfid,
"Easternmost Longitude",
DFNT_FLOAT32, 1,
366 (VOIDP) & gattr.limits[3])) < 0)
372 if ((SDsetattr(sdfid,
"Calibration Slope",
DFNT_FLOAT32, 6,
373 (VOIDP) & gattr.
slope)) < 0)
376 if ((SDsetattr(sdfid,
"Calibration Intercept",
DFNT_FLOAT32, 6,
380 if ((SDsetattr(sdfid,
"Center Roll",
DFNT_FLOAT32, 1, (VOIDP) & gattr.roll)) < 0)
384 (VOIDP) & gattr.pitch)) < 0)
387 if ((SDsetattr(sdfid,
"Center Yaw",
DFNT_FLOAT32, 1, (VOIDP) & gattr.yaw)) < 0)
390 if ((SDsetattr(sdfid,
"ILT Flags", DFNT_UINT8, 1,
391 (VOIDP) & gattr.ilt_flags)) < 0)
394 if ((SDsetattr(sdfid,
"Parameter Presence Code", DFNT_UINT8, 1,
395 (VOIDP) & gattr.parm_presence)) < 0)
398 if ((SDsetattr(sdfid,
"Number of Missing Scan Lines",
DFNT_INT16, 1,
399 (VOIDP) & gattr.n_miss_scans)) < 0)
402 if ((SDsetattr(sdfid,
"Number of Scans with Missing Channels",
403 DFNT_INT16, 6, (VOIDP) & gattr.n_scan_mis_chan)) < 0)
406 if ((SDsetattr(sdfid,
"Number of HDT Sync Losses",
DFNT_INT16, 1,
407 (VOIDP) & gattr.n_hdt_sync_loss)) < 0)
410 if ((SDsetattr(sdfid,
"Number of HDT Parity Errors",
DFNT_INT16, 1,
411 (VOIDP) & gattr.n_hdt_parity_err)) < 0)
414 if ((SDsetattr(sdfid,
"Number of WBVT Sync Losses",
DFNT_INT16, 1,
415 (VOIDP) & gattr.n_wbvt_sync_loss)) < 0)
418 if ((SDsetattr(sdfid,
"Number of WBVT Slip Occurrences",
DFNT_INT16, 1,
419 (VOIDP) & gattr.n_wbvt_slips)) < 0)
426 int tot_pixel,
int tot_line) {
427 int32
create_sds(int32,
char *, int32, int32, int32 *, int32, VOIDP *);
429 int dims[3] = {0, 0, 0}, sdsid;
430 char *band_name[6] = {
"band1",
"band2",
"band3",
"band4",
"band5",
"band6"};
431 unsigned char *tmp_ptr;
438 for (
i = 0;
i < 6;
i++) {
439 tmp_ptr = (
unsigned char *) (
counts[
i]);
440 if ((sdsid =
create_sds(sdfid, band_name[
i], DFNT_UINT8, 2,
441 (int32 *) dims, raw_vid, (VOIDP) tmp_ptr)) < 0) {
442 fprintf(
stderr,
"create_band_sds: create_sds failed on %s\n",
451 fprintf(
stderr,
"create_band_sds: set_dim_names failed on %s\n", band_name[
i]);
455 sprintf(sds_attr,
"Level-1A %s data", band_name[
i]);
456 if ((iret = SDsetattr(sdsid,
"long_name", DFNT_CHAR, strlen(sds_attr) + 1,
457 (VOIDP) sds_attr)) < 0) {
458 fprintf(
stderr,
"create_band_sds: SDsetattr failed on %s\n", band_name[
i]);
461 strcpy(sds_attr,
"radiance counts");
462 if ((iret = SDsetattr(sdsid,
"units", DFNT_CHAR, strlen(sds_attr) + 1,
463 (VOIDP) sds_attr)) < 0) {
464 fprintf(
stderr,
"create_band_sds: SDsetattr failed on %s\n", band_name[
i]);