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