API Question Precision of oapiWriteScenario

Mythos

Addon Developer
Addon Developer
Donator
Joined
Apr 28, 2012
Messages
103
Reaction score
7
Points
33
Location
Kiel
Does anyone know how to set the precision of oapiWriteScenario_float() and oapiWriteScenario_vec()? It only writes two digits after the decimal point, regardless of how much there is before the decimal point.

I don't want to do all that by formating a string and then use oapiWriteScenario_string() for every value. But it looks like I have to :facepalm:
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,882
Reaction score
2,133
Points
203
Location
between the planets
Weird. oapiWriteScenario_float writes up to six digits behind the comma, at least for me...?
 

martins

Orbiter Founder
Orbiter Founder
Joined
Mar 31, 2008
Messages
2,448
Reaction score
462
Points
83
Website
orbit.medphys.ucl.ac.uk
Interesting ... I just checked, and oapiWriteScenario_float doesn't contain any precision modifiers, so the output stream inherits whatever it had been set to previously. Curious that this never came up before. What were the last floating point items written to the scenario before you encountered the problem?

I could fix this by either providing an optional precision argument to oapiWriteScenario_float, or by adding a setprecision function for FILEHANDLEs, or by making sure that any internal functions that modify the stream's precision setting reset it before returning.
In the meantime, as a quick and dirty hack, you can cast the FILEHANDLE to an std::eek:fstream and set the precision manually.
 

Zatnikitelman

Addon Developer
Addon Developer
Joined
Jan 13, 2008
Messages
2,302
Reaction score
6
Points
38
Location
Atlanta, GA, USA, North America
You could also use oapiWriteScenario_string, and use sprintf to set the string manually.
Code:
char temp[1024];
sprintf(temp,"%.4lf, %.3lf, %.5lf",float1, float2, float3); //writes to temp with a 4, 3, and 5, decimal place floating point value
oapiWriteScenario_string(scn,"MYLINE",temp);
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
In the meantime, as a quick and dirty hack, you can cast the FILEHANDLE to an std::eek:fstream and set the precision manually.
But this will work only when the code is compiled using Visual Studio/C++ 2005 (for Orbiter 2010+, or VS/C++ 6 for older versions). The fstream classes differ between major VC++ releases.
 

Mythos

Addon Developer
Addon Developer
Donator
Joined
Apr 28, 2012
Messages
103
Reaction score
7
Points
33
Location
Kiel
Thank you Martin for the honor of chief-support :tiphat:

the output stream inherits whatever it had been set to previously.
I searched for some ways to set a standard precision. But since there is no cout object or whatever, i found nothing to use (set)precision. And so nothing else could be there that changed the precision than my VC 2008 Express itself.

What were the last floating point items written to the scenario before you encountered the problem?
I first wrote some simple 1.00, 5.00 and 0.00. Then came the DGIV landed pitch 0.4407 that was shortened to 0.44. After that again some 1.00 and 0.00 and then the main problem to write a vector containing long, rad, lat of Brighton Beach, that looked like "HDGBASEV -0.58 1738000.00 0.72". With that precision it pointed 6km away from it.

I could fix this by either providing an optional precision argument to oapiWriteScenario_float, or by adding a setprecision function for FILEHANDLEs, or by making sure that any internal functions that modify the stream's precision setting reset it before returning.
In the meantime, as a quick and dirty hack, you can cast the FILEHANDLE to an std::eek:fstream and set the precision manually.
I'd prefer to initially call a oapiWriteScenario_setprecision() or something and then set up all the writes.

I've tried
PHP:
((std::ofstream)scn).setprecision(6);
reinterpret_cast<std::ofstream>(scn).precision(6);
but all gave my a compile error
Code:
'FILEHANDLE' kann nicht in 'std::ofstream' konvertiert werden

You could also use oapiWriteScenario_string, and use sprintf to set the string manually.
This is what I thought of Plan B and started to implement already.
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I've tried
PHP:
((std::ofstream)scn).setprecision(6);
reinterpret_cast<std::ofstream>(scn).precision(6);
but all gave my a compile error
Code:
'FILEHANDLE' kann nicht in 'std::ofstream' konvertiert werden

FILEHANDLE is a pointer, so it should be cast as `std::eek:fstream *`, and to make it work properly with Orbiter 2010 streams, you need to compile it in Visual C++ 2005.
 
Top