MPTRAC
atm2grid.c
Go to the documentation of this file.
1/*
2 This file is part of MPTRAC.
3
4 MPTRAC is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 MPTRAC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with MPTRAC. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright (C) 2013-2024 Forschungszentrum Juelich GmbH
18*/
19
25#include "mptrac.h"
26
27int main(
28 int argc,
29 char *argv[]) {
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}
int main(int argc, char *argv[])
Definition: atm2grid.c:27
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
MPTRAC library declarations.
#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