diff --git a/src/LIB/SURCOUCHE/src/fmwrit_ll.f90 b/src/LIB/SURCOUCHE/src/fmwrit_ll.f90 index 11331883570c80f569dd0396c5a857e62cb2ef02..56299ed082821fde079659190f5ca3632c0fdf17 100644 --- a/src/LIB/SURCOUCHE/src/fmwrit_ll.f90 +++ b/src/LIB/SURCOUCHE/src/fmwrit_ll.f90 @@ -310,7 +310,7 @@ CONTAINS CHARACTER(LEN=*),OPTIONAL,INTENT(IN) :: HDAD_NAME ! CHARACTER(LEN=:),ALLOCATABLE :: YDAD_NAME - INTEGER :: ILEN + INTEGER :: ILEN,ILEN2 ! CALL PRINT_MSG(NVERB_DEBUG,'IO','IO_WRITE_HEADER','called for file '//TRIM(TPFILE%CNAME)) ! @@ -331,12 +331,23 @@ CONTAINS CALL IO_WRITE_FIELD(TPFILE,'MY_NAME', TPFILE%CNAME) ! IF ( ASSOCIATED(TPFILE%TDADFILE) ) THEN - ALLOCATE(CHARACTER(LEN=MAX(NFILENAMELGTMAXLFI,LEN_TRIM(TPFILE%TDADFILE%CNAME))) :: YDAD_NAME) - YDAD_NAME(:) = TPFILE%TDADFILE%CNAME + ILEN = LEN_TRIM(TPFILE%TDADFILE%CNAME) + ILEN2 = MAX(NFILENAMELGTMAXLFI,ILEN) + ALLOCATE(CHARACTER(LEN=ILEN2) :: YDAD_NAME) + IF(ILEN>0) THEN + YDAD_NAME(1:ILEN) = TPFILE%TDADFILE%CNAME(1:ILEN) + ELSE + YDAD_NAME(:) = ' ' + END IF ELSE IF (PRESENT(HDAD_NAME)) THEN - ILEN = LEN_TRIM(HDAD_NAME) - ALLOCATE(CHARACTER(LEN=MAX(NFILENAMELGTMAXLFI,ILEN)) :: YDAD_NAME) - YDAD_NAME(:) = HDAD_NAME + ILEN = LEN_TRIM(HDAD_NAME) + ILEN2 = MAX(NFILENAMELGTMAXLFI,ILEN) + ALLOCATE(CHARACTER(LEN=ILEN2) :: YDAD_NAME) + IF(ILEN>0) THEN + YDAD_NAME(1:ILEN) = HDAD_NAME(1:ILEN) + ELSE + YDAD_NAME(:) = ' ' + END IF ELSE CALL PRINT_MSG(NVERB_DEBUG,'IO','IO_WRITE_HEADER',TRIM(TPFILE%CNAME)// & ': TPFILE%TDADFILE not associated and HDAD_NAME not provided')