flaviusaetius
flaviusaetius

Reputation: 23

Writing in two different places unformatted files in Fortran

I am trying to write in two different places (the main program and a subroutine) unformatted files in my Fortran code. The problem is that when I do it, the results change and I suspect that it is because the memory assignment is overwriting the data that I am using to make the simulation in my CFD code. I ask: Is it possible that one can just use the unformatted file (to write) once in the code? I mean, I have to use the same file to save all my data and not with different files.

I copy and past the two parts of the code to show what I am want to describe:

In the main program, the loop is:

         call numcar (isave,suffix)
         longueur=index(nchamp,' ')-1
         nfichier=nchamp(1:longueur)//suffix
         longueur=index(nfichier,' ')-1
         open(10,file=nfichier(1:longueur),form='unformatted')
         write(10) real(uxn,4),real(uyn,4),real(wzn,4),real(ppo,4)
         close(10)
!        *****************************************     
         isave=isave+1

and in the subroutine, the loop is:

         call numcar (isavediv,suffix1)
         longueur1=index(ndiv,' ')-1
         nfichier1=ndiv(1:longueur1)//suffix1
         longueur1=index(nfichier1,' ')-1
         open(20,file=nfichier1(1:longueur1),form='unformatted')
         write(20) real(ppm,4)
         close(20)
!        *****************************************     
         isavediv=isavediv+1

All the variables all declared as IMPLICIT NONE in both main program and subroutine.

Upvotes: 1

Views: 127

Answers (1)

flaviusaetius
flaviusaetius

Reputation: 23

I solved my problem. The problem was that I was using the channel number 20 and a colleague of mine told me that this channel is used by the computer or some devices to process data. I changed it for channel number 10 and it worked good again. Thank you for your comments. Now it looks so:

     open(10,file=nfichier1(1:longueur1),form='unformatted')
     write(10) real(ppm,4)
     close(10)

Upvotes: 1

Related Questions