I need to exchange data between two different fortran programs, unfortunately then need to be separate (two different .exe), one is written in f90 the other in f77.
At the moment this is my solution:
- the f90 (.exe) is launched at the beginning of the f77 (master), and wait for data from the f77 using do while('true') and inquire
- when data is written to a certain file (file_in) the f90 read, elaborate and write the result to a new file (file_out)
- the f77 wait for data from f90 using do while ('true') and inquire
- and go on
This is an example code for the program in f77:
C Write data for f90
open(210, file=file_in, action='write', status='replace', form='unformatted')
write(210) data
close(210)
do while (.true.)
inquire(file=KDTree_out, exist=file_exist)
if (file_exist) then
call sleepqq(2)
exit
endif
enddo
open(220, file=KDTree_out, action='read', status='old', form='unformatted')
read(220) value
close(220, status='delete')
This an example code for the program in f90:
do while(.true.)
inquire(file=KDTree_in, exist=file_exist)
if (file_exist) then
call sleepqq(2)
! Read data
open(100, file=file_in, action='read', status='old', form='unformatted')
read(100) data
close(100, status='delete')
! Elaborate data
! Write data
open(150, file=file_out, action='write', status='replace', form='unformatted')
write(150) value
close(150)
endif
enddo
This solution seems to work pretty well, but as you can see there are some sleepqq(2) (microseconds) to avoid end of file error, but if you have and ssd or an hard disk, this wait time may vary so is not the perfect solution. Do you have any ideas?
Thanks