Need help (beginner) in fortran 95

What does this error mean?
How do I fix it?

gfortran ./main.f95 -o main
f951: Warning: command line option ‘-Wformat=1’ is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: command line option ‘-Wformat-security’ is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: ‘-Werror=’ argument ‘-Werror=format-security’ is not valid for Fortran
 ./main
At line 14 of file ./main.f95 (unit = 100, file = 'data1.dat')
Fortran runtime error: End of file

Error termination. Backtrace:
#0  0x7f27e046eb90 in ???
#1  0x7f27e046f635 in ???
#2  0x7f27e046ffdb in ???
#3  0x7f27e0684c23 in ???
#4  0x7f27e067db82 in ???
#5  0x7f27e067f482 in ???
#6  0x7f27e0684015 in ???
#7  0x40137d in ???
#8  0x40114e in ???
#9  0x7f27e00fa78f in ???
#10  0x401189 in ???
    at ../sysdeps/x86_64/start.S:120
#11  0xffffffffffffffff in ???
exit status 2

code there is :

program gaussseidel
implicit none
integer:: N,I,J,Kmax,S,K,M,W,NB
complex,Dimension(100,100)::Ya,Z,Ys
real,Dimension(100):: P,Q
complex,Dimension(100)::V
real::a,b,d,e
complex::SS,ST,Va,eps,DVamax
integer,dimension(100)::type
!ici commence mon programme
!c:saisie Dimension réseau
open(unit=100,file='data1.dat')
open(unit=200,file='result.res')
        Read(100,*)N,NB
        write(200,*)'le nombre=',N,' le nombre de branches=',NB
        do I=1,N
            do J=1,N
               Ya(I,J)=0
            enddo
        enddo
write(200,*)'la matrice admittance'
do w=1,NB
            Read(100,*)I,J,a,b,d,e
            Z(I,J)=cmplx(a,b)
            Ys(I,J)=cmplx(d,e)
            if(real(Z(I,J))>0. .and. aimag(Z(I,J))>0.)then
                Ya(I,J)=-1/Z(I,J)
            else
                Ya(I,J)=1e-6
            endif
            Ya(J,I)=Ya(I,J)
            Z(J,I)=Z(I,J)
            write(200,*)I,J,Ya(I,J)
enddo
!c:on calcul les élément de diagonale
write(200,*)'la matrice admittance, les élements diagonaux'
do I=1,N
    Ya(I,I)=(0.,0.)
     do J=1,N
       if(Z(I,J)/=0)then
          Ya(I,I)=Ya(I,I)+(-Ya(I,J)+Ys(I,J)/2)
       endif
     enddo
     write(200,*)I,I,Ya(I,I)
enddo
DVamax=cmplx(-10000,-10000)
do I=1,N
   V(I)=(1.,0.)
enddo
!c:initialisation des tensions
!c:ici commence la saisie des tableaux de planification
!c:saisie numéro nœud balancier
        Read(100,*)S
        write(200,*)S
        type(S)=0
!c:saisie de type des nœud)
     do I=1,N
        if(I/=S)then
           Read(100,*)type(I)
!c:si nœud est consommateur(c)
           if(type(I)==2)then
              Read(100,*)P(I),Q(I)
              write(200,*)'aprés calcul de type',type(I),P(I),Q(I)
           endif
           if(type(I)==1)then
              Read(100,*) a,b,P(I)
              V(I)=cmplx(a,b)
              write(200,*)'aprés calcul de type',type(I),V(I),P(I)
           endif
           V(I)=cmplx(1.,0.)
        endif
    enddo
!c:saisie de epsilon,Kmax
    Read(100,*)a,b,Kmax
    eps=cmplx(a,b)
    write(200,*)a,b,Kmax
!c:ici commence le traitement
    K=0
100 write(200,*) 'itération ',K
do I=1,N
   if (I/=S)then
           SS=(0.,0.)
           do J=1,N
              if(I/=J)then
                 SS=SS+Ya(I,J)*V(J)
              endif
           enddo
           if(type(I)==1)then
              ST=cmplx(0.,0.)
              do J=1,N
                 ST=ST+Ya(I,J)*V(J)
              enddo
              Q(I)=aimag(V(I)*ST)
           endif
           Va=V(I)
           V(I)=(1/Ya(I,I))*(cmplx(P(I),-Q(I))/V(I)-SS)
           if(real(Va-V(I))>real(DVamax) .and. aimag(Va-V(I))>aimag(DVamax))then
              DVamax=Va-V(I)
           endif
       endif
    enddo
    write(200,*)'DVamax=',cabs(DVamax),' eps=',cabs(eps)
    do M=1,N
        write(200,*)cabs(V(M)),-atan(aimag(V(M))/real(V(M)))
    enddo
    if(cabs(DVamax)>cabs(eps))then
       K=K+1
       if(K<=Kmax)then
          Go to 100
       else
          write(200,*)'on diverge'
       endif
    else
    !c:ici calculer puissance apparente du noeud Bilan
        ST=cmplx(0.,0.)
        do I=1,N
            ST=ST+Ya(S,I)*V(S)
        enddo
        P(S)=Real(V(S)*ST)
        Q(S)=aimag(V(S)*ST)
        write(200,*) 'puissance apparente du noeud Bilan'
        write(200,*)P(S),Q(S)
        write(200,*)'vecteur tensions nodales'
        do M=1,N
           write(200,*)cabs(V(M)),-atan(aimag(V(M))/real(V(M)))
        enddo
    endif
 end program

data1.dat is:

5, 7
1 2 0.0410 0.3146 0 0.07
1 3 0.042 0.321 0 0.0715
1 4 0.0309 0.273 0 0.0528
2 4 0.0238 0.1823 0 0.0405
2 5 0.0365 0.2806 0 0.0624
3 5 0.0573 0.4397 0 0.0978
4 5 0.0178 0.1367 0 0.0300
B 1 0
G 1.0 0.931
G 1.0 0.900
C 2.202 1.031
C 0.911 0.212
0.001 100

result.res file is empty

Bad integer for item 1 in list input indicates a problem with your input file. Being more specific your program is expecting an integer value but it’s encountering a problem when trying to interpret the data as an integer.

To fix this
Make sure that the ‘data1.dat’ file exists in the specified location, and that it contains the data in the format that your program expects.

Go to line 53 in your ‘main.f95’ file (as the error message indicates) and inspect how the input is being read. If you’re expecting an integer value, ensure the data in ‘data1.dat’ can be interpreted as an integer.

Obs: this is a guess. Without the code is kinda hard too assess the exact reasons.

1 Like

i add code, data1.dat file and result.res file is empty

i think error in data1.dat how i can fix it?

Hmm, it looks like the problem is whithin your logic and your data1.dat file.

As you can see the error indicates that your program has attempted to read past the end of the file “data1.dat”. This can happen if your program expects more data in the file than is actually present.

Your data1.dat contain only 14 lines.

The logic of your program is expecting a file with 15 lines.

You either add more lines or adjust the logic of your code.

I Correct the data1.dat is as follows:

9 9
1 4 0.0410 0.3146 0 0.07
4 5 0.042 0.321 0 0.0715
5 6 0.0309 0.273 0 0.0528
3 6 0.0238 0.1823 0 0.0405
6 7 0.0365 0.2806 0 0.0624
7 8 0.0573 0.4397 0 0.0978
8 2 0.0178 0.1367 0 0.0300
8 9 0.0178 0.1367 0 0.0300
9 4 0.0178 0.1367 0 0.0300
S 1.0 0.0
G 1.0 0.931
G 1.0 0.900
C 2.202 1.031
C 0.911 0.212
0.001 100

i got another error
gfortran ./main.f95 -o main
f951: Warning: command line option ‘-Wformat=1’ is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: command line option ‘-Wformat-security’ is valid for C/C++/ObjC/ObjC++ but not for Fortran
f951: Warning: ‘-Werror=’ argument ‘-Werror=format-security’ is not valid for Fortran
 ./main
At line 53 of file ./main.f95 (unit = 100, file = ‘data1.dat’)
Fortran runtime error: Bad integer for item 1 in list input

Error termination. Backtrace:
#0 0x7ffa386c4b90 in ???
#1 0x7ffa386c5635 in ???
#2 0x7ffa386c5fdb in ???
#3 0x7ffa388d0e68 in ???
#4 0x7ffa388d3ea1 in ???
#5 0x7ffa388d5482 in ???
#6 0x7ffa388da015 in ???
#7 0x401acd in ???
#8 0x40114e in ???
#9 0x7ffa3835078f in ???
#10 0x401189 in ???
at …/sysdeps/x86_64/start.S:120
#11 0xffffffffffffffff in ???
exit status 2

What does this mean and how to fix it?

1 Like

It revolves to this problem.

In the data1.dat file, you provide types as S , G , G , C , and C , but the program expects integers (as type is an integer array).

To summarize, the error is occurring because your program is trying to read a character (‘S’, ‘G’ or ‘C’) as an integer.

You either change these to integer or you change the logic of your program. (I think G = 1 and C = 2, but I’m not sure about S).

data1.dat

9 9
1 4 0.0410 0.3146 0 0.07
4 5 0.042 0.321 0 0.0715
5 6 0.0309 0.273 0 0.0528
3 6 0.0238 0.1823 0 0.0405
6 7 0.0365 0.2806 0 0.0624
7 8 0.0573 0.4397 0 0.0978
8 2 0.0178 0.1367 0 0.0300
8 9 0.0178 0.1367 0 0.0300
9 4 0.0178 0.1367 0 0.0300
0 1.0 0.0
1 1.0 0.931
1 1.0 0.900
2 2.202 1.031
2 0.911 0.212
0.001 100

error:
At line 59 of file ./main.f95 (unit = 100, file = ‘data1.dat’)
Fortran runtime error: End of file

end of file? how fix it data1.dat

Same thing here.

You need to understand what each part of your program do and adapt your file (data1.dat) accordinly.

For example, what you can take out of this?

write(200,*)'le nombre=',N,' le nombre de branches=',NB
        do I=1,N

If you understand the program, you can build the data1.dat properly.

1 Like