Phillip Helbig writes:
> > I have deleted my posting but perhaps I screwed up the source code. I "copied"
> > it by hand from the pc to alpha. The space, tab are parameters:
> >
> > CHARACTER(LEN=1), PARAMETER, PRIVATE :: space = ACHAR(32)
> > CHARACTER(LEN=1), PARAMETER, PRIVATE :: tab = ACHAR(9)
>
> OK.
>
> > my_len_trim = VERIFY(s, space//tab, BACK=.TRUE.)
>
> This looks for the concatenation of space with tab, not for one or the
> other. You need a comma instead of //. Or are you looking for the
> concatenation?
Sorry, but that's wrong on two counts. First, verify never looks for
multi-character sequences. It does take a string as its second
argument, but that string just contains a set of characters to
verify, not a substring to looks for. It wouldn't even actually make
sense as a substring. Note that VERIFY is more related to SCAN than
to INDEX. I'll not copy its definition; look it up.
Second, changing the // to a comma wouldn't even give the right number
or arguments to verify. That's not going to compile at all. Since
verify is elemental, you could change "space//tab" to "(/space,tab/)"
(without the quotes). That would at least mean something, but not
the same thing as intended. The cited code looks just fine as is in
this regard.
On the original question - that basic issue has been discussed here
before. Well, it was talking more about how to duplicate the
functionality of TRIM than how to change it. The change does make
life slightly more "interesting".
If you are using f95, then declare your my_len_trim function to be
PURE, and you can then use it in the specifications of your my_trim
function. With f90, use the same idea, but instead of just using your
my_len_trim, you'll have to write out the expression again using
VERIFY. Something like (untested)...
...
function my_trim(string)
character*(*) :: string
character*(verify(string,space//tab,back=.true.)) :: my_trim
my_trim = string
end function my_trim
I'll assume here that this is in a module and inherits space and tab
from its host; You'd *REALLY* want this to be in a module. All of the
"interesting" part is in the declarations. It would look really silly
to have to write interface body for this; by the time you put the
INTERFACE and END INTERFACE around it, the interface block would be
longer than the function it was describing.
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|