Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

fortran error: Unterminated character constant beginning at (1)?

I want to calculate the length of a big string in fortran 90. i have written the following program. the program runs okay till a length of 126 charchters (that is it gives me the length of the string on the terminal) but as soon as i add the 127th character it gives me this funny error message.(Error:Unterminated character constant beginning at (1))

PROGRAM

CHARACTER::CT*500

INTEGER::LENGTH

CT="315c4eeaa8b5f8aaf9174145bf43e1784b8fa....(around 300 characters in the sstring)"

LENGTH=LEN_TRIM(CT)

WRITE(*,*)LENGTH

END

so whats the problem? is it that the len_trim function cant take more than 126 chars? how do i calculate the string length?

Update:

in c++ there are inbuilt functions to calculate the string length. (like strlen)

is there something similar in fortran?

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    The maximum length of a character sting depends on the specific compiler that you have.

    For instance, I found out (the hard way) that the maximum length of a character string in Open Watcom was 256. On the other hand GFortran does not have such a limitation (I am regularly using strings of 8192 bytes to emulate formatted read from an input file that is opened as binary, despite being formatted with variable length records. Reading data in 8192 bytes length is order of magnitude faster than formatted read, one only needs to be wary of the last block in the file, as it usually would be lass than 8192 bytes long)

    That the value you have is so close to 128 (i.e. 2^7) may indicate that you have limitations that could be based on your compiler being a front end to a compiler written in another language (as opposed to a native compiler), that you have each of the characters using 2 bytes (as opposed to one, like you have Unicode as a default).

    Len_trim is an intrinsic function that does return the length of the string, disregarding any trailing blanks. It is meant to work as long as your compiler implementation does support string that are long enough for your purpose.

  • ?
    Lv 4
    5 years ago

    Fortran Len_trim

Still have questions? Get your answers by asking now.