OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
VaryCmd.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: VaryCmd.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: VaryCmd
10 // The class for the OPAL VARY command.
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:44 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Match/VaryCmd.h"
20 #include "Attributes/Attributes.h"
21 #include "Match/ConcreteVar.h"
22 #include "Match/Match.h"
23 #include "Match/MatchLimits.h"
24 #include "Utilities/Options.h"
25 #include <iostream>
26 
27 
28 // Class VaryCmd
29 // ------------------------------------------------------------------------
30 
31 // The attributes of class VaryCmd.
32 namespace {
33  enum {
34  NAME, // the variable reference
35  STEP, // the step size
36  LOWER, // the lower limit, if any
37  UPPER, // the upper limit, if any
38  SIZE
39  };
40 }
41 
42 
44  Action(SIZE, "VARY",
45  "The \"VARY\" sub-command defines a variable to be adjusted.") {
47  ("NAME", "the variable reference");
49  ("STEP", "the step size", 0.2);
51  ("LOWER", "the lower limit, if any");
53  ("UPPER", "the upper limit, if any");
54 
56 }
57 
58 
59 VaryCmd::VaryCmd(const std::string &name, VaryCmd *parent):
60  Action(name, parent)
61 {}
62 
63 
65 {}
66 
67 
68 VaryCmd *VaryCmd::clone(const std::string &name) {
69  return new VaryCmd(name, this);
70 }
71 
72 
74  // Fetch the command attributes.
75  double pars[4];
76  pars[0] = Attributes::getReal(itsAttr[NAME]);
77  pars[1] = Attributes::getReal(itsAttr[STEP]);
78  pars[2] = pars[3] = 0.0;
79 
80  // Set up the limits flag.
81  int limits = NO_LIMIT;
82  if(itsAttr[LOWER]) {
83  pars[2] = Attributes::getReal(itsAttr[LOWER]);
84  if(itsAttr[UPPER]) {
85  pars[3] = Attributes::getReal(itsAttr[UPPER]);
86  limits = BOTH_LIMITS;
87  } else {
88  limits = LOWER_LIMIT;
89  }
90  } else {
91  if(itsAttr[UPPER]) {
92  pars[3] = Attributes::getReal(itsAttr[UPPER]);
93  limits = UPPER_LIMIT;
94  } else {
95  limits = NO_LIMIT;
96  }
97  }
98 
99  // Make the match variable name.
100  std::string name(itsAttr[NAME].getImage());
101 
102  // Test for previously existing match variable;
103  // if found, remove it.
104  if(Match::block->findVariable(name)) {
105  if(Options::warn) {
106  std::cerr << "\n### Warning ### "
107  << "Parameter is already variable -- new attributes used.\n"
108  << std::endl;
109  }
110 
112  }
113 
114  // Add new variable to the table.
115  Match::block->addVariable(new ConcreteVar(name, itsAttr[NAME], limits, pars));
116 }
The base class for all OPAL actions.
Definition: Action.h:30
static Match * block
The block of match data.
Definition: Match.h:100
std::vector< Attribute > itsAttr
The object attributes (see Attribute.hh).
Definition: Object.h:214
bool warn
Warn flag.
Definition: Options.cpp:10
virtual void execute()
Execute the command.
Definition: VaryCmd.cpp:73
void addVariable(AbstractVar *)
Add a matching variable.
Definition: Match.cpp:55
void deleteVariable(const std::string &name)
Delete a matching variable.
Definition: Match.cpp:60
Concrete class for a matching variable.
Definition: ConcreteVar.h:33
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const
Definition: Object.cpp:194
virtual ~VaryCmd()
Definition: VaryCmd.cpp:64
const std::string name
virtual VaryCmd * clone(const std::string &name)
Make clone.
Definition: VaryCmd.cpp:68
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
VaryCmd()
Exemplar constructor.
Definition: VaryCmd.cpp:43
Attribute makeReference(const std::string &name, const std::string &help)
Create a reference attribute.
Definition: Attributes.cpp:288
The VARY command.
Definition: VaryCmd.h:28
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Definition: Attributes.cpp:205
Inform & endl(Inform &inf)
Definition: Inform.cpp:42