Debian Codegraph @

attic/Ifeffit.pm

raw
1 package Ifeffit;
2
3 ## BEGIN {
4 ## push @INC, $ENV{IFEFFIT_DIR} if $ENV{IFEFFIT_DIR};
5 ## }
6
7 require Exporter;
8 require DynaLoader;
9 @ISA = qw(Exporter DynaLoader);
10 @EXPORT = qw(ifeffit);
11 @EXPORT_OK = qw(get_scalar put_scalar get_string put_string
12 get_array put_array get_echo);
13
14 $VERSION = '1.301';
15 bootstrap Ifeffit $VERSION;
16 my $MAX_ARRAY_PTS = 16384;
17
18 sub ifeffit ($) {
19 my @com = split(/\n/, $_[0]);
20 my ($c, $ret) ;
21 foreach $c (@com) {$ret = Ifeffit::iff_exec($c); };
22 return $ret;
23 }
24
25 sub get_scalar ($) {
26 my $ptr = new_Pdbl();
27 my $val = undef;
28 if (Ifeffit::iff_get_scalar($_[0],$ptr) == 0) {
29 $val = Pdbl_value($ptr);
30 }
31 delete_Pdbl($ptr);
32 return $val;
33 }
34
35 sub put_scalar ($$) {
36 return (ifeffit("set $_[0] = $_[1]")) ? undef: $_[1];
37 }
38
39 sub get_string ($) {
40 my $str = " "x512;
41 my $len = Ifeffit::iff_get_string($_[0],$str);
42 return ($len) ? substr($str,0,$len) : " ";
43 }
44
45 sub put_string ($$) {
46 my $inp = $_[0];
47 $inp = "\$".$inp unless ($inp =~ /^(\$)/o);
48 my $str = $_[1];
49 $str = "\"" . $str . "\"" unless ($str =~ /^\".*\"$/);
50 return ifeffit("set $inp = $str");
51 }
52
53 sub get_array ($) { # note the use of MAX_ARRAY_PTS !!!
54 my ($ptr,$npts,$i);
55 my @arr = ();
56 $ptr = new_Parr($MAX_ARRAY_PTS);
57 $npts = Ifeffit::iff_get_array($_[0],$ptr);
58 if ($npts) {
59 for ($i = 0; $i < $npts; $i++) { $arr[$i] = Parr_getitem($ptr,$i);}
60 }
61 delete_Parr($ptr);
62 return @arr;
63 }
64
65 sub put_array ($$) {
66 my $npts = $#{$_[1]} + 1;
67 my ($i,$x,$p_n,$ret,$ptr);
68 if ($npts > $MAX_ARRAY_PTS) { $npts = $MAX_ARRAY_PTS;}
69 $ptr = new_Parr($npts);
70 for ($i = 0; $i < $npts; $i++) { Parr_setitem($ptr, $i, ${$_[1]}[$i]); }
71 $p_n = new_Pint();
72 Pint_assign($p_n, $npts);
73 $ret = Ifeffit::iff_put_array($_[0], $p_n, $ptr);
74 delete_Pint($p_n);
75 delete_Parr($ptr);
76 return $ret;
77 }
78
79 sub get_echo () {
80 my $str = " "x512;
81 my $len = Ifeffit::iff_get_echo($str);
82 return ($len) ? substr($str,0,$len) : " ";
83 }
84
85
86 # INITIALIZATION Code
87 # and get compiled-in parameters for max array size.
88 &ifeffit(" \n");
89 $MAX_ARRAY_PTS = get_scalar("&maxpts");
90
91 #
92
93 1;
94 __END__
95
96 =head1 NAME
97
98 Ifeffit - Perl interface to the IFEFFIT XAFS Analysis library.
99
100 =head1 SYNOPSIS
101
102 use Ifeffit;
103 use Ifeffit qw(put_scalar put_string put_array);
104 use Ifeffit qw(get_scalar get_string get_array);
105
106 my ($kmin, $my_file, $file_type ) = (0.01, "Cu.xmu", "xmu");
107 put_scalar("rbkg", 1.1);
108 put_scalar("kmin", $kmin);
109 put_string("filename", $my_file);
110
111 ifeffit(" read_data($my_file, prefix= my,");
112 ifeffit(" type= $file_type)");
113 ifeffit(" newplot (energy, xmu ) ");
114
115 my $e0 = get_scalar("e0");
116 print "e0 = $e0 , rbkg = " ,get_scalar("rbkg"), "\n";
117
118 =head1 DESCRIPTION
119
120 The Ifeffit Perl Module gives access to the ifeffit library for XAFS
121 analysis. The module provides seven perl functions - B<ifeffit>,
122 B<put_scalar>, B<get_scalar>, B<put_string>, B<get_string>, B<put_array>,
123 and B<get_array>. The B<ifeffit> is always provided (ie, exported by the
124 "use Ifeffit;" pragma), but the other commands must be explicitly imported,
125 as shown above.
126
127 =head2 ifeffit
128
129 The ifeffit function provides the main interface to the ifeffit engine.
130 The character string argument is interpreted as an ifeffit command.
131 Ifeffit returns 0 if a valid command is sent and fully processed, -1 if a
132 partial command has been sent (so that it will be expecting the rest of the
133 command next), 1 if the "quit" command has been sent, and other non-zero
134 valuses on error. The syntax for and meaning of command lines to ifeffit
135 is described in I<The Ifeffit Reference Manual> of the Ifeffit
136 distribution. The syntax for the perl function is
137
138 C<$i = ifeffit("plot(my.x, my.y)");>
139
140 =head2 put_scalar
141
142 This sets the value of a named scalar in the list of ifeffit data.
143 The set value is returned on successful execution. The syntax is
144
145 C<$i = put_scalar("kweight", 2.0);>.
146
147 which is equivalent to
148
149 C<$i = ifeffit("kweight = 2.0");>
150
151 But having a choice seems like the perl way.
152
153 =head2 get_scalar
154
155 This returns the value of a named ifeffit scalar. The syntax is
156
157 C<$value = get_scalar("x");>
158
159 =head2 put_string
160
161 This sets the value of a named ifeffit string. The value is returned
162 on successful execution. The syntax is
163
164 C<$i = put_text("home", "the merry old land of oz");>.
165
166 The same effect could be achieved with the command
167
168 C<$i = ifeffit("set \$home = 'the merry old land of oz'");>.
169
170 but B<put_text> takes care of the icky leading dollar sign, and returns the
171 string instead of a simple exit status.
172
173 =head2 get_string
174
175 This returns the value of a named ifeffit string. The syntax is
176
177 C<$bg = get_string("plot_bg");>
178
179 =head2 put_array
180
181 This copies a perl array of numeric values to an ifeffit array.
182 The syntax is
183
184 C<put_array("my.array",\@array);>
185
186 which creates (or overwrites) the ifeffit array I<my.array>, and fill it
187 with the values of the perl array I<@array>. Note that the B<reference> to
188 the array is passed into B<put_array>, not the whole array itself!
189
190 =head2 get_array
191
192 This gets the values of an ifeffit array of numeric values. The syntax is
193
194 C<@array = get_array("my.array");>
195
196 which will fill the perl array B<@array> with the ifeffit array
197 I<my.array>.
198
199 =head1 REVISION HISTORY
200
201 =over 4
202
203 =item 1.3
204
205 Begin distributing with horae package.
206
207 =item 1.3 (1)
208
209 Force enclosure of string by double quotes in the put_string function.
210 (Bruce Ravel 18 Feb. 2003)
211
212 =back
213
214 =head1 AUTHOR
215
216 Matthew Newville -- [email protected]
217
218 =head1 SEE ALSO
219
220 ifeffit, Ifeffit Reference Manual, perl(1)
221
222 PGPERL, PDL, GNU ReadLine Library
223
224
225 =cut