Debian Codegraph @

lib/Ifeffit/Path.pm

raw
1 package Ifeffit::Path; # -*- cperl -*-
2 ######################################################################
3 ## Ifeffit::PathDev: Object oriented path/data manipulation for Ifeffit
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 @indeces_used);
40 use constant ETOK=>0.262468292;
41 use File::Copy;
42 use File::Path;
43 use File::Basename;
44 use Text::Wrap;
45 $Text::Wrap::columns = 65;
46 use Ifeffit;
47 ifeffit("\&screen_echo = 0\n");
48 use Ifeffit::Tools;
49 use Ifeffit::FindFile;
50 use Chemistry::Elements qw(get_name get_Z get_symbol);
51 use Math::Round qw(round);
52 my $absorption_exists = (eval "require Xray::Absorption");
53 if ($absorption_exists) {Xray::Absorption->load('Elam')};
54
55 require Exporter;
56
57 @ISA = qw(Exporter AutoLoader Ifeffit::Tools Ifeffit::FindFile);
58 @EXPORT_OK = qw();
59
60 $VERSION = "0.8.014";
61 $cvs_info = '$Id: $ ';
62 $module_version = (split(' ', $cvs_info))[2] || 'pre_release';
63 @indeces_used = ('^^placeholder^^');
64
65 use vars qw($last_plot $last_plot_command);
66 $last_plot = "";
67 $last_plot_command = "";
68
69 my $default = Ifeffit::Path -> new(type=>'data');
70 my $echocmd = \&::Echo;
71 my @done = (" ... done!", 1);
72
73 use vars qw/$thisdir $libdir/;
74 use File::Spec;
75 $thisdir = $Ifeffit::FindFile::thisdir;
76 $libdir = File::Spec->catfile($thisdir, "lib", "artemis");
77
78 my %data_default = (kmin => 2,
79 kmax => 15,
80 dk => 1,
81 k1 => 0,
82 k2 => 0,
83 k3 => 0,
84 karb => "",
85 karb_use => 0,
86 rmin => 1,
87 rmax => 3,
88 dr => 0.1,
89 cormin => 0.25,
90 epsilon_k => '',
91 fit_space => 'R',
92 kwindow => 'Kaiser-Bessel',
93 rwindow => 'Kaiser-Bessel',
94 do_bkg => 'no',
95 use_bkg => 0,
96 data_index=> 0,
97 include => 1,
98 plot => 0,
99 made_diff => 0,
100 pcpath => 'None',
101 pcplot => 'No',
102 pcelem => 'H',
103 pcedge => 'K',
104 is_rec => 0,
105 titles => '',
106 file => '',
107 with_fit => 0,
108 with_res => 0,
109 with_bkg => 0,
110 is_xmu => 0,
111 is_chi => 1,
112 do_bkg => 0,
113 ##fix_chi => 0,
114 );
115
116
117 ## the next two regular expressions are use in the get method to
118 ## recognize the parameters associate with data and with a feff
119 ## calculation
120
121 ##my $data_params_regex = join("|", sort(keys(%data_default)));
122 ## (insert (make-regexp
123 ## '("kmin" "kmax" "dk" "k1" "k2" "k3" "karb" "karb_use" "rmin" "rmax" "dr"
124 ## "cormin" "epsilon_k" "fit_space" "kwindow" "rwindow" "do_bkg"
125 ## "use_bkg" "data_index" "include" "plot" "made_diff"
126 ## "pcpath" "pcplot" "pcelem" "pcedge" "is_rec" "titles" "file"
127 ## "with_fit" "with_res" "with_bkg"
128 ## )))
129 my $data_params_regex =
130 "cormin|d([kr]|ata_index|o_bkg)|epsilon_k|" .
131 "fi(le|t_(diff|space))|i(nclude|s_rec)|" .
132 "k([123]|arb(|_use)|m(ax|in)|window)|made_diff|" .
133 "p(c(e(dge|lem)|p(ath|lot))|lot)|r(m(ax|in)|window)|" .
134 "titles|use_bkg|with_(bkg|fit|res)";
135 ## (insert (make-regexp '("feff.inp" "atoms.inp" "feff.inp" "feff.run"
136 ## "misc.dat" "paths.dat" "files.dat" "path" "intrp")))
137 my $feff_params_regex =
138 "atoms\.inp|f(eff\.(inp|run)|iles\.dat)|intrp|misc\.dat|path(|s\.dat)";
139
140 ## (insert (make-regexp
141 ## '("label" "s02" "e0" "delr" "sigma^2" "ei" "3rd" "4th" "dphase" "k_array"
142 ## "phase_array" "amp_array")))
143 my $path_params_regex =
144 "3rd|4th|amp_array|d(elr|phase)|e[0i]|k_array|label|phase_array|s(02|igma\^2)";
145
146
147
148
149
150 sub new {
151 my $classname = shift;
152 my $self = {};
153
154 $self->{line} = 0; # meta data
155 $self->{type} = '';
156 $self->{from_project} = 0;
157
158 bless($self, $classname);
159 $self -> make(@_);
160 warn "Ifeffit::Path type undefined!\n" unless ($self->{type});
161
162 SWITCH: {
163 ($self->{type} eq 'path') and do {
164 foreach (qw(label s02 e0 delr sigma^2 ei 3rd 4th dphase k_array phase_array amp_array)) {
165 $self->{$_} = '';
166 };
167 $self->{setpath} = 0;
168 $self->{is_ss} = 0;
169 $self->{is_col} = 0;
170 last SWITCH;
171 };
172 ($self->{type} eq 'data') and do {
173 ## foreach (qw(kmin kmax dk kweight rmin rmax dr cormin
174 ## epsilon_k kwindow rwindow do_bkg use_bkg
175 ## pcplot pcelem pcedge fit_space)) {
176 foreach (keys %data_default) {
177 $self->{$_} = $data_default{$_};
178 ##$self->{$_} = (exists $default->{$_}) ? $default->{$_} : $data_default{$_};
179 };
180 last SWITCH;
181 };
182 ($self->{type} eq 'feff') and do {
183 $self->{include} = 1;
184 $self->{linkto} ||= 0;
185 $self->{mode} ||= 0;
186 last SWITCH;
187 };
188 };
189 ## flags for processing chores
190 $self->{do_k} = 1;
191 $self->{do_r} = 1;
192 $self->{do_q} = 1;
193
194 $self->{data_showing} = 'chi';
195
196 ($self->{lab} = $self->{group}) unless (exists $self->{lab} and $self->{lab});
197
198 return $self;
199 };
200
201
202 sub make {
203 my $self = shift;
204 unless ($#_ % 2) {
205 my $this = (caller(0))[3];
206 die "$this error!\n";
207 return;
208 };
209 while (@_) {
210 my $att = lc(shift);
211 my $value = shift;
212 ## worry about unmatched parens and quotation marks among the titles
213 if ($att eq 'titles') {
214 $value =~ s/\"//g;
215 my $string = "";
216 foreach my $l (split(/\n/, $value)) {
217 $l =~ s/\s+$//;
218 ## walk through the title line counting open and closed parens,
219 ## skipping unmatched close parens
220 my $count = 0;
221 foreach my $i (0..length($l)) {
222 ++$count if (substr($l, $i, 1) eq '(');
223 --$count if ($count and (substr($l, $i, 1) eq ')'));
224 };
225 ## close all unmatched parens by appending close_parens to the string
226 $l .= ')' x $count;
227 $string .= $l . $/;
228 };
229 $value = $string;
230 };
231
232 $self->{$att} = $value;
233 ($att eq 'file') and ($self->{type} eq 'path') and ($self->{feff} = $self->{file});
234 ($att eq 'feff') and ($self->{type} eq 'path') and ($self->{file} = $self->{feff});
235 if (($att eq 'path') and ($self->{type} eq 'feff')) {
236 $self->{'atoms.inp'} = File::Spec->catfile($self->{path}, 'atoms.inp');
237 $self->{'feff.inp'} = File::Spec->catfile($self->{path}, 'feff.inp');
238 $self->{'feff.run'} = File::Spec->catfile($self->{path}, 'feff.run');
239 $self->{'misc.dat'} = File::Spec->catfile($self->{path}, 'misc.dat');
240 $self->{'paths.dat'} = File::Spec->catfile($self->{path}, 'paths.dat');
241 (-e File::Spec->catfile($self->{path}, 'path00.dat')) and
242 ($self->{'paths.dat'} = File::Spec->catfile($self->{path}, 'path00.dat'));
243 $self->{'files.dat'} = File::Spec->catfile($self->{path}, 'files.dat');
244 };
245 if (($att eq 'do_xmu') and $value) {
246 $self->{do_xmu} = 1; $self->{do_k} = 1; $self->{do_r} = 1; $self->{do_q} = 1;
247 };
248 if (($att eq 'do_k') and $value) {
249 $self->{do_k} = 1; $self->{do_r} = 1; $self->{do_q} = 1;
250 };
251 if (($att eq 'do_r') and $value) {
252 $self->{do_r} = 1; $self->{do_q} = 1;
253 };
254 if (($att eq 'do_q') and $value) {
255 $self->{do_q} = 1;
256 };
257 if (($self->{type} eq 'feff') and ($att eq 'deg')) {
258 $self->{n} = $value;
259 };
260 if (($self->{type} eq 'feff') and ($att eq 'n')) {
261 $self->{deg} = $value;
262 };
263 if ($self->{type} eq 'path') {
264 foreach my $k (qw(label s02 e0 delr sigma^2 ei 3rd 4th dphase k_array phase_array amp_array)) {
265 $self->{$k} = "" if (not defined($self->{$k}));
266 };
267 };
268
269 #if ($att eq 'sameas') {
270 # $self
271 #};
272 };
273 };
274
275
276 sub SetDefault {
277 my $self = shift;
278 $default -> make(@_);
279 #$default = Ifeffit::Group -> new(@_);
280 };
281
282
283 ## return the data associated with this Path object
284 sub data {
285 my $self = shift;
286 my $data = $self->{id};
287 ($data = $self->{data}) if ($self->{type} =~ /(feff|path)/);
288 ($data = $self->{sameas}) if ($self->{type} =~ /(bkg|diff|fit|res)/);
289 ($data = 'data0') if ($self->{type} eq 'gsd');
290 return $data;
291 };
292
293 sub feff {
294 my $self = shift;
295 my $feff = $self->{id};
296 ($feff = $self->{parent}) if ($self->{type} eq 'path');
297 ($feff = 0) if ($self->{type} =~ /(bkg|diff|gds|fit|res)/);
298 return $feff;
299 };
300
301 sub parent {
302 my $self = shift;
303 return $self->{id} if (($self->{type} eq 'fit') and not $self->{parent});
304 return $self->{parent} if ($self->{type} =~ /(fit|path)/);
305 return 0;
306 };
307
308 ## return the type of this Path object
309 sub type {
310 my $self = shift;
311 if (exists $self->{type}) {
312 return $self->{type}
313 } else {
314 return 0;
315 };
316 };
317
318
319 ## returns true if this data is included in the fit
320 sub included {
321 my $self = shift;
322 return $self->{include};
323 };
324
325
326 ## this method does the hard work of returning the parameter value for
327 ## the objects parentage, when appropriate. For instance, is the kmin
328 ## of a path object is requested, this returns the kmin of the data
329 ## associated with that path. Return 0 is not found.
330
331 ## extend to a list
332 sub get {
333 my $self = shift;
334 my $p = $_[0];
335 my $f = $self->{family};
336 if ($p eq 'include') { # return a paths include value,
337 return $self->{$p} || 0; # not the include value of the data
338
339 } elsif ($p =~ /^bkg/) { # bkg parameters
340 return 0 unless exists $self->{$p};
341 return $self->{$p};
342 # fits have their own FT and fit ranges
343 } elsif (($self->type eq 'fit') and
344 $self->{parent} and
345 ($p =~ /^(d[kr]|k(m(ax|in)|window)|r(m(ax|in)|window))$/) ) {
346 ##(kmin kmax dk kwindow rmin rmax dr rwindow)
347 return $self->{$p};
348 # paths and data can have a file
349 } elsif (($self->type eq 'path') and ($p eq 'file')) {
350 return $self->{$p};
351
352 } elsif ($p =~ /^($data_params_regex)$/) { # data parameters
353 my $d = $self->data;
354 return $f->{$d}->{$p} || 0;
355
356 } elsif ($p =~ /^($feff_params_regex)$/) { # feff calc parameters
357 my $ff = $self->feff;
358 return $f->{$ff}->{$p} || 0;
359
360 } elsif (($self->type eq 'path') and
361 ($p =~ /^($path_params_regex)$/)) { # this is a path parameter
362 return $self->{$p} || "";
363
364 } else { # else return this parameter
365 return $self->{$p} || 0;
366 };
367 };
368
369
370
371 ## tidy up values for a group
372 sub fix_values {
373 my $self = shift;
374
375 ## make sure kmax and kmin are rational
376 $self -> dispose("___x = ceil(" . $self->{group} . ".k)");
377 my $maxk = Ifeffit::get_scalar("___x");
378 ($self->{kmax} = $maxk) if ($self->{kmax} == 0);
379 ($self->{kmax} += $maxk) if ($self->{kmax} < 0);
380 (($self->{kmin}, $self->{kmax}) = ($self->{kmax}, $self->{kmin})) if
381 ($self->{kmin} > $self->{kmax});
382 (($self->{rmin}, $self->{rmax}) = ($self->{rmax}, $self->{rmin})) if
383 ($self->{rmin} > $self->{rmax});
384 };
385
386
387 ## Script writing methods
388
389
390 ## args: $index: path index; $pathto: directory containing feff calc
391 ## $extpp: boolean, using extended path params?
392 ## $stash_dir: stash directory
393 sub write_path {
394 my $self = shift;
395 my ($index, $pathto, $extpp, $stash_dir) = @_;
396 my $nnnn = File::Spec->catfile($pathto,$self->{feff});
397 my $stash = $nnnn; # deal with very long file names
398 if (length($stash) > 127) {
399 my $dir = File::Spec->catfile($stash_dir, $self->{parent});
400 (-d $dir) or mkpath $dir;
401 my $new = File::Spec->catfile($dir, $self->{feff});
402 copy($stash, $new);
403 $stash = $new;
404 };
405 my $string = "## Path #$index\n";
406 if ($stash ne $nnnn) {
407 $string .= "## actual path file: $nnnn\n";
408 $string .= "## transfered to stash file: $stash\n";
409 };
410 my $prefix = "path($index, ";
411 my @cleanup = ();
412 $string .= $prefix . sprintf("label = \"%s\")\n", $self->{label}||$self->{lab});
413 ##unless ($self->{label} =~ /^\s*$/);
414 foreach (qw(feff deg S02 E0 delR sigma^2 Ei 3rd 4th dphase k_array phase_array amp_array)) {
415 next if ((not $extpp) and ($_ =~ /(dphase|(amp|k|phase)_array)/));
416 push(@cleanup,lc($_)), next if ($self->{lc($_)} =~ /^\s*$/);
417 my $pp = lc($_);
418 ($pp eq 'sigma^2') and ($pp = 'sigma2');
419 ($pp eq '3rd') and ($pp = 'third');
420 ($pp eq '4th') and ($pp = 'fourth');
421 my $arg = ($pp eq 'deg') ? 'degen' : $pp;
422 if ($_ eq 'feff') {
423 $string .= $prefix . sprintf("%s = \"%s\")\n", $pp, $stash);
424 } else {
425 $string .= $prefix . sprintf("%s = %s)\n", $arg, $self->{lc($_)});
426 };
427 };
428 $string .= $prefix . "force_read = true)\n";
429 ## make sure that math expressions from previous evaluations of this
430 ## path that are not used in the current evaluation are left lying
431 ## around in Ifeffit's memory
432 if (@cleanup) {
433 $string .= "path($index";
434 map {my $pp=$_;
435 ($pp eq 'sigma^2') and ($pp = 'sigma2');
436 ($pp eq '3rd') and ($pp = 'third');
437 ($pp eq '4th') and ($pp = 'fourth');
438 $string .= ", $pp=0"
439 } @cleanup;
440 $string .= ")\n";
441 };
442 ##$string .= " )\n";
443 return $string;
444 };
445
446
447 ## @indeces_used is a table of back references for the datum in
448 ## fit_index. the idea is to keep track of which indeces have been
449 ## used and what the next available one is.
450 sub index {
451 my $self = shift;
452 @indeces_used = ('^^placeholder^^') if ($#indeces_used==-1);
453 my $old = $self->{fit_index} || 0;
454 if ($old and ($old <= $#indeces_used)) { # @indeces_used and fit_index agree
455 return $old if ($indeces_used[$old] eq $self->{id});
456 };
457 foreach my $i (1 .. $#indeces_used) { # they disagree, use @indeces_used
458 $self->make(fit_index=>$i), return $i if ($indeces_used[$i] eq $self->{id});
459 };
460 my $new = $#indeces_used + 1; # need to assign a new one
461 $indeces_used[$new] = $self->{id};
462 $self->make(fit_index=>$new);
463 return $new;
464 };
465
466 ## a path and group has been deleted, splice it out of @indeces_used
467 sub drop {
468 my $self = shift;
469 my $dropit = 0;
470 foreach my $i (1 .. $#indeces_used) {
471 $dropit = $i, last if ($indeces_used[$i] eq $self->{id});
472 };
473 splice @indeces_used, $dropit, 1;
474 };
475
476 ## we have just deleted a project and need to start counting paths
477 ## from scratch
478 sub drop_all { $#indeces_used = 0 };
479
480
481 sub erase {
482 my $self = shift;
483 return $self->blank_path;
484 };
485
486 sub blank_path {
487 my $self = shift;
488 return "" unless ($self->{type} eq 'path');
489 return "" unless ($self->{fit_index});
490 return "erase \@path $self->{fit_index}\n";
491 ## my $string = "index=$self->{fit_index}";
492 ## foreach (qw(feff label degen s02 e0 delr sigma2 ei third fourth dphase
493 ## k_array phase_array amp_array)) {
494 ## $string .= ", $_=\"\"";
495 ## };
496 ## $string .= ")";
497 ## $string = wrap("path(", " ", $string);
498 ## return "## unsetting path $self->{fit_index}\n" . $string;
499 };
500
501
502 ## get rid of all $dataN_title_MM strings
503 sub delete_titles {
504 my $self = shift;
505 my $group = $self->{group};
506 ifeffit("show \@strings\n");
507 my ($lines, @response) = (Ifeffit::get_scalar('&echo_lines')||0, ());
508 if ($lines) {
509 map {push @response, Ifeffit::get_echo()} (1 .. $lines);
510 };
511 foreach (@response) {
512 $self -> dispose("erase $1") if (/^\s*(\$data\d+_title_\d+)/);
513 };
514 };
515
516 ## macros???
517 sub write_feffit {
518 my $self = shift;
519 my ($indeces, $iset, $nsets, $restraints) = @_;;
520 ($indeces eq "1-1") and ($indeces="1");
521 my $group = $self->{group};
522 my ($string, $dispose) = ("","");
523 my $chi = "$group.chi";
524 $string .= "feffit($indeces, group=${group}_fit, chi=$chi, k=$group.k, ";
525
526 ## determine all the k-weights to use
527 my @weights = map {sprintf "kweight=%.2f", $_} ($self->group_weights);
528 $string .= join(", ", @weights) . ", ";
529 foreach (qw(rmin rmax kmin kmax dk kwindow fit_space do_bkg)) {
530 next if ($self->get($_) =~ /^\s*$/);
531 $string .= " $_=".$self->get($_).",";
532 };
533 $string .= " data_set=$iset, data_total=$nsets, ";
534 if ($self->{epsilon_k} and ($self->{epsilon_k} > 0)) {
535 ($string .= "epsilon_k=$self->{epsilon_k}, ");
536 };
537 $string .= $restraints;
538 $string =~ s/,\s*$/\)/;
539 $string = wrap("", " ", $string) . $/;
540 return $dispose.$string;
541 ##return $str.$dispose.$string;
542 };
543
544 sub write_ff2chi {
545 my $self = shift;
546 my $indeces = $_[0];
547 my $group = $self->{group};
548 my $out = $_[1] || $group.'_fit';
549 my $string = "ff2chi($indeces, group=$out,";
550 ## foreach (qw(kmin kmax)) {
551 ## next if ($self->{$_} =~ /^\s*$/);
552 ## $string .= " $_=$self->{$_},";
553 ## };
554 $string =~ s/,$/\)/;
555 $string = wrap("", " ", $string) . $/;
556 return $string;
557 };
558
559 sub write_fft {
560 my $self = shift;
561 my $r_paths = $self->{family};
562 my $kw = $_[0] || $self->default_k_weight;
563 my $rout = $_[1] || 10;
564 my $group = $self->{group};
565 #($self = $$r_paths{$self->{sameas}}) if ($self->{sameas} and ($self->type ne 'fit'));
566 #($self = $$r_paths{$self->{data}}) if ($self->{data});
567 my $string = "($group.chi, k=$group.k, ";
568 foreach (qw(kmin kmax dk kwindow)) {
569 $string .= "$_=".$self->get($_).", ";
570 };
571 $string .= "kweight=$kw, rmax_out=$rout, ";
572 ## ($self->{pcpath} eq "Yes") and
573 ## ($string .=
574 ## ", pc_edge=\"" . lc($self->{pcelem}) . " " . lc($self->{pcedge}) . "\", pc_caps=1");
575 if ($self->get('pcpath') ne "None") {
576 my $pcp = $$r_paths{$self->get('pcpath')}->{fit_index};
577 $string .= "pc_feff_path=$pcp, ";
578 };
579 $string =~ s/, $/\)\n/;
580 $string = wrap("fftf", " ", $string);
581 return $string;
582 };
583
584 sub write_bft {
585 my $self = shift;
586 my $r_paths = $self->{family};
587 my $group = $self->{group};
588 #($self = $$r_paths{$self->{sameas}}) if ($self->{sameas} and ($self->type ne 'fit'));
589 #($self = $$r_paths{$self->{data}}) if ($self->{data});
590 my $string = "(real=$group.chir_re, imag=$group.chir_im, ";
591 foreach (qw(rmin rmax dr rwindow)) {
592 $string .= "$_=".$self->get($_).", ";
593 };
594 $string =~ s/, $/\)\n/;
595 $string = wrap("fftr", " ", $string);
596 return $string;
597 };
598
599 sub chi_noise {
600 my $self = shift;
601 my $r_paths = $self->{family};
602 my $group = $self->{group};
603 ($self->{sameas}) and ($self = $$r_paths{$self->{sameas}});
604 ($self->{data}) and ($self = $$r_paths{$self->{data}});
605 my $string = "($group.chi, k=$group.k, ";
606 foreach (qw(kmin kmax dk kwindow)) {
607 $string .= "$_=$self->{$_}, ";
608 };
609 my $kw = $_[1] || $self->default_k_weight;
610 $string .= "kweight=$kw, ";
611 $string =~ s/, $/\)\n/;
612 $string = wrap("chi_noise", " ", $string);
613 $self->dispose($string);
614 return (Ifeffit::get_scalar("epsilon_k"),
615 Ifeffit::get_scalar("epsilon_r"),
616 Ifeffit::get_scalar("kmax_suggest"),
617 );
618 };
619
620 ## Plotting methods
621
622 # sub plot_E {
623 # my $self = shift;
624
625 # };
626
627 sub plot_k {
628 my $self = shift;
629 my ($list, $r_pf, $r_extra, $stash_dir) = @_;
630 my $r_paths = $self->{family};
631
632 my $w = $$r_pf{kweight};
633
634 ## plotting flags
635 my $do_win = $$r_pf{win}; # plot the window function
636 my $do_bkg = $$r_pf{bkg}; # plot the background for each selected fit
637 my $do_res = $$r_pf{res}; # plot the residual for each selected fit
638
639 my ($indic_min, $indic_max) = (1000000, -1000000);
640 my $indic_command = "## determine indicator boundaries\n";
641 $indic_command .= "set ind___min = 1000000\nset ind___max = -1000000\n";
642
643 ## stacking
644 my $stack = ($$r_extra[0]) ? $$r_extra[1] : 0;
645 my $stack_delta = ($$r_extra[0]) ? $$r_extra[2] : 0;
646
647 ## MDS offset (over-rides stacking)
648 my $ds_delta = $$r_extra[3];
649 my $ds_offset = -1 * $ds_delta;
650 ($stack, $stack_delta) = (0,0) if $ds_offset;
651
652 my $data = $self->data;
653 $data = $$r_paths{$data};
654 ($w eq 'w') and ($w = $data->default_k_weight());
655
656 my ($plot, $indent) = ("newplot", " ");
657 my @p = $list -> info('selection');
658 ##print "in plot_k: ", join(" ", @p), $/;
659 my %hash;
660 my ($key, $style, $n);
661 my $i = -1;
662 my $set = $self->data; # identify this data
663 $set = $$r_paths{$set}->descriptor;
664
665 my $command = '';
666 foreach my $p (@p) {
667 next if ($p eq 'gsd');
668 next if ($p =~ /feff\d+$/);
669 next if (($p =~ /feff\d+\.\d+/) and not $$r_paths{$p}->{include});
670 next if (($$r_paths{$p}->{type} eq 'data') and (not -e $$r_paths{$p}->{file}));
671 my $group = pathgroup($p, $r_paths);
672 next unless $group;
673
674 my $data = $p;
675 $data = $$r_paths{$p}->{data} if ($$r_paths{$p}->{type} =~ /(feff|path)/);
676 $data = $$r_paths{$p}->{sameas} if ($$r_paths{$p}->{type} =~ /(bkg|diff|fit|res)/);
677 $data = $$r_paths{$data};
678 $w = $$r_pf{kweight};
679 ($w = $data->default_k_weight()) if ($w eq 'kw');
680
681 ($ds_offset += $ds_delta) if ($$r_paths{$p}->type eq 'data');
682
683 ## bring this path up to date for current plot
684 ## what about multiple feff calcs and indeces?????
685 #($$r_paths{$_}->{do_k}) and do {
686 # $$r_paths{$_}->{do_k} = 0;
687 if ($$r_paths{$p}->{type} eq 'path') {
688 #my $n = $1 + 1;
689 my $ii = $$r_paths{$p}->index;
690 my $parent = $$r_paths{$p}->{parent};
691 my $pathto = $$r_paths{$parent}->{path};
692 $command .= $$r_paths{$p} -> write_path($ii, $pathto, 0, $stash_dir);
693 $command .= "ff2chi($ii, group=$group)\n";
694 } elsif (($$r_paths{$p}->{type} eq 'fit') and $$r_paths{$p}->{parent}) {
695
696 ## this is a fit, but not the parent of the fit branch
697 unless ($$r_paths{$p}->get('imported')) {
698 ## read this fit into its group if it has not already been imported
699 $command .= "read_data(file=\"" .
700 $$r_paths{$p}->get('fitfile') .
701 "\",\n" .
702 " type=chi, group=". $$r_paths{$p}->get('group') . ")\n";
703 $$r_paths{$p}->make(imported=>1);
704 };
705 ## bkg plot has been requested
706 if (($do_bkg) and (-e $$r_paths{$p}->get('bkgfile'))) {
707 unless ($$r_paths{$p}->get('imported_bkg')) {
708 (my $gr = $$r_paths{$p}->get('group')) =~ s/fit/bkg/;
709 ## read this fit into its group if it has not already been imported
710 $command .= "read_data(file=\"" .
711 $$r_paths{$p}->get('bkgfile') .
712 "\",\n type=chi, group=$gr)\n";
713 $$r_paths{$p}->make(imported_bkg=>1);
714 };
715 };
716 ## residual plot has been requested
717 if ($do_res) {
718 unless ($$r_paths{$p}->get('imported_res')) {
719 (my $gr = $$r_paths{$p}->get('group')) =~ s/fit/res/;
720 ## read this fit into its group if it has not already been imported
721 $command .= "read_data(file=\"" .
722 $$r_paths{$p}->get('resfile') .
723 "\",\n type=chi, group=$gr)\n";
724 $$r_paths{$p}->make(imported_res=>1);
725 };
726 };
727 };
728 #};
729 $key = $$r_paths{$p}->{lab};
730 ##($_ =~ /^feff(\d+)\.(\d+)/) and ($n = $1+1) and ($key = sprintf("%4.4d", $2+1));
731 if ($p =~ /feff(\d+)\.(\d+)/) {
732 my $f = $$r_paths{$p}->{parent};
733 $f = $$r_paths{$f}->{lab};
734 $f =~ s/FEFF(\d+)/$1/;
735 my $pa = $$r_paths{$p}->{lab};
736 $pa =~ s/feff0?//;
737 $pa =~ s/\.dat//;
738 $key = "$f/$pa";
739 };
740
741 STYLE: {
742 ($style = $$r_pf{datastyle}), last STYLE if ($$r_paths{$p}->{type} eq 'data');
743 ($style = $$r_pf{fitstyle}), last STYLE if ($$r_paths{$p}->{type} eq 'fit');
744 ($style = $$r_pf{partsstyle});
745 };
746
747 ++$i;
748 $i = $i % 10;
749 my ($ytext, $ylabel);
750 if ($w == 0) {
751 $ytext = "\"" . join('.', $group, 'chi') . "\"";
752 $ylabel = '\\gx(k)'
753 } elsif ($w == 1) {
754 $ytext = "\"" . join('.', $group, 'k') . '*' . join('.', $group, 'chi') . "\"";
755 $ylabel = 'k\\gx(k)';
756 } else {
757 $ytext = "\"" . join('.', $group, 'k') . "^$w*" . join('.', $group, 'chi') . "\"";
758 $ylabel = 'k\\u' . $w . '\\d\\gx(k)';
759 };
760 $stack -= $stack_delta if ($$r_paths{$p}->{type} eq 'fit');
761 my $stst = $stack + $ds_offset;
762 (my $yyy = $ytext) =~ s/\"$/+$stst\"/;
763 %hash = (plot => $plot,
764 'x' => join('.', $group, 'k'),
765 'y' => $yyy,
766 xlabel => '"k (\\A\\u-1\\d)"',
767 ylabel => $ylabel,
768 fg => $$r_pf{fg},
769 bg => $$r_pf{bg},
770 grid => $$r_pf{showgrid},
771 gridcolor => $$r_pf{grid},
772 xmin => $$r_pf{kmin},
773 xmax => $$r_pf{kmax},
774 style => $style,
775 color => "\"" . $$r_pf{'c'.$i} . "\"",
776 key => $key,
777 title => "\"\'$set\' in k space\"");
778 my $this = plotstring(\%hash);
779 $this = wrap("", $indent, $this);
780 $command .= $this;
781 ($plot, $indent) = ('plot', " ");
782
783 ## determine indicator boundries
784 #$indic_command .= "set i___ndic.x = $hash{'x'}\n";
785 $indic_command .= "set i___ndic.y = $hash{'y'}\n";
786 $indic_command .= "set ind___min = min(ind___min, 1.05*floor(i___ndic.y))\n";
787 $indic_command .= "set ind___max = max(ind___max, 1.05* ceil(i___ndic.y))\n";
788
789 $stack += $stack_delta;
790
791
792 ## A fit has been selected AND bkg and/or res have been requested
793 if (($$r_paths{$p}->{type} eq 'fit') and $$r_paths{$p}->{parent}) {
794 if (($do_bkg) and (-e $$r_paths{$p}->get('bkgfile'))) {
795 (my $gr = $group) =~ s/fit/bkg/;
796 ++$i;
797 $i = $i % 10;
798 (my $this_ytext = $ytext) =~ s/$group/$gr/g;
799 $stack -= $stack_delta if ($$r_paths{$p}->{type} eq 'fit');
800 $stst = $stack + $ds_offset;
801 (my $yyy = $this_ytext) =~ s/\"$/+$stst\"/;
802 %hash = (plot => 'plot',
803 'x' => join('.', $gr, 'k'),
804 'y' => $yyy, #$this_ytext,
805 xlabel => '"k (\\A\\u-1\\d)"',
806 ylabel => $ylabel,
807 fg => $$r_pf{fg},
808 bg => $$r_pf{bg},
809 grid => $$r_pf{showgrid},
810 gridcolor => $$r_pf{grid},
811 xmin => $$r_pf{rmin},
812 xmax => $$r_pf{rmax},
813 style => $style,
814 color => "\"" . $$r_pf{'c'.$i} . "\"",
815 key => 'Bkg for '.$$r_paths{$p}->short_descriptor,
816 title => "\"\'$set\' in k space\"");
817 my $this = plotstring(\%hash);
818 $this = wrap("", $indent, $this);
819 $command .= $this;
820 $stack += $stack_delta;
821 };
822 if ($do_res) {
823 (my $gr = $group) =~ s/fit/res/;
824 ++$i;
825 $i = $i % 10;
826 (my $this_ytext = $ytext) =~ s/$group/$gr/g;
827 $stst = $stack + $ds_offset;
828 (my $yyy = $this_ytext) =~ s/\"$/+$stst\"/;
829 %hash = (plot => 'plot',
830 'x' => join('.', $gr, 'k'),
831 'y' => $yyy,
832 xlabel => '"k (\\A\\u-1\\d)"',
833 ylabel => $ylabel,
834 fg => $$r_pf{fg},
835 bg => $$r_pf{bg},
836 grid => $$r_pf{showgrid},
837 gridcolor => $$r_pf{grid},
838 xmin => $$r_pf{rmin},
839 xmax => $$r_pf{rmax},
840 style => $style,
841 color => "\"" . $$r_pf{'c'.$i} . "\"",
842 key => 'Resid for '.$$r_paths{$p}->short_descriptor,
843 title => "\"\'$set\' in R space\"");
844 my $this = plotstring(\%hash);
845 $this = wrap("", $indent, $this);
846 $command .= $this;
847 $stack += $stack_delta;
848 };
849 };
850
851 };
852 if ($do_win) {
853 ++$i;
854 $i = $i % 10;
855 my ($group, $kmin, $kmax, $dk, $kwin) = ($self->{group}, $self->{kmin},
856 $self->{kmax}, $self->{dk},
857 $self->{kwindow});
858 my $kw = ($$r_pf{kweight} eq 'kw') ? $self->default_k_weight() : $$r_pf{kweight};
859 ($self->{do_r}) and do {
860 my $this = "$group.chi, k=$group.k, kweight=$kw, kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin, rmax_out=$$r_pf{rmax_out})";
861 $command .= wrap('fftf(', ' ', $this) . "\n";
862 $self -> make(do_r=>0);
863 };
864 $self -> dispose("___x = ceil($group.chi*$group.k^$kw)", 1); # scale window to plot
865 my $scale = $$r_pf{window_multiplier} * Ifeffit::get_scalar("___x");
866 my $color = "\"" . $$r_pf{'c'.$i} . "\"";
867 my $this = sprintf("plot(%s.k, %s.win*%f, style=lines, color=%s, key=window)",
868 $group, $group, $scale, $color);
869 $this = wrap("", " ", $this) . $/;
870 $command .= $this;
871 };
872
873 if ($$r_extra[5]) {
874 foreach my $i (7 .. $#{$r_extra}) {
875 next unless (lc($$r_extra[$i]->[1]) =~ /[kq]/);
876 my $val = $$r_extra[$i]->[2];
877 next if ($val < 0);
878 $indic_command .= $self->plot_vertical_line($val, "", 0, 0, 1)
879 };
880 };
881 $$r_extra[6] = $indic_command;
882
883 $last_plot_command = $command;
884 return $command;
885 };
886
887 sub plot_R {
888 my $self = shift;
889 my ($list, $r_pf, $r_extra, $stash_dir) = @_;
890 my $r_paths = $self->{family};
891
892 my ($indic_min, $indic_max) = (1000000, -1000000);
893 my $indic_command = "## determine indicator boundaries\n";
894 $indic_command .= "set ind___min = 1000000\nset ind___max = -1000000\n";
895
896 ## stacking
897 my $stack = ($$r_extra[0]==2) ? $$r_extra[1] : 0;
898 my $stack_delta = ($$r_extra[0]==2) ? $$r_extra[2] : 0;
899
900 ## inverting
901 my $invert = ($$r_pf{r_pl} =~ /m/) ? $$r_extra[4] : 0;
902 ($invert = 0) if ($$r_extra[0]==2);
903
904 ## MDS offset (over-rides stacking)
905 my $ds_delta = $$r_extra[3];
906 my $ds_offset = -1 * $ds_delta;
907 ($stack, $stack_delta) = (0,0) if $ds_offset;
908
909 ## plotting flags
910 my $do_win = $$r_pf{win}; # plot the window function
911 my $do_bkg = $$r_pf{bkg}; # plot the background for each selected fit
912 my $do_res = $$r_pf{res}; # plot the residual for each selected fit
913
914 my ($plot, $indent) = ("newplot", " ");
915 my @p = $list -> info('selection');
916 ##print ">>", join("|", @p), "<<\n";
917 my %hash;
918 my ($key, $style, $n);
919 my $i = -1;
920 my $set = $self->data; # identify this data
921 $set = $$r_paths{$set}->descriptor;
922
923 my $command = '';
924 my $data_window = 0;
925 foreach my $p (@p) {
926 next if ($p eq 'gsd');
927 next if ($p =~ /feff\d+$/);
928 ## change the next line to allow plotting excluded paths??? (+ the
929 ## same in the other plot_ methods)
930 next if (($$r_paths{$p}->type eq 'path') and not $$r_paths{$p}->{include});
931
932 next if (($$r_paths{$p}->type eq 'data') and (not -e $$r_paths{$p}->{file}));
933
934 my $group = pathgroup($p, $r_paths);
935 next unless $group;
936 ($p =~ /(\d+)_res$/) and $$r_paths{$p} -> make(do_k=>0, do_r=>0, do_q=>0);
937
938 my $data = $$r_paths{$p}->data;
939 $data = $$r_paths{$p}->get('id') if ($$r_paths{$p}->type eq 'fit');
940 $data = $$r_paths{$data};
941 my ($kmin, $kmax, $dk, $kwin) =
942 ($data->get('kmin'), $data->get('kmax'), $data->get('dk'), lc($data->get('kwindow')));
943
944 my $kw = ($$r_pf{kweight} eq 'kw') ? $data->default_k_weight() : $$r_pf{kweight};
945
946 my $pcplot = "";
947 if ($data->get('pcpath') ne "None") {
948 my $pcp = $$r_paths{$data->get('pcpath')}->{fit_index};
949 ($pcplot = ", pc_feff_path=$pcp") if $pcp;
950 };
951
952 ($ds_offset += $ds_delta) if ($$r_paths{$p}->type eq 'data');
953
954 ## bring this path up to date for current plot
955 #($$r_paths{$p}->{do_k}) and do {
956 # $$r_paths{$p}->{do_k} = 0;
957
958 if ($$r_paths{$p}->{type} eq 'path') {
959 #my $n = $1 + 1;
960 my $ii = $$r_paths{$p}->index;
961 my $parent = $$r_paths{$p}->{parent};
962 my $pathto = $$r_paths{$parent}->{path};
963 $command .= $$r_paths{$p} -> write_path($ii, $pathto, 0, $stash_dir);
964 $command .= "ff2chi($ii, group=$group)\n";
965 } elsif (($$r_paths{$p}->{type} eq 'fit') and $$r_paths{$p}->{parent}) {
966 ## this is a fit, but not the parent of the fit branch
967 unless ($$r_paths{$p}->get('imported')) {
968 ## read this fit into its group if it has not already been imported
969 $command .= "read_data(file=\"" .
970 $$r_paths{$p}->get('fitfile') .
971 "\",\n" .
972 " type=chi, group=". $$r_paths{$p}->get('group') . ")\n";
973 $$r_paths{$p}->make(imported=>1);
974 };
975 ## bkg plot has been requested
976 if (($do_bkg) and (-e $$r_paths{$p}->get('bkgfile'))) {
977 unless ($$r_paths{$p}->get('imported_bkg')) {
978 (my $gr = $$r_paths{$p}->get('group')) =~ s/fit/bkg/;
979 ## read this fit into its group if it has not already been imported
980 $command .= "read_data(file=\"" .
981 $$r_paths{$p}->get('bkgfile') .
982 "\",\n type=chi, group=$gr)\n";
983 $$r_paths{$p}->make(imported_bkg=>1);
984 };
985 };
986 ## residual plot has been requested
987 if ($do_res) {
988 unless ($$r_paths{$p}->get('imported_res')) {
989 (my $gr = $$r_paths{$p}->get('group')) =~ s/fit/res/;
990 ## read this fit into its group if it has not already been imported
991 $command .= "read_data(file=\"" .
992 $$r_paths{$p}->get('resfile') .
993 "\",\n type=chi, group=$gr)\n";
994 $$r_paths{$p}->make(imported_res=>1);
995 };
996 };
997 };
998
999 my $suff = "chi";
1000 ## needs to be generalized for multiple data sets...
1001 my $window;
1002 if ($p =~ /data\d+$/) {
1003 $window = "kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin";
1004 $data_window = 1;
1005 } elsif ($data_window != 1) {
1006 $window = "kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin";
1007 } else {
1008 #$window = "altwindow=data0.win";
1009 $window = "kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin";
1010 };
1011 my $thisun = "$group.$suff, k=$group.k, kweight=$kw, rmax_out=$$r_pf{rmax_out}, $window$pcplot)";
1012 my $fft_command = wrap('fftf(', ' ', $thisun);
1013 $command .= $fft_command . "\n";
1014
1015 $key = $$r_paths{$p}->{lab};
1016 STYLE: {
1017 ($style = $$r_pf{datastyle}), last STYLE if ($$r_paths{$p}->{type} eq 'data');
1018 ($style = $$r_pf{fitstyle}), last STYLE if ($$r_paths{$p}->{type} eq 'fit');
1019 ($style = $$r_pf{partsstyle});
1020 };
1021 #($p =~ /^feff(\d+)\.(\d+)/) and ($n = $1+1) and ($key = sprintf("%4.4d", $2+1));
1022 if ($p =~ /feff(\d+)\.(\d+)/) {
1023 my $f = $$r_paths{$p}->{parent};
1024 $f = $$r_paths{$f}->{lab};
1025 $f =~ s/FEFF(\d+)/$1/;
1026 my $pa = $$r_paths{$p}->{lab};
1027 $pa =~ s/feff0?//;
1028 $pa =~ s/\.dat//;
1029 $key = "$f/$pa";
1030 };
1031 ## foreach my $p (qw(r_env r_mag r_re r_im r_pha)) {
1032 ## next if ($$r_pf{$p} =~ /^\s+$/);
1033 my $part = 0;
1034 my $ylabel = '';
1035 SWITCH: {
1036 ($part, $ylabel) =
1037 ('chir_mag', sprintf("\"Env[\\gx(R)] (\\A\\u-%s\\d)\"", $kw+1)),
1038 last SWITCH if ($$r_pf{r_pl} eq 'e');
1039 ($part, $ylabel) =
1040 ('chir_mag', sprintf("\"|\\gx(R)| (\\A\\u-%s\\d)\"", $kw+1)),
1041 last SWITCH if ($$r_pf{r_pl} eq 'm');
1042 ($part, $ylabel) =
1043 ('chir_re', sprintf("\"Re[\\gx(R)] (\\A\\u-%s\\d)\"", $kw+1)),
1044 last SWITCH if ($$r_pf{r_pl} eq 'r');
1045 ($part, $ylabel) =
1046 ('chir_im', sprintf("\"Im[\\gx(R)] (\\A\\u-%s\\d)\"", $kw+1)),
1047 last SWITCH if ($$r_pf{r_pl} eq 'i');
1048 ($part, $ylabel) =
1049 ('chir_pha', sprintf("\"Phase[\\gx(R)] (\\A\\u-%s\\d)\"", $kw+1)),
1050 last SWITCH if ($$r_pf{r_pl} eq 'p');
1051 };
1052 next unless $part;
1053 ++$i;
1054 $i = $i % 10;
1055 my $inv = "";
1056 ($inv = "-1*") if ($invert and ($$r_paths{$p}->type eq 'path'));
1057 $stack -= $stack_delta if ($$r_paths{$p}->{type} eq 'fit');
1058 my $stst = $stack + $ds_offset;
1059 %hash = (plot => $plot,
1060 'x' => join('.', $group, 'r'),
1061 'y' => "\"$inv" . join('.', $group, $part) . "+$stst\"",
1062 xlabel => "\"R (\\A)\"",
1063 ylabel => $ylabel,
1064 fg => $$r_pf{fg},
1065 bg => $$r_pf{bg},
1066 grid => $$r_pf{showgrid},
1067 gridcolor => $$r_pf{grid},
1068 xmin => $$r_pf{rmin},
1069 xmax => $$r_pf{rmax},
1070 style => $style,
1071 color => "\"" . $$r_pf{'c'.$i} . "\"",
1072 key => $inv.$key,
1073 title => "\"\'$set\' in R space\"");
1074 my $this = plotstring(\%hash);
1075 $this = wrap("", $indent, $this);
1076 $command .= $this;
1077 ($plot, $indent) = ('plot', " ");
1078
1079 ## determine indicator boundries
1080 #$indic_command .= "set i___ndic.x = $hash{'x'}\n";
1081 $indic_command .= "set i___ndic.y = $hash{'y'}\n";
1082 $indic_command .= "set ind___min = min(ind___min, 1.05*floor(i___ndic.y))\n";
1083 $indic_command .= "set ind___max = max(ind___max, 1.05* ceil(i___ndic.y))\n";
1084
1085 $stack += $stack_delta;
1086
1087 ## A fit has been selected AND bkg and/or res have been requested
1088 if (($$r_paths{$p}->{type} eq 'fit') and $$r_paths{$p}->{parent}) {
1089 if (($do_bkg) and (-e $$r_paths{$p}->get('bkgfile'))) {
1090 (my $gr = $group) =~ s/fit/bkg/;
1091 ++$i;
1092 $i = $i % 10;
1093 $inv = "";
1094 ($inv = "-1*") if $invert;
1095 $stack -= $stack_delta if ($$r_paths{$p}->{type} eq 'fit');
1096 $stst = $stack + $ds_offset;
1097 %hash = (plot => 'plot',
1098 'x' => join('.', $gr, 'r'),
1099 'y' => "\"$inv" . join('.', $gr, $part) . "+$stst\"",
1100 xlabel => "\"R (\\A)\"",
1101 ylabel => $ylabel,
1102 fg => $$r_pf{fg},
1103 bg => $$r_pf{bg},
1104 grid => $$r_pf{showgrid},
1105 gridcolor => $$r_pf{grid},
1106 xmin => $$r_pf{rmin},
1107 xmax => $$r_pf{rmax},
1108 style => $style,
1109 color => "\"" . $$r_pf{'c'.$i} . "\"",
1110 key => $inv.'Bkg for '.$$r_paths{$p}->short_descriptor,
1111 title => "\"\'$set\' in R space\"");
1112 my $this = plotstring(\%hash);
1113 $this = wrap("", $indent, $this);
1114 (my $this_fft = $fft_command) =~ s/$group/$gr/g;
1115 $command .= $this_fft . "\n";
1116 $command .= $this;
1117 $stack += $stack_delta;
1118 };
1119 if ($do_res) {
1120 (my $gr = $group) =~ s/fit/res/;
1121 ++$i;
1122 $i = $i % 10;
1123 $stst = $stack + $ds_offset;
1124 %hash = (plot => 'plot',
1125 'x' => join('.', $gr, 'r'),
1126 'y' => "\"" . join('.', $gr, $part) . "+$stst\"",
1127 xlabel => "\"R (\\A)\"",
1128 ylabel => $ylabel,
1129 fg => $$r_pf{fg},
1130 bg => $$r_pf{bg},
1131 grid => $$r_pf{showgrid},
1132 gridcolor => $$r_pf{grid},
1133 xmin => $$r_pf{rmin},
1134 xmax => $$r_pf{rmax},
1135 style => $style,
1136 color => "\"" . $$r_pf{'c'.$i} . "\"",
1137 key => 'Resid for '.$$r_paths{$p}->short_descriptor,
1138 title => "\"\'$set\' in R space\"");
1139 my $this = plotstring(\%hash);
1140 $this = wrap("", $indent, $this);
1141 (my $this_fft = $fft_command) =~ s/$group/$gr/g;
1142 $command .= $this_fft . "\n";
1143 $command .= $this;
1144 $stack += $stack_delta;
1145 };
1146 };
1147
1148 ## envelope plot NOT QUITE RIGHT WITH OFFSETS
1149 if ($$r_pf{r_pl} eq 'e') { #($p eq 'r_env') {
1150 $hash{plot} = 'plot';
1151 $hash{'y'} = '-1*'.$hash{'y'};
1152 $hash{key} = '';
1153 my $this = plotstring(\%hash);
1154 $this = wrap("", $indent, $this);
1155 $command .= $this;
1156 };
1157 };
1158 if ($do_win) {
1159 ++$i;
1160 $i = $i % 10;
1161 my ($group, $kmin, $kmax, $dk, $kwin) = ($self->{group}, $self->{kmin},
1162 $self->{kmax}, $self->{dk},
1163 $self->{kwindow});
1164 my $kw = ($$r_pf{kweight} eq 'kw') ? $self->default_k_weight() : $$r_pf{kweight};
1165 my ($rmin, $rmax, $dr, $rwin) = ($self->{rmin}, $self->{rmax}, $self->{dr},
1166 $self->{rwindow});
1167 my $this = "$group.chi, k=$group.k, kweight=$kw, kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin, rmax_out=$$r_pf{rmax_out})";
1168 $this = wrap('fftf(', ' ', $this) . "\n";
1169 $command .= $this;
1170 ## must have the chir_mag in memory now to compute $scale
1171 $self -> dispose($this, 1); # $self -> make(do_r=>0);
1172 ($self->{do_q}) and do {
1173 my $this = "real=$group.chir_re, imag=$group.chir_im, rmin=$rmin, rmax=$rmax, dr=$dr, rwindow=$rwin)";
1174 $command .= wrap('fftr(', ' ', $this) . "\n";
1175 $self -> make(do_q=>0);
1176 };
1177 $self -> dispose("___x = ceil($group.chir_mag)", 1); # scale window to plot
1178 my $scale = $$r_pf{window_multiplier} * Ifeffit::get_scalar("___x");
1179 my $color = "\"" . $$r_pf{'c'.$i} . "\"";
1180 $this = sprintf("plot(%s.r, %s.rwin*%f, style=lines, color=%s, key=window)",
1181 $group, $group, $scale, $color);
1182 $this = wrap("", " ", $this) . $/;
1183 $command .= $this;
1184 };
1185
1186 if ($$r_extra[5]) {
1187 foreach my $i (7 .. $#{$r_extra}) {
1188 next unless (lc($$r_extra[$i]->[1]) eq 'r');
1189 my $val = $$r_extra[$i]->[2];
1190 next unless $val;
1191 next if ($val < 0);
1192 $indic_command .= $self->plot_vertical_line($val, "", 0, 0, 1)
1193 };
1194 };
1195 $$r_extra[6] = $indic_command;
1196
1197
1198 $last_plot_command = $command;
1199 return $command;
1200 };
1201
1202
1203 sub plot_q { #}
1204 my $self = shift;
1205 my ($list, $r_pf, $r_extra, $stash_dir) = @_;
1206 my $r_paths = $self->{family};
1207
1208 ## plotting flags
1209 my $do_win = $$r_pf{win}; # plot the window function
1210 my $do_bkg = $$r_pf{bkg}; # plot the background for each selected fit
1211 my $do_res = $$r_pf{res}; # plot the residual for each selected fit
1212
1213 my ($indic_min, $indic_max) = (1000000, -1000000);
1214 my $indic_command = "## determine indicator boundaries\n";
1215 $indic_command .= "set ind___min = 1000000\nset ind___max = -1000000\n";
1216
1217 ## stacking
1218 my $do_stack = 0;
1219 ($do_stack = 1) if ($$r_extra[0]==2);
1220 ($do_stack = 1) if (($$r_pf{q_pl} =~ /[ir]/) and ($$r_extra[0]==1));
1221 my $stack = ($do_stack) ? $$r_extra[1] : 0;
1222 my $stack_delta = ($do_stack) ? $$r_extra[2] : 0;
1223
1224 ## inverting
1225 my $invert = (($$r_pf{q_pl} =~ /m/) and ($$r_extra[4] == 2)) ? 1 : 0;
1226 ($invert = 0) if $do_stack;
1227
1228 ## MDS offset (over-rides stacking)
1229 my $ds_delta = $$r_extra[3];
1230 my $ds_offset = -1 * $ds_delta;
1231 ($stack, $stack_delta) = (0,0) if $ds_offset;
1232
1233 ## my $pcplot = ($self->{pcplot} eq "Yes") ?
1234 ## ", pc_edge=\"" . lc($self->{pcelem}) . " " . lc($self->{pcedge}) . "\", pc_caps=1" :
1235 ## "";
1236 my $pcplot = "";
1237 if ($self->get('pcpath') ne "None") {
1238 my $pcp = $$r_paths{$self->get('pcpath')}->{fit_index};
1239 $pcplot = ", pc_feff_path=$pcp";
1240 };
1241
1242
1243 my ($plot, $indent) = ("newplot", " ");
1244 my @p = $list -> info('selection');
1245 my %hash;
1246 my ($key, $style,$n);
1247 my $i = -1;
1248 my $set = $self->data; # identify this data
1249 $set = $$r_paths{$set}->descriptor;
1250
1251 my $command = '';
1252 my $data_kwindow = 0;
1253 my $data_rwindow = 0;
1254 foreach my $p (@p) {
1255 next if ($p eq 'gsd');
1256 next if ($p =~ /feff\d+$/);
1257 next if (($p =~ /feff\d+\.\d+/) and not $$r_paths{$p}->{include});
1258 ## next if (($p =~ /(\d+)_res$/) and (lc($self->{fit_space}) ne 'r'));
1259 next if (($$r_paths{$p}->{type} eq 'data') and (not -e $$r_paths{$p}->{file}));
1260 my $group = pathgroup($p, $r_paths);
1261 next unless $group;
1262 ($p =~ /(\d+)_res$/) and $$r_paths{$p} -> make(do_k=>0, do_r=>0, do_1=>0);
1263
1264 my $data = $$r_paths{$p}->data;
1265 $data = $$r_paths{$p}->get('id') if ($$r_paths{$p}->type eq 'fit');
1266 $data = $$r_paths{$data};
1267 my ($kmin, $kmax, $dk, $kwin) =
1268 ($data->get('kmin'), $data->get('kmax'), $data->get('dk'), lc($data->get('kwindow')));
1269 my ($rmin, $rmax, $dr, $rwin) =
1270 ($data->get('rmin'), $data->get('rmax'), $data->get('dr'), lc($data->get('rwindow')));
1271
1272 my $kw = ($$r_pf{kweight} eq 'kw') ? $self->default_k_weight() : $$r_pf{kweight};
1273
1274 ($ds_offset += $ds_delta) if ($$r_paths{$p}->type eq 'data');
1275
1276 ## bring this path up to date for current plot
1277 #($$r_paths{$_}->{do_k}) and do {
1278 # $$r_paths{$_}->{do_k} = 0;
1279 if ($$r_paths{$p}->{type} eq 'path') {
1280 #my $n = $1 + 1;
1281 my $ii = $$r_paths{$p}->index;
1282 my $parent = $$r_paths{$p}->{parent};
1283 my $pathto = $$r_paths{$parent}->{path};
1284 $command .= $$r_paths{$p} -> write_path($ii, $pathto, 0, $stash_dir);
1285 $command .= "ff2chi($ii, group=$group)\n";
1286 } elsif (($$r_paths{$p}->{type} eq 'fit') and $$r_paths{$p}->{parent}) {
1287 ## this is a fit, but not the parent of the fit branch
1288 unless ($$r_paths{$p}->get('imported')) {
1289 ## read this fit into its group if it has not already been imported
1290 $command .= "read_data(file=\"" .
1291 $$r_paths{$p}->get('fitfile') .
1292 "\",\n" .
1293 " type=chi, group=". $$r_paths{$p}->get('group') . ")\n";
1294 $$r_paths{$p}->make(imported=>1);
1295 };
1296 ## bkg plot has been requested
1297 if (($do_bkg) and (-e $$r_paths{$p}->get('bkgfile'))) {
1298 unless ($$r_paths{$p}->get('imported_bkg')) {
1299 (my $gr = $$r_paths{$p}->get('group')) =~ s/fit/bkg/;
1300 ## read this fit into its group if it has not already been imported
1301 $command .= "read_data(file=\"" .
1302 $$r_paths{$p}->get('bkgfile') .
1303 "\",\n type=chi, group=$gr)\n";
1304 $$r_paths{$p}->make(imported_bkg=>1);
1305 };
1306 };
1307 ## residual plot has been requested
1308 if ($do_res) {
1309 unless ($$r_paths{$p}->get('imported_res')) {
1310 (my $gr = $$r_paths{$p}->get('group')) =~ s/fit/res/;
1311 ## read this fit into its group if it has not already been imported
1312 $command .= "read_data(file=\"" .
1313 $$r_paths{$p}->get('resfile') .
1314 "\",\n type=chi, group=$gr)\n";
1315 $$r_paths{$p}->make(imported_res=>1);
1316 };
1317 };
1318 };
1319 #};
1320 my $window;
1321 my $suff = "chi";
1322 if ($p =~ /data\d+$/) {
1323 $window = "kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin";
1324 $data_kwindow = 1;
1325 } elsif ($data_kwindow != 1) {
1326 $window = "kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin";
1327 } else {
1328 #$window = "altwindow=data0.win";
1329 $window = "kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin";
1330 };
1331 my $this = "$group.$suff, k=$group.k, kweight=$kw, rmax_out=$$r_pf{rmax_out}, $window$pcplot)";
1332 my $fft_command = wrap('fftf(', ' ', $this);
1333 $command .= $fft_command . "\n";
1334 if ($p =~ /data\d+$/) {
1335 $window = "rmin=$rmin, rmax=$rmax, dr=$dr, rwindow=$rwin";
1336 $data_rwindow = 1;
1337 } elsif ($data_rwindow != 1) {
1338 $window = "rmin=$rmin, rmax=$rmax, dr=$dr, rwindow=$rwin";
1339 } else {
1340 #$window = "altwindow=data0.rwin";
1341 $window = "rmin=$rmin, rmax=$rmax, dr=$dr, rwindow=$rwin";
1342 };
1343 $this = "real=$group.chir_re, imag=$group.chir_im, $window)";
1344 my $bft_command = wrap('fftr(', ' ', $this);
1345 $command .= $bft_command . "\n";
1346
1347 $key = $$r_paths{$p}->{lab};
1348 if ($p =~ /^feff(\d+)\.(\d+)/) {
1349 my $f = $$r_paths{$p}->{parent};
1350 $f = $$r_paths{$f}->{lab};
1351 $f =~ s/FEFF(\d+)/$1/;
1352 my $pa = $$r_paths{$p}->{lab};
1353 $pa =~ s/feff0?//;
1354 $pa =~ s/\.dat//;
1355 $key = "$f/$pa";
1356 };
1357
1358 STYLE: {
1359 ($style = $$r_pf{datastyle}), last STYLE if ($$r_paths{$p}->{type} eq 'data');
1360 ($style = $$r_pf{fitstyle}), last STYLE if ($$r_paths{$p}->{type} eq 'fit');
1361 ($style = $$r_pf{partsstyle});
1362 };
1363
1364 ## foreach my $p (qw(q_env q_mag q_re q_im q_pha)) {
1365 ## next if ($$r_pf{$p} =~ /^\s+$/);
1366 my $part = 0;
1367 my $ylabel = '';
1368 SWITCH: {
1369 ($part, $ylabel) =
1370 ('chiq_mag', sprintf("\"Env[\\gx(q)] (\\A\\u-%s\\d)\"", $kw)),
1371 last SWITCH if ($$r_pf{q_pl} eq 'e');
1372 ($part, $ylabel) =
1373 ('chiq_mag', sprintf("\"|\\gx(q)| (\\A\\u-%s\\d)\"", $kw)),
1374 last SWITCH if ($$r_pf{q_pl} eq 'm');
1375 ($part, $ylabel) =
1376 ('chiq_re', sprintf("\"Re[\\gx(q)] (\\A\\u-%s\\d)\"", $kw)),
1377 last SWITCH if ($$r_pf{q_pl} eq 'r');
1378 ($part, $ylabel) =
1379 ('chiq_im', sprintf("\"Im[\\gx(q)] (\\A\\u-%s\\d)\"", $kw)),
1380 last SWITCH if ($$r_pf{q_pl} eq 'i');
1381 ($part, $ylabel) =
1382 ('chiq_pha', sprintf("\"Phase[\\gx(q)] (\\A\\u-%s\\d)\"", $kw)),
1383 last SWITCH if ($$r_pf{q_pl} eq 'p');
1384 };
1385 next unless $part;
1386 my $inv = "";
1387 ($inv = "-1*") if ($invert and ($$r_paths{$p}->type eq 'path'));
1388 ++$i;
1389 $i = $i % 10;
1390 $stack -= $stack_delta if ($$r_paths{$p}->{type} eq 'fit');
1391 my $stst = $stack + $ds_offset;
1392 %hash = (plot => $plot,
1393 'x' => join('.', $group, 'q'),
1394 'y' => "\"$inv" . join('.', $group, $part) . "+$stst\"",
1395 xlabel => "\"k (\\A\\u-1\\d)\"",
1396 ylabel => $ylabel,
1397 fg => $$r_pf{fg},
1398 bg => $$r_pf{bg},
1399 grid => $$r_pf{showgrid},
1400 gridcolor => $$r_pf{grid},
1401 xmin => $$r_pf{qmin},
1402 xmax => $$r_pf{qmax},
1403 style => $style,
1404 color => "\"" . $$r_pf{'c'.$i} . "\"",
1405 key => $key,
1406 title => "\"\'$set\' in q space\"");
1407 $this = plotstring(\%hash);
1408 $this = wrap("", $indent, $this);
1409 $command .= $this;
1410 ($plot, $indent) = ('plot', " ");
1411
1412 ## determine indicator boundries
1413 #$indic_command .= "set i___ndic.x = $hash{'x'}\n";
1414 $indic_command .= "set i___ndic.y = $hash{'y'}\n";
1415 $indic_command .= "set ind___min = min(ind___min, 1.05*floor(i___ndic.y))\n";
1416 $indic_command .= "set ind___max = max(ind___max, 1.05* ceil(i___ndic.y))\n";
1417
1418 $stack += $stack_delta;
1419
1420 ## A fit has been selected AND bkg and/or res have been requested
1421 if (($$r_paths{$p}->{type} eq 'fit') and $$r_paths{$p}->{parent}) {
1422 if (($do_bkg) and (-e $$r_paths{$p}->get('bkgfile'))) {
1423 (my $gr = $group) =~ s/fit/bkg/;
1424 ++$i;
1425 $i = $i % 10;
1426 $inv = "";
1427 ($inv = "-1*") if ($invert and ($$r_paths{$p}->type eq 'path'));
1428 $stst = $stack + $ds_offset;
1429 %hash = (plot => 'plot',
1430 'x' => join('.', $gr, 'r'),
1431 'y' => "\"$inv" . join('.', $gr, $part) . "+$stst\"",
1432 xlabel => "\"R (\\A)\"",
1433 ylabel => $ylabel,
1434 fg => $$r_pf{fg},
1435 bg => $$r_pf{bg},
1436 grid => $$r_pf{showgrid},
1437 gridcolor => $$r_pf{grid},
1438 xmin => $$r_pf{rmin},
1439 xmax => $$r_pf{rmax},
1440 style => $style,
1441 color => "\"" . $$r_pf{'c'.$i} . "\"",
1442 key => 'Bkg for '.$$r_paths{$p}->short_descriptor,
1443 title => "\"\'$set\' in R space\"");
1444 my $this = plotstring(\%hash);
1445 $this = wrap("", $indent, $this);
1446 (my $this_fft = $fft_command) =~ s/$group/$gr/g;
1447 $command .= $this_fft . "\n";
1448 (my $this_bft = $bft_command) =~ s/$group/$gr/g;
1449 $command .= $this_bft . "\n";
1450 $command .= $this;
1451 $stack += $stack_delta;
1452 };
1453 if ($do_res) {
1454 (my $gr = $group) =~ s/fit/res/;
1455 ++$i;
1456 $i = $i % 10;
1457 $stst = $stack + $ds_offset;
1458 %hash = (plot => 'plot',
1459 'x' => join('.', $gr, 'r'),
1460 'y' => "\"" . join('.', $gr, $part) . "+$stst\"",
1461 xlabel => "\"R (\\A)\"",
1462 ylabel => $ylabel,
1463 fg => $$r_pf{fg},
1464 bg => $$r_pf{bg},
1465 grid => $$r_pf{showgrid},
1466 gridcolor => $$r_pf{grid},
1467 xmin => $$r_pf{rmin},
1468 xmax => $$r_pf{rmax},
1469 style => $style,
1470 color => "\"" . $$r_pf{'c'.$i} . "\"",
1471 key => 'Resid for '.$$r_paths{$p}->short_descriptor,
1472 title => "\"\'$set\' in R space\"");
1473 my $this = plotstring(\%hash);
1474 $this = wrap("", $indent, $this);
1475 (my $this_fft = $fft_command) =~ s/$group/$gr/g;
1476 $command .= $this_fft . "\n";
1477 (my $this_bft = $bft_command) =~ s/$group/$gr/g;
1478 $command .= $this_bft . "\n";
1479 $command .= $this;
1480 $stack += $stack_delta;
1481 };
1482 };
1483
1484 ## envelope plot
1485 if ($$r_pf{q_pl} eq 'e') {
1486 $hash{plot} = 'plot';
1487 $hash{'y'} = '-1*'.$hash{'y'};
1488 $hash{key} = '';
1489 my $this = plotstring(\%hash);
1490 $this = wrap("", $indent, $this);
1491 $command .= $this;
1492 };
1493
1494 };
1495 if ($do_win) {
1496 ++$i;
1497 $i = $i % 10;
1498 my ($group, $kmin, $kmax, $dk, $kwin) = ($self->{group}, $self->{kmin},
1499 $self->{kmax}, $self->{dk},
1500 $self->{kwindow});
1501 my $kw = ($$r_pf{kweight} eq 'kw') ? $self->default_k_weight() : $$r_pf{kweight};
1502 ## ($self->{do_r}) and do {
1503 ## my $this = "$group.chi, kweight=$kw, kmin=$kmin, kmax=$kmax, dk=$dk, kwindow=$kwin)";
1504 ## $command .= wrap('fftf(', ' ', $this) . "\n";
1505 ## $self -> make(do_r=>0);
1506 ## };
1507 $self -> dispose("___x = ceil($group.chi*$group.k^$kw)", 1); # scale window to plot
1508 my $scale = $$r_pf{window_multiplier} * Ifeffit::get_scalar("___x");
1509 my $color = "\"" . $$r_pf{'c'.$i} . "\"";
1510 my $this = sprintf("plot(%s.k, %s.win*%f, style=lines, color=%s, key=window)",
1511 $group, $group, $scale, $color);
1512 $this = wrap("", " ", $this) . $/;
1513 $command .= $this;
1514 };
1515
1516 if ($$r_extra[5]) {
1517 foreach my $i (7 .. $#{$r_extra}) {
1518 next unless (lc($$r_extra[$i]->[1]) =~ /[kq]/);
1519 my $val = $$r_extra[$i]->[2];
1520 next if ($val < 0);
1521 $indic_command .= $self->plot_vertical_line($val, "", 0, 0, 1)
1522 };
1523 };
1524 $$r_extra[6] = $indic_command;
1525
1526 $last_plot_command = $command;
1527 return $command;
1528 };
1529
1530
1531
1532
1533 ## args are: x-position, y-range, plotting mode, key, yoffset, and
1534 ## newplot flag
1535 sub plot_vertical_line {
1536 my $self = shift;
1537 my ($x, $key, $yoffset, $new, $style) = @_;
1538 ##my $delta = $ymax - $ymin;
1539 my ($line, $color) = ($default->{indicatorline}, $default->{indicatorcolor});
1540 # ($style==1) ?
1541 # ($default->{indicatorline}, $default->{indicatorcolor}) :
1542 # ($default->{borderline}, $default->{bordercolor});
1543 my $command = "";
1544 $command .= "set ind___delta = ind___max-ind___min\n";
1545 $command .= "set v___ert.x = $x*ones(2)\n";
1546 $command .= "set v___ert.y = range(ind___min, ind___max, ind___delta)\n";
1547 if ($new) {
1548 $command .= "newplot(v___ert.x, \"v___ert.y+$yoffset\", key=\"$key\", style=$line, color=\"$color\")\n";
1549 } else {
1550 $command .= "plot(v___ert.x, \"v___ert.y+$yoffset\", key=\"$key\", style=$line, color=\"$color\")\n";
1551 };
1552 return $command;
1553 };
1554
1555
1556 sub floor_ceil {
1557 my ($x, $y, $rpf, $space) = @_;
1558 my ($ymin, $ymax, $i) = (1e10, -1e10, 0);
1559 foreach my $xx (@$x) {
1560 next if ($xx < $$rpf{$space.'min'});
1561 last if ($xx > $$rpf{$space.'max'});
1562 ($ymin = $$y[$i]) if ($$y[$i] < $ymin);
1563 ($ymax = $$y[$i]) if ($$y[$i] > $ymax);
1564 ++$i;
1565 };
1566 return sort ($ymin, $ymax);
1567 };
1568
1569
1570 ## sub pathgroup {
1571 ## my $self = shift;
1572 ## ##$$r_paths{$g}->{group} and return $$r_paths{$g}->{group};
1573 ## return 0 if (($g =~ /feff\d+\.\d+/) and not $self->{include});
1574 ## return $g unless ($g =~ /(feff\d+)\.(\d+)/);
1575 ## my $index = $$r_paths{$g}->index;
1576 ## my $g_ = join("_", $1, "$index");
1577 ## $$r_paths{$g}->{group} = $g_;
1578 ## return $g_;
1579 ## };
1580
1581 sub pathgroup {
1582 my ($g, $r_paths) = @_;
1583 if ($g =~ /(data\d)\.(\d)$/) {
1584 return $1 . "_" . ("fit", "res", "bkg", "diff")[$2];
1585 };
1586 ##$$r_paths{$g}->{group} and return $$r_paths{$g}->{group};
1587 return 0 unless exists $$r_paths{$g};
1588 return 0 if (($g =~ /feff\d+\.\d+/) and not $$r_paths{$g}->{include});
1589 return $$r_paths{$g}->{group} if ($g =~ /data\d+\.\d\.\d+$/);
1590 return $g unless ($g =~ /(feff\d+)\.(\d+)/);
1591 my $index = $$r_paths{$g}->index;
1592 my $g_ = join("_", $1, "$index");
1593 $$r_paths{$g}->{group} = $g_;
1594 return $g_;
1595 };
1596
1597
1598 ## return a sensible path list lable for this path
1599 sub pathlabel {
1600 my $self = shift;
1601 my $pattern = $_[0] || 'Path %i [%p]';
1602 my $r_paths = $self->{family};
1603 return $self->{group} unless ($self->{type} eq 'path');
1604
1605 my %table = (i => sprintf("%d", substr($self->{feff},4,4)),
1606 I => sprintf("%4.4d", substr($self->{feff},4,4)),
1607 p => "",
1608 r => $self->get('reff'),
1609 n => $self->get('nleg'),
1610 a => $self->get('zcwif'),
1611 d => $self->get('deg'),
1612 's' => "",
1613 );
1614
1615 ## find the %p token
1616 my $pathdesc = substr($self->{intrpline}, CORE::index($self->{intrpline}, ":")+2);
1617 my $core = substr($pathdesc, 0, CORE::index($self->{intrpline}, " "));
1618 ## escape metacharacters in the core token, then find all the stuff
1619 ## between the core tokens
1620 $core =~ s/([\\\.\^\$\*\+\?\{\}\[\]\(\)\|])/\\$1/g;
1621 $core =~ s/\s+$//;
1622 ($pathdesc = $1) if ($pathdesc =~ /$core(.*)$core/);
1623 $pathdesc =~ s/^\s+//;
1624 $pathdesc =~ s/\s+$//;
1625 $table{p} = $pathdesc;
1626
1627 ## flag special paths
1628 ($self->{is_ss} = 1) if ($self->{nleg} == 2);
1629 ($self->{is_col} = 1) if ($self->{intrpline} =~ /\d :/);
1630
1631 ## find the %s token
1632 ($table{'s'} = 'SS') if $self->{is_ss};
1633 ($table{'s'} = 'col.') if $self->{is_col};
1634
1635 $pattern =~ s/\%([adinprsI])/$table{$1}/g;
1636
1637 ## deal with an ambiguous label (perhaps from a poor pattern,
1638 ## perhaps from a path clone)
1639 my $suff = 0;
1640 foreach my $k (sort (keys %$r_paths)) {
1641 next unless (exists $$r_paths{$k}->{type});
1642 next unless ($$r_paths{$k}->{type} eq 'path');
1643 next unless ($self->{parent} eq $$r_paths{$k}->{parent});
1644 ## are these in the same feff calc?
1645 next unless ($$r_paths{$k}->{parent} eq $self->{parent});
1646 #print "skipping self\n",
1647 next if ($k eq $self->{id});
1648
1649 ## escape the pattern
1650 (my $patt = $pattern) =~ s/([\\\.\^\$\*\+\?\{\}\[\]\(\)\|])/\\$1/g;
1651 if ($$r_paths{$k}->{lab} =~ /^$patt\s*:\s*(\d+)/) {
1652 ($suff = $1+1); # if ($1 >= $suff);
1653 } elsif ($$r_paths{$k}->{lab} eq $pattern) {
1654 $suff ||= 1;
1655 };
1656 };
1657
1658 ## finally return the label
1659 $self->{lab} = ($suff) ? $pattern . " : $suff" : $pattern;
1660 };
1661
1662
1663 sub pathstate {
1664 my $self = shift;
1665 my $state;
1666 if ($_[0]) {
1667 $state = $_[0];
1668 } else {
1669 $state = ($self->get('include')) ? "enabled" : "disabled";
1670 };
1671 ($state .= "_ss") if $self->{is_ss};
1672 ($state .= "_col") if $self->{is_col};
1673 ##print $state, $/;
1674 return $state;
1675 };
1676
1677
1678 sub intrpline {
1679 my $self = shift;
1680 return "" unless ($self->type eq "path");
1681 my $parent = $self->get("parent");
1682 foreach my $l (split(/\n/, $self->{family}->{$parent}->get('intrp'))) {
1683 my $ss = substr($self->{file},4,4);
1684 return substr($l, 2) if ($l =~ /^\d\s+$ss/);
1685 };
1686 return "";
1687 };
1688
1689 sub plotstring {
1690 my $rh = $_[0];
1691 my $string = $$rh{plot} . "(";
1692 $string .= $$rh{'x'} . ', ' . $$rh{'y'} . ', ';
1693 if ($$rh{plot} eq 'newplot') {
1694 foreach (qw(xlabel ylabel fg bg grid gridcolor xmin xmax style color key title)) {
1695 #next unless $$rh{$_};
1696 if ($_ eq 'grid') {
1697 $string .= ($$rh{grid}) ? 'grid, ' : 'nogrid, ';
1698 } elsif ($_ eq 'gridcolor') {
1699 $string .= "gridcolor=\"$$rh{gridcolor}\", " if $$rh{grid};
1700 } elsif ($_ eq 'key') {
1701 $string .= "key=\"$$rh{key}\", ";
1702 } else {
1703 $string .= $_ . "=$$rh{$_}, ";
1704 };
1705 };
1706 } else {
1707 foreach (qw(style color key)) {
1708 next unless $$rh{$_};
1709 if ($_ eq 'key') {
1710 $string .= "key=\"$$rh{key}\", ";
1711 } else {
1712 $string .= $_ . "=$$rh{$_}, ";
1713 };
1714 };
1715 };
1716 $string =~ s/, $/\)\n/;
1717 return $string;
1718 };
1719
1720
1721 sub descriptor {
1722 my $self = shift;
1723 my $r_paths = $self->{family};
1724 SWITCH: {
1725 ($self->{type} eq 'gsd') and do {
1726 return "Guess, Def, Set";
1727 last SWITCH;
1728 };
1729 ($self->{type} eq 'data') and do {
1730 return $self->{lab};
1731 last SWITCH;
1732 };
1733 ($self->{type} eq 'fit') and do {
1734 return join(": ", $$r_paths{$self->{sameas}}->{lab}, $self->{lab});
1735 last SWITCH;
1736 };
1737 ($self->{type} eq 'bkg') and do {
1738 return join(": ", $$r_paths{$self->{sameas}}->{lab}, $self->{lab});
1739 last SWITCH;
1740 };
1741 ($self->{type} eq 'res') and do {
1742 return join(": ", $$r_paths{$self->{sameas}}->{lab}, $self->{lab});
1743 last SWITCH;
1744 };
1745 ($self->{type} eq 'diff') and do {
1746 return join(": ", $$r_paths{$self->{sameas}}->{lab}, $self->{lab});
1747 last SWITCH;
1748 };
1749 ($self->{type} eq 'feff') and do {
1750 return join(": ", $$r_paths{$self->{data}}->{lab}, $self->{lab});
1751 last SWITCH;
1752 };
1753 ($self->{type} eq 'path') and do {
1754 return join(": ", $$r_paths{$self->{parent}}->{lab}, $self->{lab});
1755 last SWITCH;
1756 };
1757 };
1758 return $self->{lab} || "";
1759 };
1760
1761 sub short_descriptor {
1762 my $self = shift;
1763 my $r_paths = $self->{family};
1764 SWITCH: {
1765 ($self->{type} eq 'gsd') and do {
1766 return "GDS";
1767 last SWITCH;
1768 };
1769 ($self->{type} eq 'data') and do {
1770 return 'data';
1771 last SWITCH;
1772 };
1773 (($self->{type} eq 'fit') and $self->{parent}) and do {
1774 return 'fit';
1775 last SWITCH;
1776 };
1777 ($self->{type} eq 'fit') and do {
1778 return 'fit';
1779 last SWITCH;
1780 };
1781 ($self->{type} eq 'bkg') and do {
1782 return 'bkg';
1783 last SWITCH;
1784 };
1785 ($self->{type} eq 'res') and do {
1786 return 'resid';
1787 last SWITCH;
1788 };
1789 ($self->{type} eq 'diff') and do {
1790 return 'diff';
1791 last SWITCH;
1792 };
1793 ($self->{type} eq 'feff') and do {
1794 my $this = $self->{id};
1795 return (split(/\./, $this))[1];
1796 last SWITCH;
1797 };
1798 ($self->{type} eq 'path') and do {
1799 ## note that this is similar to the plot key
1800 my $f = $self->{parent};
1801 $f = $$r_paths{$f}->{id};
1802 $f = (split(/\./, $f))[1];
1803 my $pa = $self->{lab};
1804 $pa =~ s/feff0?//;
1805 $pa =~ s/\.dat//;
1806 my $key = "${f}_$pa";
1807 $key =~ s/\s+//;
1808 return $key;
1809 last SWITCH;
1810 };
1811 };
1812 return $self->{lab} || "";
1813 };
1814
1815
1816 sub param_summary {
1817 my $self = shift;
1818 my $pkw = shift;
1819 my $rp = $self->{family};
1820 my $this = $self;
1821 $this = $$rp{$this->data};
1822 ## ($this = $$rp{$self->{sameas}}) if (exists $$rp{$self->{sameas}});
1823 ## ($this = $$rp{$self->{data}}) if (exists $$rp{$self->{data}});
1824 my $text = "";
1825 $text .= "Fitting parameters:\n";
1826 my @kw = ();
1827 push @kw, "1" if $this->{k1};
1828 push @kw, "2" if $this->{k2};
1829 push @kw, "3" if $this->{k3};
1830 push @kw, $this->{karb} if $this->{karb_use};
1831 push @kw, "1" unless @kw;
1832 $text .= sprintf("- k-range: [ %.3f : %.3f ] dk=%.2f
1833 - R-range: [ %.3f : %.3f ] dR=%.2f
1834 - kweight=%s k-window=%s R-window=%s
1835 - fit space=%s fit background: %s
1836 - phase correction: %s
1837 - plotting kweight=%s
1838 -
1839 ",
1840 $this->{kmin}, $this->{kmax}, $this->{dk},
1841 $this->{rmin}, $this->{rmax}, $this->{dr},
1842 join(",", @kw), $this->{kwindow}, $this->{rwindow},
1843 $this->{fit_space},
1844 ((lc($this->{do_bkg}) eq 'yes') ? 'yes' : 'no'),
1845 $this->{pcpath}, $pkw,
1846 );
1847 };
1848
1849
1850 ## look for FEFF.INP, Feff.Inp, and Feff.inp if feff.inp is not found
1851 sub verify_feffinp {
1852 my $self = shift;
1853 my $feffinp = $self->{'feff.inp'};
1854 #print $self->{lab}, "0: ", $feffinp, $/;
1855 if (not -e $feffinp) { # did not find feff.inp,
1856 # look for FEFF.INP
1857 my $fi = uc(basename($feffinp));
1858 $feffinp = File::Spec->catfile(dirname($feffinp), $fi);
1859 #print $self->{lab}, "1: ", $feffinp, $/;
1860 };
1861 if (not -e $feffinp) { # did not find FEFF.INP
1862 # look for Feff.Inp
1863 my $fi = basename($feffinp);
1864 my @parts = map { ucfirst $_ } (split(/\./, $fi));
1865 $fi = join(".", @parts);
1866 $feffinp = File::Spec->catfile(dirname($feffinp), $fi);
1867 #print $self->{lab}, "2: ", $feffinp, $/;
1868 }
1869 if (not -e $feffinp) { # did not find Feff.Inp
1870 # look for Feff.inp
1871 my $fi = basename($feffinp);
1872 my @parts = split(/\./, $fi);
1873 $fi = join(".", ucfirst($parts[0]), lc($parts[1]));
1874 $feffinp = File::Spec->catfile(dirname($feffinp), $fi);
1875 #print $self->{lab}, "3: ", $feffinp, $/;
1876 }
1877 if (not -e $feffinp) { # did not find Feff.inp
1878 # give up, reset to feff.inp
1879 $feffinp = $self->{'feff.inp'};
1880 };
1881 #print $self->{lab}, "4: ", $feffinp, $/;
1882 $self->make('feff.inp' => $feffinp);
1883 };
1884
1885 ## this function reads feff.inp, files.dat, and paths.dat to present
1886 ## an easily digestable summary of the feff calculation
1887 sub intrp {
1888 my $self = shift;
1889 return 0 unless ($self->{type} eq 'feff');
1890 $self->{edge} = "K";
1891 my %label;
1892 my @title;
1893
1894 my %intrp_data = (text => "",
1895 ntitle => 0,
1896 switch => 0,
1897 rmult => 1,
1898 rmax => 1000,
1899 maxr => 1000, # *
1900 cwcrit => 2.5, # *
1901 factor => 1000,
1902 natom => 0,
1903 central => "",
1904 betamax => $_[0] || 20, # *
1905 minamp => 0, # *
1906 core_token => $_[1] || '[+]',); # *
1907 my @potentials;
1908
1909 ## need to read the potentials list so we have the element symbols
1910 ## as fallbacks for atoms tokens. close FEFF when the potetial list
1911 ## if over ...
1912 open FEFF, $self->{'feff.inp'} or
1913 die "could not open $self->{'feff.inp'} for reading in intrp\n";
1914 FL: while (<FEFF>) {
1915 next if (/^\s*\*/);
1916 next if (/^\s*$/);
1917 if ( /^\s*poten/i ) {
1918 my $pot = "foo";
1919 while ($pot) {
1920 my $pot = <FEFF>;
1921 if ($pot =~ /^\s*\d/) {
1922 my @line = split(" ", $pot);
1923 $potentials[$line[0]] = get_symbol($line[1]);
1924 } elsif ($pot =~ /^\s*\w/) {
1925 last FL;
1926 };
1927 };
1928 };
1929 };
1930 close FEFF;
1931
1932 ## now we need to find the atomic coordinates of the absorber atom
1933 open FEFF, $self->{'feff.inp'} or
1934 die "could not open $self->{'feff.inp'} for reading in intrp\n";
1935 my $flag = 0;
1936 my @xyz = (0,0,0);
1937 FA: while (<FEFF>) {
1938 chomp;
1939 $flag = 1, next FA if (/^\s*ato/i);
1940 next FA unless $flag;
1941 next if (/^\s*\*/);
1942 next if (/^\s*$/);
1943 my @line = split(" ", $_);
1944 next FA unless ($line[3] == 0);
1945 @xyz = (@line[0..2]);
1946 last FA;
1947 };
1948 close FEFF;
1949
1950 $intrp_data{central} = $potentials[0];
1951 $self->{central} = $intrp_data{central};
1952 ## and start over again at the top to fetch the hash of atomic positions
1953 open FEFF, $self->{'feff.inp'} or
1954 die "could not open $self->{'feff.inp'} for reading in intrp\n";
1955 FEFFLOOP: while (<FEFF>) {
1956 chomp;
1957 last if (/^\s*END/i);
1958 next FEFFLOOP if (/^\s*\*/);
1959 next FEFFLOOP if (/^\s*$/);
1960 SWITCH: {
1961 # reading atoms list
1962 ($intrp_data{switch}) and do {
1963 my ($x, $y, $z, $ipot, $tag) = split;
1964 #($ipot eq "0") and ($intrp_data{core_token} = $tag || '[+]');
1965
1966 my $r = sqrt(($x-$xyz[0])**2 + ($y-$xyz[1])**2 + ($z-$xyz[2])**2);
1967 next FEFFLOOP if ($r > $intrp_data{rmax});
1968 my $key = round($intrp_data{rmult}*$intrp_data{factor}*($x-$xyz[0])) .
1969 round($intrp_data{rmult}*$intrp_data{factor}*($y-$xyz[1])) .
1970 round($intrp_data{rmult}*$intrp_data{factor}*($z-$xyz[2]));
1971 $label{$key} = $tag || $potentials[$ipot]; # use tag if there, else
1972 ++$intrp_data{natom}; # use the atomic symbol
1973 last SWITCH;
1974 };
1975 # get crits
1976 ( /^\s*crit\s*[=,\s]\s*(-?(\d+\.?\d*|\.\d+))/i ) and do {
1977 $intrp_data{cwcrit} = $1;
1978 ## $intrp_data{cwcrit} = (split( /[=,\s]+/ ))[2];
1979 last SWITCH;
1980 };
1981 # get edge
1982 (/^\s*(hole|edge)\s*[=,\s]\s*(\d{1,2}|k|l[123]|m[1-5])/i) and do {
1983 $intrp_data{edge} = $2; #(split( /[=,\s]+/ ))[2];
1984 ($intrp_data{edge} = 'K') if ($intrp_data{edge} eq 1);
1985 ($intrp_data{edge} = 'L1') if ($intrp_data{edge} eq 2);
1986 ($intrp_data{edge} = 'L2') if ($intrp_data{edge} eq 3);
1987 ($intrp_data{edge} = 'L3') if ($intrp_data{edge} eq 4);
1988 $self->{edge} = $intrp_data{edge};
1989 last SWITCH;
1990 };
1991 # get title lines
1992 ( /^\s*title/i ) and do {
1993 chomp;
1994 $title[$intrp_data{ntitle}] = substr($_, 0, 69);
1995 ++$intrp_data{ntitle};
1996 last SWITCH;
1997 };
1998 # beginning of atoms list
1999 ( /^\s*atom/i ) and do {
2000 $intrp_data{switch} = 1;
2001 last SWITCH;
2002 };
2003 # get rmax
2004 ( /^\s*r(max|path)\s*[=,\s]\s*(-?(\d+\.?\d*|\.\d+))/i ) and do {
2005 $intrp_data{rmax} = $2;
2006 ## my @line = split( /[=,\s]+/ );
2007 ## $intrp_data{rmax} = ($line[0] =~ (/r(max|path)/i)) ? $line[1] : $line[2];
2008 last SWITCH;
2009 };
2010 # need to apply rmult to correctly make tags
2011 # this will fail if RMULTIPLIER comes after the atoms list
2012 ( /^\s*rmult[a-z]*\s*[=,\s]\s*(-?(\d+\.?\d*|\.\d+))/i ) and do {
2013 $intrp_data{rmult} = $1;
2014 ## my @line = split( /[=,\s]+/ );
2015 ## $intrp_data{rmult} = ($line[0] =~ (/rmult/i)) ? $line[1] : $line[2];
2016 last SWITCH;
2017 };
2018 };
2019 };
2020 close FEFF;
2021
2022 my (@fname, @sig2, @amp, @degen, @nleg, @reff);
2023 $intrp_data{switch} = 0;
2024 open FILES, $self->{'files.dat'} or
2025 die "could not open $self->{'files.dat'} for reading in intrp\n";
2026 while (<FILES>) {
2027 if ( /^\s*--------/ ) { # find end of header
2028 ($intrp_data{switch} = 1);
2029 } elsif ($intrp_data{switch}) {
2030 next if ( /^\s*file/i );
2031 next if ( /^\s*$/ );
2032 chomp;
2033 #++$npath; # get path info for each path
2034 my @line = split;
2035 unless ($line[0]) { shift(@line); }
2036 my $ip = sprintf("%d", substr($line[0], 4, 4)); # want index as an integer
2037 ($fname[$ip], $sig2[$ip], $amp[$ip], $degen[$ip],
2038 $nleg[$ip], $reff[$ip] ) = @line;
2039 };
2040 };
2041 close FILES;
2042
2043 open PATHS, $self->{'paths.dat'} or
2044 die "could not open $self->{'paths.dat'} for reading in intrp\n";
2045 $intrp_data{switch} = 0;
2046 my (@leg, @token);
2047 my ($nl, $np, $skip) = (-1, 0, 0);
2048 while (<PATHS>) {
2049 ($intrp_data{switch} = 1), next if ( /^\s*--------/ );
2050 if ($intrp_data{switch}) {
2051 next if ( /label/i );
2052 next if ( /^\s*$/ );
2053 chomp;
2054 if ( /degeneracy/i ) {
2055 my @line = split; # path index is $line[0]
2056 $skip = 1, next unless ($fname[$line[0]]); # skip paths in paths.dat that are
2057 $skip = 0;
2058 last if ( $line[$#line] > $intrp_data{maxr} );
2059 if ( ($np) && ($fname[$np]) ) { # write path tokens for prev. path
2060 $intrp_data{text} .= sprintf "%1s : %s", $intrp_data{nshadow}||" ", $intrp_data{core_token};
2061 map { $intrp_data{text} .= sprintf " %-6s", $_ } (@token);
2062 @token = (); @leg = ();
2063 } # write out path information for current path
2064 $np = $line[0];
2065 if ( $amp[$np] < $intrp_data{minamp} ) { # skip paths smaller than $opt_a
2066 $skip = 1;
2067 next;
2068 }
2069 ($intrp_data{text} .= sprintf "$/%s %4.4u %3u %5.3f %6.2f ",
2070 $nleg[$np], $np, int($degen[$np]+0.1), $reff[$np], $amp[$np])
2071 if $fname[$np];
2072 $intrp_data{nshadow} = 0;
2073 $nl=-1;
2074 } else { # Collect tokens for each leg and count
2075 next if ($skip);
2076 ++$nl; # number of forward scatterings.
2077 my $beta = 180;
2078 ## how does this next bit work???
2079 if (/\'/) {
2080 my $pos = $[; # Find beta angle. Good work Steve!
2081 $pos = CORE::index($_, "'"); # This is about as annoying as possible.
2082 $pos = CORE::index($_, "'", $pos+1);
2083 my @findbeta = split( /\s+/, substr( $_, $pos+1) );
2084 ($beta = $findbeta[2]) if (exists($findbeta[2]) and length($findbeta[2]));
2085 }
2086 @leg = split;
2087 unless ($nl == $nleg[$np]-1) {
2088 ($beta < $intrp_data{betamax}) && ++$intrp_data{nshadow};
2089 };
2090 if ( $leg[3] eq "0" ) {
2091 $token[$nl] = $intrp_data{core_token};
2092 } else {
2093 ## rmultiplier has already been applied in paths.dat
2094 # my $tag = round($intrp_data{rmult}*$intrp_data{factor}*($leg[0]-$xyz[0])) .
2095 # round($intrp_data{rmult}*$intrp_data{factor}*($leg[1]-$xyz[1])) .
2096 # round($intrp_data{rmult}*$intrp_data{factor}*($leg[2]-$xyz[2]));
2097 my $tag = round($intrp_data{factor}*($leg[0]-$xyz[0])) .
2098 round($intrp_data{factor}*($leg[1]-$xyz[1])) .
2099 round($intrp_data{factor}*($leg[2]-$xyz[2]));
2100 $token[$nl] = $label{$tag} || "<?>";
2101 # paths.dat might contain hand made entries,
2102 # use <?> as token for a hand made atom
2103 };
2104 };
2105 };
2106 };
2107 ## tokens for final path
2108 $intrp_data{text} .= sprintf "%1s : %s", $intrp_data{nshadow}||" ", $intrp_data{core_token};
2109 map { $intrp_data{text} .= sprintf " %-6s", $_ } (@token);
2110 close PATHS;
2111
2112 my $head = "";
2113 my $energy = ($absorption_exists) ? sprintf("%s edge energy = %s eV", $intrp_data{edge},
2114 Xray::Absorption->get_energy($intrp_data{central},
2115 $intrp_data{edge}))
2116 : "";
2117 map { $head .= "# $_\n" } (@title);
2118 $head .= "#$/# Central atom: " . get_name($intrp_data{central}) . " (" .
2119 get_Z($intrp_data{central}) . ") $energy\n";
2120 $head .= "# The central atom is denoted by this token: $intrp_data{core_token}\n";
2121 $head .= "# Cluster size = $intrp_data{rmax} Angstroms, containing $intrp_data{natom} atoms.\n";
2122 ($head .= "# rmultiplier = $intrp_data{rmult}\n") if ( $intrp_data{rmult} != 1);
2123 $head .= "# Curved wave criteria = $intrp_data{cwcrit}.\n";
2124 $head .= "# Cutoff angle for forward scattering is $intrp_data{betamax} degrees.\n";
2125 $head .= "# ------------------------------------------------------------\n";
2126 $head .= "# degen reff amp fs scattering path";
2127
2128 return $head . $intrp_data{text};
2129 };
2130 #$head .= "# $npath paths were calculated by feff.\n";
2131 #($head .= "# This list is truncated at $intrp_data{maxr} Angstroms.\n")
2132 # if ( $intrp_data{maxr} < 999 );
2133 #($head .= "# This list contains paths of amplitude larger than $intrp_data{minamp}\n")
2134 # if ( $intrp_data{minamp} > 0.0002 );
2135
2136
2137
2138 sub default_k_weight {
2139 my $self = $_[0];
2140 my $kw = 1; # return 1 is none others selected
2141 SWITCH: {
2142 $kw = sprintf("%.3f", $self->{karb}), last SWITCH
2143 if ($self->{karb_use} and ($self->{karb} =~ /^\s*-?(\d+\.?\d*|\.\d+)\s*$/));
2144 $kw = 1, last SWITCH if $self->{k1};
2145 $kw = 2, last SWITCH if $self->{k2};
2146 $kw = 3, last SWITCH if $self->{k3};
2147 };
2148 return $kw;
2149 };
2150
2151 sub count_data_sets {
2152 my $self = shift;
2153 my $r_paths = $self->{family};
2154 my $nsets = 0;
2155 foreach my $k (keys %$r_paths) {
2156 next unless exists($$r_paths{$k}->{type});
2157 next unless ($$r_paths{$k}->{type} eq 'data');
2158 next unless $$r_paths{$k}->{include};
2159 ++$nsets;
2160 ## next unless $$r_paths{$k}->{include};
2161 ## my $this = $$r_paths{$k}->{k1} + $$r_paths{$k}->{k2} + $$r_paths{$k}->{k3};
2162 ## $this += $$r_paths{$k}->{karb_use}
2163 ## if ($$r_paths{$k}->{karb} =~ /^\s*-?(\d+\.?\d*|\.\d+)\s*$/);
2164 ## $nsets += ($this || 1);
2165 ## };
2166 };
2167 return $nsets;
2168 };
2169
2170
2171 sub group_weights {
2172 my $self = shift;
2173 my @list = ();
2174 push(@list, 1) if $self->{k1};
2175 push(@list, 2) if $self->{k2};
2176 push(@list, 3) if $self->{k3};
2177 push(@list, $self->{karb}) if $self->{karb_use};
2178 push(@list, 1) unless @list;
2179 return @list;
2180 };
2181
2182
2183 sub x_minmax {
2184 my $self = shift;
2185 my $group = $self->{group};
2186 my $suff = "";
2187 SUFF: {
2188 $suff = 'energy', last SUFF if (lc($_[0]) eq 'e');
2189 $suff = 'k', last SUFF if (lc($_[0]) eq 'k');
2190 $suff = 'r', last SUFF if (lc($_[0]) eq 'r');
2191 $suff = 'q', last SUFF if (lc($_[0]) eq 'q');
2192 };
2193 $self->dispose("set ___min = floor($group.$suff)",1);
2194 $self->dispose("set ___max = ceil($group.$suff)", 1);
2195 my @vals = (Ifeffit::get_scalar("___min"),
2196 Ifeffit::get_scalar("___max"));
2197 $self->dispose("erase ___min ___max", 1);
2198 return @vals;
2199 };
2200
2201
2202 ## used in intrp method
2203 ## sub _round {
2204 ## my $number = shift;
2205 ## return int($number + .5 * ($number <=> 0));
2206 ## };
2207
2208
2209 1;
2210 __END__