The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Astro::XSPEC::Model::Parse - parse an XSPEC model.dat file

VERSION

version 0.01

SYNOPSIS

  $parser = Astro::XSPEC::Model::Parse->new(
    model => { start => \&model_start_handler,
               end   => \&model_end_handler,
             },
    par => \&par_handler,
    args => \%myargs,
  );

  $parser->parse_file( $file );

DESCRIPTION

Astro::XSPEC::Model::Parse is an event driver parser for XSPEC model.dat model description files.

Methods

new
  $parser = Astro::XSPEC::Model::Parse->new( %args );

This constructs a new parser. It takes the following optional named arguments:

model

This is a hash which may contain one or more of the following optional entries:

start

This is a subroutine reference which will be called for each model before the model's parameters are parsed.

end

This is a subroutine reference which will be called for each model, after the model's parameters are parsed.

par

This is a subroutine reference which will be called for each parameter.

args

This is a hashref containing arbitrary data which will be passed to each handler.

norm

If a model is additive and this parameter is true, add a norm parameter to the model.

parse_file
  $parser->parse_file( $filename );

Parses the file associated with the specified filename.

Handlers

Handlers are called at the beginning and end of each model definition and for each model parameter. A handler is called only if defined. Hashes passed to the handler are not reused and may be stashed.

model handlers

The model handlers are called as

  handler( $event, \%event_info, \%user_args );

where $event is either start or end, %event_info contains the event specific information, and %user_args is the %args parameter passed in the parser constructor.

%event_info may contain one or more of the following fields:

name

model name

npars

number of parameters

elo, ehi

the low and high energies for which the model is valid

subname

the name of the subroutine

type

the type of model (add, mul, mix, or con, or acn)

calcvar

true if the model variances are calculated by the model function

forcecalc

true if if the model should be forced to perform a calculation for each spectrum.

parameter handler

The parameter handler is called as

  handler( \%par_info, \%user_args );

where %par_info contains the parameter specific information, and %user_args is the %args parameter passed in the parser constructor.

The fields in %par_info will vary depending upon the type of parameter. The possible fields are:

type
name
units
value
hard_min, hard_max
soft_min, soft_max
delta
periodic

LICENSE AND COPYRIGHT

Copyright (c) 2010 The Smithsonian Astrophysical Observatory

Astro::XSPEC::Model::Parse is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

AUTHOR

Diab Jerius <djerius@cpan.org>