0

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

8
  • Your "F77" program isn't F77, but it (the fragment shown) is F90. That wasn't the only reason you need separate programs? Commented Aug 29, 2015 at 8:57
  • The F77 program is a user subroutine of a commercial software. While I need F90 for github.com/jmhodges/kdtree2/tree/master/src-f90. So they need to be separate Commented Aug 29, 2015 at 9:29
  • I've nothing to say on your question directly, and I don't know the full details of your case. However, if it were my project I'd be looking at ways to do this without multiple programs sharing data with temporary files. The distinction between "F77" and "F90" is generally not required: if you're compiling both lumps of code then they're both Fortran as far as the compiler is concerned. That is, there is no reason why the vast majority of F77 code can't coexist in a program with F90. [Some care required.] Commented Aug 29, 2015 at 9:52
  • Ok, I can not merge F77 and 'mine' F90 code, because as I said 'The F77 program is a user subroutine of a commercial software'. So I can write an user subroutine to do what I want but in F77, but to do what I want I need github.com/jmhodges/kdtree2/tree/master/src-f90 that is in F90. The two programs are not compiled at the same time. The master launch an exe file that could be generated from python/fortran/... I hope to be enough clear. Commented Aug 29, 2015 at 9:57
  • My comments were just to say that there is something to consider. If you have and it's not appropriate. then that's fair enough. Commented Aug 29, 2015 at 10:00

1 Answer 1

0

Thanks to agentp, this solved my problem:

consider using a second file as a flag which you write to after closing/flushing the data file, that should help with some of the timing issues

[EDIT] I am having some issue with the file that I use to flag that the data file is ready. I am not always able to delete this file.

This is my solution, after a data file is ready I write on one program:

open(202, file=chk_file2)
close(202)

In the other program I have this code to get the flag and delete the file, because I need to exchange data many times:

do while (.true.)
   inquire(file=chk_file2, exist=file_exist)
   if (file_exist) then
102   continue
      istat = 1
      do while (istat.eq.0)
         open(401, file=chk_file2, iostat=istat, err=102)
         close(401, status='delete', err=102)
      enddo
      exit
   endif
enddo

Or:

do while (.true.)
   inquire(file=chk_file2, exist=file_exist)
   if (file_exist) then
102   continue
      do while (.true.)
          open(400, file=chk_file2, iostat=istat, err=102)
          if (istat.eq.0) then
              close(400, status='delete', err=102)
              exit
          endif
      enddo
      exit
   endif
enddo

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.