MPTRAC
atm_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 atm_t *atm;
46
47 /* Print usage information... */
48 USAGE;
49
50 /* Check arguments... */
51 if (argc < 6)
52 ERRMSG("Missing or invalid command-line arguments.\n\n"
53 "Usage: atm_conv <ctl> <atm_in> <atm_in_type> <atm_out> <atm_out_type>\n\n"
54 "Use -h for full help.");
55
56 /* Allocate... */
57 ALLOC(atm, atm_t, 1);
58
59 /* Read control parameters... */
60 mptrac_read_ctl(argv[1], argc, argv, &ctl);
61
62 /* Read atmospheric data... */
63 ctl.atm_type = atoi(argv[3]);
64 if (!mptrac_read_atm(argv[2], &ctl, atm))
65 ERRMSG("Cannot open file!");
66
67 /* Write atmospheric data... */
68 if (ctl.atm_type_out == 3) {
69
70 /* For CLaMS trajectory files... */
71 ctl.t_start = ctl.t_stop;
72 ctl.atm_type_out = atoi(argv[5]);
73 mptrac_write_atm(argv[4], &ctl, atm, ctl.t_stop);
74
75 } else {
76
77 /* Otherwise... */
78 ctl.atm_type_out = atoi(argv[5]);
79 mptrac_write_atm(argv[4], &ctl, atm, 0);
80 }
81
82 /* Free... */
83 free(atm);
84
85 return EXIT_SUCCESS;
86}
87
88/*****************************************************************************/
89
91void usage(
92 void) {
93
94 printf("\nMPTRAC atm_conv tool.\n\n");
95 printf("Convert atmospheric particle data between file formats.\n");
96 printf("\n");
97 printf("Usage:\n");
98 printf
99 (" atm_conv <ctl> <atm_in> <atm_in_type> <atm_out> <atm_out_type>\n");
100 printf("\n");
101 printf("Arguments:\n");
102 printf(" <ctl> Control file.\n");
103 printf(" <atm_in> Atmospheric input file.\n");
104 printf(" <atm_in_type> Input format: 0=ASCII, 1=binary, 2=netCDF,\n");
105 printf
106 (" 3=CLaMS trajectory/position netCDF, 4=CLaMS position netCDF.\n");
107 printf(" <atm_out> Atmospheric output file.\n");
108 printf(" <atm_out_type> Output format: 0=ASCII, 1=binary, 2=netCDF,\n");
109 printf
110 (" 3=CLaMS trajectory/position netCDF, 4=CLaMS position netCDF.\n");
111 printf("\nFurther information:\n");
112 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
113}
int main(int argc, char *argv[])
Definition: atm_conv.c:39
void usage(void)
Print command-line help.
Definition: atm_conv.c:91
void mptrac_write_atm(const char *filename, const ctl_t *ctl, const atm_t *atm, const double t)
Writes air parcel data to a file in various formats.
Definition: mptrac.c:6840
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:5430
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:5561
MPTRAC library declarations.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2115
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:1922
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:466
Air parcel data.
Definition: mptrac.h:3257
Control parameters.
Definition: mptrac.h:2203
int atm_type
Type of atmospheric data files (0=ASCII, 1=binary, 2=netCDF, 3=CLaMS_traj, 4=CLaMS_pos).
Definition: mptrac.h:3020
int atm_type_out
Type of atmospheric data files for output (-1=same as ATM_TYPE, 0=ASCII, 1=binary,...
Definition: mptrac.h:3025
double t_stop
Stop time of simulation [s].
Definition: mptrac.h:2537
double t_start
Start time of simulation [s].
Definition: mptrac.h:2534