Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28495 Discussions

reading European-format real numbers

David_DiLaura1
281 Views

I have an application that reads a user-generated text file for input -- virtually all of it is numeric. To relax the formatting requirements for the user I'm using list-directed read statements [ read(2,*) . . . ]. Files from Europe often usea comma to delimit the whole and fractional part of a real number. Assuming I can detect the origin of the file, is there a way to change the assumption made by the list-directed read statement about the delimiter?

David

0 Kudos
3 Replies
onkelhotte
New Contributor II
281 Views

AFAIK you cannot alter the read statement to catch a , as a delimiter. So you have to read it as a string and convert every numeric step by step. There you have to replace the , with a .

character*255 code

integer*4 npos

npos=index(code,',')

if (npos.ne.0) code(npos:npos)='.'

Markus

0 Kudos
Steven_L_Intel1
Employee
281 Views
Fortran 2008 allows you to specify the "decimal" delimiter as comma, but this feature is not yet available in Intel Fortran.
0 Kudos
DavidWhite
Valued Contributor II
281 Views

You can use the IFNLS library routines to set and get the LOCALE settings, which includes which character is used for the decimal.

The NLSFormatNumber function can be used to output numbers in the correct format, but unfortunately no way to handle on reading. If your application is to be used in multiple LOCALES, I would recommend modifying Markus' code to get the local decimal character rather than assume that it is ",".

Regards,

David

0 Kudos
Reply