MPTRAC
Functions
atm2grid.c File Reference

Convert atmospheric data file to grid data file. More...

#include "mptrac.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Convert atmospheric data file to grid data file.

Definition in file atm2grid.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 27 of file atm2grid.c.

29 {
30
31 ctl_t ctl;
32
33 atm_t *atm;
34
35 met_t *met0 = NULL, *met1 = NULL;
36
37 /* Allocate... */
38 ALLOC(atm, atm_t, 1);
39
40 /* Check arguments... */
41 if (argc < 3)
42 ERRMSG("Give parameters: <ctl> <atm_in>");
43
44 /* Read control parameters... */
45 read_ctl(argv[1], argc, argv, &ctl);
46
47 /* Check grid basename... */
48 if (ctl.grid_basename[0] == '-')
49 ERRMSG("You need to specify GRID_BASENAME!");
50
51 /* Read atmospheric data... */
52 if (!read_atm(argv[2], &ctl, atm))
53 ERRMSG("Cannot open file!");
54
55 /* Get time from filename... */
56 int year, mon, day, hour, min, sec;
57 double r, t = time_from_filename(argv[2], ctl.atm_type < 2 ? 20 : 19);
58 jsec2time(t, &year, &mon, &day, &hour, &min, &sec, &r);
59
60 /* Set output filename... */
61 char filename[3 * LEN];
62 sprintf(filename, "%s_%04d_%02d_%02d_%02d_%02d.%s",
63 ctl.grid_basename, year, mon, day, hour, min,
64 ctl.grid_type == 0 ? "tab" : "nc");
65
66 /* Write grid data... */
67 write_grid(filename, &ctl, met0, met1, atm, t);
68
69 /* Free... */
70 free(atm);
71
72 return EXIT_SUCCESS;
73}
double time_from_filename(const char *filename, const int offset)
Extracts and converts a timestamp from a filename to Julian seconds.
Definition: mptrac.c:8413
void read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
Definition: mptrac.c:4805
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.
Definition: mptrac.c:1832
int 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.
Definition: mptrac.c:4215
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.
Definition: mptrac.c:9283
#define LEN
Maximum length of ASCII data lines.
Definition: mptrac.h:236
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:1901
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:347
Air parcel data.
Definition: mptrac.h:3120
Control parameters.
Definition: mptrac.h:2155
int atm_type
Type of atmospheric data files (0=ASCII, 1=binary, 2=netCDF, 3=CLaMS_traj, 4=CLaMS_pos).
Definition: mptrac.h:2905
int grid_type
Type of grid data files (0=ASCII, 1=netCDF).
Definition: mptrac.h:3024
char grid_basename[LEN]
Basename of grid data files.
Definition: mptrac.h:2973
Meteo data structure.
Definition: mptrac.h:3341
Here is the call graph for this function: