Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Problem in fortran

Problem in fortran

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:
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
end if
end do

open(10,file='result.txt',form='formatted', status='unknown')
write(10,*) (vel(k),k=1,nx)

Any help is appreciated.

RE: Problem in fortran

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


real :: vel(0:nz+1, 0:nx+1) 
but then you try it to use as 1-dimensional


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

RE: Problem in fortran

As i am new to fortran, so kindly tell me that how to write it as 2 dimension?

RE: Problem in fortran

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?

RE: Problem in fortran

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.

RE: Problem in fortran

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.

RE: Problem in fortran

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 :)

RE: Problem in fortran

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" 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)

RE: Problem in fortran

Thnx salgerman. I have got your point :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close