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 

Overriding Intrinsic Functions in Fortran 95

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



Joined: 19 Mar 2008
Posts: 29

PostPosted: Mon Jun 08, 2020 9:33 pm    Post subject: Overriding Intrinsic Functions in Fortran 95 Reply with quote

I am converting a set of old Fortran (77?) files to Fortran 95. In the old Fortran, there are 2 variables TRIM and RANGE which are Intrinsic functions n Fortran 95. Is there any way to suppress the use of the TRIM and RANGE functions in Fortran 95 in order to use TRIM and RANGE as variables in the new Fortran 95 code? Thank you.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1884

PostPosted: Tue Jun 09, 2020 2:23 am    Post subject: Reply with quote

Why is a "conversion" needed for variables with the same name as F95 intrinsic functions? Fortran has no reserved names, and user-created names supplant intrinsic names (and even keywords). In the following example, trim and range are variables, whereas nint, int, log10 and abs remain intrinsic functions:

Code:
subroutine sub(x, trim, range)
trim = nint(x*10.0)*0.1
range = int(log10(abs(x)))
return
end


Last edited by mecej4 on Tue Jun 09, 2020 2:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
AKS



Joined: 19 Mar 2008
Posts: 29

PostPosted: Tue Jun 09, 2020 2:40 pm    Post subject: Reserved words Reply with quote

Perhaps I jumped to conclusions, but Fortran 95 definitely did not like me using TRIM and RANGE as variables from the previous code.Thanks for your quick response.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1884

PostPosted: Tue Jun 09, 2020 2:54 pm    Post subject: Reply with quote

It will be necessary to see the statements in question that the compiler "did not like", and the actual error messages issued.

Better yet, provide the complete source code of the program unit that the compiler rejected.

For an independent discussion of this issue by a member of the Fortran Standard J3/WG5 committee, please see https://stevelionel.com/drfortran/2020/06/07/doctor-fortran-in-no-reserve/ .
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Tue Jun 09, 2020 8:44 pm    Post subject: Reply with quote

mecej4 shind some lights upon my poor soul here !

Quote:
Fortran has no reserved names,

you learn something new everyday ! ..... was this an F90 or F95 'innovation' ? I thought F77 it was forbidden to use 'reserved' names.

Quote:
and user-created names supplant intrinsic names


I'd personally call that a dangerously devilish(take note Dan !) development !

Quote:
(and even keywords)


you mean one could use a variable, for example, called 'subroutine' !!! ???

Presumeably, in such cases, IMPLICIT NONE is a very big no-no ?
_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1884

PostPosted: Wed Jun 10, 2020 12:33 am    Post subject: Reply with quote

That no keywords are reserved is an attribute for which Fortran is notorious.

Just for laughs, this is a valid but deplorable program in free form:

Code:
program program
real real
integer integer
character character
!
do integer = 1, 5
   real = integer
   character = achar (integer + 64)
   print *,integer, real, character
end do
end program


So is the following version, now in fixed form:

Code:
      programprogram;realreal;integerinteger;charactercharacter
      dointeger=1,5;real=integer;character=achar(integer+64)
      print*,integer,real,character;enddo;endprogram


If you take the additional step of replacing semicolons by newlines+6 blanks, the old Salford/Silverfrost FTN77 compiler will also compile this program.
Back to top
View user's profile Send private message
John-Silver



Joined: 30 Jul 2013
Posts: 1520
Location: Aerospace Valley

PostPosted: Fri Jun 12, 2020 10:17 am    Post subject: Reply with quote

good grief ! that's A-mazing !

But whatif you had something like

Do DoVariable = 1,10

and wrote it as:

DoDoVariable=1,10

would the DoDo confuse it (would it detect x2 Do statements I wanda and a variable called Variable ?
_________________
''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... Smile "
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2551
Location: Sydney

PostPosted: Mon Jun 15, 2020 2:37 pm    Post subject: Reply with quote

John,

perhaps more confusing ?
Code:
      complex a, dodovariable
      integer dovariable
      dodovariable = (1,10)
      dodovariable =  1,10
      a = dovariable + dodovariable
      end do
      end
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1884

PostPosted: Tue Jun 23, 2020 9:42 am    Post subject: Reply with quote

And then, for extra credit, find a Fortran-aware editor that correctly indents the DO loop in John C's example code!
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 -> General 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