Silverfrost Forums

Welcome to our forums

Problem in fortran!

26 Aug 2014 3:29 #14506

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 realele(0:nx+1) !sea level elevation realvel(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.

27 Aug 2014 1:20 #14509

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

27 Aug 2014 2:34 #14511

Thnx 😃

27 Aug 2014 11:51 #14520

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 'Real8' for about 17 digits precision. append 'd0' to the number which is then interpreted as REAL8 , 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
27 Aug 2014 1:52 #14523

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 REAL8 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 real8 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

27 Aug 2014 3:57 #14525

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

27 Aug 2014 5:54 #14526

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

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

Eddie

27 Aug 2014 10:51 #14527

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

Please login to reply.