|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mike.smartcam
Joined: 02 Aug 2014 Posts: 40 Location: Lancashire, United Kingdom
|
Posted: Wed Dec 03, 2014 4:19 pm Post subject: Array variables |
|
|
The following code was originally written for the Watcom compiler and I assume worked ok:
Code: | SUBROUTINE RECTANG(I)
IMPLICIT NONE
COMMON T1,N,NM_N,M,NM_M,FN,MI,FS,MF,NF,NI,NM_NI,NM_MI,NIF,MIF,TF
INTEGER MI(20,20),NI(20),FS(50,30),MIF(20,20),NIF(20)
INTEGER NF(30),MF(20,30),TF(40)
DOUBLE PRECISION N(30),M(20,30)
CHARACTER *40 NM_N(30),NM_M(30),FN(50)*30,T1(40)
CHARACTER *40 NM_NI(20),NM_MI(20)
COMMON /POCK/P,PNI,PI,NM_P,NM_PNI,NM_PI,PF,PNIF,PIF
CHARACTER *40 NM_P(10),NM_PNI(3),NM_PI
INTEGER PI(2,31),PNI(2,3),PF(2,31,10),PNIF(2,3),PIF(2,31)
DOUBLE PRECISION P(2,31,10)
DOUBLE PRECISION LENGTH,WIDTH,C_RAD,PT_MAX
CHARACTER *60 CP
DOUBLE PRECISION L1,L2,PIE,R_L,APH_R,HP,DTEMP
INTEGER I,J1,J2,J3
PRINT*,'SUBROUTINE RECTANG'
HP(L1,L2) = DSQRT(L1*L1+L2*L2)
PIE = DACOS(-1D0)
PNI(I,2) = 8
PNIF(I,2) =2
PNI(I,3) = 1
PNIF(I,3) =2 |
As you can see the variable 'HP' is defined without any array parameters yet in the code it is clearly used as an array variable.
The Silverfrost compiler objects to the code, does any one have any information which may resolve the problem please? _________________ Regards
Mike |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Wed Dec 03, 2014 5:43 pm Post subject: |
|
|
No, the code looks like it has been corrupted.
Look for the places where HP is used (presumably without indexes).
If HP is an array then it needs a DIMENSION and its indexes ought to be integer values.
My guess is that it will be used as a scalar and that it should appear as a scalar in the assignment. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Wed Dec 03, 2014 10:29 pm Post subject: |
|
|
Mike,
There has been a similar discussion recently here:
http://forums.silverfrost.com/viewtopic.php?t=2955
There is a chance that your HP is a statement function. It is a bit unusual that there is a PRINT first, but Watcom is a law unto itself, and perhaps HP means 'hypotenuse' or 'hypotenuse (by) Pythagorus' L1 and L2 are DOUBLE PRECISION so unlikely to be array subscripts, don't you agree?
Eddie |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Wed Dec 03, 2014 11:06 pm Post subject: |
|
|
Indeed, HP appears to be a "statement function". One could guess that someone trying to troubleshoot the program added a print statement at the beginning of the subroutine executable statements, but made a slip.
Just move the PRINT statement down one line (blank lines do not count). |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Dec 04, 2014 7:52 pm Post subject: |
|
|
Statement function for calculating a hypotenuse. Just move the print statement as suggested.
With all these kinds of errors you can get a list of what variables are in the code using /LIST /DUMP. This will produce a listing file showing you that it is a function not a variable.
There was a time when obtaining a variable dump with the code listing was a standard procedure but it seems to not be a popular debugging technique now. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Fri Dec 05, 2014 6:32 am Post subject: |
|
|
I'm completely confused as to why you all want to move the PRINT statement down 1 line !
It's just there to say 'Here starteth the routine' , probably writing to the ternìminal in the good old days of screen and file output.
Keep it where it is I say.
Need to trace where the function is defined though :O) |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Fri Dec 05, 2014 6:42 am Post subject: |
|
|
The statement function HP = must proceed executable statements
Code: | SUBROUTINE RECTANG(I)
IMPLICIT NONE
COMMON T1,N,NM_N,M,NM_M,FN,MI,FS,MF,NF,NI,NM_NI,NM_MI,NIF,MIF,TF
INTEGER MI(20,20),NI(20),FS(50,30),MIF(20,20),NIF(20)
INTEGER NF(30),MF(20,30),TF(40)
DOUBLE PRECISION N(30),M(20,30)
CHARACTER *40 NM_N(30),NM_M(30),FN(50)*30,T1(40)
CHARACTER *40 NM_NI(20),NM_MI(20)
COMMON /POCK/P,PNI,PI,NM_P,NM_PNI,NM_PI,PF,PNIF,PIF
CHARACTER *40 NM_P(10),NM_PNI(3),NM_PI
INTEGER PI(2,31),PNI(2,3),PF(2,31,10),PNIF(2,3),PIF(2,31)
DOUBLE PRECISION P(2,31,10)
DOUBLE PRECISION LENGTH,WIDTH,C_RAD,PT_MAX
CHARACTER *60 CP
DOUBLE PRECISION L1,L2,PIE,R_L,APH_R,HP,DTEMP
INTEGER I,J1,J2,J3
HP(L1,L2) = DSQRT(L1*L1+L2*L2) ! statement function
PRINT*,'SUBROUTINE RECTANG'
PIE = DACOS(-1D0)
PNI(I,2) = 8
PNIF(I,2) =2
PNI(I,3) = 1
PNIF(I,3) =2
|
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7925 Location: Salford, UK
|
Posted: Fri Dec 05, 2014 9:04 am Post subject: |
|
|
John-Silver
The point is that this is the definition of the function HP.
It is old Fortran that is depreciated but still works. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Fri Dec 05, 2014 12:47 pm Post subject: |
|
|
The confusion expressed by John Silver reinforces the wisdom of the Fortran 95 standard's authors, when they say (in Section B.2 Obsolescent features: B.2.3, Statement functions): Quote: | Statement functions are subject to a number of non-intuitive restrictions and are a potential source of error since their syntax is easily confused with that of an assignment statement. |
Table 2.1 of the standard shows the order in which statements may appear, and clearly shows that statement functions must come before executable statements. Whether to move the PRINT statement a line down or to move the statement function definition a line up is subject to the programmer's whim, and the compiler will be indifferent regarding which line was moved. |
|
Back to top |
|
|
mike.smartcam
Joined: 02 Aug 2014 Posts: 40 Location: Lancashire, United Kingdom
|
Posted: Fri Dec 05, 2014 1:41 pm Post subject: |
|
|
Thanks to everyone for the information _________________ Regards
Mike |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Fri Dec 05, 2014 4:00 pm Post subject: |
|
|
Just to clear any incorrect conclusions that could be reached from what has been written in this thread, I installed the OpenWatcom F77 compiler on Win32, and ran it on the code posted by Mike.Smartcam. It said:
Code: | Open Watcom FORTRAN 77/32 Optimizing Compiler Version 1.9
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
asf.f(22): *ERR* ST-02 statement function definition appears after first executable statement |
|
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Fri Dec 05, 2014 6:11 pm Post subject: |
|
|
If non-intuitiveness is the criterion to discard anything, perhaps we should dispense with most programming languages!
In my view, part of the problem is that as a language that occupies a specialist niche, Fortran isn't taught anymore, and computer science bookshelves aren't full of books on it (like McCracken or Etter), most people who program in it are largely or wholly self-taught, and some worthy programs were in any case written to match the facilities of a particular computer and compiler that now only exists in museums. Slef-teaching is an important part of learning, but it often results in an incomplete knowledge of a particular subject.
There isn't the slightest bit of non-intuitiveness about the local definition of an inline function with its scope limited to the routine it is defined in. I know that sooner or later I may fall over the definition of a statement function, which is why I would always add a comment or two explaining what it is and does.
Incidentally, what is the assumed type of the result of a statement function if IMPLICIT NONE is in use. I imagine that this is an obstacle to its use in recent-standard compliant use.
Eddie |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Fri Dec 05, 2014 10:24 pm Post subject: |
|
|
Quote: | What is the assumed type of the result of a statement function if IMPLICIT NONE is in use? | The function name must appear in a type declaration statement, in the same way that the name of any variable must be given a type. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Fri Dec 05, 2014 10:55 pm Post subject: |
|
|
Would that be
Code: | DOUBLE PRECISION HP
HP(L1,L2) = DSQRT(L1*L1+L2*L2) |
or
Code: | DOUBLE PRECISION HP(L1,L2) = DSQRT(L1*L1+L2*L2) |
(with or without ::)? |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2554 Location: Sydney
|
Posted: Fri Dec 05, 2014 11:26 pm Post subject: |
|
|
If there is a problem with statement functions and so they were made obsolete, then why were contained functions introduced ? Surely the confusion about scope of variables in a statement function is very similar to that for a contained subroutine of function. |
|
Back to top |
|
|
|
|
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
|