replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Problem in fortran!
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem in fortran!

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
awais980



Joined: 26 Aug 2014
Posts: 2

PostPosted: Tue Aug 26, 2014 4:29 pm    Post subject: Problem in fortran! Reply with quote

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

I only don't know how to write results in 2 dimensions because i am totally new to Fortran. And I am trying to learn its syntax.
Any help is appreciated.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed Aug 27, 2014 2:20 am    Post subject: Reply with quote

You could try:
write(10,*) (ele(k),k=1,nx)

or

do iz = 1,nz
write(10,*) (vel(iz,k),k=1,nx)
end do
Back to top
View user's profile Send private message
awais980



Joined: 26 Aug 2014
Posts: 2

PostPosted: Wed Aug 27, 2014 3:34 am    Post subject: Reply with quote

Thnx Smile
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 506
Location: Sunderland

PostPosted: Wed Aug 27, 2014 12:51 pm    Post subject: Reply with quote

A few points:-
1. Don't comment the obvious "!Value of g". Use something like "set acceleration due to gravity m/s^2"
2. Gravity is 9.80665m/s^2, generally accepted average value.
3. "Real" uses 4 bytes per number and has only about 7 decimal digits precision, try "Real*8" for about 17 digits precision. append "d0" to the number which is then interpreted as REAL*8 , i.e. g=9.80665d0. There are other ways of achieving these things.
4. Try pi=2d0*asin(1d0) for a more accurate value, again, there are other ways.
Regards
Ian
Back to top
View user's profile Send private message Send e-mail
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed Aug 27, 2014 2:52 pm    Post subject: Reply with quote

Ian,

I feel uncomfortable with your explanation of
REAL*8, PARAMETER :: g=9.80665d0

I can only see 6 figures of accuracy required in your definition of G.

I have used anything from 9.8, 9.81 or 9.807 for my definition of G.

My understanding is there can be considerable variability in the gravitational field strength, so REAL*8 implies a greater uniformity than is typically available.
Apart from the physical properties of G, I agree with the point you are making.
We should certainly be doing better than real,parameter:: pi=3.14 !pi
I typically use
real*8 PI
PI = 4 * atan(1.0d0)
This uses the available F77 intrinsic function

I don't think that FTN95 allows:
real*8, parameter :: PI = 4 * atan (1.0d0)

John
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 506
Location: Sunderland

PostPosted: Wed Aug 27, 2014 4:57 pm    Post subject: Reply with quote

John,
Regarding gravity, according to the International Bureau of Weights and Measures, under the International System of Units (SI), the Earth's standard acceleration due to gravity is 9.80665m/s^2.
I agree that this is only 6 decimal digits, but the point I was making was that it is always better to use REAL*8 in calulations. As awais980 is a new starter in FORTRAN, then it is better for him to start his millions of routines in his libraries to the higher precision rather than have to change when round off errors etc. become a problem.

The ASIN function is available in FTN95 and because of the truncation errors of the trig calculation depending on the precision of the arithmetic, multiplying by 2 rather than 4 should provide a better result bearing in mind that these are stored in binary, the ASIN version would have an additional binary digit of precision. I dont use F77, so I am unaware that the ASIN function does not exist. Alternatively, I may be a raving looney!

Regards
Ian
Back to top
View user's profile Send private message Send e-mail
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Wed Aug 27, 2014 6:54 pm    Post subject: Reply with quote

Is it just me and my Fortran-66 background, but in Fortran-77 was there an intrinsic ATAN that would take both REAL*4 and REAL*8 parameters and give the appropriate type of result, or did one need to use DATAN to take a REAL*8 parameter and give a REAL*8 result?

I still can't bring myself not to use DATAN2 mostly, and DATAN in this context!

Eddie
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Wed Aug 27, 2014 11:51 pm    Post subject: Reply with quote

Ian, your recommendation of using REAL*8 is very good advice for a new user. However, I don't agree with your statement about less precision when multiplying by 4 instead of 2 as all these * do is change the value of the exponent.
I have been doing some work lately comparing marine surveys based on Geoid vs Ellipsoid reference datums. It is surprising how variable the reference geoid surface is. The variation in sea surface level is influenced by varying gravity and changes by up to 2 metres in the bay I am studying.

Eddie, you are correct as generic was not in F77. I felt uncomfortable as I typed F77 intrinsic as well. Before F90 when I was moving code between CDC and mini computers, I always used ZATAN and declared them with the appropriate precision of REAL or REAL*8, so I was keen to take up the generic form when it became available.

John
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group