OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
l1czcs.c
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------
2  Program: l1czcs
3 
4  Description:
5  Create CZCS L1-A HDF file from a CZCS CRT full-resolution
6  L1 files.
7 
8  Arguments:
9  Type Name I/O Description
10  ---- ---- --- -----------
11  int argc I count of command line args - 3 always
12  char *[] argv I command line arguments:
13  [1] = input file name
14  [2] = output path
15 
16  Modification history:
17 
18  W. Robinson, SAIC 5 Mar 2004 derived from seadas l1aczcs. Improved
19  to have additional parameters for improved
20  processing and a switch to a c routine for
21  reading the CRTT dataset
22 
23 ----------------------------------------------------------------------------*/
24 
25 #include <unistd.h>
26 #include <libgen.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <sys/utsname.h>
30 
31 #include "l1czcs.h"
32 
33 #include <timeutils.h>
34 #include <passthebuck.h>
35 #include <GetStationInfo.h>
36 
37 #define PROGRAM "l1czcs"
38 #define VERSION "1.1"
39 #define RET_GOOD 0
40 #define RET_ERR 1
41 #define RET_WARN 2
42 
43 #define MAXLINE 3000
44 
45 int main(int argc, char *argv[]) {
46  /*
47  * for the library functions, define here
48  */
49 
50  char ifile[132], ofile[256], opath[132];
51  char *fbase;
52 
53  gattr_struc gattr;
54  l1_data_struc l1_data;
55 
56  char seadas_vs[64], prog_version[64];
57 
58  int i, ilen;
59 
60  memset(ifile, 0, sizeof (ifile));
61 
62  if (argc == 3) {
63  strcpy(ifile, argv[1]);
64  strcpy(opath, argv[2]);
65  } else {
66  fbase = basename(argv[0]);
67  printf("%s %s (%s %s)\n",
68  fbase, VERSION, __DATE__, __TIME__);
69  printf("Usage: %s ifile opath\n\n", fbase);
70  printf("Return 0 if OK, 1 if file cannot be created, 2 if no navigation\n");
71  return RET_ERR;
72  }
73 
74  if (access(ifile, F_OK) || access(ifile, R_OK)) {
75  printf("%s - Input file '%s' does not exist or cannot read\n",
76  argv[0], ifile);
77  return RET_ERR;
78  }
79 
80  /*
81  * Read in all the data from the CRTT file
82  */
83  if (read_crtt(ifile, &gattr, &l1_data) != 0) {
84  printf("%s - Error in reading or processing the data\n", argv[0]);
85  return RET_ERR;
86  }
87  /*
88  * clean up the data (eliminate bad msec lines)
89  */
90  if (cz_clean(&gattr, &l1_data) != 0) {
91  printf("%s - Dataset contains no good data lines\n", argv[0]);
92  return RET_ERR;
93  }
94 
95  StationInfo stationInfo;
96  if (GetStationInfo(NULL, &stationInfo) == LIFE_IS_GOOD) {
97  strcpy(gattr.datacenter, stationInfo.data_center);
98  strcpy(gattr.stn_name, stationInfo.station_name);
99  gattr.stn_lat = stationInfo.station_latitude;
100  gattr.stn_lon = stationInfo.station_longitude;
101  }
102 
103  sprintf(prog_version, "%s %s", PROGRAM, VERSION);
104  struct utsname osname;
105  uname(&osname);
106  sprintf(gattr.soft_id, "%s, %s, %s %s", seadas_vs, prog_version, osname.sysname,
107  osname.release);
108 
109  strcpy(gattr.datatype, "LAC");
110  gattr.lac_pixl_start_no = 1;
111  gattr.lac_pixl_subsample = 1;
112 
113  get_time((char*) &gattr.process_time);
114 
115  strcpy(gattr.proc_ctl, argv[0]);
116  for (i = 1; i < argc; i++) {
117  strcat(gattr.proc_ctl, " ");
118  strcat(gattr.proc_ctl, argv[i]);
119  }
120 
121  strcpy(gattr.input_files, basename(ifile));
122 
123  ilen = strlen(opath);
124  if (opath[ ilen - 1 ] == '/')
125  sprintf(ofile, "%sC%13.13s.L1A_LAC", opath, gattr.start_time);
126  else
127  sprintf(ofile, "%s/C%13.13s.L1A_LAC", opath, gattr.start_time);
128 
129  if (!access(ofile, F_OK)) {
130  printf("%s - Output file '%s' already existed\n", argv[0], ofile);
131  return RET_ERR;
132  }
133 
134  printf("\n Writing data to output file...\n");
135  if (czcs_l1_write(ofile, l1_data, gattr)
136  == 0)
137  printf(" output file created\n");
138  else {
139  printf(" output file not created\n");
140  return RET_ERR;
141  }
142  /*
143  * if a file can be made but it is unsuitable for further processing,
144  * report a status of 1. conditions are:
145  * - no navigation (ILT code = 0, or lat, lon limits all =
146  */
147  if ((gattr.ilt_flags) == 0 || (gattr.limits[0] == gattr.limits[1])
148  || (gattr.limits[2] == gattr.limits[3])) {
149  printf("%s - Navigation is unavailable for this granule\n", argv[0]);
150  return RET_ERR;
151  } else
152  return RET_GOOD;
153 }
int GetStationInfo(char *stationInfoFile, StationInfo *stationInfo)
#define PROGRAM
Definition: l1czcs.c:37
#define NULL
Definition: decode_rs.h:63
int czcs_l1_write(char *ofile, l1_data_struc l1_data, gattr_struc gattr)
Definition: czcs_l1_write.c:8
#define VERSION
Definition: l1czcs.c:38
char * data_center
int cz_clean(gattr_struc *gattr, l1_data_struc *l1_data)
Definition: cz_clean.c:3
int main(int argc, char *argv[])
Definition: l1czcs.c:45
#define LIFE_IS_GOOD
Definition: passthebuck.h:4
void get_time(char *pr_time)
Definition: get_time.c:28
int read_crtt(char *, gattr_struc *, l1_data_struc *)
Definition: read_crtt.c:11
#define basename(s)
Definition: l0chunk_modis.c:29
#define RET_GOOD
Definition: l1czcs.c:39
float station_longitude
char * station_name
float station_latitude
#define RET_ERR
Definition: l1czcs.c:40
int i
Definition: decode_rs.h:71
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")