Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

passing arguments like in OPEN calling convention

cecio
Novice
798 Views

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')

0 Kudos
7 Replies
TimP
Honored Contributor III
798 Views
Are you asking about keyword and optional arguments (literally the header for the corresponding sections in Metcalf, Reid, Cohen and Chivers, Sleightholme books)?
0 Kudos
cecio
Novice
798 Views
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
0 Kudos
lklawrie
Beginner
798 Views
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.
0 Kudos
cecio
Novice
798 Views
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....
0 Kudos
jimdempseyatthecove
Honored Contributor III
798 Views
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
0 Kudos
Steven_L_Intel1
Employee
798 Views
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=.
0 Kudos
lklawrie
Beginner
798 Views
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.
0 Kudos
Reply