When compiling this program in Fortran, it gives some errors

0

Errors in Fortran when compiling the program that works with .dat or .txt files.

Program

Program liga

    Implicit none

        integer :: i,j,suma
        integer, parameter :: N = 4, M = 20
        real:: A(i,j), p(j),u(j)
        u(3)= (/3.0,1.0,0.0/)

        open (UNIT = 8, FILE = 'partidos.dat')
        open (UNIT=9, FILE= 'puntos.dat')


        read (8,*)
        read (8,*)
        read (8,*)

            do i= 2,N

            read (8,*) A(i,j) 

            end do 

            do i=1,N

              suma=0.0 

               do j= 1,3 

                 suma=suma+(A(i,j)*u(j))= p(j)

               end do 

               p(j)=suma

            end do 

       write (9,*) 
       write (9,*) 'Puntos de los equipos'
       write (9,*)

       write (9,*) p(j)


end program

The errors it throws:

gfortran -Wall -o "programa_liga" "programa_liga.f90" (in directory: /Users/joaquinbenavente/Desktop/TFS)
programa_liga.f90:2:1:
  Program liga
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:4:1:
   Implicit none
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:6:1:
    integer :: i,j,suma
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:7:1:
    integer, parameter :: N = 4, M = 20
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:8:1:
    real:: A(i,j), p(j),u(j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:9:1:
    u(3)= (/3.0,1.0,0.0/)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:11:1:
    open (UNIT = 8, FILE = 'partidos.dat')
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:12:1:
    open (UNIT=9, FILE= 'puntos.dat')
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:15:1:
    read (8,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:16:1:
    read (8,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:17:1:
    read (8,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:19:1:
     do i= 2,N
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:21:1:
     read (8,*) A(i,j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:23:1:
        end do
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:25:1:
        do i=1,N
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:27:1:
          suma=0.0
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:29:1:
           do j= 1,3
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:31:1:
             suma=suma+(A(i,j)*u(j))= p(j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:31:12:
             suma=suma+(A(i,j)*u(j))= p(j)
            1
Error: Unclassifiable statement at (1)
programa_liga.f90:33:1:
           end do
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:35:1:
           p(j)=suma
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:37:1:
        end do
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:39:1:
      write (9,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:40:1:
      write (9,*) 'Puntos de los equipos'
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:41:1:
      write (9,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:43:1:
      write (9,*) p(j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:46:1:
  end program
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:8:12:
    real:: A(i,j), p(j),u(j)
            1
Error: Variable ‘i’ cannot appear in the expression at (1)
programa_liga.f90:8:14:
    real:: A(i,j), p(j),u(j)
              1
Error: Variable ‘j’ cannot appear in the expression at (1)
programa_liga.f90:8:16:
    real:: A(i,j), p(j),u(j)
                1
Error: The module or main program array ‘a’ at (1) must have constant shape
programa_liga.f90:8:20:
    real:: A(i,j), p(j),u(j)
                    1
Error: Variable ‘j’ cannot appear in the expression at (1)
programa_liga.f90:8:22:
    real:: A(i,j), p(j),u(j)
                      1
Error: The module or main program array ‘p’ at (1) must have constant shape
programa_liga.f90:8:25:
    real:: A(i,j), p(j),u(j)
                         1
Error: Variable ‘j’ cannot appear in the expression at (1)
programa_liga.f90:8:27:
    real:: A(i,j), p(j),u(j)
                           1
Error: The module or main program array ‘u’ at (1) must have constant shape
programa_liga.f90:9:3:
    u(3)= (/3.0,1.0,0.0/)
   1
Error: Incompatible ranks 0 and 1 in assignment at (1)
Compilation failed.

After some changes the program is as follows:

Program liga

    Implicit none

        integer :: i,j,suma
        integer, parameter :: N = 4, M = 20
        real:: A(N,M), p(M),u(M)
        real:: u(3)
        u= (/3.0,1.0,0.0/)

        open (UNIT = 8, FILE = 'partidos.dat')
        open (UNIT=9, FILE= 'puntos.dat')


        read (8,*)
        read (8,*)
        read (8,*)

            do i= 2,N

            read (8,*) A(i,j) 

            end do 

            do i=1,N

              suma=0.0 

               do j= 1,3 

                 suma=suma+(A(i,j)*u(j))= p(j)

               end do 

               p(j)=suma

            end do 

       write (9,*) 
       write (9,*) 'Puntos de los equipos'
       write (9,*)

       write (9,*) p(j)


end program

The errors are:

   gfortran -Wall -o "programa_liga" "programa_liga.f90" (in directory: /Users/joaquinbenavente/Desktop/TFS)
programa_liga.f90:2:1:
  Program liga
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:4:1:
   Implicit none
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:6:1:
    integer :: i,j,suma
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:7:1:
    integer, parameter :: N = 4, M = 20
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:8:1:
    real:: A(N,M), p(M),u(M)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:9:1:
    real:: u(3)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:9:11:
    real:: u(3)
           1
Error: Symbol ‘u’ at (1) already has basic type of REAL
programa_liga.f90:10:1:
    u= (/3.0,1.0,0.0/)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:12:1:
    open (UNIT = 8, FILE = 'partidos.dat')
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:13:1:
    open (UNIT=9, FILE= 'puntos.dat')
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:16:1:
    read (8,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:17:1:
    read (8,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:18:1:
    read (8,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:20:1:
     do i= 2,N
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:22:1:
     read (8,*) A(i,j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:24:1:
        end do
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:26:1:
        do i=1,N
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:28:1:
          suma=0.0
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:30:1:
           do j= 1,3
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:32:1:
             suma=suma+(A(i,j)*u(j))= p(j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:32:12:
             suma=suma+(A(i,j)*u(j))= p(j)
            1
Error: Unclassifiable statement at (1)
programa_liga.f90:34:1:
           end do
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:36:1:
           p(j)=suma
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:38:1:
        end do
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:40:1:
      write (9,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:41:1:
      write (9,*) 'Puntos de los equipos'
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:42:1:
      write (9,*)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:44:1:
      write (9,*) p(j)
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:47:1:
  end program
 1
Warning: Nonconforming tab character at (1) [-Wtabs]
programa_liga.f90:10:3:
    u= (/3.0,1.0,0.0/)
   1
Error: Different shape for array assignment at (1) on dimension 1 (20 and 3)
Compilation failed.
    
asked by Joaquin 03.02.2017 в 12:23
source

1 answer

1

Original source

The tabulator character is not part of the fortran standard.

Compiling with -Wall assumes the following:

  

-Wall

     
    

Enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. This currently includes -Waliasing, -Wampersand, -Wconversion, -Wsurprising, -Wc-binding-type, -Wintrinsics-std, -Wno-tabs , -Wintrinsic-shadow, -Wline-truncation, - Wtarget-lifetime, -Wreal-q-constant and -Wunused.

  

The flag highlighted in black implies that the compiler does not allow to use tabs in the coding.

To silence this error try compiling with -Wtabs

We go with the errors:

    integer :: i,j,suma
    integer, parameter :: N = 4, M = 20
    real:: A(i,j), p(j),u(j)

What dimensions will the arrays A , p and u have? The arrays should have known dimensions and certainly can not come from variables unless they are declared as parameter :

    real:: A(4,20), p(20),u(20)

    real:: A(N,M), p(M),u(M)

Another problem with arrays:

    u(3)= (/3.0,1.0,0.0/)

If just in the previous line you have declared u as a vector ... Why do you try to assign 3 values to one of the positions of the vector? That will not work. You have to initialize u with the set of values (without using indexes):

    real:: u(3)
    u= (/3.0,1.0,0.0/)

Another detail:

suma=suma+(A(i,j)*u(j))= p(j)

This instruction is wrong ... Do you want to assign p(j) the value of suma ? Otherwise? Is that last assignment an operator of addition, subtraction, ...? It is difficult to put code at this point because I do not finish understanding what you intend to do with p(j) at this point.

New errors:

  • you're redeclaiming u

    real:: A(N,M), p(M),u(M)
    real:: u(3)
    
  • The sum is still wrong

    suma=suma+(A(i,j)*u(j))= p(j)
    
  • If you want to assign the value of suma to p(j) then you should do something like this:

    suma=suma+(A(i,j)*u(j))
    p(j) = suma
    
        
    answered by 03.02.2017 в 12:43