siegel@scivax.stsci.EDU ("HOWARD SIEGEL") (02/11/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 I hate to say this but..... R T F M!!! From the Programming In VAX FORTRAN (AA-D034D-TE) section 6.2.1.6: A character constant is a string of printable ASCII characters enclosed in apostrophes. A character constants has the form: 'c1c2c3c4...cn' where: c is a printable character. The length of the character constant is the number of characters between the apostrophes... The length of a character constant must be in the range 1 to 2000. This explicitly states that there must be at least one character between the apostrophes. This has been true since I started using VAXen way back under VMS 2.x! >What the REAL problem is, is that FORTRAN character variables always have >fixed length; if you say RED = 'HI' it really gets padded to RED = 'HI ' >(since you declared RED as CHARACTER*8). Thus, you cannot have zero-length >character variables. This is only partially correct. The length of the character constant is exactly the number of chars between the apostrophes (with appropriate exceptions for getting the apostrophe character into a character constant as described in the manual). The 'problem' refered to is also documented in section 7.3. Whenever a character variable is assigned a value, if the length of the character expression (constant or variable) is longer than the destination variable, it is truncated; if the length of the char expression is shorter, it is padded on the right with spaces. This has also been true for as long as I can remember. However it is possible to get a character variable of zero length. You can use a substring expression which has zero length (ie. RED(1:0)). Also, if you pass this type of string to a subroutine for an argument that has been declared as a "Passed-length character argument" (char*(*)), then the subroutine will have a zero length character string. You could also use the dynamic string subroutines (STR$xxx) in the run time library. I have not used these routines myself so I can not comment on how well the documentation is or exactly how to use the routines. +-----------------------------------------+------------------------------------+ ! Howard Siegel - TRW, Inc. ! ! ! ! "I am quite sure that you could ! ! ARPA: siegel@scivax.arpa ! elevate an earwig to the level ! ! USnail: One Space Park ! of of a nuclear scientist, but ! ! MS. O2/2751 ! it would still be a very stupid ! ! Redondo Beach, Ca. 90278 ! thing to do!" ! ! AT&T: 213/535-5083 ! ! +-----------------------------------------+------------------------------------+ ------