MPTRAC
met_conv.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-2026 Forschungszentrum Juelich GmbH
18*/
19
25#include "mptrac.h"
26
27/* ------------------------------------------------------------
28 Functions...
29 ------------------------------------------------------------ */
30
32void usage(
33 void);
34
35/* ------------------------------------------------------------
36 Main...
37 ------------------------------------------------------------ */
38
39int main(
40 int argc,
41 char *argv[]) {
42
43 ctl_t ctl;
44
45 clim_t *clim;
46
47 met_t *met;
48
49 dd_t *dd;
50
51 /* Print usage information... */
52 USAGE;
53
54 /* Check arguments... */
55 if (argc < 6)
56 ERRMSG("Missing or invalid command-line arguments.\n\n"
57 "Usage: met_conv <ctl> <met_in> <met_in_type> <met_out> <met_out_type>\n\n"
58 "Use -h for full help.");
59
60 /* Allocate... */
61 mptrac_alloc(NULL, NULL, &clim, &met, NULL, NULL, NULL, &dd);
62
63 /* Read control parameters... */
64 mptrac_read_ctl(argv[1], argc, argv, &ctl);
65
66 /* Read climatological data... */
67 mptrac_read_clim(&ctl, clim);
68
69 /* Read meteo data... */
70 ctl.met_type = atoi(argv[3]);
71 if (!mptrac_read_met(argv[2], &ctl, clim, met, dd))
72 ERRMSG("Cannot open file!");
73
74 /* Write meteo data... */
75 ctl.met_type = atoi(argv[5]);
76 mptrac_write_met(argv[4], &ctl, met);
77
78 /* Report timers... */
80
81 /* Free... */
82 mptrac_free(NULL, NULL, clim, met, NULL, NULL, NULL, dd);
83
84 return EXIT_SUCCESS;
85}
86
87/*****************************************************************************/
88
90void usage(
91 void) {
92
93 printf("\nMPTRAC met_conv tool.\n\n");
94 printf("Convert meteorological data between file formats.\n");
95 printf("\n");
96 printf("Usage:\n");
97 printf
98 (" met_conv <ctl> <met_in> <met_in_type> <met_out> <met_out_type>\n");
99 printf("\n");
100 printf("Arguments:\n");
101 printf(" <ctl> Control file.\n");
102 printf(" <met_in> Meteorological input file.\n");
103 printf
104 (" <met_in_type> Input format: 0=netCDF, 1=binary, 2=pck, 3=zfp,\n");
105 printf(" 4=zstd, 5=cms, 6=GRIB, 7=SZ3.\n");
106 printf(" <met_out> Meteorological output file.\n");
107 printf
108 (" <met_out_type> Output format: 0=netCDF, 1=binary, 2=pck, 3=zfp,\n");
109 printf(" 4=zstd, 5=cms, 6=GRIB, 7=SZ3.\n");
110 printf("\nFurther information:\n");
111 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
112}
int main(int argc, char *argv[])
Definition: met_conv.c:39
void usage(void)
Print command-line help.
Definition: met_conv.c:90
void mptrac_free(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, depo_t *depo, dd_t *dd)
Frees memory resources allocated for MPTRAC.
Definition: mptrac.c:6397
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:6683
void mptrac_alloc(ctl_t **ctl, cache_t **cache, clim_t **clim, met_t **met0, met_t **met1, atm_t **atm, depo_t **depo, dd_t **dd)
Allocates and initializes memory resources for MPTRAC.
Definition: mptrac.c:6314
int mptrac_read_met(const char *filename, const ctl_t *ctl, const clim_t *clim, met_t *met, dd_t *dd)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
Definition: mptrac.c:7767
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:6743
void mptrac_write_met(const char *filename, const ctl_t *ctl, met_t *met)
Writes meteorological data to a file, supporting multiple formats and compression options.
Definition: mptrac.c:8206
MPTRAC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2405
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:2212
#define PRINT_TIMERS
Print the current state of all timers.
Definition: mptrac.h:2464
Climatological data.
Definition: mptrac.h:3787
Control parameters.
Definition: mptrac.h:2493
int met_type
Type of meteo data files (0=netCDF, 1=binary, 2=pck, 3=ZFP, 4=ZSTD, 5=cms, 6=grib,...
Definition: mptrac.h:2866
Domain decomposition data structure.
Definition: mptrac.h:4023
Meteo data structure.
Definition: mptrac.h:3846