N
NM
Sometimes ago I was having a problem in linking between C++ and Fortran
program. That was solved (using input from this newsgroup) using the Fortran
keyword "sequence" with the derived types (to assume contiguous space).
Now I am having problem again. In order to show the problem I have created
small program and this time there is no data straucture being passed between
C++ and Fortran.
Here is how the program looks like
file read_do_calc.f=================== subroutine read_do_calc()
double precision :: a,b,c,d,e,f,val
open(60,file='binary_file',status='unknown',form='unformatted')
read(60) a
read(60) b
read(60) c
read(60) d
read(60) e
read(60) f
close(60)
write(*,*) a,' ',b,' ',c,' ',d,' ',e,' ',f
val = a + (b*c*d*(e*e))*f
write(*,*) 'val = ',val
return
endfile fort_main.f================ program main
call read_do_calc()
endprogram mainfile main.cpp============= extern "C" {
void read_do_calc_(void);
}
int main(void)
{
read_do_calc_();
return 0;
} compile read_do_calc.f
create the fortran program
create the c++ program (either using icc or g++ , it did not matter in my
case)
output of the two programs given below
-1.00000000000000 2.00000000000000 0.138888888888889
val = 0.000000000000000E+000
-1.00000000000000 2.00000000000000 0.138888888888889
val = -6.965998958219366E-018Notice the value of the variable "val" is
different in the two cases.The version of ifort I am using is
(ICC) 9.0 20050430Copyright (C) 1985-2005 Intel Corporation. All rights
reserved.The file "binary_file" is attached. The values there was captured
from a nontrivial program whose computation looks like that of the
subroutine read_do_calc().Can anyone please help me? What am I doing wrong
this time? Thanks.NM
program. That was solved (using input from this newsgroup) using the Fortran
keyword "sequence" with the derived types (to assume contiguous space).
Now I am having problem again. In order to show the problem I have created
small program and this time there is no data straucture being passed between
C++ and Fortran.
Here is how the program looks like
file read_do_calc.f=================== subroutine read_do_calc()
double precision :: a,b,c,d,e,f,val
open(60,file='binary_file',status='unknown',form='unformatted')
read(60) a
read(60) b
read(60) c
read(60) d
read(60) e
read(60) f
close(60)
write(*,*) a,' ',b,' ',c,' ',d,' ',e,' ',f
val = a + (b*c*d*(e*e))*f
write(*,*) 'val = ',val
return
endfile fort_main.f================ program main
call read_do_calc()
endprogram mainfile main.cpp============= extern "C" {
void read_do_calc_(void);
}
int main(void)
{
read_do_calc_();
return 0;
} compile read_do_calc.f
ifort -c read_do_calc.f
create the fortran program
ifort -o fort_prog fort_main.f read_do_calc.o
create the c++ program (either using icc or g++ , it did not matter in my
case)
icc -o cpp_prog main.cpp
read_do_calc.o -L/lusr/share/software/intel/lib -lifcore
output of the two programs given below
-0.430331482911935 1.00000000000000 -0.774596669241483./fort_prog
-1.00000000000000 2.00000000000000 0.138888888888889
val = 0.000000000000000E+000
-0.430331482911935 1.00000000000000 -0.774596669241483./cpp_prog
-1.00000000000000 2.00000000000000 0.138888888888889
val = -6.965998958219366E-018Notice the value of the variable "val" is
different in the two cases.The version of ifort I am using is
Corporation. All rights reserved.and the version of icc is>icc --versionicc>ifort --versionifort (IFORT) 9.0 20050430Copyright (C) 1985-2005 Intel
(ICC) 9.0 20050430Copyright (C) 1985-2005 Intel Corporation. All rights
reserved.The file "binary_file" is attached. The values there was captured
from a nontrivial program whose computation looks like that of the
subroutine read_do_calc().Can anyone please help me? What am I doing wrong
this time? Thanks.NM