- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
i need to "unify" source files for some different fortran compiler.
I have written several intermediate routines to interface with different compilers the rigth way.
But.. i have some difference in OPEN calling conventions.
In one compiler i use IOINTENT='BOTH' and in intel i have to use STAUS='OLD'.
I would like to create an intermediate routine for this case too but is there a way in fortran for linux to pass parameters to a routine like in a OPEN call? ( XXX='yyy')
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you asking about keyword and optional arguments (literally the header for the corresponding sections in Metcalf, Reid, Cohen and Chivers, Sleightholme books)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
don't konw that book.....
i'm only searching a way to pass io-specifier-list ( if it is possible...).
Something like this :
.
readonly=1
openformycompiler(UNIT=M90,FILE=CH,ERR=100,ACCESS='DIRECT'',FORM='UNFORMATTED',RECL=ML, readonly)
..
..
function openformycompiler(UNIT=M90,FILE=CH,ERR=100,ACCESS='DIRECT'',FORM='UNFORMATTED',RECL=ML, readonly)
integer*2 readonly
if (readonly=1) then
OPEN(UNIT=M90,FILE=CH,ERR=100,ACCESS='DIRECT' ,READONLY,STATUS='OLD',FORM='UNFORMATTED',RECL=ML)
else
OPEN(UNIT=M90,FILE=CH,ERR=100,ACCESS='DIRECT' ,READWRITE,STATUS='OLD',FORM='UNFORMATTED',RECL=ML)
endif
return
end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I believe you can just "do" this. You need to know the names of the parameters in the subroutine. But if you have:
Subroutine Sub1(Arg1, Arg2, Arg3)
you can call it as:
Call Sub1(Arg1,Arg2,Arg3)
OR
Call Sub1(Arg1=xxx,Arg2=yyy,Arg3=zzz)
or, of course:
Call Sub1(Arg3=xxx,Arg1=yyy,Arg2=zzz)
(Have no idea what happens if you specify one of the parameters twice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks.
trying with:
character*1 chara
call callsub(chara='A')
stop
end
subroutine callsub(chara)
character*1 chara
write(*,*)chara
return
end
if i try compiler give...
call callsub(chara='A')
--------------------------^
error #6632: Keyword arguments are invalid without an explicit interface. [CHARA]
no idea on how to create an interface in this case....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
interface
subroutine callsub(chara)
character*1 chara
end subroutine callsub
end interface
Generally you place the interface into a module (such that it is declared only once), then USE the module in the sources that reference the subroutine.
This module may also have a CONTAINS section that contains the subroutine (or you may choose to have the subroutine located elsewhere, and example of this is the C runtime library functions).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't think this will help you, though. OPEN is not a subroutine, it is a statement. IOINTENT is a nonstandard keyword for OPEN (STATUS is standard). However, STATUS means something different from what I gather IOINTENT means in the other compiler. STATUS is about file existence prior to the OPEN where I assume IOINTENT controls what you're going to do to the file once it is opened - the standard equivalent of that is ACTION='READ' | 'WRITE' | 'READWRITE',
Given that this is syntax, it isn't something you can control with a procedure argument. Conditional compilation may be what you need. But perhaps first see if the other compiler supports ACTION=.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you had used:
character*1 chara
call callsub(chara='A')
stop
contains
subroutine callsub(chara)
character*1 chara
write(*,*)chara
return
end
end
you would have been okay, I think.
Jim gave you the interface statement you would need.
![](/skins/images/C4F7392A5C68ACA60290C9576F107044/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page