GPS Code Collection
perturbation.c
Go to the documentation of this file.
1/*
2 This file is part of the GPS Code Collection.
3
4 the GPS Code Collections is free software: you can redistribute it
5 and/or modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation, either version 3 of
7 the License, or (at your option) any later version.
8
9 The GPS Code Collection is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with the GPS Code Collection. If not, see
16 <http://www.gnu.org/licenses/>.
17
18 Copyright (C) 2019-2025 Forschungszentrum Juelich GmbH
19*/
20
26#include "libgps.h"
27
28/* ------------------------------------------------------------
29 Main...
30 ------------------------------------------------------------ */
31
32int main(
33 int argc,
34 char *argv[]) {
35
36 gps_t *gps;
37
38 char metbase[LEN];
39
40 /* Allocate... */
41 ALLOC(gps, gps_t, 1);
42
43 /* Check arguments... */
44 if (argc < 4)
45 ERRMSG("Give parameters: <ctl> <out.nc> <gps1.nc> [<gps2.nc> ...]");
46
47 /* Get control parameters... */
48 const double dt_met = scan_ctl(argc, argv, "DT_MET", -1, "21600", NULL);
49 const double gauss_dx = scan_ctl(argc, argv, "GAUSS_DX", -1, "-999", NULL);
50 const double gauss_dy = scan_ctl(argc, argv, "GAUSS_DY", -1, "-999", NULL);
51 const double grid_zmin = scan_ctl(argc, argv, "GRID_ZMIN", -1, "0", NULL);
52 const double grid_zmax = scan_ctl(argc, argv, "GRID_ZMAX", -1, "40", NULL);
53 const int grid_nz = (int) scan_ctl(argc, argv, "GRID_NZ", -1, "-1", NULL);
54 const double ham_dz = scan_ctl(argc, argv, "HAM_DZ", -1, "-999", NULL);
55 const double ham_dz2 = scan_ctl(argc, argv, "HAM_DZ2", -1, "-999", NULL);
56 scan_ctl(argc, argv, "METBASE", -1, "", metbase);
57 const double prof_zmax_min =
58 scan_ctl(argc, argv, "PROF_ZMAX_MIN", -1, "35", NULL);
59 const double prof_zmin_max =
60 scan_ctl(argc, argv, "PROF_ZMIN_MAX", -1, "5", NULL);
61 const int poly_dim = (int) scan_ctl(argc, argv, "POLY_DIM", -1, "5", NULL);
62 const double poly_zmin = scan_ctl(argc, argv, "POLY_ZMIN", -1, "0", NULL);
63 const double poly_zmax = scan_ctl(argc, argv, "POLY_ZMAX", -1, "40", NULL);
64
65 /* Read individual GPS-RO data files... */
66 for (int iarg = 3; iarg < argc; iarg++) {
67 FILE *in;
68 if (!(in = fopen(argv[iarg], "r")))
69 continue;
70 else {
71 fclose(in);
72 read_gps_prof(argv[iarg], gps, prof_zmin_max, prof_zmax_min);
73 }
74 }
75
76 /* Check number of profiles... */
77 if (gps->nds <= 0)
78 ERRMSG("No profiles found!");
79
80 /* Grid profile... */
81 if (grid_nz > 0)
82 grid_gps(gps, grid_zmin, grid_zmax, grid_nz);
83
84 /* Get tropopause... */
85 tropopause(gps);
86
87 /* Get perturbations from horizontal Gaussian mean... */
88 if (gauss_dx > 0 && gauss_dy > 0)
89 gauss(gps, gauss_dx, gauss_dy);
90
91 /* Get perturbations from vertical Hamming filter... */
92 if (ham_dz > 0)
93 hamming_low_pass(gps, ham_dz);
94
95 /* Use vertical Hamming filter to reduce noise... */
96 if (ham_dz2 > 0)
97 hamming_high_pass(gps, ham_dz2);
98
99 /* Use meteo data for detrending... */
100 if (metbase[0] != '-')
101 detrend_met(gps, metbase, dt_met);
102
103 /* Remove polynomial fit from perturbation profile... */
104 if (poly_dim > 0)
105 poly(gps, poly_dim, poly_zmin, poly_zmax);
106
107 /* Write GPS-RO data file... */
108 write_gps(argv[2], gps);
109
110 /* Free... */
111 free(gps);
112
113 return EXIT_SUCCESS;
114}
void write_gps(char *filename, gps_t *gps)
Write GPS-RO data file.
Definition: libgps.c:1080
void gauss(gps_t *gps, double dx, double dy)
Calculate horizontal Gaussian mean to extract perturbations.
Definition: libgps.c:94
void read_gps_prof(char *filename, gps_t *gps, double prof_zmin_max, double prof_zmax_min)
Read GPS-RO profile.
Definition: libgps.c:528
void poly(gps_t *gps, int dim, double zmin, double zmax)
Remove polynomial fit from perturbation profile.
Definition: libgps.c:443
void grid_gps(gps_t *gps, double zmin, double zmax, int nz)
Interpolate GPS data to regular altitude grid.
Definition: libgps.c:136
void hamming_low_pass(gps_t *gps, double dz)
Apply vertical Hamming filter to extract perturbations.
Definition: libgps.c:331
void detrend_met(gps_t *gps, char *metbase, double dt_met)
Detrending by means of meteo data.
Definition: libgps.c:57
void hamming_high_pass(gps_t *gps, double dz)
Apply vertical Hamming filter to reduce noise.
Definition: libgps.c:389
void tropopause(gps_t *gps)
Find tropopause height.
Definition: libgps.c:908
GPS Code Collection library declarations.
int main(int argc, char *argv[])
Definition: perturbation.c:32
GPS-RO profile data.
Definition: libgps.h:153
int nds
Number of profiles.
Definition: libgps.h:156