Fortran namelists with Ruby

For those interested in manipulating fortran namelists with ruby,

It is a very early stage of work and bugs may be present!

questions/bugs to [email protected]
Usage: see below


require ‘./lib/nml’

parse an existing namelist

nml =

returns a hash of hashes with group names

as keys of the second level of hashes

namelist groups can be retrieved by

referencing these keys

# get namelist group '&share'

share = nml[:share]

the return value is of type NV, which is

a Hash extended with the methods <<, del

and keep

<<(args) merges its args with the first key

of the reciever hash

keep(*args) returns a new NV object which

only contains the variables indicated through

args array

 share=share.keep(:wrf_core, :max_dom, :start_date)

del(*args) deletes specified variables of

a particular group

 share=share.del(:wrf_core, :max_dom)

After manipulating namelist groups, write them

to a new namelist

Step 1 - Create a new Namelist Group

 # create a namelist group 'share'
   nshare = NML_Group.create(:share)

 # add group variables, these can be new hashes
 # or modified NV hashes from the previous manipulation
   nshare << share
   nshare << {:a => 1}

# << operations can be nested
  nshare << share << {:a => 1}

Step 2 - Construct a new namelist

# Push namelist groups to NML_Writer using <<
NML_Writer << nshare << ngrid << ungrib << nmet

# Write out to STDOUT
NML_Writer >> STDOUT

# Write to a file or other object supporting puts
outfile ="","w")
NML_Writer >> outfile

Saji N Hameed,
ARC-ENV, Center for Advanced Information Science and Technology,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,

Tel: +81242 37-2736
Fax:+81242 37-2760
email: [email protected]