[comp.os.vms] FORTRAN singularity

CURLEY@WHARTON.UPENN.EDU ("Curley, Robert F.") (01/24/88)

I tripped over the following this week (VMS 4.6, FORTRAN 4.71-271)
------------------------------------------------------------------------
$TYPE TEST.FOR
	CHARACTER*8 RED
	RED = ''
	END

$ FORTRAN TEST
%FORT-E-ZERLENSTR, Zero-length string 
 	[RED = ''] in module TEST$MAIN at line 2
%FORT-F-MISSDEL, Missing operator or delimiter symbol 
 	[RED = ''] in module TEST$MAIN at line 2
%FORT-F-ENDNOOBJ, DRA7:[CURLEY.WORKING]TEST.FOR;1 completed with 2 diagnostics-
 object deleted
-----------------------------------------------------------------------
Colorado TSC said that there are no zero length strings permitted in
FORTRAN.


.__. ._ _.._  ..._ ___ _... .. ... _._. .._ __  _.. .  .__ ...__ .... .__. __.
PPPPP   EEEEEE N    N N    N !Robert F. Curley        Curley@Wharton.UPENN.edu
P    P  E      NN   N NN   N !Division of Medical Physics
PPPPP   EEEE   N N  N N N  N !Department of Radiation Oncology
P       E      N  N N N  N N !University of Pennsylvania
P       E      N   NN N   NN !P.O. Box 7806
P       EEEEEE N    N N    N !Philadelphia, PA 19101             (215)662-3083
.__. ._ _.._  ..._ ___ _... .. ... _._. .._ __  _.. .  .__ ...__ .... .__. __.

-------

CURLEY@WHARTON.UPENN.EDU ("Curley, Robert F.") (01/24/88)

I tripped over the following this week (VMS 4.6, FORTRAN 4.71-271)
------------------------------------------------------------------------
$TYPE TEST.FOR
	CHARACTER*8 RED
	RED = ''
	END

$ FORTRAN TEST
%FORT-E-ZERLENSTR, Zero-length string 
 	[RED = ''] in module TEST$MAIN at line 2
%FORT-F-MISSDEL, Missing operator or delimiter symbol 
 	[RED = ''] in module TEST$MAIN at line 2
%FORT-F-ENDNOOBJ, DRA7:[CURLEY.WORKING]TEST.FOR;1 completed with 2 diagnostics-
 object deleted
-----------------------------------------------------------------------
Colorado TSC said that there are no zero length strings permitted in
FORTRAN.


__. ._ _.._  ..._ ___ _... .. ... _._. .._ __  _.. .  .__ ...__ .... .__. __.
PPPPP   EEEEEE N    N N    N !Robert F. Curley        Curley@Wharton.UPENN.edu
P    P  E      NN   N NN   N !Division of Medical Physics
PPPPP   EEEE   N N  N N N  N !Department of Radiation Oncology
P       E      N  N N N  N N !University of Pennsylvania
P       E      N   NN N   NN !P.O. Box 7806
P       EEEEEE N    N N    N !Philadelphia, PA 19101             (215)662-3083
__. ._ _.._  ..._ ___ _... .. ... _._. .._ __  _.. .  .__ ...__ .... .__. __.

-------

gil@icus.UUCP (Gil Kloepfer Jr.) (02/08/88)

In article <8802061416.AA15860@ucbvax.Berkeley.EDU> CURLEY@WHARTON.UPENN.EDU ("Curley, Robert F.") writes:
>
>I tripped over the following this week (VMS 4.6, FORTRAN 4.71-271)
>------------------------------------------------------------------------
>$TYPE TEST.FOR
>	CHARACTER*8 RED
>	RED = ''
>	END
>
>$ FORTRAN TEST
>%FORT-E-ZERLENSTR, Zero-length string 
> 	[RED = ''] in module TEST$MAIN at line 2
>%FORT-F-MISSDEL, Missing operator or delimiter symbol 
> 	[RED = ''] in module TEST$MAIN at line 2
>%FORT-F-ENDNOOBJ, DRA7:[CURLEY.WORKING]TEST.FOR;1 completed with 2 diagnostics-
> object deleted
>-----------------------------------------------------------------------
>Colorado TSC said that there are no zero length strings permitted in
>FORTRAN.

This is correct.

The reason for this is because FORTRAN only has fixed-length strings.  The
fact that you assign a shorter string constant to a character variable is
really a convenience and not a language feature.  In effect, FORTRAN pads
the string in any case with blanks, so for the example above, all the
following statements are equivalent:

	RED=' '
	RED='  '
	RED='   '
	RED='    '  (etc.  You get the idea...)

If you want to give the string a "length" so to speak, the way I have been
doing it is to use a group of subroutines which looks back from the end of
the character variable until it finds a non-blank character or the beginning
of the string.  It then returns that position in the string, and that is the
"length", or usable length of the string.  As I did, you can write a bunch
of C-like subroutines for string manipulation.

Note also (important!) that the VAX FORTRAN LEN() function returns the
_declared_ length of the string.  This means that no matter what you assigned
to RED in the example above, the number returned by LEN would be 5.

This is a very important concept to get straight since many programmers get
frustrated by character strings, and begin using arrays of "BYTE"'s as
character strings.  This is OK, except that moving BYTE arrays is inefficient
when compared to the simple assignment function of character variables (I'm
not sure on this, but it would seem logical that the developers of the VAX
FORTRAN compiler took advantage of the string move INSTRUCTION of the
VAX when handling string moves, etc).  If asked what my preference was:
use BYTE arrays of CHARACTER variables for character strings, I would choose
the latter without a thought.

Hope this helps many.  FORTRAN was not originally designed to handle character
strings at all, and thus many people tend to doubt that the more recent versions
of FORTRAN and some extended FORTRANs can actually handle character manipulation
well, if at all.  It does, indeed, function well when you understand its
merits and limitations.

+====================================+========================================+
| Gil Kloepfer, Jr.                  | Net-Address:                           |
| Senior Programmer                  | {boulder,ihnp4,talcott}!icus!gil       |
| Bowne Management Systems, Inc.     | Voice:  Home: (516) 968-6860           |
| 235 E. Jericho Turnpike            |         Office: (516) 248-6840 x796    |
| Mineola, New York  11501           | Internet: gil@icus.UUCP                | 
+====================================+========================================+
| Disclaimer: My employers know I'm right, but will never admit to it...      |
+=============================================================================+

art@ccelsn.ARPA (Art McClinton (703)883-6356) (02/09/88)

	 "Curley, Robert F." <CURLEY@wharton.upenn.edu>
	I tripped over the following this week (VMS 4.6, FORTRAN 4.71-271)
	$TYPE TEST.FOR
		CHARACTER*8 RED
		RED = ''
		END
	
	$ FORTRAN TEST
	%FORT-E-ZERLENSTR, Zero-length string 
	-----------------------------------------------------------------------
	Colorado TSC said that there are no zero length strings permitted in
	FORTRAN.
	
	-------
	
Yes Bob, the TSC is correct.   Fortran does not allow a null character 
string.  It resulted in our not using the character variable in several
of our projects.  However, even if it did allow a null string, the
statement RED='' would result in RED being set to 8 blanks.  To set
RED to a single character A, one would use the statement RED(1:1)='A'.
*
*---Art
*
*Arthur T. McClinton Jr.     ARPA: art@mitre.arpa
*Mitre Corporation           Phone: 703-883-6356
*7525 Colshire Drive         Internal Mitre: ART@MWVMS or M10319@MWVM
*McLean, Va. 22102-3481      DCS: MCCLINTON
*
* I apologize for the presently non-replyable return addresses.  Hope to
* fix that soon.