I need help to read a decimal number in a text file using JNA. It looks funny but the problem is real.
I created a simple Java program which calls a simple Fortran subroutine using JNA.
Main class :
package Appli;
public class Appli {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// call to subroutine lecture with LECT
LectInterface.LECT.lecture();
}
}
Interface :
package Appli;
import com.sun.jna.Library;
import com.sun.jna.Native;
/**
* Interface.
*/
public interface LectInterface extends Library {
// dynamic library.
public final static LectInterface LECT = (LectInterface) Native.loadLibrary("libLect.so", LectInterface.class);
/**
* Fonction LECTURE.
*
*/
public double lecture();
}
The Fortran subroutine just reads a number in a text file:
SUBROUTINE LECTURE ()
DOUBLE PRECISION VALDOUBLE
INTEGER IFILE
PARAMETER(IFILE=1)
WRITE(*,*)'START LECTURE'
OPEN(UNIT=1,FILE='/home/Fortran/fort.txt')
READ(IFILE,*) VALDOUBLE
WRITE(*,*)VALDOUBLE
WRITE(*,*)'END LECTURE'
END SUBROUTINE
The text file :
2.36
When I call this subroutine with my Java program (using NetBeans) it returns :
run :
START LECTURE
2.000000000000000
END LECTURE
I use NetBeans 8, java 7, gfortran and JNA-4.1.0
I compile with:
gfortran -fno-underscoring -fPIC -c -g -o LECTURE.o LECTURE.f
Then
gfortran -shared -o libLect.so LECTURE.o
I can't explain why the READ function only takes the first part of the number (before the decimal point), for example:
2.200 => 2.000000000000000
0.12 => 0.000000000000000
12.023 => 12.000000000000000
100000.0182 => 100000.000000000000000
I did several tests with the compilers ifort (Intel) and pgf90 (PGI).
With pgf90, the result is still false, but with ifort, the value is read correctly.
Compilation: ifort -c -fPIC LECTURE.f
Creation of the dynamic library: ifort -shared -o libLect.so LECTURE.o
Result: 2.3
I also compile the sources with gfortran using the same options than ifort. The value is false (2.0).
Is there a compilation option to add with gfortran?