GPS Code Collection
Functions
tropopause.c File Reference

Extract tropopause data. More...

#include "libgps.h"

Go to the source code of this file.

Functions

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

Detailed Description

Extract tropopause data.

Definition in file tropopause.c.

Function Documentation

◆ main()

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

Definition at line 32 of file tropopause.c.

34 {
35
36 gps_t *gps;
37
38 FILE *in;
39
40 double clp_tlon[NDS], clp_tlat[NDS], wmo_1st_tlon[NDS], wmo_1st_tlat[NDS],
41 wmo_2nd_tlon[NDS], wmo_2nd_tlat[NDS];
42
43 float clp_th[NDS], clp_tp[NDS], clp_tq[NDS], clp_tt[NDS], wmo_1st_th[NDS],
44 wmo_1st_tp[NDS], wmo_1st_tq[NDS], wmo_1st_tt[NDS], wmo_2nd_th[NDS],
45 wmo_2nd_tp[NDS], wmo_2nd_tq[NDS], wmo_2nd_tt[NDS];
46
47 /* Allocate... */
48 ALLOC(gps, gps_t, 1);
49
50 /* Check arguments... */
51 if (argc < 4)
52 ERRMSG("Give parameters: <ctl> <out.nc> <gps1.nc> [<gps2.nc> ...]");
53
54 /* Read individual GPS-RO data files... */
55 for (int iarg = 3; iarg < argc; iarg++)
56 if (!(in = fopen(argv[iarg], "r")))
57 continue;
58 else {
59 fclose(in);
60 read_gps_prof(argv[iarg], gps);
61 }
62
63 /* Check number of profiles... */
64 if (gps->nds <= 0)
65 ERRMSG("No profiles found!");
66
67 /* ------------------------------------------------------------
68 Get tropopause data...
69 ------------------------------------------------------------ */
70
71 /* Cold point... */
72 tropopause_spline(gps, 2);
73 for (int ids = 0; ids < gps->nds; ids++) {
74 clp_tlon[ids] = gps->tlon[ids];
75 clp_tlat[ids] = gps->tlat[ids];
76 clp_tp[ids] = (float) gps->tp[ids];
77 clp_th[ids] = (float) gps->th[ids];
78 clp_tt[ids] = (float) gps->tt[ids];
79 clp_tq[ids] = (float) gps->tq[ids];
80 }
81
82 /* WMO 1st tropopause... */
83 tropopause_spline(gps, 3);
84 for (int ids = 0; ids < gps->nds; ids++) {
85 wmo_1st_tlon[ids] = gps->tlon[ids];
86 wmo_1st_tlat[ids] = gps->tlat[ids];
87 wmo_1st_tp[ids] = (float) gps->tp[ids];
88 wmo_1st_th[ids] = (float) gps->th[ids];
89 wmo_1st_tt[ids] = (float) gps->tt[ids];
90 wmo_1st_tq[ids] = (float) gps->tq[ids];
91 }
92
93 /* WMO 2nd tropopause... */
94 tropopause_spline(gps, 4);
95 for (int ids = 0; ids < gps->nds; ids++) {
96 wmo_2nd_tlon[ids] = gps->tlon[ids];
97 wmo_2nd_tlat[ids] = gps->tlat[ids];
98 wmo_2nd_tp[ids] = (float) gps->tp[ids];
99 wmo_2nd_th[ids] = (float) gps->th[ids];
100 wmo_2nd_tt[ids] = (float) gps->tt[ids];
101 wmo_2nd_tq[ids] = (float) gps->tq[ids];
102 }
103
104 /* ------------------------------------------------------------
105 Write netCDF files...
106 ------------------------------------------------------------ */
107
108 /* Create netCDF file... */
109 int ncid, varid, dimid[10];
110 printf("Write tropopause file: %s\n", argv[2]);
111 NC(nc_create(argv[2], NC_CLOBBER, &ncid));
112
113 /* Set dimensions... */
114 NC(nc_def_dim(ncid, "NDS", (size_t) gps->nds, &dimid[0]));
115
116 /* Add variables... */
117 add_var(ncid, "time", "s", "time (seconds since 2000-01-01T00:00Z)",
118 NC_DOUBLE, dimid, &varid, 1);
119
120 add_var(ncid, "clp_lat", "degrees_north", "cold point latitude", NC_DOUBLE,
121 dimid, &varid, 1);
122 add_var(ncid, "clp_lon", "degrees_east", "cold point longitude", NC_DOUBLE,
123 dimid, &varid, 1);
124 add_var(ncid, "clp_z", "km", "cold point height", NC_FLOAT, dimid, &varid,
125 1);
126 add_var(ncid, "clp_p", "hPa", "cold point pressure", NC_FLOAT, dimid,
127 &varid, 1);
128 add_var(ncid, "clp_t", "K", "cold point temperature", NC_FLOAT, dimid,
129 &varid, 1);
130 add_var(ncid, "clp_q", "ppv", "cold point water vapor", NC_FLOAT, dimid,
131 &varid, 1);
132
133 add_var(ncid, "wmo_1st_lat", "degrees_north", "WMO 1st tropopause latitude",
134 NC_DOUBLE, dimid, &varid, 1);
135 add_var(ncid, "wmo_1st_lon", "degrees_east", "WMO 1st tropopause longitude",
136 NC_DOUBLE, dimid, &varid, 1);
137 add_var(ncid, "wmo_1st_z", "km", "WMO 1st tropopause height", NC_FLOAT,
138 dimid, &varid, 1);
139 add_var(ncid, "wmo_1st_p", "hPa", "WMO 1st tropopause pressure", NC_FLOAT,
140 dimid, &varid, 1);
141 add_var(ncid, "wmo_1st_t", "K", "WMO 1st tropopause temperature", NC_FLOAT,
142 dimid, &varid, 1);
143 add_var(ncid, "wmo_1st_q", "ppv", "WMO 1st tropopause water vapor",
144 NC_FLOAT, dimid, &varid, 1);
145
146 add_var(ncid, "wmo_2nd_lat", "degrees_north", "WMO 2nd tropopause latitude",
147 NC_DOUBLE, dimid, &varid, 1);
148 add_var(ncid, "wmo_2nd_lon", "degrees_east", "WMO 2nd tropopause longitude",
149 NC_DOUBLE, dimid, &varid, 1);
150 add_var(ncid, "wmo_2nd_z", "km", "WMO 2nd tropopause height", NC_FLOAT,
151 dimid, &varid, 1);
152 add_var(ncid, "wmo_2nd_p", "hPa", "WMO 2nd tropopause pressure", NC_FLOAT,
153 dimid, &varid, 1);
154 add_var(ncid, "wmo_2nd_t", "K", "WMO 2nd tropopause temperature", NC_FLOAT,
155 dimid, &varid, 1);
156 add_var(ncid, "wmo_2nd_q", "ppv", "WMO 2nd tropopause water vapor",
157 NC_FLOAT, dimid, &varid, 1);
158
159 /* Leave define mode... */
160 NC(nc_enddef(ncid));
161
162 /* Write data... */
163 NC(nc_inq_varid(ncid, "time", &varid));
164 NC(nc_put_var_double(ncid, varid, gps->time));
165
166 NC(nc_inq_varid(ncid, "clp_lat", &varid));
167 NC(nc_put_var_double(ncid, varid, clp_tlat));
168 NC(nc_inq_varid(ncid, "clp_lon", &varid));
169 NC(nc_put_var_double(ncid, varid, clp_tlon));
170 NC(nc_inq_varid(ncid, "clp_z", &varid));
171 NC(nc_put_var_float(ncid, varid, clp_th));
172 NC(nc_inq_varid(ncid, "clp_p", &varid));
173 NC(nc_put_var_float(ncid, varid, clp_tp));
174 NC(nc_inq_varid(ncid, "clp_t", &varid));
175 NC(nc_put_var_float(ncid, varid, clp_tt));
176 NC(nc_inq_varid(ncid, "clp_q", &varid));
177 NC(nc_put_var_float(ncid, varid, clp_tq));
178
179 NC(nc_inq_varid(ncid, "wmo_1st_lat", &varid));
180 NC(nc_put_var_double(ncid, varid, wmo_1st_tlat));
181 NC(nc_inq_varid(ncid, "wmo_1st_lon", &varid));
182 NC(nc_put_var_double(ncid, varid, wmo_1st_tlon));
183 NC(nc_inq_varid(ncid, "wmo_1st_z", &varid));
184 NC(nc_put_var_float(ncid, varid, wmo_1st_th));
185 NC(nc_inq_varid(ncid, "wmo_1st_p", &varid));
186 NC(nc_put_var_float(ncid, varid, wmo_1st_tp));
187 NC(nc_inq_varid(ncid, "wmo_1st_t", &varid));
188 NC(nc_put_var_float(ncid, varid, wmo_1st_tt));
189 NC(nc_inq_varid(ncid, "wmo_1st_q", &varid));
190 NC(nc_put_var_float(ncid, varid, wmo_1st_tq));
191
192 NC(nc_inq_varid(ncid, "wmo_2nd_lat", &varid));
193 NC(nc_put_var_double(ncid, varid, wmo_2nd_tlat));
194 NC(nc_inq_varid(ncid, "wmo_2nd_lon", &varid));
195 NC(nc_put_var_double(ncid, varid, wmo_2nd_tlon));
196 NC(nc_inq_varid(ncid, "wmo_2nd_z", &varid));
197 NC(nc_put_var_float(ncid, varid, wmo_2nd_th));
198 NC(nc_inq_varid(ncid, "wmo_2nd_p", &varid));
199 NC(nc_put_var_float(ncid, varid, wmo_2nd_tp));
200 NC(nc_inq_varid(ncid, "wmo_2nd_t", &varid));
201 NC(nc_put_var_float(ncid, varid, wmo_2nd_tt));
202 NC(nc_inq_varid(ncid, "wmo_2nd_q", &varid));
203 NC(nc_put_var_float(ncid, varid, wmo_2nd_tq));
204
205 /* Close file... */
206 NC(nc_close(ncid));
207
208 /* Free... */
209 free(gps);
210
211 return EXIT_SUCCESS;
212}
void add_var(int ncid, const char *varname, const char *unit, const char *longname, int type, int dimid[], int *varid, int ndims)
Add variable to netCDF file.
Definition: libgps.c:30
void read_gps_prof(char *filename, gps_t *gps)
Read GPS-RO profile.
Definition: libgps.c:520
void tropopause_spline(gps_t *gps, int met_tropo)
Find tropopause height using cubic spline interpolation.
Definition: libgps.c:922
#define NC(cmd)
Execute netCDF library command and check result.
Definition: libgps.h:134
#define NDS
Maximum number of GPS-RO profiles.
Definition: libgps.h:100
GPS-RO profile data.
Definition: libgps.h:153
double time[NDS]
Time (seconds since 2000-01-01T00:00Z).
Definition: libgps.h:162
double tlon[NDS]
Tropopause longitude [deg].
Definition: libgps.h:198
double tt[NDS]
Tropopause temperature [K].
Definition: libgps.h:192
double tp[NDS]
Tropopause pressure [hPa].
Definition: libgps.h:189
int nds
Number of profiles.
Definition: libgps.h:156
double th[NDS]
Tropopause height [km].
Definition: libgps.h:186
double tlat[NDS]
Tropopause latitude [deg].
Definition: libgps.h:201
double tq[NDS]
Tropopause water vapor [ppmv].
Definition: libgps.h:195
Here is the call graph for this function: