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

void usage (void)
 Print command-line help. More...
 
int main (int argc, char *argv[])
 

Detailed Description

Convert atmospheric data file to grid data file.

Definition in file atm2grid.c.

Function Documentation

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 95 of file atm2grid.c.

96 {
97
98 printf("\nMPTRAC atm2grid tool.\n\n");
99 printf
100 ("Convert an atmospheric particle data file to gridded output data.\n");
101 printf("\n");
102 printf("Usage:\n");
103 printf(" atm2grid <ctl> <atm_in> [KEY VALUE ...]\n");
104 printf("\n");
105 printf("Arguments:\n");
106 printf(" <ctl> Control file.\n");
107 printf(" <atm_in> Atmospheric input file.\n");
108 printf(" [KEY VALUE] Optional control parameters.\n");
109 printf("\n");
110 printf("Notes:\n");
111 printf(" GRID_BASENAME must be set in the control parameters.\n");
112 printf("\nFurther information:\n");
113 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
114}

◆ main()

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

Definition at line 39 of file atm2grid.c.

41 {
42
43 ctl_t ctl;
44
45 atm_t *atm;
46
47 met_t *met0 = NULL, *met1 = NULL;
48
49 /* Allocate... */
50 ALLOC(atm, atm_t, 1);
51
52 /* Print usage information... */
53 USAGE;
54
55 /* Check arguments... */
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 /* Read control parameters... */
62 mptrac_read_ctl(argv[1], argc, argv, &ctl);
63
64 /* Check grid basename... */
65 if (ctl.grid_basename[0] == '-')
66 ERRMSG("You need to specify GRID_BASENAME!");
67
68 /* Read atmospheric data... */
69 if (!mptrac_read_atm(argv[2], &ctl, atm))
70 ERRMSG("Cannot open file!");
71
72 /* Get time from filename... */
73 int year, mon, day, hour, min, sec;
74 double r, t = time_from_filename(argv[2], ctl.atm_type < 2 ? 20 : 19);
75 jsec2time(t, &year, &mon, &day, &hour, &min, &sec, &r);
76
77 /* Set output filename... */
78 char filename[3 * LEN];
79 sprintf(filename, "%s_%04d_%02d_%02d_%02d_%02d.%s",
80 ctl.grid_basename, year, mon, day, hour, min,
81 ctl.grid_type == 0 ? "tab" : "nc");
82
83 /* Write grid data... */
84 write_grid(filename, &ctl, met0, met1, atm, t);
85
86 /* Free... */
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.
Definition: mptrac.c:11017
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.
Definition: mptrac.c:5117
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:2294
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.
Definition: mptrac.c:5248
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:11839
#define LEN
Maximum length of ASCII data lines.
Definition: mptrac.h:345
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2102
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:1909
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:453
Air parcel data.
Definition: mptrac.h:3241
Control parameters.
Definition: mptrac.h:2190
int atm_type
Type of atmospheric data files (0=ASCII, 1=binary, 2=netCDF, 3=CLaMS_traj, 4=CLaMS_pos).
Definition: mptrac.h:3007
int grid_type
Type of grid data files (0=ASCII, 1=netCDF).
Definition: mptrac.h:3129
char grid_basename[LEN]
Basename of grid data files.
Definition: mptrac.h:3078
Meteo data structure.
Definition: mptrac.h:3495
Here is the call graph for this function: