41 {
42
44
46
47 met_t *met0 = NULL, *met1 = NULL;
48
49
51
52
54
55
56 if (argc < 3)
57 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
58 "Usage: atm2grid <ctl> <atm_in> [KEY VALUE ...]\n\n"
59 "Use -h for full help.");
60
61
63
64
66 ERRMSG(
"You need to specify GRID_BASENAME!");
67
68
70 ERRMSG(
"Cannot open file!");
71
72
73 int year, mon, day, hour, min, sec;
75 jsec2time(t, &year, &mon, &day, &hour, &min, &sec, &r);
76
77
78 char filename[3 *
LEN];
79 sprintf(filename, "%s_%04d_%02d_%02d_%02d_%02d.%s",
82
83
84 write_grid(filename, &ctl, met0, met1, atm, t);
85
86
87 free(atm);
88
89 return EXIT_SUCCESS;
90}
double time_from_filename(const char *filename, const int offset)
Extracts and converts a timestamp from a filename to Julian seconds.
int mptrac_read_atm(const char *filename, const ctl_t *ctl, atm_t *atm)
Reads air parcel data from a specified file into the given atmospheric structure.
void jsec2time(const double jsec, int *year, int *mon, int *day, int *hour, int *min, int *sec, double *remain)
Converts Julian seconds to calendar date and time components.
void mptrac_read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
void write_grid(const char *filename, const ctl_t *ctl, met_t *met0, met_t *met1, const atm_t *atm, const double t)
Writes grid data to a file in ASCII or netCDF format.
#define LEN
Maximum length of ASCII data lines.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define USAGE
Print usage information on -h or --help.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
int atm_type
Type of atmospheric data files (0=ASCII, 1=binary, 2=netCDF, 3=CLaMS_traj, 4=CLaMS_pos).
int grid_type
Type of grid data files (0=ASCII, 1=netCDF).
char grid_basename[LEN]
Basename of grid data files.