| Changing the locale The Fortran Runtime Environment (RTE) implementation changes LC_NUMERIC to "POSIX" before the first Fortran I/O statement. (This is documented in the "XL Fortran Compiler Reference"; you can find a PDF version of this document by following the "XL Fortran Manuals" link below.)
The Fortran RTE will return LC_NUMERIC to its original value at the end of the program, but for a mixed-language program this may leave C or C++ code with a different locale than expected after a call to a Fortran subroutine.
To ensure that Fortran I/O and C or C++ code expecting a numeric locale other than "POSIX" behave correctly, it is recommended to set LC_NUMERIC to "POSIX" before calling a Fortran subroutine, and to reset it after the call returns.
For example: void do_fsub(double val) { char * ploc = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "POSIX"); fsub(val); setlocale(LC_NUMERIC, ploc); } Changing the decimal separator While Fortran requires "POSIX" for its numeric locale when doing I/O, the Fortran 2003 standard and IBM XL Fortran V11.1 provide a standard-compliant method to specify a decimal separator other than the period (".") using the DECIMAL= specifier. (This is documented in the "XL Fortran Language Reference" for V11.1; you can find a PDF version of this document by following the "XL Fortran Manuals" link below.)
The DECIMAL= specifier accepts the values "POINT" and "COMMA"; "POINT" is the default. By using the DECIMAL= specifier, Fortran can read and write floating-point values where a comma (",") is used as the decimal separator instead of a period (".").
For example: subroutine fsub(v) real, intent(in) :: v open(8,FILE="regular") open(9,FILE="special",DECIMAL="COMMA") write(8,*) "by default in 'regular' v prints:", v write(9,*) "by default in 'special' v prints:", v write(8,*,DECIMAL="COMMA") "switching decimal in 'regular'," & "v prints:", v write(9,*,DECIMAL="POINT") "switching decimal in 'special'," & "v prints:", v end subroutine fsub |