~ubuntu-branches/ubuntu/precise/flightgear/precise

« back to all changes in this revision

Viewing changes to src/FDM/JSBSim/math/FGFunction.cpp

  • Committer: Package Import Robot
  • Author(s): Ove Kaaven
  • Date: 2011-09-03 22:16:12 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20110903221612-2cjy0z7ztj5nkln5
Tags: 2.4.0-1
* New upstream release. Closes: #638588.
* Build-Depend on OpenSceneGraph 3.0, and the Subversion library.
* Recommend fgfs-scenery-base.
* Enable parallel builds (shorter compile times on multicore CPUs).
* Removed hack that tried to build without optimizations if
  building with optimizations fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
namespace JSBSim {
45
45
 
46
 
static const char *IdSrc = "$Id$";
 
46
static const char *IdSrc = "$Id: FGFunction.cpp,v 1.36 2011/04/05 20:20:21 andgi Exp $";
47
47
static const char *IdHdr = ID_FUNCTION;
48
48
 
49
49
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167
167
    // data types
168
168
    if (operation == property_string || operation == p_string) {
169
169
      property_name = element->GetDataLine();
170
 
      FGPropertyManager* newNode = PropertyManager->GetNode(property_name);
171
 
      if (newNode == 0) {
172
 
        cerr << "The property " << property_name << " is undefined." << endl;
173
 
        abort();
174
 
      } else {
 
170
      if (property_name.find("#") != string::npos) {
 
171
        if (is_number(Prefix)) {
 
172
          property_name = replace(property_name,"#",Prefix);
 
173
        }
 
174
      }
 
175
      FGPropertyManager* newNode = 0L;
 
176
      if (PropertyManager->HasNode(property_name)) {
 
177
        newNode = PropertyManager->GetNode(property_name);
175
178
        Parameters.push_back(new FGPropertyValue( newNode ));
 
179
      } else {
 
180
        cerr << fgcyan << "Warning: The property " + property_name + " is initially undefined."
 
181
             << reset << endl;
 
182
        Parameters.push_back(new FGPropertyValue( property_name,
 
183
                                                  PropertyManager ));
176
184
      }
177
185
    } else if (operation == value_string || operation == v_string) {
178
186
      Parameters.push_back(new FGRealValue(element->GetDataAsNumber()));
204
212
               operation == random_string ||
205
213
               operation == avg_string )
206
214
    {
207
 
      Parameters.push_back(new FGFunction(PropertyManager, element));
 
215
      Parameters.push_back(new FGFunction(PropertyManager, element, Prefix));
208
216
    } else if (operation != description_string) {
209
217
      cerr << "Bad operation " << operation << " detected in configuration file" << endl;
210
218
    }
241
249
{
242
250
  unsigned int i;
243
251
  double scratch;
 
252
  double temp=0;
244
253
 
245
254
  if (cached) return cachedValue;
246
255
 
247
 
  double temp = Parameters[0]->GetValue();
248
 
 
 
256
  temp = Parameters[0]->GetValue();
 
257
  
249
258
  switch (Type) {
250
259
  case eTopLevel:
251
260
    break;
265
274
    }
266
275
    break;
267
276
  case eQuotient:
268
 
    temp /= Parameters[1]->GetValue();
 
277
    if (Parameters[1]->GetValue() != 0.0)
 
278
      temp /= Parameters[1]->GetValue();
 
279
    else
 
280
      temp = HUGE_VAL;
269
281
    break;
270
282
  case ePow:
271
283
    temp = pow(temp,Parameters[1]->GetValue());
363
375
  if ( !Name.empty() ) {
364
376
    string tmp;
365
377
    if (Prefix.empty())
366
 
      tmp  = PropertyManager->mkPropertyName(Name, false); // Allow upper case
367
 
    else
368
 
      tmp  = PropertyManager->mkPropertyName(Prefix + "/" + Name, false); // Allow upper case
 
378
      tmp  = PropertyManager->mkPropertyName(Name, false);
 
379
    else {
 
380
      if (is_number(Prefix)) {
 
381
        if (Name.find("#") != string::npos) { // if "#" is found
 
382
          Name = replace(Name,"#",Prefix);
 
383
          tmp  = PropertyManager->mkPropertyName(Name, false);
 
384
        } else {
 
385
          cerr << "Malformed function name with number: " << Prefix
 
386
            << " and property name: " << Name
 
387
            << " but no \"#\" sign for substitution." << endl;
 
388
        }
 
389
      } else {
 
390
        tmp  = PropertyManager->mkPropertyName(Prefix + "/" + Name, false);
 
391
      }
 
392
    }
369
393
 
370
394
    PropertyManager->Tie( tmp, this, &FGFunction::GetValue);
371
395
  }