passing arguments like in OPEN calling convention

passing arguments like in OPEN calling convention

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

8 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Are you asking about keyword and optional arguments (literally the header for the corresponding sections in Metcalf, Reid, Cohen and Chivers, Sleightholme books)?

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

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.

Linda

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....

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

www.quickthreadprogramming.com

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=.

Steve - Intel Developer Support

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.

Linda

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui