cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vary_input.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2017 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*vary_input sets input lines to feed into cloudy in optimization runs */
4 #include "cddefines.h"
5 #include "input.h"
6 #include "save.h"
7 #include "grid.h"
8 
9 void vary_input(bool *lgLimOK,
10  int grid_index)
11 {
12  long int i,
13  np;
14 
15  DEBUG_ENTRY( "vary_input()" );
16 
17  // this would indicate int overflow, but is mainly there to keep the compiler from
18  // whining about an unused variable...
19  if( grid_index < -1 )
20  TotalInsanity();
21 
22  /* set up chCardSav(n) array like Gary's input file, using input
23  * variable parameters p(i), and format information held in
24  * the common block /parmv/. Results written to common /kardsv/.
25  */
26 
27  /* will be set false if limit to a variable exceeded
28  * this is returned to calling code as problem indication*/
29  *lgLimOK = true;
30 
31  if( cpu.i().lgMaster() || !grid.lgGrid )
32  fprintf( ioQQQ, " **************************************************\n" );
33 
34  /* echo the variable input lines for this run */
35  for( i=0; i < optimize.nvary; i++ )
36  {
37  bool lgLimitHit = false;
38 
39  np = optimize.nvfpnt[i];
40 
41  // check if the keyword _LOG is present; the optimizer may not work
42  // correctly if it is not optimizing logarithmic quantities.
43  //
44  // exceptions are the commands ILLUMINATE and RATIO since they vary
45  // quantities of order unity anyway, and the commands DLAW and FUDGE
46  // since they are entirely defined by the user.
47  //
48  // it is ok not to convert to upper case first since the command line
49  // image is completely under our own control.
51  {
52  if( !nMatch( " LOG", optimize.chVarFmt[i] ) )
53  {
54  fprintf( ioQQQ, " vary_input: internal error - keyword _LOG not found!\n" );
55  TotalInsanity();
56  }
57  }
58 
59  /* write formatted to the character string chCardSav(np),
60  * using the format held in chVarFmt(np) */
61 
62  /* >>chng 05 aug 09, by RP, both were == change to > and < */
63  if( grid.paramIncrements[i] >= 0. &&
64  ( optimize.vparm[0][i] < optimize.varang[i][0] ||
65  optimize.vparm[0][i] > optimize.varang[i][1] ) )
66  {
67  *lgLimOK = false;
68  lgLimitHit = true;
69  }
70  if( grid.paramIncrements[i] < 0. &&
71  ( optimize.vparm[0][i] > optimize.varang[i][0] ||
72  optimize.vparm[0][i] < optimize.varang[i][1] ) )
73  {
74  *lgLimOK = false;
75  lgLimitHit = true;
76  }
77 
78  /* now generate the actual command with parameter,
79  * there will be from 1 to 3 numbers on the line */
80  if( optimize.nvarxt[i] == 1 )
81  {
82  /* case with 1 parameter */
83  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i] );
84  }
85 
86  else if( optimize.nvarxt[i] == 2 )
87  {
88  /* case with 2 parameters */
89  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i],
90  optimize.vparm[1][i] );
91  }
92 
93  else if( optimize.nvarxt[i] == 3 )
94  {
95  /* case with 3 parameters */
96  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i],
97  optimize.vparm[1][i], optimize.vparm[2][i] );
98  }
99 
100  else if( optimize.nvarxt[i] == 4 )
101  {
102  /* case with 4 parameters */
103  sprintf( input.chCardSav[np], optimize.chVarFmt[i], optimize.vparm[0][i],
104  optimize.vparm[1][i], optimize.vparm[2][i], optimize.vparm[3][i] );
105  }
106 
107  else if( optimize.nvarxt[i] == 5 )
108  {
109  /* case with 5 parameters */
110  sprintf( input.chCardSav[np], optimize.chVarFmt[i],
111  optimize.vparm[0][i], optimize.vparm[1][i], optimize.vparm[2][i],
112  optimize.vparm[3][i], optimize.vparm[4][i]);
113  }
114 
115  else
116  {
117  fprintf(ioQQQ,"The number of variable options on this line makes no sense to me5\n");
119  }
120 
121  if( cpu.i().lgMaster() || !grid.lgGrid )
122  {
123  fprintf( ioQQQ, " %s\n", input.chCardSav[np] );
124  if( lgLimitHit )
125  fprintf( ioQQQ, " >>> Limit to variable exceeded.\n" );
126  }
127  }
128 
129  if( cpu.i().lgMaster() && grid.lgGrid )
130  {
131  // write the line images to an input script, one file for each grid point
132  fstream io;
133  string fnam = GridPointPrefix(grid_index) + save.chRedirectPrefix + ".in";
134  open_data( io, fnam.c_str(), mode_w );
135  // input.nSave has unusual definition, it is one less than the number of lines stored
136  for( int i=0; i <= input.nSave; ++i )
137  io << input.chCardSav[i] << endl;
138  }
139 
140  return;
141 }
long int nSave
Definition: input.h:62
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
Definition: cpu.cpp:751
NORETURN void TotalInsanity(void)
Definition: service.cpp:1067
t_input input
Definition: input.cpp:12
bool lgGrid
Definition: grid.h:42
long int nvfpnt[LIMPAR]
Definition: optimize.h:198
t_cpu_i & i()
Definition: cpu.h:415
long nMatch(const char *chKey, const char *chCard)
Definition: service.cpp:537
realnum varang[LIMPAR][2]
Definition: optimize.h:201
void vary_input(bool *lgLimOK, int grid_index)
Definition: vary_input.cpp:9
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:267
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:192
#define EXIT_FAILURE
Definition: cddefines.h:168
bool lgMaster() const
Definition: cpu.h:393
#define cdEXIT(FAIL)
Definition: cddefines.h:484
t_optimize optimize
Definition: optimize.cpp:6
t_grid grid
Definition: grid.cpp:5
const ios_base::openmode mode_w
Definition: cpu.h:268
bool lgOptimizeAsLinear[LIMPAR]
Definition: optimize.h:184
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:729
realnum paramIncrements[LIMPAR]
Definition: grid.h:35
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1217
string GridPointPrefix(int n)
char chCardSav[NKRD][INPUT_LINE_LENGTH]
Definition: input.h:48
static t_cpu cpu
Definition: cpu.h:423
t_save save
Definition: save.cpp:5
string chRedirectPrefix
Definition: save.h:417
long int nvarxt[LIMPAR]
Definition: optimize.h:198
long int nvary
Definition: optimize.h:204