29 {
30
32
34
36
37 FILE *out;
38
39 static double cutImag[
EX], cutReal[
EX], lx[
EX], A[
EX], phi[
EX];
40
41
44
45
46 if (argc < 4)
47 ERRMSG(
"Give parameters: <ctl> <spec.tab> <met0>");
48
49
51 double wavemax =
52 (int)
scan_ctl(argv[1], argc, argv,
"SPEC_WAVEMAX", -1,
"7", NULL);
53
54
56
57
58 if (!
read_met(argv[3], &ctl, clim, met))
59 ERRMSG(
"Cannot read meteo data!");
60
61
62 LOG(1,
"Write spectral data file: %s", argv[2]);
63 if (!(out = fopen(argv[2], "w")))
64 ERRMSG(
"Cannot create file!");
65
66
67 fprintf(out,
68 "# $1 = time [s]\n"
69 "# $2 = altitude [km]\n"
70 "# $3 = longitude [deg]\n" "# $4 = latitude [deg]\n");
71 for (int ix = 0; ix <= wavemax; ix++) {
72 fprintf(out, "# $%d = wavelength (PW%d) [km]\n", 5 + 3 * ix, ix);
73 fprintf(out, "# $%d = amplitude (PW%d) [K]\n", 6 + 3 * ix, ix);
74 fprintf(out, "# $%d = phase (PW%d) [deg]\n", 7 + 3 * ix, ix);
75 }
76
77
78 for (
int ip = 0; ip < met->
np; ip++) {
79
80
81 fprintf(out, "\n");
82
83
84 for (
int iy = 0; iy < met->
ny; iy++) {
85
86
87 for (
int ix = 0; ix < met->
nx; ix++) {
88 cutReal[ix] = met->
t[ix][iy][ip];
89 cutImag[ix] = 0.0;
90 }
91
92
94
95
96
97
98
99 for (
int ix = 0; ix < met->
nx; ix++) {
101 / ((ix < met->
nx / 2) ? (
double) ix : -(double) (met->
nx - ix));
102 A[ix] = (ix == 0 ? 1.0 : 2.0) / (met->
nx)
103 * sqrt(gsl_pow_2(cutReal[ix]) + gsl_pow_2(cutImag[ix]));
104 phi[ix] =
RAD2DEG(atan2(cutImag[ix], cutReal[ix]));
105 }
106
107
108 fprintf(out,
"%.2f %g %g %g", met->
time,
Z(met->
p[ip]), 0.0,
110 for (int ix = 0; ix <= wavemax; ix++)
111 fprintf(out, " %g %g %g", lx[ix], A[ix], phi[ix]);
112 fprintf(out, "\n");
113 }
114 }
115
116
117 fclose(out);
118
119
120 free(clim);
121 free(met);
122
123 return EXIT_SUCCESS;
124}
void fft_help(double *fcReal, double *fcImag, const int n)
Computes the Fast Fourier Transform (FFT) of a complex sequence.
double scan_ctl(const char *filename, int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scans a control file or command-line arguments for a specified variable.
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.
int read_met(const char *filename, ctl_t *ctl, clim_t *clim, met_t *met)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
void read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define Z(p)
Convert pressure to altitude.
#define EX
Maximum number of longitudes for meteo data.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define RAD2DEG(rad)
Converts radians to degrees.
#define LOG(level,...)
Print a log message with a specified logging level.
#define DEG2DX(dlon, lat)
Convert a longitude difference to a distance in the x-direction (east-west) at a specific latitude.
int nx
Number of longitudes.
int ny
Number of latitudes.
int np
Number of pressure levels.
float t[EX][EY][EP]
Temperature [K].
double lon[EX]
Longitude [deg].
double lat[EY]
Latitude [deg].
double p[EP]
Pressure levels [hPa].