41 {
42
44 int prof_in, prof_out;
45
48
49 gsl_matrix *matrix;
50
51 size_t nr, nc;
52
53
55
56
57 if (argc < 11)
58 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
59 "Usage: matfmt <ctl> <atm> <obs> <rowspace> <colspace> <sort> <matrix_in> <matrixfmt_in> <matrix_out> <matrixfmt_out> [KEY VALUE ...]\n\n"
60 "Use -h for full help.");
61
62
64
65
66 prof_in = (int)
scan_ctl(argc, argv,
"PROF_IN", -1,
"0", NULL);
67 prof_out = (int)
scan_ctl(argc, argv,
"PROF_OUT", -1,
"0", NULL);
68
69
70 if (argv[4][0] != 'x' && argv[4][0] != 'y')
71 ERRMSG(
"Unknown row space, use x or y!");
72 if (argv[5][0] != 'x' && argv[5][0] != 'y')
73 ERRMSG(
"Unknown column space, use x or y!");
74 if (argv[6][0] != 'r' && argv[6][0] != 'c')
75 ERRMSG(
"Unknown sort order, use r or c!");
76
77
78 if (argv[4][0] == 'x' || argv[5][0] == 'x')
79 read_atm(NULL, argv[2], &ctl, &atm, 0);
80
81
82 if (argv[4][0] == 'y' || argv[5][0] == 'y')
83 read_obs(NULL, argv[3], &ctl, &obs, 0);
84
85
86 if (argv[4][0] == 'y')
87 nr =
obs2y(&ctl, &obs, NULL, NULL, NULL);
88 else
89 nr =
atm2x(&ctl, &atm, NULL, NULL, NULL);
90
91 if (argv[5][0] == 'y')
92 nc =
obs2y(&ctl, &obs, NULL, NULL, NULL);
93 else
94 nc =
atm2x(&ctl, &atm, NULL, NULL, NULL);
95
96
97 matrix = gsl_matrix_alloc(nr, nc);
98
99
102
103
106 write_matrix(NULL, argv[9], &ctl, matrix, &atm, &obs, argv[4], argv[5],
107 argv[6], prof_out);
108
109
110 gsl_matrix_free(matrix);
111
112 return EXIT_SUCCESS;
113}
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs, int profile)
Read observation data from an input file.
void write_matrix(const char *dirname, const char *filename, const ctl_t *ctl, const gsl_matrix *matrix, const atm_t *atm, const obs_t *obs, const char *rowspace, const char *colspace, const char *sort, int dataset)
Write a fully annotated matrix (e.g., Jacobian or gain matrix) to file.
void read_matrix(const char *dirname, const char *filename, const ctl_t *ctl, gsl_matrix *matrix, int dataset)
Read a numerical matrix from a file.
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm, int profile)
Read atmospheric input data from a file.
double scan_ctl(int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scan control file or command-line arguments for a configuration variable.
size_t obs2y(const ctl_t *ctl, const obs_t *obs, gsl_vector *y, int *ida, int *ira)
Convert observation radiances into a measurement vector.
size_t atm2x(const ctl_t *ctl, const atm_t *atm, gsl_vector *x, int *iqa, int *ipa)
Convert atmospheric data to state vector elements.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define USAGE
Print usage information on -h or --help.
Atmospheric profile data.
int write_matrix
Write matrix file (0=no, 1=yes).
int matrixfmt
Matrix data file format (1=ASCII, 2=binary, 3=netCDF).
Observation geometry and radiance data.