forked from NOAA-EMC/wgrib2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrb2_cmd.c
49 lines (40 loc) · 1019 Bytes
/
grb2_cmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <string.h>
#include "c_wgrib2api.h"
/* 10/2024 Public Domain Wesley Ebisuzaki
* handles arguments for wgrib2
*/
static int n_cmds = -1;
char cmd[N_CMDS][CMD_LEN];
char *cmds[N_CMDS+1];
void wgrib2_init_cmds(void) {
cmds[0] = "wgrib2 C_api";
n_cmds = 1;
return;
}
int wgrib2_add_cmd(const char *string) {
int j;
j = strlen(string);
if (j >= CMD_LEN) fatal_error("add_cmd: string too long %s", string);
if (n_cmds >= N_CMDS) fatal_error("add_cmd: too many options %s", string);
strncpy(&(cmd[n_cmds][0]), string, j+1);
cmds[n_cmds] = &(cmd[n_cmds][0]);
n_cmds++;
return 0;
}
int wgrib2_cmd(void) {
return wgrib2(n_cmds, (const char **) cmds);
}
int wgrib2_list_cmd(void) {
int i;
if (n_cmds < 0) {
fprintf(stderr,"no wgrib2 cmds\n");
return 0;
}
fprintf(stderr,"wgrib2 ");
for (i = 1; i < n_cmds; i++) {
fprintf(stderr,"%s ", cmds[i]);
}
fprintf(stderr,"\n");
return 0;
}