Good day. wrote the program, launched. the program itself does not give any errors, it seems to work. creates a file but does not write anything to the file . already two programs behave the same way. here is one

program ioposneg implicit none integer::i,a,x do i=1,10 open(10,file='posneg') read(10,*) a if (a>0) then open(15,file='pos') x=a write(15,*) x else open(20,file='neg') x=a write(20,*) x end if end do print*,'finished' end program ioposneg 

and here is the second

 program ioformat implicit none real::x=0,ex integer::i character(len=5)::c='x',ec='ex' open(10,file='xex') write(10,2) c,ec 2 format(2a10) do i=1,11 ex=x**2 open(10,file='xex') write(10,5)x,ex 5 format(2f10.5) x=x+0.1 end do print*,'finished' end program ioformat 

The read file of the first program looks like this:

 2 3 -9 15 -25 -47 85 68 -10 -5 

    1 answer 1

    It turned out that you need to open the file outside the loop. It worked as soon as it opened the opening of the file for the loop in this way:

     implicit none integer::i,a open(10,file='posneg') open(15,file='pos') open(20,file='neg') do i=1,10 read(10,*) a if (a>0) then write(15,*) a else write(20,*) a end if end do print*,'finished' end program ioposneg 

    the same with the second program