-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_params.c
312 lines (227 loc) · 7.64 KB
/
print_params.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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/**************************************************************************
* print_params.c: prints the param data base to a file
*
* $Id: print_params.c 4627 2008-10-01 16:48:11Z markstro $
*
$Revision: 4627 $
$Log: print_params.c,v $
Revision 1.15 2001/11/27 16:00:10 markstro
Unknown
Revision 1.14 2001/05/04 20:58:22 markstro
Added the xml print file
Revision 1.13 1999/10/22 17:14:36 markstro
Added private variables
Revision 1.12 1999/08/24 16:34:13 markstro
Version 1.1.1
Revision 1.11 1998/12/22 19:49:11 markstro
unknown
Revision 1.10 1998/04/02 17:50:47 markstro
Unknown
Revision 1.9 1996/04/29 16:23:07 markstro
Unknown
* Revision 1.8 1996/02/19 20:00:36 markstro
* Now lints pretty clean
*
Revision 1.7 1995/02/01 17:47:33 markstro
Addition of Rosenbrock optimization. Start of sensitivity. Many bug fixes.
* Revision 1.6 1994/11/22 17:20:05 markstro
* (1) Cleaned up dimensions and parameters.
* (2) Some changes due to use of malloc_dbg.
*
* Revision 1.5 1994/09/30 14:54:50 markstro
* Initial work on function prototypes.
*
* Revision 1.4 1994/05/23 14:27:23 markstro
* Cleaned out a lot of includes in include files
*
* Revision 1.3 1994/05/18 17:15:51 markstro
* TERRA changed mhms to mms
*
* Revision 1.2 1994/01/31 20:17:06 markstro
* Make sure that all source files have CVS log.
*
**************************************************************************/
#define PRINT_PARAMS_C
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "mms.h"
#define PRINTLEN 77
/*--------------------------------------------------------------------*\
| FUNCTION : print_params
| COMMENT :
| PARAMETERS :
| RETURN VALUE :
| RESTRICTIONS :
\*--------------------------------------------------------------------*/
int print_params (void) {
char pathname[MAXPATHLEN], *infostr;
FILE *param_file;
PARAM *param;
DIMEN *dim;
long i, j;
/*
* get param file path name, open file
*/
(void)sprintf (pathname, "%s.par_name", MAltContFile);
if ((param_file = fopen (pathname, "w")) == NULL) {
(void)fprintf(stderr,
"ERROR - print_params - creating file '%s'\n", pathname);
perror("");
return(1);
}
/*
* write header
*/
(void)fprintf(param_file, "Program MMS \n");
(void)fprintf(param_file, "============\n\n");
(void)fprintf(param_file, "Printout of parameters.\n\n");
/*
* write file name
*/
(void)fprintf(param_file, "Parameter file: %s\n", *control_svar("param_file"));
(void)fprintf(param_file, "\n");
/*
* write the run info string
*/
infostr = (char *) umalloc (strlen(Mparaminfo) + 1);
(void)strcpy(infostr, Mparaminfo);
/*
(void)fprintf(param_file, "%s\n\n", insert_crs(infostr, PRINTLEN));
*/
(void)fprintf(param_file, "%s\n\n", infostr);
//ufree(infostr);
/*
* write out dimensions
*/
(void)fprintf(param_file, "--------------- DIMENSIONS ---------------\n");
for (i = 0; i < dim_db->count; i++) {
dim = (DIMEN *)(dim_db->itm[i]);
(void)fprintf(param_file, "\n");
(void)fprintf(param_file, "Name : %s\n", dim->name);
(void)fprintf(param_file, "Value : %ld\n", dim->value);
/* DANGER added for data dictionary print out */
(void)fprintf(param_file, "Desc : %s\n", dim->descr);
if (dim->fixed)
(void)fprintf(param_file, "Fixed\n");
/* end DANGER */
}
/*
* write out parameter values etc
*/
(void)fprintf(param_file, "\n--------------- PARAMETERS ---------------\n");
for (i = 0; i < Mnparams; i++) {
param = Mparambase[i];
(void)fprintf(param_file, "\n");
(void)fprintf(param_file, "Name : %s\n", param->name);
(void)fprintf(param_file, "Module : %s\n", param->module);
(void)fprintf(param_file, "Descr : %s\n", param->descr);
(void)fprintf(param_file, "Help : %s\n", param->help);
(void)fprintf(param_file, "Ndimen : %ld\n", param->ndimen);
(void)fprintf(param_file, "Dimensions: ");
for (j = 0; j < param->ndimen; j++) {
(void)fprintf(param_file, "%s - %ld",
param->dimen[j]->name, param->dimen[j]->value);
if (j < param->ndimen - 1)
(void)fprintf(param_file, ", ");
} /* j */
(void)fprintf(param_file, "\n");
(void)fprintf(param_file, "Size : %ld\n", param->size);
(void)fprintf(param_file, "Type : %s\n", Mtypes[param->type]);
(void)fprintf(param_file, "Units : %s\n", param->units);
if (param->format)
(void)fprintf(param_file, "Format : %s\n", param->format);
(void)fprintf(param_file, "Width : %ld\n", param->column_width);
switch(param->type) {
case M_LONG:
(void)fprintf (param_file, "Max : %ld\n", *(long *)(param->max));
(void)fprintf (param_file, "Min : %ld\n", *(long *)(param->min));
(void)fprintf (param_file, "Default : %ld\n", *(long *)(param->def));
break;
case M_FLOAT:
(void)fprintf (param_file, "Max : %f\n",*(float *)(param->max));
(void)fprintf (param_file, "Min : %f\n",*(float *)(param->min));
(void)fprintf (param_file, "Default : %f\n",*(float *)(param->def));
break;
case M_DOUBLE:
(void)fprintf (param_file, "Max : %lf\n",*(double *)(param->max));
(void)fprintf (param_file, "Min : %lf\n",*(double *)(param->min));
(void)fprintf (param_file, "Default : %lf\n",*(double *)(param->def));
break;
}
if (param->bound_status == M_BOUNDED) {
(void)fprintf(param_file, "Bounded : %s\n", (param->bound_dimen)->name);
}
/* DANGER commented out for data dictionary print out */
/*
(void)fprintf(param_file, "Value(s):\n");
if (param->ndimen >= 3) {
for (j = 0; j < param->dimen[2]->value; j++) {
(void)fprintf(param_file, "[%ld]\n", j + 1);
nk = param->dimen[1]->value;
for (k = 0; k < nk; k++) {
(void)fprintf(param_file, "%5ld:", k + 1);
nl = param->dimen[0]->value;
for (l = 0; l < nl; l++) {
print_param(param_file, param, l, nl, k, nk, j);
}
(void)fprintf(param_file, "\n");
}
}
} else if (param->ndimen == 2) {
nk = param->dimen[1]->value;
for (k = 0; k < nk; k++) {
(void)fprintf(param_file, "%5ld:", k + 1);
nl = param->dimen[0]->value;
for (l = 0; l < nl; l++) {
print_param(param_file, param, l, nl, k,0,0);
}
(void)fprintf(param_file, "\n");
}
} else {
nl = param->dimen[0]->value;
for (l = 0; l < nl; l++) {
print_param(param_file, param, l,0,0,0,0);
}
(void)fprintf(param_file, "\n");
}
*/
/* end DANGER */
} /* i */
fclose(param_file);
return(0);
}
/*--------------------------------------------------------------------*\
| FUNCTION : print_param
| COMMENT :
| PARAMETERS :
| RETURN VALUE :
| RESTRICTIONS :
\*--------------------------------------------------------------------*/
void print_param (FILE *param_file, PARAM *param, long l, long nl, long k,
long nk, long j) {
long ind;
switch (param->ndimen) {
case 1:
ind = l;
break;
case 2:
ind = l + k * nl;
break;
default:
ind = l + k * nl + j * nl * nk;
break;
} /* switch (param->ndimen) */
switch (param->type) {
case M_DOUBLE:
(void)fprintf(param_file, " %10lg", *((double *) param->value + ind));
break;
case M_FLOAT:
(void)fprintf(param_file, " %10g", *((float *) param->value + ind));
break;
case M_LONG:
(void)fprintf(param_file, " %10ld", *((long *) param->value + ind));
break;
} /* switch (param->type) */
}