API Question Precision of oapiWriteScenario

Mythos

Addon Developer
Addon Developer
Donator
Joined
Apr 28, 2012
Messages
105
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:
 
Weird. oapiWriteScenario_float writes up to six digits behind the comma, at least for me...?
 
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::ofstream and set the precision manually.
 
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);
 
In the meantime, as a quick and dirty hack, you can cast the FILEHANDLE to an std::ofstream 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.
 
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::ofstream 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.
 
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::ofstream *`, and to make it work properly with Orbiter 2010 streams, you need to compile it in Visual C++ 2005.
 
Back
Top