View Full Version : Decimal separator

05-20-2009, 07:59 AM

is there a way to tell PV-WAVE to always use "." as decimal point even if the operating system (in my case Windows XP) is configured to use ","?

Andreas Malecki

05-21-2009, 09:01 AM
Can you provide more details on what you're trying to do? Is this related to reading or importing your data?


Don B.

05-22-2009, 02:32 AM
That's correct. I'm writing and reading floating point numbers to/from files using PRINTF and READF. Because of the data format I need to ensure that the decimal separator is forced to be "." and nothing else, but I didn't find anything about this topic in the documentation.

05-22-2009, 11:01 AM
The easiest way to accomplish this is through the use of string manipulation routines. Let's say your data file (samp.dat) looks something like this:

Reading the data as strings rather than floats, you can delete the periods from the lines and then convert the commas to periods, turning them into reasonable floating point (or double) values. The following code (getdata.pro) is an example:

FUNCTION getdata
file = 'samp.dat' & tmp = '' & line = 0 & bigsize = 100
; create an array to hold all the data in the file
data = STRARR(bigsize)
; open the file, read each line as a string until we hit the end of the file
OPENR, lun, file, /Get_lun
READF, lun, tmp
; replace the period with nothing (remove it from the line)
tmp = STRSUBST(tmp, '\\.', '')
; change the comma to a period
tmp = STRSUBST(tmp, ',', '.')
; put the modified string into the data array
data(line) = tmp
; keep track of how many lines we read
line = line + 1
; all done...close the file and release the LUN
; shrink the big array down to the number of lines we read,
; and at the same time convert the array from strings to floating
; point numbers, then send the array back to the calling routine.
data = FLOAT(data(0:line-1))
RETURN, data
If you save both of these files to disk and run them, you get:

WAVE> x=getdata()
% Compiled module: GETDATA.
WAVE> print, x
1234.56 2345.67 3456.78 4567.89
WAVE> info, x
X FLOAT = Array(4)

Hope this helps,

Don B.

05-26-2009, 01:59 AM
Okay. That will do the job, of course. Thanks.

I would have hoped to get instructions about how to manipulate the language/environment settings used by PV-WAVE in order to ensure that the built-in functions use the correct notation. In my case that would be the English notation regardless of the system settings. But this seems to be impossible, isn't it? It's just, because it is very insecure, as in Windows you can take any character to be the decimal separator. So I can only make sure that my data output works with some special cases like "," and ".", but not in every other possible case.