forked from kettner/hydrotrend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hydrotrend_main.c
122 lines (95 loc) · 2.33 KB
/
hydrotrend_main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* hydrotrend_1.c
*
*
* Created by Albert Kettner on 1/23/09.
* Copyright 2009 Univ of CO. All rights reserved.
*
*/
#include "hydrotrend_cli.h"
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "hydrotrend_irf.h"
#include "bmi_hydrotrend.h"
int fprint_current_time( FILE* file, char* label );
int fprint_header( FILE* fp );
int fprint_footer( FILE* fp );
int
main (int argc, char **argv)
{
char *in_prefix = NULL;
char *in_dir = NULL;
char *out_dir = NULL;
/*-----------------------------------------------------------------
* Check the command line input; get file name or directory name
*-----------------------------------------------------------------*/
{
ht_args_st* args = parse_command_line ( argc, argv);
if ( !args )
{
fprintf (stderr, " ERROR in HydroCommandLine: HydroTrend Aborted \n\n");
exit (EXIT_FAILURE);
}
in_prefix = args->in_file;
in_dir = args->in_dir;
out_dir = args->out_dir;
free( args );
}
fprint_header ( stdout );
fprint_current_time ( stdout, "Start" );
{
Bmi * model = (Bmi*)malloc(sizeof(Bmi));
register_bmi_hydrotrend(model);
hydro_initialize(model->data, in_dir, in_prefix, out_dir);
model->update_until(model, 10.5);
model->finalize(model);
free(model);
}
fprint_current_time( stdout, "Stop" );
fprint_footer ( stdout );
free( in_prefix );
free( in_dir );
if (out_dir)
free (out_dir);
return EXIT_SUCCESS;
}
int
fprint_header( FILE* fp )
{
int n = 0;
{
n += fprintf (fp, " =====================================\n\n");
n += fprintf (fp, " ----- HydroTrend %d.%d Model Run ----- \n\n",
HT_MAJOR_VERSION, HT_MINOR_VERSION );
}
return n;
}
int
fprint_footer( FILE* fp )
{
int n = 0;
{
n += fprintf (fp, " =====================================\n\n");
}
return n;
}
#define TMLEN (100) /* length of the time stamp */
int
fprint_current_time( FILE* fp, char* label )
{
int n = 0;
{
char pst[TMLEN];
struct tm *timeptr;
time_t tloc;
time (&tloc);
timeptr = localtime (&tloc);
/*--------------------------------
* Print the program start time
*--------------------------------*/
strftime (pst, TMLEN, "%X %x", timeptr);
n += fprintf (fp, " \t%s: %s \n\n", label, pst);
}
return n;
}