ifc 7.1/RH 7.2: Passing string to char array functions

ifc 7.1/RH 7.2: Passing string to char array functions

Hi,

I am using 7.1 and I've inherited legacy code that has functions that take in Characater X(*) as argument -- see StrCopy() below. In many places in the code, function is called like StrCopy(SomeVariable, 'My Literal String'C).

It works with Sun Workshop Pro on Solaris, IBM's VisualFortran on AIX etc. I am wondering if there is a quick fix for these kind of things in ifc 7.1 -- may be as an option?

Otherwise, I have to keep converting Strings to Arrays before passing it on to functions. The code is too voluminous (and there are many functions like this) :-(

By the way, I am a Fortran newbie.

Cheers
- vsb

-----------------------------------------
PROGRAM AR_FN_PASS_LITERAL
INTEGER temp
CHARACTER RECEPTOR(15)
CHARACTER SOURCE(15)
INTEGER StrCopy
CHARACTER (LEN=15) :: String = 'Hello World'C

Call Str2Arr(SOURCE, 'Hello World'C)
temp = StrCopy(RECEPTOR, SOURCE)
PRINT *, 'length ', temp
PRINT *, 'source ', SOURCE
PRINT *, 'target ', RECEPTOR

END PROGRAM

INTEGER FUNCTION StrCopy( Out, In )
Implicit None
Character Out(*), In(*)
Integer Pos
Pos = 1
Do While( In(Pos).ne.Char(0) )
Out(Pos) = In(Pos)
Pos = Pos + 1
End Do
Out(Pos) = Char(0)
StrCopy = Pos - 1
Return
End ! of StrCopy

Subroutine Str2Arr( Out, In )
Implicit None
Character(LEN=*) :: In
Character Out(*)
Integer Pos
Pos = 1
Do While( In(Pos:Pos).ne.Char(0) )
Out(Pos) = In(Pos:Pos)
Pos = Pos + 1
End Do
Out(Pos) = Char(0)
Return
End

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

What about this "doesn't work"? It seems to work fine in Intel Fortran 8.1. I don't have 7.1 on Linux easily available to check.

Retired 12/31/2016

When I try to do "StrCopy(SomeVariable, 'My Literal String'C)." instead of using the kludge function to do a Str2Array first, the compiled code at run time gives an error that "2nd dummy argument is an array, but actual argument is a scalar." Perfectly valid error, but I am trying to see if this error can be avoided without code changes because legacy code is too voluminous and 7.1 is the compiler standard we have to follow -- unfortunately, 8.1 is not an option for me.

Thanks!

Interesting. I'm not that familiar with 7.1 - but I would not expect to see that sort of error (which wasn't in your example) unless one of the run-time checking options (-Cx) were enabled.

An alternative, I suppose, is to make the routine a generic with one specific procedure that takes a character argument as the source.

Steve

Retired 12/31/2016

Steve,

Thanks! If I don't use -C option, it simply gives an error at run-time saying "Address Error". No other information is specified.

I normally compile with "-g -C -O0 -Vaxlib"

Leave a Comment

Please sign in to add a comment. Not a member? Join today