Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in fortran

Status
Not open for further replies.

awais980

Programmer
Aug 25, 2014
5
PK
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.
 
It's exactly wkat the error message says:
Array VEL appears in this expression as rank 1, but was declared as rank 2

You declared the array as 2-dimensional
Code:
real :: vel(0:nz+1, 0:nx+1)
but then you try it to use as 1-dimensional
Code:
write(10,*) (vel(k), k=1,nx)
 
As i am new to fortran, so kindly tell me that how to write it as 2 dimension?
 
are you new to arrays, too?
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?
 
In matlab we simply put values like this e.g x=1 2 3,2 4 5; But how to write it in fortran. I am totally new to fortran and i am trying to understand the index at this stage.
 
Nobody is talking matlab, I asked "how do you do it with pencil and paper?"

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.
 
salgerman, thnx for reply :)
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 :)
 
This is though...without know exactly what you are trying to do. The thing, I don't know what you are trying to write, if you have not even assigned a single value to "vel"...is this the full program? or just part of it? or, did you mean to write "(ele(k), k=1,nx)", in the first place? 'cause that would work, but you are missing 0 and nx+1 indexes.

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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top