- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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' )
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As a workaround, I used '"~/a.txt"' instead of '~/a.txt'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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' )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much IanH! It works!
I did not notice such option for namelist write.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page