## Problem in fortran

## Problem in fortran

(OP)

I am getting this error while compiling on fortran 95!

C:\..\first.F95(21) : error 199 - Array VEL appears in this expression as rank 1, but was declared as rank 2

C:\..\first.F95(21) : error 199 - Array VEL appears in this expression as rank 1, but was declared as rank 2

Here is the code:

PROGRAM first

real,parameter:: g=9.8 !Value of g

real,parameter:: rhoref=1028.0 !reference density

real,parameter:: pi=3.14 !pi

integer,parameter:: nx=11 !horizontal

integer,parameter:: nz=5 !vertical

real:: wspeed !wind speed

integer:: k !grid index

character(3):: txt

real::ele(0:nx+1) !sea level elevation

real::vel(0:nz+1,0:nx+1) !vertical velocity

do k=0, nx+1

if(k>50) then

ele(k)=1

else

ele(k)=0

end if

end do

open(10,file='result.txt',form='formatted', status='unknown')

write(10,*) (vel(k),k=1,nx)

ENDPROGRAM first

Any help is appreciated.

C:\..\first.F95(21) : error 199 - Array VEL appears in this expression as rank 1, but was declared as rank 2

C:\..\first.F95(21) : error 199 - Array VEL appears in this expression as rank 1, but was declared as rank 2

Here is the code:

PROGRAM first

real,parameter:: g=9.8 !Value of g

real,parameter:: rhoref=1028.0 !reference density

real,parameter:: pi=3.14 !pi

integer,parameter:: nx=11 !horizontal

integer,parameter:: nz=5 !vertical

real:: wspeed !wind speed

integer:: k !grid index

character(3):: txt

real::ele(0:nx+1) !sea level elevation

real::vel(0:nz+1,0:nx+1) !vertical velocity

do k=0, nx+1

if(k>50) then

ele(k)=1

else

ele(k)=0

end if

end do

open(10,file='result.txt',form='formatted', status='unknown')

write(10,*) (vel(k),k=1,nx)

ENDPROGRAM first

Any help is appreciated.

## RE: Problem in fortran

Array VEL appears in this expression as rank 1, but was declared as rank 2You declared the array as 2-dimensional

## CODE

## CODE

## RE: Problem in fortran

## RE: Problem in fortran

are you new to two-dimensional matrices, too?

don't let not knowing Fortran confuse you. How do you use/write a 2-D matrix with pencil and paper?

## RE: Problem in fortran

## RE: Problem in fortran

A 2D matrix is addressed like this A(i,j), right?...same in Fortran; at least when you are talking about addressing individual entries. Fortran can do stuff like matlab, by the way, in that an entire array (or part of it) can be manipulated in one shot...there are plenty of tutorial on line, please google it.

But the main point as addressed in the very first reply was that you have declared a two-dimensional arrays, yet, you are addressing it using only one-dimension...where is the other one? Or, maybe you should go back and declare your array to be just one-dimensional, in the first place.

## RE: Problem in fortran

I know that i declared 2-d arrays and after that I am using 1-d array. My only question is that what changes should I bring in this command "write(10,*) (vel(k),k=1,nx)". Because I am not getting into syntax of write command.

Once again thnx :)

## RE: Problem in fortran

Whenever you are ready to write 'vel'...there will be choices and you are going to have to learn about formatting. But anyway, it will similar to a single array, but with nested implicit loops: write(0,*) ((vel(i,j), j=0,x+1), i=0,nx+1)

## RE: Problem in fortran