[comp.lang.fortran] INDEX

delaney@xn.ll.mit.edu (John R. Delaney) (05/31/91)

A colleague has run into an apparent inconsistency in the way the
underscore character is handled in the FORTRAN 77 which came with SUN's 4.1
OS. That character is acceptable in variable names and can be printed out
if in a string. But the INDEX function acts as if it wasn't there in the
same strings.

Is this a well-know problem or are we experiencing some sort of local
quirk?

Thanks in advance,

John

martelli@cadlab.sublink.ORG (Alex Martelli) (06/04/91)

delaney@xn.ll.mit.edu (John R. Delaney) writes:
:A colleague has run into an apparent inconsistency in the way the
:underscore character is handled in the FORTRAN 77 which came with SUN's 4.1
:OS. That character is acceptable in variable names and can be printed out
:if in a string. But the INDEX function acts as if it wasn't there in the
:same strings.
:
:Is this a well-know problem or are we experiencing some sort of local
:quirk?

I think you are experiencing *several* quirks... first, no Fortran 77 compiler
comes with SunOs 4.1 - Sun Fortran is an "unbundled" program, to be purchased
separately.  It would thus be necessary to know about f77's version number -
use 'f77 -V source.f' to see version id's for each compiler pass.  With what
we have, which identifies itself as version 1.3.1, this program:
      PROGRAM PROI
*
      CALL INDEX_CHECK('FIRST_STRING', 'STST')
      CALL INDEX_CHECK('FIRST_STRING', 'ST_ST')
      CALL INDEX_CHECK('SECOND STRING', 'ND ST')
      CALL INDEX_CHECK('SECOND STRING', 'ND_ST')
      STOP
      END

      SUBROUTINE INDEX_CHECK(HAYSTACK, NEEDLE)
      CHARACTER*(*) HAYSTACK,NEEDLE
      WRITE(*,*) 'INDEX(',HAYSTACK,',',NEEDLE,')=',
     .            INDEX(HAYSTACK,NEEDLE)
      RETURN
      END

gives the following, expected output:
INDEX(FIRST_STRING,STST)=  0
INDEX(FIRST_STRING,ST_ST)=  4
INDEX(SECOND STRING,ND ST)=  5
INDEX(SECOND STRING,ND_ST)=  0

Thus, in no sense does INDEX() "act is if [the underline] wasn't there".
What does this program output for you?  What release does -V tell you that
you have?  I suspect that you may have misanalized your problem...
-- 
Alex Martelli - CAD.LAB s.p.a., v. Stalingrado 53, Bologna, Italia
Email: (work:) martelli@cadlab.sublink.org, (home:) alex@am.sublink.org
Phone: (work:) ++39 (51) 371099, (home:) ++39 (51) 250434; 
Fax: ++39 (51) 366964 (work only), Fidonet: 332/407.314 (home only).