|
Fortran::F90Namelist::Group - Parse F90 namelist groups and export in different formats |
Fortran::F90Namelist::Group - Parse F90 namelist groups and export in different formats
use Fortran::F90Namelist::Group; my $nlgrp = Fortran::F90Namelist::Group->new() or die "Couldn't get object\n";
$nlgrp->parse(<<' HERE');
&runpars
x=2,y=3
vec1=1,2,3
vec2=3*1.3
/
&more_runpars
z=7
vec1=0,1,2,3
/
HERE
Read from file:
# Read namelist group from file `some_lists.nml': $nlgrp->parse(file => 't/files/some_lists.nml');
# Read namelist group from file handle open(my $fh , "< t/files/some_lists.nml") or die "Couldn't get file handle\n"; $nlgrp->parse(file => $fh); # or open(NLGROUP , "< t/files/some_lists.nml") or die "Couldn't get file handle\n"; $nlgrp->parse(file => \*NLGROUP);
# Print names of all namelists in file `start.in'
$nlgrp->parse(file => 't/files/start.in') or die "Couldn't parse\n";
print join(" ", $nlgrp->names), "\n";
Extract or merge namelists from group and return Fortran::F90Namelist object:
my $nl_1 = $nlgrp->first(); # Extract first namelist from group my $nl_3 = $nlgrp->nth(3); # Extract 4th namelist from group my $nl_all = $nlgrp->flatten(); # Flatten all namelists into one
Write namelist group:
# Write namelist group in F90 namelist format print $nlgrp->output();
# Write namelist as IDL structure print $nlgrp->output(format => 'idl');
Fortran::F90Namelist::Group is a module for parsing Fortran90 namelist groups into an internal format based on Fortran::F90Namelist, and re-exporting in different formats. Parsing is done by Fortran::F90Namelist, see the documentation of that module for more details.
Additional options are:
undef for an empty group.
This allows to write:
while (my $nl = $nlgrp->pop()) {
print $nl->name(), " has ", $nl->nslots(), "slots\n";
}
$nlgrp->parse(file => 't/files/some_lists.nml'); my $nl = $nlgrp->flatten();
is another way of doing
my $nl = Fortran::F90Namelist->new();
$nl->parse(file => 't/files/some_lists.nml',
all => 1 );
Options are:
The hash method returns a hash reference of the following structure:
{ namelist1 => { var1 => { 'value' => [ value1, value2, ..],
'type' => numerical_type,
'stype' => "type string"
},
var2 => { 'value' => [ value1, value2, ..],
'type' => numerical_type
'stype' => "type string"
},
...
},
namelist2 => { var1 => { 'value' => [ value1, value2, ..],
'type' => numerical_type,
'stype' => "type string"
},
...
},
...
}
Here numerical_type is a number identifying each data type, while stype is a textual description of the given data type.
E.g.
{ 'hydro_init_pars' => { 'u0' => { 'value' => [ 0., -3.141593, 0. ],
'type' => 6,
'stype' => 'single precision float'
},
'u1' => { 'value' => [ 0., 0., 0.],
'type' => 6,
'stype' => 'single precision float'
},
},
'density_init_pars' => { 'rho0' => { 'value' => [ -2.78 ],
'type' => 6,
'stype' => 'single precision float'
},
'ilnrho' => { 'value' => [ 3 ],
'type' => 4,
'stype' => 'integer'
},
},
}
Note: This is currently just the internal format used to represent
namelists and can thus change in the future.
In particular the type numbers should not be considered to be stable
between releases.
Wolfgang Dobler <Wolfgang.Dobler@kis.uni-freiburg.de>
Copyright (c) 2007, Wolfgang Dobler <Wolfgang.Dobler@kis.uni-freiburg.de>. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same conditions as Perl or under the GNU General Public License, version 2 or later.
Use completely at your own risk.
|
Fortran::F90Namelist::Group - Parse F90 namelist groups and export in different formats |