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 

Assigning array elements (Fortran)

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



Joined: 05 Jul 2007
Posts: 10

PostPosted: Wed Dec 03, 2008 12:07 pm    Post subject: Assigning array elements (Fortran) Reply with quote

I am having a problem getting array elements assigned. I am first trying to set all array elements to zero. The relevant code is:

SUBROUTINE SOLVER(N_COMPS,MAX_PANS,ALPHA,U,N_OUTER,
& VECT_POINTS_PERP,PANEL_VECTA,DIST_POINTS,A,V_PERP,VTAN,
& GAMMA,N_PTS,TOT_PTS)
!
IMPLICIT NONE
!
INTEGER :: I, J
INTEGER, INTENT(IN) :: N_COMPS,MAX_PANS, TOT_PTS

REAL*8 :: A(N_COMPS*(MAX_PANS+1),TOT_PTS-N_COMPS)

REAL*8 :: U_NORM((MAX_PANS*3)+N_COMPS)
!
! Initialise arrays
DO I = 1, N_COMPS*(MAX_PANS+1)
DO J = 1, TOT_PTS-N_COMPS
A(I,J) = 0.0
ENDDO
ENDDO

DO I = 1, (MAX_PANS*3)+N_COMPS
U_NORM(I) = 0.0
ENDDO

When I use Checkmate to debug the code, the 'A' array has all elements set to 0.0 correctly, but the 'U_NORM' array has a random assortment of: 0.0, 'Invalid floating point number', 'Undefined', or a very small number (e.g. 2.9e-291).

I cannot see why this is occurring. Can anyone shed any light?
Back to top
View user's profile Send private message
IanLambley



Joined: 17 Dec 2006
Posts: 490
Location: Sunderland

PostPosted: Wed Dec 03, 2008 1:08 pm    Post subject: Reply with quote

First if you are setting whole arrays to zero, or any other single value, then you can simply use

A=0
U_norm=0

Secondly, try putting =0d0 to force use of a real*8 zero, especially as you have used IMPLICIT NONE

Regards

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



Joined: 05 Jul 2007
Posts: 10

PostPosted: Wed Dec 03, 2008 1:35 pm    Post subject: Reply with quote

Thanks for the tip in setting a whole array to a single value (although I was only using that as an example - I get the same results when actually trying to set the array elements to calculated values further down in the code).

I have tried using =0d0, but it makes no difference at all.

I have just tried compiling and debugging on an old compiler I have (which I cannot use commerically), and it sets all values to 0.0 as I thought it should, which suggests that the code is fine. I have also tried debugging on a 32 bit system rather than my standard 64 bit system, but again it does not make any difference at all, and I'm getting increasingly frustrated!
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7928
Location: Salford, UK

PostPosted: Wed Dec 03, 2008 3:06 pm    Post subject: Reply with quote

This code works OK for me but I have had to use my own input values.

The arrays A and U_NORM have sizes that require a back-handed calculation to get the sizes of the input arrays and this is probably where things are going wrong. The size (i.e. shape) of the two dimensional array A must match in the main program and the subroutine (strictly the first dimension only for a 2-D array).

The alternative is to use Fortran 90 assumed shape arrays.
Back to top
View user's profile Send private message AIM Address
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Thu Dec 04, 2008 12:07 am    Post subject: Reply with quote

You are asking for a lot of problems when defining the array dimension as you have. It may be legal fortran 90+, although I don't expect it is.
Why use such a messy coding technique ?

REAL*8 :: A(N_COMPS*(MAX_PANS+1),TOT_PTS-N_COMPS)
REAL*8 :: U_NORM((MAX_PANS*3)+N_COMPS)

My solution would be to transfer the dimensions in the argument list (fortran 77) or use implied array sizes, as Paul has suggested.
If, as I suspect, the array A is not dimensioned as you imply in the calling routine, then calculate the dimensions before you call.

In the calling routine:-
na1 = N_COMPS*(MAX_PANS+1)
na2 = TOT_PTS-N_COMPS ! never negative ?
nu = (MAX_PANS*3)+N_COMPS
!
call SOLVER (N_COMPS, MAX_PANS, ALPHA, U, N_OUTER,
& VECT_POINTS_PERP, PANEL_VECTA, DIST_POINTS, A, V_PERP, VTAN,
& GAMMA, N_PTS, TOT_PTS, na1, na2, nu)


In the routine SOLVER, use

REAL*8 A(na1,na2) ! dummy argument
REAL*8 U_NORM(nu) ! local automatic array ?

! zero with
A = 0
U_NORM = 0

should all work with all 90+ compilers.

You have checked any of the dimensions are -ve ?
I'm sure that the array dimensions are of use elsewhere in the routines.
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