What is error in this fortran program?

user3705273

I am writing following fortran 90 program and compiling with GNU Fortran Compiler. However, I am getting some errors that I can't resolve. Can someone explain me where I am going wrong?

PROGRAM FILE1
IMPLICIT NONE

INTEGER:: status,a,b,c,i,j

a=5
b=6
c=1

REAL,ALLOCATABLE,DIMENSION (:,:) :: arr1

ALLOCATE (arr1(a,b))

DO i=1,a,1
    DO j=1,b,1
        arr1(i,j)=c
        c=c+1
    END DO
END DO

DO i=1,a,1
    DO j=1,b,1
        WRITE (*,100,ADVANCE=NO) arr1(i,j)
        100 FORMAT (1X,I4.1)
    END DO
        WRITE (*,110)
        110 FORMAT ('',/)
END DO

DEALLOCATE(arr1)

END PROGRAM

I got several errors, e.g. in statement REAL,ALLOCATABLE,DIMENSION (:,:) :: arr1 Error: Unexpected data declaration statement at (1). I checked syntax from several sources, but no luck. There is error in statement WRITE (*,100,ADVANCE=NO) arr1(i,j) too. Can someone comment?

Bahman

The posted code has a couple of issues:

  1. you need to define all your variables before you execute any other statement.

    a=5
    b=6
    c=1
    

should come after your last variable definition:

REAL,ALLOCATABLE,DIMENSION (:,:) :: arr1
  1. You need to quote NO in the WRITE statement:

    WRITE (*,100,ADVANCE="NO") arr1(i,j)
    
  2. Since you are writing a REAL value, you need to give a floating point format in such as f or g

    100 FORMAT (1X,f7.3)
    

The working code would be:

PROGRAM FILE1
IMPLICIT NONE

INTEGER:: status,a,b,c,i,j

REAL,ALLOCATABLE,DIMENSION (:,:) :: arr1

a=5
b=6
c=1

ALLOCATE (arr1(a,b))

DO i=1,a,1
    DO j=1,b,1
        arr1(i,j)=c
        c=c+1
    END DO
END DO

DO i=1,a,1
    DO j=1,b,1
        WRITE (*,100,ADVANCE="NO") arr1(i,j)
        100 FORMAT (1X,f7.3)
    END DO
        WRITE (*,110)
        110 FORMAT ('',/)
END DO

DEALLOCATE(arr1)

END PROGRAM

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to stop a fortran program abnormally

Fortran memory allocation does not give an error, but the program is killed by OS at initialization

Output of a fortran program into a variable

What is the meaning of (/ ... /) in Fortran

Module or main program array must have constant shape error in Fortran

What is the point of BLOCK in Fortran?

What is the meaning of arguments in the arguments in this pre-1977 fortran program?

What does "error: stray ‘\344’ in program" means?

what are the considerations for pointers/copies for OMP parallelized fortran program

What is this strange error in my c program?

What is causing a parse error in this program?

What is the error in this object oriented program?

Error linking fortran subroutine into c++ program

What is error in this C program?

Can anyone explain what is the error in the following program?

Errors in very simple fortran program

What is the error in this python program?

Fortran compiler for mac to read program

What causes run time error in the following program?

What are the possible causes of "Abnormal Program Termination" error in a C Program?

Program failing to write to a file in FORTRAN

What's the error in my program?

What's the best way to terminate a program on error?

Fortran: pipe to program

In the following pl sql program what is the error ? Is it a compilation error?

Fortran program giving a wrong output?

What is the proper way to catch an error and halt a program?

what is the error in the below c program-0001?

Unable to run this program. What is the error?