I need a portable function/subroutine to locate the position of the last non-blank character in a string. I've found two options: LEN_TRIM
and LNBLNK
. However, different compilers seem to have different standards. The official documentation for the following compilers suggests that LEN_TRIM is part of the Fortran 95 standard on the following platforms:
However, it appears that nothing is guaranteed on compilers released before the F95 standard. My experience has been that older compilers might specify either LEN_TRIM
or LNBLNK
, but not necessarily both. My solution has been to use preprocessor conditionals:
#ifdef USE_LEN_TRIM
iNameLen = LEN_TRIM(cabase)
iExtLen = LEN_TRIM(caext)
#else
iNameLen = LNBLNK(cabase)
iExtLen = LNBLNK(caext)
#endif
and then pass -DUSE_LEN_TRIM
to the preprocessor. However, I am not a big fan of preprocessor conditionals & extra compile-time flags. Do you have any suggestions for a portable (before the Fortran 95 standard) function that locate the position of the last non-blank character in a string?