JURASSIC
Functions
matfmt.c File Reference

Convert matrix data files. More...

#include "jurassic.h"

Go to the source code of this file.

Functions

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

Detailed Description

Convert matrix data files.

Definition in file matfmt.c.

Function Documentation

◆ main()

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

Definition at line 39 of file matfmt.c.

41 {
42
43 ctl_t ctl;
44 int prof_in, prof_out;
45
46 static atm_t atm;
47 static obs_t obs;
48
49 gsl_matrix *matrix;
50
51 size_t nr, nc;
52
53 /* Print usage information... */
54 USAGE;
55
56 /* Check arguments... */
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 /* Read control parameters... */
63 read_ctl(argc, argv, &ctl);
64
65 /* Read dataset indices... */
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 /* Check matrix metadata... */
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 /* Read atmospheric data if needed... */
78 if (argv[4][0] == 'x' || argv[5][0] == 'x')
79 read_atm(NULL, argv[2], &ctl, &atm, 0);
80
81 /* Read observation data if needed... */
82 if (argv[4][0] == 'y' || argv[5][0] == 'y')
83 read_obs(NULL, argv[3], &ctl, &obs, 0);
84
85 /* Determine matrix size... */
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 /* Allocate matrix... */
97 matrix = gsl_matrix_alloc(nr, nc);
98
99 /* Read matrix data... */
100 ctl.matrixfmt = atoi(argv[8]);
101 read_matrix(NULL, argv[7], &ctl, matrix, prof_in);
102
103 /* Write matrix data... */
104 ctl.write_matrix = 1;
105 ctl.matrixfmt = atoi(argv[10]);
106 write_matrix(NULL, argv[9], &ctl, matrix, &atm, &obs, argv[4], argv[5],
107 argv[6], prof_out);
108
109 /* Free... */
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.
Definition: jurassic.c:5516
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.
Definition: jurassic.c:5810
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.
Definition: jurassic.c:7753
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.
Definition: jurassic.c:5643
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.
Definition: jurassic.c:5193
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.
Definition: jurassic.c:6612
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.
Definition: jurassic.c:4627
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.
Definition: jurassic.c:125
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1325
#define USAGE
Print usage information on -h or --help.
Definition: jurassic.h:1206
Atmospheric profile data.
Definition: jurassic.h:1375
Control parameters.
Definition: jurassic.h:1428
int write_matrix
Write matrix file (0=no, 1=yes).
Definition: jurassic.h:1572
int matrixfmt
Matrix data file format (1=ASCII, 2=binary, 3=netCDF).
Definition: jurassic.h:1491
Observation geometry and radiance data.
Definition: jurassic.h:1657
Here is the call graph for this function: