Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
공지
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 토론

ifx namelist: character string has gone after ~

tkdhss111
초보자
761 조회수

Hi, I am not a Fortran expert by any means but have been searching for a solution to a particular problem that I'm having and have not had any success in finding a solution. Any help or feedback would be much appreciated.

 

Problem: character string has gone after ~  in namelist read

 

! test_nml.f90

program test_nml
implicit none
type t_ty
  character(10) :: a = '~/a.txt'
  character(10) :: b = '~/b.txt'
end type
integer u

type(t_ty) t

namelist /mynml/ t

print mynml

open ( u, file = 'test.nml' )
write ( u, nml = mynml )
close ( u )

t%a = 'NA'
t%b = 'NA'

open ( u, file = 'test.nml' )
read ( u, nml = mynml )
close ( u )

print mynml

end program

!=============================
! Outputs
!-------------------------------------------
! ifx test_nml.f90 && ./a.out
! &MYNML
! T%A = ~/a.txt ,
! T%B = ~/b.txt
! /
! &MYNML
! T%A = ~ ,                                   (<- character string has gone after ~)
! T%B = NA                                  (<- Not available)
! /
!
!-----------------------------------------
! ifx --version
! ifx (IFX) 2024.2.1 20240711
!-----------------------------------------
! OS:
! Ubuntu 24.04.1 LTS

0 포인트
1 솔루션
IanH
명예로운 기여자 III
627 조회수

Just as for list directed input, a bare slash terminates namelist input there and then.

Character objects need to be delimited to generally survive being written and read by namelist statements.

 

write ( u, nml = mynml, delim = 'quote' )

원본 게시물의 솔루션 보기

3 응답
tkdhss111
초보자
660 조회수

As a workaround, I used  '"~/a.txt"' instead of  '~/a.txt'.

0 포인트
IanH
명예로운 기여자 III
628 조회수

Just as for list directed input, a bare slash terminates namelist input there and then.

Character objects need to be delimited to generally survive being written and read by namelist statements.

 

write ( u, nml = mynml, delim = 'quote' )
tkdhss111
초보자
564 조회수

Thank you very much IanH! It works!

I did not notice such option for namelist write.

응답