forked from pihmadmin/PIHM_v2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
160 lines (156 loc) · 5.96 KB
/
print.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
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
/*******************************************************************************
* File : print.c *
* Version : Nov, 2007 (2.0) *
* Function : print out model results output files *
* Developer of PIHM2.0: Mukesh Kumar ([email protected]) *
* Developer of PIHM1.0: Yizhong Qu ([email protected]) *
*-----------------------------------------------------------------------------*
* *
* *
*..............MODIFICATIONS/ADDITIONS in PIHM 2.0............................*
* a) This file is downgraded from Version 1.0, as no ancillary results are *
* being output *
* b) Only state variables and flux to/in/accross river and its bed are being *
* output *
* c) Addition of Average Function to output average variables at regular time *
* intervals *
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "nvector_serial.h"
#include "sundialstypes.h"
#include "pihm.h"
#include "cvode.h"
#include "cvdense.h"
/*Temporal average of State vectors */
void avgResults_NV(FILE *fpin,realtype *tmpVarCal,N_Vector tmpNV,int tmpIntv, int tmpNumObj,realtype tmpt,int tmpInitObj)
{
int j;
for(j=0;j<tmpNumObj;j++)
{
tmpVarCal[j]=tmpVarCal[j]+NV_Ith_S(tmpNV,j+tmpInitObj);
}
if(((int)tmpt%tmpIntv)==0)
{
fprintf(fpin,"%lf\t",tmpt);
for(j=0;j<tmpNumObj;j++)
{
fprintf(fpin,"%lf\t",tmpVarCal[j]/tmpIntv);
tmpVarCal[j]=0;
}
fprintf(fpin,"\n");
fflush(fpin);
}
}
/* Temporal average of Derived states */
void avgResults_MD(FILE *fpin,realtype *tmpVarCal,Model_Data tmpDS,int tmpIntv, int tmpNumObj,realtype tmpt,int tmpFC)
{
int j;
switch(tmpFC)
{
case 3:
case 4:
case 5:
for(j=0;j<tmpNumObj;j++)
{
tmpVarCal[j]=tmpVarCal[j]+tmpDS->EleET[j][tmpFC-3];
}
break;
case 6:
for(j=0;j<tmpNumObj;j++)
{
tmpVarCal[j]=tmpVarCal[j]+tmpDS->EleIS[j];
}
break;
case 7:
for(j=0;j<tmpNumObj;j++)
{
tmpVarCal[j]=tmpVarCal[j]+(tmpDS->EleSnowCanopy[j]+tmpDS->EleSnowGrnd[j]);
}
break;
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
for(j=0;j<tmpNumObj;j++)
{
tmpVarCal[j]=tmpVarCal[j]+tmpDS->FluxRiv[j][tmpFC-8];
}
break;
case 19:
for(j=0;j<tmpNumObj;j++)
{
tmpVarCal[j]=tmpVarCal[j]+tmpDS->Recharge[j];
}
break;
default:
break;
}
if(((int)tmpt%tmpIntv)==0)
{
fprintf(fpin,"%lf\t",tmpt);
for(j=0;j<tmpNumObj;j++)
{
fprintf(fpin,"%lf\t",tmpVarCal[j]/tmpIntv);
tmpVarCal[j]=0;
}
fprintf(fpin,"\n");
fflush(fpin);
}
}
/* print individual states */
void PrintData(FILE **outp,Control_Data *cD, Model_Data DS, N_Vector CV_Y, realtype t)
{
int k;
if(cD->gwD==1)
{
avgResults_NV(outp[0],DS->PrintVar[0],CV_Y,cD->gwDInt,DS->NumEle+DS->NumRiv,t,2*DS->NumEle);
}
if(cD->surfD==1)
{
avgResults_NV(outp[1],DS->PrintVar[1],CV_Y,cD->surfDInt,DS->NumEle,t,0*DS->NumEle);
}
for(k=0;k<3;k++)
{
if(cD->et[k]==1)
{
avgResults_MD(outp[2+k],DS->PrintVar[2+k],DS,cD->etInt,DS->NumEle,t,3+k);
}
}
if(cD->IsD==1)
{
avgResults_MD(outp[5],DS->PrintVar[5],DS,cD->IsDInt,DS->NumEle,t,6);
}
if(cD->snowD==1)
{
avgResults_MD(outp[6],DS->PrintVar[6],DS,cD->snowDInt,DS->NumEle,t,7);
}
for(k=0;k<=10;k++)
{
if(cD->rivFlx[k]==1)
{
avgResults_MD(outp[7+k],DS->PrintVar[k+7],DS,cD->rivFlxInt,DS->NumRiv,t,k+8);
}
}
if(cD->rivStg==1)
{
avgResults_NV(outp[18],DS->PrintVar[18],CV_Y,cD->rivStgInt,DS->NumRiv,t,3*DS->NumEle);
}
if(cD->Rech==1)
{
avgResults_MD(outp[20],DS->PrintVar[20],DS,cD->RechInt,DS->NumEle,t,19);
}
if(cD->usD==1)
{
avgResults_NV(outp[19],DS->PrintVar[19],CV_Y,cD->usDInt,DS->NumEle,t,1*DS->NumEle);
}
}