]> git.mxchange.org Git - flightgear.git/blob - src/FDM/YASim/FGFDM.cpp
Fuel consumption. Simple implementation without support for tank selection
[flightgear.git] / src / FDM / YASim / FGFDM.cpp
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <Main/fg_props.hxx>
5
6 #include "Jet.hpp"
7 #include "SimpleJet.hpp"
8 #include "Gear.hpp"
9 #include "Atmosphere.hpp"
10 #include "PropEngine.hpp"
11 #include "Propeller.hpp"
12 #include "PistonEngine.hpp"
13
14 #include "FGFDM.hpp"
15 namespace yasim {
16
17 // Some conversion factors
18 static const float KTS2MPS = 0.514444444444;
19 static const float FT2M = 0.3048;
20 static const float DEG2RAD = 0.0174532925199;
21 static const float RPM2RAD = 0.10471975512;
22 static const float LBS2N = 4.44822;
23 static const float LBS2KG = 0.45359237;
24 static const float KG2LBS = 2.2046225;
25 static const float CM2GALS = 264.172037284;
26 static const float HP2W = 745.700;
27 static const float INHG2PA = 3386.389;
28 static const float K2DEGF = 1.8;
29 static const float CIN2CM = 1.6387064e-5;
30
31 // Stubs, so that this can be compiled without the FlightGear
32 // binary.  What's the best way to handle this?
33
34 //     float fgGetFloat(char* name, float def) { return 0; }
35 //     void fgSetFloat(char* name, float val) {}
36
37 FGFDM::FGFDM()
38 {
39     _nextEngine = 0;
40
41     // Map /controls/elevator to the approach elevator control.  This
42     // should probably be settable, but there are very few aircraft
43     // who trim their approaches using things other than elevator.
44     _airplane.setElevatorControl(parseAxis("/controls/elevator-trim"));
45 }
46
47 FGFDM::~FGFDM()
48 {
49     int i;
50     for(i=0; i<_axes.size(); i++) {
51         AxisRec* a = (AxisRec*)_axes.get(i);
52         delete[] a->name;
53         delete a;
54     }
55     for(i=0; i<_thrusters.size(); i++) {
56         EngRec* er = (EngRec*)_thrusters.get(i);
57         delete[] er->prefix;
58         delete er->eng;
59         delete er;
60     }
61     for(i=0; i<_weights.size(); i++) {
62         WeightRec* wr = (WeightRec*)_weights.get(i);
63         delete[] wr->prop;
64         delete wr;
65     }
66     for(i=0; i<_controlProps.size(); i++)
67         delete (PropOut*)_controlProps.get(i);
68 }
69
70 void FGFDM::iterate(float dt)
71 {
72     getExternalInput(dt);
73     _airplane.iterate(dt);
74     setOutputProperties();
75 }
76
77 Airplane* FGFDM::getAirplane()
78 {
79     return &_airplane;
80 }
81
82 void FGFDM::init()
83 {
84     // Allows the user to start with something other than full fuel
85     _airplane.setFuelFraction(fgGetFloat("/sim/fuel-fraction", 1));
86
87     // This has a nasty habit of being false at startup.  That's not
88     // good.
89     fgSetBool("/controls/gear-down", true);
90 }
91
92 // Not the worlds safest parser.  But it's short & sweet.
93 void FGFDM::startElement(const char* name, const XMLAttributes &atts)
94 {
95     XMLAttributes* a = (XMLAttributes*)&atts;
96     float v[3];
97     char buf[64];
98
99     if(eq(name, "airplane")) {
100         _airplane.setWeight(attrf(a, "mass") * LBS2KG);
101     } else if(eq(name, "approach")) {
102         float spd = attrf(a, "speed") * KTS2MPS;
103         float alt = attrf(a, "alt", 0) * FT2M;
104         float aoa = attrf(a, "aoa", 0) * DEG2RAD;
105         _airplane.setApproach(spd, alt, aoa);
106         _cruiseCurr = false;
107     } else if(eq(name, "cruise")) {
108         float spd = attrf(a, "speed") * KTS2MPS;
109         float alt = attrf(a, "alt") * FT2M;
110         _airplane.setCruise(spd, alt);
111         _cruiseCurr = true;
112     } else if(eq(name, "cockpit")) {
113         v[0] = attrf(a, "x");
114         v[1] = attrf(a, "y");
115         v[2] = attrf(a, "z");
116         _airplane.setPilotPos(v);
117     } else if(eq(name, "wing")) {
118         _airplane.setWing(parseWing(a, name));
119     } else if(eq(name, "hstab")) {
120         _airplane.setTail(parseWing(a, name));
121     } else if(eq(name, "vstab")) {
122         _airplane.addVStab(parseWing(a, name));
123     } else if(eq(name, "propeller")) {
124         parsePropeller(a);
125     } else if(eq(name, "thruster")) {
126         SimpleJet* j = new SimpleJet();
127         _currObj = j;
128         v[0] = attrf(a, "x"); v[1] = attrf(a, "y"); v[2] = attrf(a, "z");
129         j->setPosition(v);
130         _airplane.addThruster(j, 0, v);
131         v[0] = attrf(a, "vx"); v[1] = attrf(a, "vy"); v[2] = attrf(a, "vz");
132         j->setDirection(v);
133         j->setThrust(attrf(a, "thrust") * LBS2N);
134     } else if(eq(name, "jet")) {
135         Jet* j = new Jet();
136         _currObj = j;
137         v[0] = attrf(a, "x");
138         v[1] = attrf(a, "y");
139         v[2] = attrf(a, "z");
140         float mass = attrf(a, "mass") * LBS2KG;
141         j->setMaxThrust(attrf(a, "thrust") * LBS2N,
142                         attrf(a, "afterburner", 0) * LBS2N);
143         j->setVectorAngle(attrf(a, "rotate", 0) * DEG2RAD);
144
145         float n1min = attrf(a, "n1-idle", 55);
146         float n1max = attrf(a, "n1-max", 102);
147         float n2min = attrf(a, "n2-idle", 73);
148         float n2max = attrf(a, "n2-max", 103);
149         j->setRPMs(n1min, n1max, n2min, n2max);
150
151         j->setTSFC(attrf(a, "tsfc", 0.8));
152         if(a->hasAttribute("egt"))  j->setEGT(attrf(a, "egt"));
153         if(a->hasAttribute("epr"))  j->setEPR(attrf(a, "epr"));
154         if(a->hasAttribute("exhaust-speed"))
155             j->setVMax(attrf(a, "exhaust-speed") * KTS2MPS);
156         
157         j->setPosition(v);
158         _airplane.addThruster(j, mass, v);
159         sprintf(buf, "/engines/engine[%d]", _nextEngine++);
160         EngRec* er = new EngRec();
161         er->eng = j;
162         er->prefix = dup(buf);
163         _thrusters.add(er);
164     } else if(eq(name, "gear")) {
165         Gear* g = new Gear();
166         _currObj = g;
167         v[0] = attrf(a, "x");
168         v[1] = attrf(a, "y");
169         v[2] = attrf(a, "z");
170         g->setPosition(v);
171         v[0] = 0;
172         v[1] = 0;
173         v[2] = attrf(a, "compression", 1);
174         g->setCompression(v);
175         g->setBrake(attrf(a, "skid", 0));
176         g->setStaticFriction(attrf(a, "sfric", 0.8));
177         g->setDynamicFriction(attrf(a, "dfric", 0.7));
178         g->setSpring(attrf(a, "spring", 1));
179         g->setDamping(attrf(a, "damp", 1));
180         _airplane.addGear(g);
181     } else if(eq(name, "fuselage")) {
182         float b[3];
183         v[0] = attrf(a, "ax");
184         v[1] = attrf(a, "ay");
185         v[2] = attrf(a, "az");
186         b[0] = attrf(a, "bx");
187         b[1] = attrf(a, "by");
188         b[2] = attrf(a, "bz");
189         float taper = attrf(a, "taper", 1);
190         float mid = attrf(a, "midpoint", 0.5);
191         _airplane.addFuselage(v, b, attrf(a, "width"), taper, mid);
192     } else if(eq(name, "tank")) {
193         v[0] = attrf(a, "x");
194         v[1] = attrf(a, "y");
195         v[2] = attrf(a, "z");
196         float density = 6.0; // gasoline, in lbs/gal
197         if(a->hasAttribute("jet")) density = 6.72; 
198         density *= LBS2KG*CM2GALS;
199         _airplane.addTank(v, attrf(a, "capacity") * LBS2KG, density);
200     } else if(eq(name, "ballast")) {
201         v[0] = attrf(a, "x");
202         v[1] = attrf(a, "y");
203         v[2] = attrf(a, "z");
204         _airplane.addBallast(v, attrf(a, "mass") * LBS2KG);
205     } else if(eq(name, "weight")) {
206         parseWeight(a);
207     } else if(eq(name, "stall")) {
208         Wing* w = (Wing*)_currObj;
209         w->setStall(attrf(a, "aoa") * DEG2RAD);
210         w->setStallWidth(attrf(a, "width", 2) * DEG2RAD);
211         w->setStallPeak(attrf(a, "peak", 1.5));
212     } else if(eq(name, "flap0")) {
213         ((Wing*)_currObj)->setFlap0(attrf(a, "start"), attrf(a, "end"),
214                                     attrf(a, "lift"), attrf(a, "drag"));
215     } else if(eq(name, "flap1")) {
216         ((Wing*)_currObj)->setFlap1(attrf(a, "start"), attrf(a, "end"),
217                                     attrf(a, "lift"), attrf(a, "drag"));
218     } else if(eq(name, "slat")) {
219         ((Wing*)_currObj)->setSlat(attrf(a, "start"), attrf(a, "end"),
220                                    attrf(a, "aoa"), attrf(a, "drag"));
221     } else if(eq(name, "spoiler")) {
222         ((Wing*)_currObj)->setSpoiler(attrf(a, "start"), attrf(a, "end"),
223                                       attrf(a, "lift"), attrf(a, "drag"));
224     } else if(eq(name, "actionpt")) {
225         v[0] = attrf(a, "x");
226         v[1] = attrf(a, "y");
227         v[2] = attrf(a, "z");
228         ((Thruster*)_currObj)->setPosition(v);
229     } else if(eq(name, "dir")) {
230         v[0] = attrf(a, "x");
231         v[1] = attrf(a, "y");
232         v[2] = attrf(a, "z");
233         ((Thruster*)_currObj)->setDirection(v);
234     } else if(eq(name, "control-setting")) {
235         // A cruise or approach control setting
236         const char* axis = a->getValue("axis");
237         float value = attrf(a, "value", 0);
238         if(_cruiseCurr)
239             _airplane.addCruiseControl(parseAxis(axis), value);
240         else
241             _airplane.addApproachControl(parseAxis(axis), value);
242     } else if(eq(name, "control-input")) {
243
244         // A mapping of input property to a control
245         int axis = parseAxis(a->getValue("axis"));
246         int control = parseOutput(a->getValue("control"));
247         int opt = 0;
248         opt |= a->hasAttribute("split") ? ControlMap::OPT_SPLIT : 0;
249         opt |= a->hasAttribute("invert") ? ControlMap::OPT_INVERT : 0;
250         opt |= a->hasAttribute("square") ? ControlMap::OPT_SQUARE : 0;
251         
252         ControlMap* cm = _airplane.getControlMap();
253         if(a->hasAttribute("src0")) {
254                            cm->addMapping(axis, control, _currObj, opt,
255                            attrf(a, "src0"), attrf(a, "src1"), 
256                            attrf(a, "dst0"), attrf(a, "dst1"));
257         } else {
258             cm->addMapping(axis, control, _currObj, opt);
259         }
260     } else if(eq(name, "control-output")) {
261         // A property output for a control on the current object
262         ControlMap* cm = _airplane.getControlMap();
263         int type = parseOutput(a->getValue("control"));
264         int handle = cm->getOutputHandle(_currObj, type);
265
266         PropOut* p = new PropOut();
267         p->prop = fgGetNode(a->getValue("prop"), true);
268         p->handle = handle;
269         p->type = type;
270         p->left = !(a->hasAttribute("side") &&
271                         eq("right", a->getValue("side")));
272         p->min = attrf(a, "min", cm->rangeMin(type));
273         p->max = attrf(a, "max", cm->rangeMax(type));
274         _controlProps.add(p);
275
276     } else if(eq(name, "control-speed")) {
277         ControlMap* cm = _airplane.getControlMap();
278         int type = parseOutput(a->getValue("control"));
279         int handle = cm->getOutputHandle(_currObj, type);
280         float time = attrf(a, "transition-time", 0);
281         
282         cm->setTransitionTime(handle, time);
283     } else {
284         SG_LOG(SG_FLIGHT,SG_ALERT,"Unexpected tag '"
285                << name << "' found in YASim aircraft description");
286         exit(1);
287     }
288 }
289
290 void FGFDM::getExternalInput(float dt)
291 {
292     // The control axes
293     ControlMap* cm = _airplane.getControlMap();
294     cm->reset();
295     int i;
296     for(i=0; i<_axes.size(); i++) {
297         AxisRec* a = (AxisRec*)_axes.get(i);
298         float val = fgGetFloat(a->name, 0);
299         cm->setInput(a->handle, val);
300     }
301     cm->applyControls(dt);
302
303     // Weights
304     for(i=0; i<_weights.size(); i++) {
305         WeightRec* wr = (WeightRec*)_weights.get(i);
306         _airplane.setWeight(wr->handle, LBS2KG * fgGetFloat(wr->prop));
307     }
308 }
309
310 void FGFDM::setOutputProperties()
311 {
312     char buf[256];
313     int i;
314
315     float grossWgt = _airplane.getModel()->getBody()->getTotalMass() * KG2LBS;
316     fgSetFloat("/yasim/gross-weight-lbs", grossWgt);
317
318     ControlMap* cm = _airplane.getControlMap();
319     for(i=0; i<_controlProps.size(); i++) {
320         PropOut* p = (PropOut*)_controlProps.get(i);
321         float val = (p->left
322                      ? cm->getOutput(p->handle)
323                      : cm->getOutputR(p->handle));
324         float rmin = cm->rangeMin(p->type);
325         float rmax = cm->rangeMax(p->type);
326         float frac = (val - rmin) / (rmax - rmin);
327         val = frac*(p->max - p->min) + p->min;
328         p->prop->setFloatValue(val);
329     }
330
331     float totalFuel = 0, totalCap = 0;
332     float fuelDensity = 720; // in kg/m^3, default to gasoline: ~6 lb/gal
333     for(i=0; i<_airplane.numTanks(); i++) {
334         fuelDensity = _airplane.getFuelDensity(i);
335         sprintf(buf, "/consumables/fuel/tank[%d]/level-gal_us", i);
336         fgSetFloat(buf, CM2GALS*_airplane.getFuel(i)/fuelDensity);
337         sprintf(buf, "/consumables/fuel/tank[%d]/level-lbs", i);
338         fgSetFloat(buf, KG2LBS*_airplane.getFuel(i));
339         totalFuel += _airplane.getFuel(i);
340         totalCap += _airplane.getTankCapacity(i);
341     }
342     if(totalCap != 0) {
343         fgSetFloat("/consumables/fuel/total-fuel-lbs", KG2LBS*totalFuel);
344         fgSetFloat("/consumables/fuel/total-fuel-gals",
345                    CM2GALS*totalFuel/fuelDensity);
346         fgSetFloat("/consumables/fuel/total-fuel-norm", totalFuel/totalCap);
347     }
348
349     for(i=0; i<_thrusters.size(); i++) {
350         EngRec* er = (EngRec*)_thrusters.get(i);
351         Thruster* t = er->eng;
352
353         sprintf(buf, "%s/fuel-flow-gph", er->prefix);
354         fgSetFloat(buf, (t->getFuelFlow()/fuelDensity) * 3600 * CM2GALS);
355
356         if(t->getPropEngine()) {
357             PropEngine* p = t->getPropEngine();
358
359             sprintf(buf, "%s/rpm", er->prefix);
360             fgSetFloat(buf, p->getOmega() / RPM2RAD);
361         }
362
363         if(t->getPistonEngine()) {
364             PistonEngine* p = t->getPistonEngine();
365             
366             sprintf(buf, "%s/mp-osi", er->prefix);
367             fgSetFloat(buf, p->getMP() * (1/INHG2PA));
368
369             sprintf(buf, "%s/egt-degf", er->prefix);
370             fgSetFloat(buf, p->getEGT() * K2DEGF + 459.4);
371         }
372
373         if(t->getJet()) {
374             Jet* j = t->getJet();
375
376             sprintf(buf, "%s/n1", er->prefix);
377             fgSetFloat(buf, j->getN1());
378
379             sprintf(buf, "%s/n2", er->prefix);
380             fgSetFloat(buf, j->getN2());
381
382             sprintf(buf, "%s/epr", er->prefix);
383             fgSetFloat(buf, j->getEPR());
384
385             sprintf(buf, "%s/egt-degf", er->prefix);
386             fgSetFloat(buf, j->getEGT() * K2DEGF + 459.4);
387         }
388     }
389 }
390
391 Wing* FGFDM::parseWing(XMLAttributes* a, const char* type)
392 {
393     Wing* w = new Wing();
394
395     float defDihed = 0;
396     if(eq(type, "vstab"))
397         defDihed = 90;
398     else
399         w->setMirror(true);
400
401     float pos[3];
402     pos[0] = attrf(a, "x");
403     pos[1] = attrf(a, "y");
404     pos[2] = attrf(a, "z");
405     w->setBase(pos);
406
407     w->setLength(attrf(a, "length"));
408     w->setChord(attrf(a, "chord"));
409     w->setSweep(attrf(a, "sweep", 0) * DEG2RAD);
410     w->setTaper(attrf(a, "taper", 1));
411     w->setDihedral(attrf(a, "dihedral", defDihed) * DEG2RAD);
412     w->setCamber(attrf(a, "camber", 0));
413     w->setIncidence(attrf(a, "incidence", 0) * DEG2RAD);
414
415     // The 70% is a magic number that sorta kinda seems to match known
416     // throttle settings to approach speed.
417     w->setInducedDrag(0.7*attrf(a, "idrag", 1));
418
419     float effect = attrf(a, "effectiveness", 1);
420     w->setDragScale(w->getDragScale()*effect);
421
422     _currObj = w;
423     return w;
424 }
425
426 void FGFDM::parsePropeller(XMLAttributes* a)
427 {
428     float cg[3];
429     cg[0] = attrf(a, "x");
430     cg[1] = attrf(a, "y");
431     cg[2] = attrf(a, "z");
432     float mass = attrf(a, "mass") * LBS2KG;
433     float moment = attrf(a, "moment");
434     float radius = attrf(a, "radius");
435     float speed = attrf(a, "cruise-speed") * KTS2MPS;
436     float omega = attrf(a, "cruise-rpm") * RPM2RAD;
437     float power = attrf(a, "cruise-power") * HP2W;
438     float rho = Atmosphere::getStdDensity(attrf(a, "cruise-alt") * FT2M);
439
440     // Hack, fix this pronto:
441     float engP = attrf(a, "eng-power") * HP2W;
442     float engS = attrf(a, "eng-rpm") * RPM2RAD;
443
444     Propeller* prop = new Propeller(radius, speed, omega, rho, power);
445     PistonEngine* eng = new PistonEngine(engP, engS);
446     PropEngine* thruster = new PropEngine(prop, eng, moment);
447     _airplane.addThruster(thruster, mass, cg);
448
449     if(a->hasAttribute("displacement"))
450         eng->setDisplacement(attrf(a, "displacement") * CIN2CM);
451
452     if(a->hasAttribute("compression"))
453         eng->setCompression(attrf(a, "compression"));        
454
455     if(a->hasAttribute("turbo-mul")) {
456         float mul = attrf(a, "turbo-mul");
457         float mp = attrf(a, "wastegate-mp", 1e6) * INHG2PA;
458         eng->setTurboParams(mul, mp);
459     }
460
461     if(a->hasAttribute("takeoff-power")) {
462         float power0 = attrf(a, "takeoff-power") * HP2W;
463         float omega0 = attrf(a, "takeoff-rpm") * RPM2RAD;
464         prop->setTakeoff(omega0, power0);
465     }
466
467     if(a->hasAttribute("max-rpm")) {
468         float max = attrf(a, "max-rpm") * RPM2RAD;
469         float min = attrf(a, "min-rpm") * RPM2RAD;
470         thruster->setVariableProp(min, max);
471     }
472
473     char buf[64];
474     sprintf(buf, "/engines/engine[%d]", _nextEngine++);
475     EngRec* er = new EngRec();
476     er->eng = thruster;
477     er->prefix = dup(buf);
478     _thrusters.add(er);
479
480     _currObj = thruster;
481 }
482
483 // Turns a string axis name into an integer for use by the
484 // ControlMap.  Creates a new axis if this one hasn't been defined
485 // yet.
486 int FGFDM::parseAxis(const char* name)
487 {
488     int i;
489     for(i=0; i<_axes.size(); i++) {
490         AxisRec* a = (AxisRec*)_axes.get(i);
491         if(eq(a->name, name))
492             return a->handle;
493     }
494
495     // Not there, make a new one.
496     AxisRec* a = new AxisRec();
497     a->name = dup(name);
498     a->handle = _airplane.getControlMap()->newInput();
499     _axes.add(a);
500     return a->handle;
501 }
502
503 int FGFDM::parseOutput(const char* name)
504 {
505     if(eq(name, "THROTTLE"))  return ControlMap::THROTTLE;
506     if(eq(name, "MIXTURE"))   return ControlMap::MIXTURE;
507     if(eq(name, "STARTER"))   return ControlMap::STARTER;
508     if(eq(name, "MAGNETOS"))  return ControlMap::MAGNETOS;
509     if(eq(name, "ADVANCE"))   return ControlMap::ADVANCE;
510     if(eq(name, "REHEAT"))    return ControlMap::REHEAT;
511     if(eq(name, "BOOST"))     return ControlMap::BOOST;
512     if(eq(name, "VECTOR"))    return ControlMap::VECTOR;
513     if(eq(name, "PROP"))      return ControlMap::PROP;
514     if(eq(name, "BRAKE"))     return ControlMap::BRAKE;
515     if(eq(name, "STEER"))     return ControlMap::STEER;
516     if(eq(name, "EXTEND"))    return ControlMap::EXTEND;
517     if(eq(name, "INCIDENCE")) return ControlMap::INCIDENCE;
518     if(eq(name, "FLAP0"))     return ControlMap::FLAP0;
519     if(eq(name, "FLAP1"))     return ControlMap::FLAP1;
520     if(eq(name, "SLAT"))      return ControlMap::SLAT;
521     if(eq(name, "SPOILER"))   return ControlMap::SPOILER;
522     if(eq(name, "CASTERING")) return ControlMap::CASTERING;
523     SG_LOG(SG_FLIGHT,SG_ALERT,"Unrecognized control type '"
524            << name << "' in YASim aircraft description.");
525     exit(1);
526
527 }
528
529 void FGFDM::parseWeight(XMLAttributes* a)
530 {
531     WeightRec* wr = new WeightRec();
532
533     float v[3];
534     v[0] = attrf(a, "x");
535     v[1] = attrf(a, "y");
536     v[2] = attrf(a, "z");
537
538     wr->prop = dup(a->getValue("mass-prop"));
539     wr->size = attrf(a, "size", 0);
540     wr->handle = _airplane.addWeight(v, wr->size);
541
542     _weights.add(wr);
543 }
544
545 bool FGFDM::eq(const char* a, const char* b)
546 {
547     // Figure it out for yourself. :)
548     while(*a && *b && *a == *b) { a++; b++; }
549     return !(*a || *b);
550 }
551
552 char* FGFDM::dup(const char* s)
553 {
554     int len=0;
555     while(s[len++]);
556     char* s2 = new char[len+1];
557     char* p = s2;
558     while((*p++ = *s++));
559     s2[len] = 0;
560     return s2;
561 }
562
563 int FGFDM::attri(XMLAttributes* atts, char* attr)
564 {
565     if(!atts->hasAttribute(attr)) {
566         SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
567                "' in YASim aircraft description");
568         exit(1);
569     }
570     return attri(atts, attr, 0);
571 }
572
573 int FGFDM::attri(XMLAttributes* atts, char* attr, int def)
574 {
575     const char* val = atts->getValue(attr);
576     if(val == 0) return def;
577     else         return atol(val);
578 }
579
580 float FGFDM::attrf(XMLAttributes* atts, char* attr)
581 {
582     if(!atts->hasAttribute(attr)) {
583         SG_LOG(SG_FLIGHT,SG_ALERT,"Missing '" << attr <<
584                "' in YASim aircraft description");
585         exit(1);
586     }
587     return attrf(atts, attr, 0);
588 }
589
590 float FGFDM::attrf(XMLAttributes* atts, char* attr, float def)
591 {
592     const char* val = atts->getValue(attr);
593     if(val == 0) return def;
594     else         return (float)atof(val);    
595 }
596
597 }; // namespace yasim