forked from pacificclimate/VIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_proc.c
86 lines (72 loc) · 2.72 KB
/
cmd_proc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vicNl.h"
#include <unistd.h> /* This is where you get getopt() from, stupid. */
static char vcid[] = "$Id$";
void cmd_proc(int argc, char *argv[], char* global_file_name, ProgramState* state)
/**********************************************************************
cmd_proc Keith Cherkauer 1997
This routine checks the command line for valid program options. If
no options are found, or an invalid combination of them appear, the
routine calls usage() to print the model usage to the screen, before
exiting execution.
Modifications:
11-18-98 Added comment block to cmd_proc() and fixed routine so
that it will exit if global command file is not defined
using the "-g" flag. KAC
30-Oct-03 Added -v option to display version information. TJB
**********************************************************************/
{
const char *optstring = "g:vo";
int optchar;
bool GLOBAL_SET;
if(argc==1) {
usage(argv[0]);
exit(1);
}
GLOBAL_SET = false;
while((optchar = getopt(argc, argv, optstring)) != EOF) {
switch((char)optchar) {
case 'v':
/** Version information **/
state->display_current_settings(DISP_VERSION,(filenames_struct*)NULL);
exit(0);
break;
case 'o':
/** Compile-time options information **/
state->display_current_settings(DISP_COMPILE_TIME,(filenames_struct*)NULL);
exit(0);
break;
case 'g':
/** Global Parameters File **/
strcpy(global_file_name, optarg);
GLOBAL_SET = true;
break;
default:
/** Print Usage if Invalid Command Line Arguments **/
usage(argv[0]);
exit(1);
break;
}
}
if(!GLOBAL_SET) {
fprintf(stderr,"ERROR: Must set global control file using the '-g' flag\n");
usage(argv[0]);
exit(1);
}
}
void usage(char *temp)
/**********************************************************************
usage Keith Cherkauer May 27, 1996
This routine prints out usage details.
**********************************************************************/
{
fprintf(stderr,"Usage: %s [-v | -o | -g<global_parameter_file>]\n",temp);
fprintf(stderr," v: display version information\n");
fprintf(stderr," o: display compile-time options settings (set in user_def.h)\n");
fprintf(stderr," g: read model parameters from <global_parameter_file>.\n");
fprintf(stderr," <global_parameter_file> is a file that contains all needed model\n");
fprintf(stderr," parameters as well as model option flags, and the names and\n");
fprintf(stderr," locations of all other files.\n");
}