string segmentation problem : upcase_trim_adjustl

:-) Hello .
;-) This time a problem ( extracted form Meso-NH ) with strings routines .

We try to manage the string read in NAMELIST in a reproducible form, so we use this kind or routine/statement :

UPCASE(TRIM(ADJUSTL(HSTATU)))

No problem with g95/gfortran/ifort

bug_pgi> g95 test_upcase_trim_adjustl.f90 -o test_upcase_trim_adjustl
bug_pgi> test_upcase_trim_adjustl
TEST :: sub_upcase_trim_adjustl
HSTATU >>>> keep <<<<
YSTATU = UPCASE(TRIM(ADJUSTL(HSTATU))) >>>>KEEP###<<<<
PASSED :: sub_upcase_trim_adjustl

With pgf90 ( 10.9 ) Segmentation Violation ( ;-) in French in the text )

bug_pgi> pgf90 test_upcase_trim_adjustl.f90 -o test_upcase_trim_adjustl
bug_pgi> test_upcase_trim_adjustl
TEST :: sub_upcase_trim_adjustl
Erreur de segmentation

Here is the test code “test_upcase_trim_adjustl.f90”

Bye Juan

MODULE mode_sub                                                                         

CONTAINS
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  FUNCTION UPCASE(HSTRING)                                                                                 

    IMPLICIT NONE 
    CHARACTER(LEN=*)            :: HSTRING
    CHARACTER(LEN=LEN(HSTRING)) :: UPCASE 

    INTEGER :: JC
    INTEGER, PARAMETER :: IAMIN = IACHAR("a")
    INTEGER, PARAMETER :: IAMAJ = IACHAR("A")

    DO JC=1,LEN(HSTRING)
       IF (HSTRING(JC:JC) >= "a" .AND. HSTRING(JC:JC) <= "z") THEN
          UPCASE(JC:JC) = ACHAR(IACHAR(HSTRING(JC:JC)) - IAMIN + IAMAJ)
       ELSE                                                            
          UPCASE(JC:JC) = HSTRING(JC:JC)                               
       END IF                                                          
    END DO                                                             

  END FUNCTION UPCASE

  SUBROUTINE sub_upcase_trim_adjustl(HSTATU)

    IMPLICIT NONE 
    CHARACTER(LEN=*),  INTENT(IN)  :: HSTATU  ! status for the closed file

    ! local variable 
    CHARACTER(LEN=LEN(HSTATU))     :: YSTATU

    YSTATU = UPCASE(TRIM(ADJUSTL(HSTATU))) // "######"
    print*,"  HSTATU                                 >>>>" , HSTATU ,"<<<<"
    print*,"  YSTATU = UPCASE(TRIM(ADJUSTL(HSTATU))) >>>>" , YSTATU ,"<<<<"


  END SUBROUTINE sub_upcase_trim_adjustl

END MODULE mode_sub
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
PROGRAM test_upcase_trim_adjustl

  USE mode_sub

  IMPLICIT NONE

  CHARACTER(LEN=7)     :: CSTATU

  CSTATU = " keep "

  print*," TEST   :: sub_upcase_trim_adjustl  "
  CALL sub_upcase_trim_adjustl(CSTATU)
  print*," PASSED :: sub_upcase_trim_adjustl  " ; print*

END PROGRAM test_upcase_trim_adjustl

Hello,

we recreated your behavior with the current compilers, and we have
logged it as TPR 17413. The line it fails on is

YSTATU = UPCASE(TRIM(ADJUSTL(HSTATU)))

regards,
dave

:-) Thank you Dave .

Bye

A work-around is to rearrange the upcase call,e .g.,

TRIM(UPCASE(ADJUSTL(HSTATU)))


regards,
dave

TPR 17413 has been fixed as of the 12.10 release.

thanks,
dave