From: Saji Hameed Date: 2012-04-04T15:09:52+09:00 Subject: Fortran namelists with Ruby --f46d042c647b5e0bc404bcd44515 Content-Type: text/plain; charset=UTF-8 For those interested in manipulating fortran namelists with ruby, checkout https://github.com/sajinh/fortran-namelist It is a very early stage of work and bugs may be present! questions/bugs to saji@u-aizu.ac.jp Usage: see below saji require './lib/nml' # parse an existing namelist nml = NML_Reader.read(nml_file) # 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 = File.new("namelist.wps.asia","w") NML_Writer >> outfile outfile.close -- Saji N Hameed, ARC-ENV, Center for Advanced Information Science and Technology, University of Aizu, Tsuruga, Ikki-machi, Aizuwakamatsu-shi, Fukushima 965-8580, Japan Tel: +81242 37-2736 Fax:+81242 37-2760 email: saji@u-aizu.ac.jp url: http://www.u-aizu.ac.jp bib: http://www.researcherid.com/rid/B-9188-2009 --f46d042c647b5e0bc404bcd44515 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
For those interested in manipulating fortran namelists with ruby,
ch= eckout https://githu= b.com/sajinh/fortran-namelist

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

=C2=A0questions/bugs to saji@u-aiz= u.ac.jp
=C2=A0 Usage: see below

saji

require './lib/nml' =20 # parse an existing namelist
nml =3D NML_Reader.read(nml_file) # 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'

=C2=A0share =3D 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=3Dshare.keep(:wrf_core, :max_dom, :start_date) # del(*args) deletes specified variables of # a particular group
share=3Dshare.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 =3D NML_Group.create(:share) =20 # add group variables, these can be new hashes # or modified NV hashes from the previous manipulation
nshare << share=20 nshare << {:a =3D> 1}=20 # << operations can be nested
nshare << share << {:a =3D> 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 =20 # Write to a file or other object supporting puts
outfile =3D File.new("nam= elist.wps.asia","w") NML_Writer >> outfile outfile.close

--

Saji N Hameed,
ARC-ENV, Cen= ter for Advanced Information Science and Technology,
University of Aizu,= Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,
Japan =C2=A0 =C2=A0 =C2=A0 =C2=A0
Tel: +81242 37-2736
Fax:+81242 37-2760=C2=A0email: saji@= u-aizu.ac.jp
=C2=A0url: http://www.u-aizu.ac.jp
=C2=A0bib: http://www.researcherid.com/rid/B-9188-2009
--f46d042c647b5e0bc404bcd44515--