-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmass1bc.in
251 lines (191 loc) · 6.47 KB
/
mass1bc.in
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!@PERL@
# -*- cperl -*-
# -------------------------------------------------------------
# file: mass1bc.pl
# This script makes a MASS1/MASS2 format boundary condition file from
# a MASS1 time-series output file
# -------------------------------------------------------------
# -------------------------------------------------------------
# Copyright (c) 2017 Battelle Memorial Institute
# Licensed under modified BSD License. A copy of this license can be
# found in the LICENSE file in the top level directory of this
# distribution.
# -------------------------------------------------------------
# -------------------------------------------------------------
# Created October 4, 1999 by William A. Perkins
# Last Change: 2017-08-28 08:32:42 d3g096
# -------------------------------------------------------------
# RCS ID: $Id$
use strict;
use Getopt::Std;
use Date::Manip;
=pod
=head1 NAME
mass1bc.pl -- produce MASS1 or MASS2 boundary condition files from
MASS1 gage file output
=head1 SYNOPSIS
perl mass1bc.pl B<-f> I<field> [ B<-0> | B<-O> offset ] [ B<-o> I<output> ] [ I<file> ]
perl mass1bc.pl B<-l>
=head1 DESCRIPTION
This is a simple script to extract a specific value from the gage
output of a MASS1 simulation and format it such that it could be used
as a MASS1 or MASS2 boundary condition file. The the field is
specified using the B<-f> option with the name of the field, for
example C<temp> for temperature. The B<-l> option will list available
fields.
This script is part of the @PACKAGE@ distribution (Version @VERSION@)
=head1 OPTIONS
=over
=item B<-l>
list the available fields by name and exit
=item B<-f> I<field>
specify the field to be extracted. The I<field> is specified by name,
for example: depth, temp, conc, etc. Use the B<-l> option to list
available fields.
=item B<-O> I<offset>
apply an (negative) offset to the output time. The format of
I<time_offset> is very flexible; the ParseDateDelta function in
L<Date::Manip> is used to parse the offset. The default is "-30
minutes", which assumes that the MASS1 output is hourly.
=item B<-0>
specify a zero time offset. The same effect can be accomplished by
specifying C<-O "+ 0 minutes">
=item B<-o> I<output>
send output to the file named I<output> instead of standard output
=back
=head1 EXAMPLES
To obtain a list of available fields, use the B<-l> option:
perk@mack> perl mass1bc.pl -l
The following "field"s are recognized:
conc: TDG Gas Concentration
depth: Depth
temp: Water Temperature
wselev: Water Surface Elevation
vel: Velocity
flow: Discharge
sat: TDG Saturation
tdgpress: TDG Pressure
usage: mass1bc.pl -f field [-0|-O offset] [-o output] [file]
mass1bc.pl -l
=head1 AUTHOR
William A. Perkins
=cut
# -------------------------------------------------------------
# variable initialization
# -------------------------------------------------------------
my $program;
($program = $0) =~ s/.*\///;
my $usage =
"usage: $program -f field [-0|-O offset] [-o output] [-S start] [-E end] [file]\n" .
" $program -l";
# fields that can be used for BC files
my %fields =
(
wselev => 3, flow => 4, vel => 5, depth => 6,
conc => 7, temp => 8, sat => 9, tdgpress => 10
);
my %fieldnames =
(
wselev => "Water Surface Elevation",
flow => "Discharge",
vel => "Velocity",
depth => "Depth",
conc => "TDG Gas Concentration",
temp => "Water Temperature",
sat => "TDG Saturation",
tdgpress => "TDG Pressure"
);
Date::Manip::Date_Init('SetDate=now,UTC');
#Date::Manip::Date_Init("TZ=-08:00");
my $field = undef;
my $offset = undef;
my $title = undef;
my $start = Date::Manip::ParseDate("01/01/1800 00:00:00");
my $end = Date::Manip::ParseDate("01/01/3800 00:00:00");
# -------------------------------------------------------------
# handle command line
# -------------------------------------------------------------
my %opts = ();
die "$usage\n" unless getopts("f:o:O:t:l0S:E:", \%opts);
if ($opts{l}) {
printf(STDERR "The following \"field\"s are recognized:\n");
foreach (keys(%fields)) {
printf(STDERR "\t%s:\t%s\n", $_, $fieldnames{$_});
}
printf(STDERR "$usage\n");
exit(0);
}
unless ($opts{f}) {
printf(STDERR "$program: error: a field must be specified\n");
die "$usage\n";
}
$field = $opts{f};
$title = $opts{t} if $opts{t};
if (! $fields{$field}) {
printf(STDERR "$program: error: the specified field \"%s\" is not known\n", $field);
printf(STDERR "$program: error: use -l to get a list of fields\n");
die "$usage\n";
}
if ($opts{O}) {
$offset = Date::Manip::ParseDateDelta($opts{O});
unless ($offset) {
printf(STDERR "$program: error: time offset \"%s\" not understood\n", $opts{O});
die "$usage\n";
}
} elsif ($opts{0}) {
$offset = Date::Manip::ParseDateDelta("0 hour");
}
if ($opts{S}) {
$start = Date::Manip::ParseDate($opts{S});
unless ($start) {
printf(STDERR "$program: error: start date/time \"%s\" not understood\n", $opts{S});
die "$usage\n";
}
}
if ($opts{E}) {
$end = Date::Manip::ParseDate($opts{E});
unless ($end) {
printf(STDERR "$program: error: end date/time \"%s\" not understood\n", $opts{E});
die "$usage\n";
}
}
if ($opts{o}) {
my $name = $opts{o};
unless (open(OUTPUT, ">$name")) {
printf(STDERR "$program: error: unable to open file \"%s\" for writing\n",
$name);
die "$usage\n";
}
} else {
unless (open(OUTPUT, ">&STDOUT")) {
die "$program: error: Unable to dup STDOUT\n";
}
}
# -------------------------------------------------------------
# main program
# -------------------------------------------------------------
my $fldno = $fields{$field};
my $line = 0;
if ($title) {
printf(OUTPUT "# %s: %s (Automatically generated using $program)\n",
$title, $fieldnames{$field});
} else {
printf(OUTPUT "# %s (Automatically generated using $program)\n",
$fieldnames{$field});
}
while (<>) {
chop;
$line++;
if (/^\d\d-\d\d-\d\d\d\d/) {
my @fld = split();
my $datestr = $fld[0] . " " . $fld[1];
$datestr =~ s/-/\//g;
my $date = Date::Manip::ParseDate($datestr);
die "$program: error: line ${line}: date not understood\n" unless ($date);
my $value = $fld[$fldno - 1];
$date = Date::Manip::DateCalc($date, $offset) if ($offset);
next if ($date < $start);
next if ($date > $end);
printf(OUTPUT "%s %15.3f /\n", Date::Manip::UnixDate($date, '%m-%d-%Y %H:%M:%S'), $value);
}
}