cloudy
trunk
Main Page
Related Pages
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
source
parse_grid.cpp
Go to the documentation of this file.
1
/* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and
2
* others. For conditions of distribution and use see copyright notice in license.txt */
3
/*ParseGrid parse the grid command lines */
4
#include "
cddefines.h
"
5
#include "
optimize.h
"
6
#include "
grid.h
"
7
8
/* ParseGrid - called from ParseCommands if GRID command found */
9
void
ParseGrid
(
10
/* command line, which was changed to all caps in main parsing routine */
11
char
*chCard)
12
{
13
bool
lgEOL;
14
long
int
i;
15
16
DEBUG_ENTRY
(
"ParseGrid()"
);
17
18
/* RP fake optimizer to run a grid of calculations, also accepts
19
* keyword XSPEC */
20
strcpy(
optimize
.
chOptRtn
,
"XSPE"
);
21
grid
.
lgGrid
=
true
;
22
23
if
(
nMatch
(
"REPE"
,chCard) )
24
{
25
/* just keep repeating, don't actually change the values in the grid.
26
* useful for debugging unintentional crosstalk */
27
grid
.
lgStrictRepeat
=
true
;
28
}
29
30
/* 06 aug 22, change to accept three parameters: lower and upper limit and number of points. */
31
/* scan off range for the previously selected variable */
32
if
(
optimize
.
nparm
> 0 )
33
{
34
realnum
highvalue;
35
long
numPoints=0;
36
37
ASSERT
(
optimize
.
nparm
<
LIMPAR
);
38
39
i = 5;
40
optimize
.
varang
[
optimize
.
nparm
-1][0] = (
realnum
)
FFmtRead
(chCard,&i,
INPUT_LINE_LENGTH
,&lgEOL);
41
optimize
.
varang
[
optimize
.
nparm
-1][1] = (
realnum
)
FFmtRead
(chCard,&i,
INPUT_LINE_LENGTH
,&lgEOL);
42
grid
.
paramIncrements
[
optimize
.
nparm
-1] = (
realnum
)
FFmtRead
(chCard,&i,
INPUT_LINE_LENGTH
,&lgEOL);
43
44
if
(
grid
.
paramIncrements
[
optimize
.
nparm
-1] <= 0. )
45
{
46
fprintf(
ioQQQ
,
" The increment (third parameter) must be a positive number.\n"
);
47
fprintf(
ioQQQ
,
" Sorry.\n"
);
48
cdEXIT
( EXIT_FAILURE );
49
}
50
51
if
(
grid
.
paramIncrements
[
optimize
.
nparm
-1] > (
optimize
.
varang
[
optimize
.
nparm
-1][1] -
optimize
.
varang
[
optimize
.
nparm
-1][0] ) )
52
{
53
fprintf(
ioQQQ
,
" The increment (third parameter) must not be greater than the difference between the limits (first and second parameters.\n"
);
54
fprintf(
ioQQQ
,
" Sorry.\n"
);
55
cdEXIT
( EXIT_FAILURE );
56
}
57
58
if
( lgEOL )
59
{
60
fprintf(
ioQQQ
,
" This command has changed since the definition given in Porter et al. 2006, PASP, 118, 920.\n"
);
61
fprintf(
ioQQQ
,
" The grid command now requires three parameters: lower limit, upper limit, and increment.\n"
);
62
fprintf(
ioQQQ
,
" The keywords RANGE and STEPS are no longer necessary.\n"
);
63
fprintf(
ioQQQ
,
" Sorry.\n"
);
64
cdEXIT
( EXIT_FAILURE );
65
}
66
else
67
{
68
++
optimize
.
nRangeSet
;
69
}
70
71
/* Swap if second range parameter is less than the first. */
72
if
(
optimize
.
varang
[
optimize
.
nparm
-1][1] <
optimize
.
varang
[
optimize
.
nparm
-1][0] )
73
{
74
realnum
temp =
optimize
.
varang
[
optimize
.
nparm
-1][0];
75
optimize
.
varang
[
optimize
.
nparm
-1][0] =
optimize
.
varang
[
optimize
.
nparm
-1][1];
76
optimize
.
varang
[
optimize
.
nparm
-1][1] = temp;
77
}
78
79
ASSERT
(
optimize
.
varang
[
optimize
.
nparm
-1][1] -
optimize
.
varang
[
optimize
.
nparm
-1][0] > 0. );
80
81
{
82
realnum
integer, tempNumPoints = (
optimize
.
varang
[
optimize
.
nparm
-1][1] -
83
optimize
.
varang
[
optimize
.
nparm
-1][0])/
grid
.
paramIncrements
[
optimize
.
nparm
-1];
84
realnum
fraction = modf( tempNumPoints, &integer );
85
86
if
( fraction > 0.99f || fraction < 0.01f )
87
{
88
optimize
.
varang
[
optimize
.
nparm
-1][1] += 0.01f *
grid
.
paramIncrements
[
optimize
.
nparm
-1];
89
fprintf(
ioQQQ
,
"\n NOTE The range is very nearly (or exactly) an integer multiple of the increment.\n"
);
90
fprintf(
ioQQQ
,
" NOTE The upper limit has been increased by a small fraction of the increment to ensure that\n"
);
91
fprintf(
ioQQQ
,
" NOTE the specified upper limit is included in the grid.\n\n"
);
92
}
93
}
94
95
numPoints = 0;
96
highvalue =
optimize
.
varang
[
optimize
.
nparm
-1][0];
97
/* find the number of parameter values by incrementing from the lower limit up to the upper limit. */
98
while
( highvalue <=
optimize
.
varang
[
optimize
.
nparm
-1][1] )
99
{
100
++numPoints;
101
highvalue +=
grid
.
paramIncrements
[
optimize
.
nparm
-1];
102
}
103
104
grid
.
numParamValues
[
optimize
.
nparm
-1] = numPoints;
105
106
if
(
grid
.
numParamValues
[
optimize
.
nparm
-1] < 2 )
107
{
108
fprintf(
ioQQQ
,
" NOTE must have at least two grid points\n"
);
109
}
110
else
if
(
grid
.
numParamValues
[
optimize
.
nparm
-1] > 20 )
111
{
112
fprintf(
ioQQQ
,
" NOTE There are %li grid points. Are you "
113
"sure you want that many?\n"
,
114
grid
.
numParamValues
[
optimize
.
nparm
-1]);
115
}
116
117
grid
.
numParamValues
[
optimize
.
nparm
-1] =
MAX2
( 2,
grid
.
numParamValues
[
optimize
.
nparm
-1] );
118
}
119
120
return
;
121
}
Generated for cloudy by
1.8.1.1