-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgauges.h
More file actions
52 lines (48 loc) · 1.18 KB
/
gauges.h
File metadata and controls
52 lines (48 loc) · 1.18 KB
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
/**
# Tide gauges
An array of *Gauge* structures passed to *output_gauges()* will create
a file (called *name*) for each gauge. Each time *output_gauges()* is
called a line will be appended to the file. The line contains the time
and the value of each scalar in *list* in the cell containing
*(x,y)*. The *desc* field can be filled with a longer description of
the gauge. */
typedef struct {
char * name;
double x, y;
char * desc;
FILE * fp;
} Gauge;
void output_gauges (Gauge * gauges, scalar * list)
{
int n = 0;
for (Gauge * g = gauges; g->name; g++, n++);
coord a[n];
n = 0;
for (Gauge * g = gauges; g->name; g++, n++) {
double xp = g->x, yp = g->y;
unmap (&xp, &yp);
a[n].x = xp, a[n].y = yp;
}
int len = list_len(list);
double v[n*len];
interpolate_array (list, a, n, v, false);
if (pid() == 0) {
n = 0;
for (Gauge * g = gauges; g->name; g++) {
if (!g->fp) {
g->fp = fopen (g->name, "w");
if (g->desc)
fprintf (g->fp, "%s\n", g->desc);
}
if (v[n] != nodata) {
fprintf (g->fp, "%g", t);
for (scalar s in list)
fprintf (g->fp, " %g", v[n++]);
fputc ('\n', g->fp);
fflush (g->fp);
}
else
n += len;
}
}
}