Debian Codegraph @

lib/Ifeffit/Parameter.pm

raw
1 package Ifeffit::Parameter; # -*- cperl -*-
2 ######################################################################
3 ## Ifeffit::Path: Object oriented GDS parameter manipulation
4 ##
5 ## Artemis is copyright (c) 2001-2010 Bruce Ravel
6 ## [email protected]
7 ## http://feff.phys.washington.edu/~ravel/
8 ##
9 ## Ifeffit is copyright (c) 1992-2010 Matt Newville
10 ## [email protected]
11 ## http://cars.uchicago.edu/~newville/ifeffit/
12 ##
13 ## The latest version of Artemis can always be found at
14 ## http://feff.phys.washington.edu/~ravel/software/exafs
15 ##
16 ## -------------------------------------------------------------------
17 ## All rights reserved. This program is free software; you can
18 ## redistribute it and/or modify it provided that the above notice
19 ## of copyright, these terms of use, and the disclaimer of
20 ## warranty below appear in the source code and documentation, and
21 ## that none of the names of The Naval Research Laboratory, The
22 ## University of Chicago, University of Washington, or the authors
23 ## appear in advertising or endorsement of works derived from this
24 ## software without specific prior written permission from all
25 ## parties.
26 ##
27 ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29 ## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31 ## HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32 ## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34 ## OTHER DEALINGS IN THIS SOFTWARE.
35 ## -------------------------------------------------------------------
36 ######################################################################
37
38 use strict;
39 use vars qw($VERSION $cvs_info $module_version @ISA @EXPORT @EXPORT_OK);
40
41 require Exporter;
42
43 @ISA = qw(Exporter AutoLoader Ifeffit::Tools);
44 # Items to export into callers namespace by default. Note: do not export
45 # names by default without a very good reason. Use EXPORT_OK instead.
46 # Do not simply export all your public functions/methods/constants.
47 @EXPORT_OK = qw();
48
49 $VERSION = "0.8.014";
50
51 sub new {
52 my $classname = shift;
53 my $self = {};
54 $self->{index} = "";
55 $self->{type} = "";
56 $self->{name} = "";
57 $self->{mathexp} = "";
58 $self->{note} = "";
59 $self->{autonote} = 1;
60 $self->{bestfit} = "";
61 $self->{error} = "";
62 $self->{modified} = 0;
63 $self->{highlight} = 0;
64 bless($self, $classname);
65 $self -> make(@_);
66 return $self;
67 };
68
69 sub make {
70 my $self = shift;
71 unless ($#_ % 2) {
72 my $this = (caller(0))[3];
73 die "$this error!\n";
74 return;
75 };
76 while (@_) {
77 my $att = lc(shift);
78 my $value = shift;
79 $self->{$att} = $value unless (($self->{type} eq 'sep') and not ($att =~ /(mathexp|note)/));
80 if (($att eq 'type') and ($value eq 'sep')) {
81 $self->{name} = "";
82 $self->{mathexp} = "-" x 25;;
83 $self->{bestfit} = "";
84 $self->{modified} = 0;
85 $self->{note} = "separator";
86 $self->{autonote} = 0;
87 };
88 };
89 };
90
91 ## generic methods for returning attributes of the parameter object
92 sub Index { return shift->{index} };
93 sub type { return shift->{type} };
94 sub name {
95 my $self = shift;
96 return ($self->type eq 'sep') ? "-" x 7 : $self->{name};
97 };
98 sub mathexp { return shift->{mathexp} };
99 sub note { return shift->{note} };
100 sub autonote { return shift->{autonote} };
101 sub bestfit { return shift->{bestfit} };
102 sub error { return shift->{error} };
103 sub modified { return shift->{modified} };
104
105 ## return (and optionally set) the current highlighting code
106 sub highlight {
107 my $self = shift;
108 $self->{highlight}+= $_[0] if $_[0];
109 return $self->{highlight};
110 };
111
112
113
114 sub write_gsd {
115 my $self = shift;
116 my $use_bestfit = shift;
117 my $name = $self -> name;
118 my $choice = $self -> type;
119 my $value = ($use_bestfit and ($choice eq 'guess') and (not $self->modified)) ?
120 $self -> bestfit :
121 $self -> mathexp;
122 my $string;
123 return "" if ($choice eq 'skip');
124 return "" if ($choice eq 'eval');
125 $value =~ s/^\s+//; # strip leading blanks
126 $value =~ s/\s+$//; # strip trailing blanks
127 ($value = "0") if ($value =~ /^\s*$/);
128 ($choice = "def") if ($choice eq "restrain");
129 ($value = $1) if ($value =~ /([-+]?[\d\.]+)\s*\(.*\)/);
130 $string = sprintf("%-5s %s = %s\n", $choice, $name, $value);
131 return $string;
132 };
133
134
135
136 1;
137 __END__