-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathewOut2D.cpp
175 lines (147 loc) · 5.09 KB
/
ewOut2D.cpp
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
/*
* EasyWave - A realtime tsunami simulation program with GPU support.
* Copyright (C) 2014 Andrey Babeyko, Johannes Spazier
* GFZ German Research Centre for Geosciences (http://www.gfz-potsdam.de)
*
* Parts of this program (especially the GPU extension) were developed
* within the context of the following publicly funded project:
* - TRIDEC, EU 7th Framework Programme, Grant Agreement 258723
* (http://www.tridec-online.eu)
*
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved by
* the European Commission - subsequent versions of the EUPL (the "Licence"),
* complemented with the following provision: For the scientific transparency
* and verification of results obtained and communicated to the public after
* using a modified version of the work, You (as the recipient of the source
* code and author of this modified version, used to produce the published
* results in scientific communications) commit to make this modified source
* code available in a repository that is easily and freely accessible for a
* duration of five years after the communication of the obtained results.
*
* You may not use this work except in compliance with the Licence.
*
* You may obtain a copy of the Licence at:
* https://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <stdio.h>
#include <string.h>
#include "utilits.h"
#include "easywave.h"
#include <cmath>
static char *IndexFile;
static int Nrec2DOutput;
int ewStart2DOutput()
{
FILE *fp;
char buf[64];
// start index file
sprintf( buf, "%s.2D.idx", Par.modelName );
IndexFile = strdup(buf);
fp = fopen( IndexFile, "wt" );
fprintf( fp, "%g %g %d %g %g %d\n", LonMin, LonMax, NLon, LatMin, LatMax, NLat );
fclose( fp );
Nrec2DOutput = 0;
return 0;
}
int ewOut2D()
{
FILE *fp;
short nOutI,nOutJ;
int i,j,m;
float ftmp;
double dtmp,lonOutMin,lonOutMax,latOutMin,latOutMax;
char record[128];
CNode& Node = *gNode;
Nrec2DOutput++;
nOutI = Imax-Imin+1;
lonOutMin = getLon(Imin); lonOutMax = getLon(Imax);
nOutJ = Jmax-Jmin+1;
latOutMin = getLat(Jmin); latOutMax = getLat(Jmax);
// write ssh
sprintf( record, "%s.2D.%5.5d.ssh", Par.modelName, Par.time );
fp = fopen( record, "wb" );
fwrite( "DSBB", 4, 1, fp );
fwrite( &nOutI, sizeof(short), 1, fp );
fwrite( &nOutJ, sizeof(short), 1, fp );
fwrite( &lonOutMin, sizeof(double), 1, fp );
fwrite( &lonOutMax, sizeof(double), 1, fp );
fwrite( &latOutMin, sizeof(double), 1, fp );
fwrite( &latOutMax, sizeof(double), 1, fp );
dtmp = -1.; fwrite( &dtmp, sizeof(double), 1, fp );
dtmp = +1.; fwrite( &dtmp, sizeof(double), 1, fp );
for( j=Jmin; j<=Jmax; j++ ) {
for( i=Imin; i<=Imax; i++ ) {
m = idx(j,i);
if (fabs(Node(m, iH)) < Par.sshTransparencyThreshold)
ftmp = (float)9999;
else
ftmp = (float)Node(m, iH);
fwrite( &ftmp, sizeof(float), 1, fp );
}
}
fclose( fp );
// updating contents file
fp = fopen( IndexFile, "at" );
fprintf( fp, "%3.3d %s %d %d %d %d\n", Nrec2DOutput, utlTimeSplitString(Par.time), Imin, Imax, Jmin, Jmax );
fclose( fp );
return 0;
}
int ewDump2D()
{
FILE *fp;
short nOutI,nOutJ;
int i,j;
float ftmp;
double dtmp,lonOutMin,lonOutMax,latOutMin,latOutMax;
char record[128];
CNode& Node = *gNode;
nOutI = Imax-Imin+1;
lonOutMin = getLon(Imin); lonOutMax = getLon(Imax);
nOutJ = Jmax-Jmin+1;
latOutMin = getLat(Jmin); latOutMax = getLat(Jmax);
// write ssh max
sprintf( record, "%s.2D.sshmax", Par.modelName );
fp = fopen( record, "wb" );
fwrite( "DSBB", 4, 1, fp );
fwrite( &nOutI, sizeof(short), 1, fp );
fwrite( &nOutJ, sizeof(short), 1, fp );
fwrite( &lonOutMin, sizeof(double), 1, fp );
fwrite( &lonOutMax, sizeof(double), 1, fp );
fwrite( &latOutMin, sizeof(double), 1, fp );
fwrite( &latOutMax, sizeof(double), 1, fp );
dtmp = 0.; fwrite( &dtmp, sizeof(double), 1, fp );
dtmp = 1.; fwrite( &dtmp, sizeof(double), 1, fp );
for( j=Jmin; j<=Jmax; j++ ) {
for( i=Imin; i<=Imax; i++ ) {
ftmp = (float)Node(idx(j,i), iHmax);
fwrite( &ftmp, sizeof(float), 1, fp );
}
}
fclose( fp );
// write arrival times
sprintf( record, "%s.2D.time", Par.modelName );
fp = fopen( record, "wb" );
fwrite( "DSBB", 4, 1, fp );
fwrite( &nOutI, sizeof(short), 1, fp );
fwrite( &nOutJ, sizeof(short), 1, fp );
fwrite( &lonOutMin, sizeof(double), 1, fp );
fwrite( &lonOutMax, sizeof(double), 1, fp );
fwrite( &latOutMin, sizeof(double), 1, fp );
fwrite( &latOutMax, sizeof(double), 1, fp );
dtmp = 0.; fwrite( &dtmp, sizeof(double), 1, fp );
dtmp = 1.; fwrite( &dtmp, sizeof(double), 1, fp );
for( j=Jmin; j<=Jmax; j++ ) {
for( i=Imin; i<=Imax; i++ ) {
ftmp = (float)Node(idx(j,i), iTime) / 60;
fwrite( &ftmp, sizeof(float), 1, fp );
}
}
fclose( fp );
return 0;
}