Debian Codegraph @

artemis_parts/athena.pl

raw
1 # -*- cperl -*-
2 ## This file is part of Artemis, copyright (c) 2002-2008 Bruce Ravel
3 ##
4 ## READING ATHENA PROJECT FILES IN ARTEMIS
5
6
7 sub read_athena {
8
9 my $prjfile = $_[0];
10
11 # my $was_mac = $paths{data0} ->
12 # fix_mac($prjfile, $stash_dir, lc($config{general}{mac_eol}), $top);
13 # Echo("Fixed EOL characters for \"$prjfile\".") if ($was_mac == 1);
14 # return, Echo("Skipped \"$prjfile\" due to EOL characters.") if ($was_mac == -1);
15
16 my ($tmp, $text);
17 my $orig = $prjfile;
18 my $athena_fh = gzopen($prjfile, "rb") or die "could not open $prjfile as an Athena project\n";
19 ##open(ORIG, "< $prjfile")
20 ## or die "Can't open $prjfile for reading: $!";
21
22 track({file=>$prjfile, mode=>"reading from", command=>sub{my $size = -s $prjfile; print "size : $size\n"}}) if $debug_file_path;
23
24 ##my $athena_fh = *ORIG;
25 my @athena_index = ();
26 my %athena_group = ();
27 my $nline = 0;
28 my $line = q{};
29 my $cpt = new Safe;
30 ##while (<ORIG>) {
31 while ($athena_fh->gzreadline($line) > 0) {
32 ++$nline;
33 next unless ($line =~ /^\$old_group/);
34 push @athena_index, $nline;
35 ## need to make a map to the groups by old group name so that
36 ## background removal with a standard can be performed correctly
37 $ {$cpt->varglob('old_group')} = $cpt->reval( $line );
38 my $og = $ {$cpt->varglob('old_group')};
39 $athena_group{$og} = {index=>$nline, hlist=>0};
40 };
41 $athena_fh->gzclose();
42 ##close ORIG;
43
44
45 $ath_params{plot} ||= 'chir_mag';
46 $ath_params{params} ||= "project";
47 map {$_ -> configure(-state=>'disabled')}
48 ($gsd_menu, $feff_menu, $paths_menu, $data_menu, $sum_menu, $fit_menu); #, $settings_menu);
49 $edit_menu -> menu -> entryconfigure(13, -state=>'disabled');
50 SWITCH: {
51 $opparams -> packForget(), last SWITCH if ($current_canvas eq 'op');
52 $gsd -> packForget(), last SWITCH if ($current_canvas eq 'gsd');
53 $feff -> packForget(), last SWITCH if ($current_canvas eq 'feff');
54 $path -> packForget(), last SWITCH if ($current_canvas eq 'path');
55 $logviewer -> packForget(), last SWITCH if ($current_canvas eq 'logview');
56 };
57 $current_canvas = 'athena';
58
59 my $ath = $fat -> Frame(-relief=>'flat',
60 -borderwidth=>0,
61 -highlightcolor=>$config{colors}{background})
62 -> pack(-fill=>'both', -expand=>1);
63
64 my $frm = $ath -> Frame() -> pack(-side=>'top', -anchor=>'w', -padx=>6);
65
66 $frm -> Label(-text=>"Athena project ", @title2)
67 -> pack(-side=>'left', -anchor=>'w', -padx=>4);
68 $frm -> Label(-textvariable=>\$orig,
69 -foreground=>$config{colors}{button})
70 -> pack(-side=>'right', -anchor=>'e');
71
72
73 $widgets{athena_return} = $ath -> Button(-text=>'Cancel and return to the main window', @button3_list,
74 #-background=>$config{colors}{background},
75 #-activebackground=>$config{colors}{activebackground},
76 -command=>sub{$ath->packForget;
77 $current_canvas = "";
78 $edit_menu -> menu -> entryconfigure(13, -state=>'normal');
79 &display_properties;
80 Echo("Restored normal view");
81 })
82 -> pack(-side=>'bottom', -fill=>'x');
83
84 my $labframe = $ath -> LabFrame(-label=>'Athena records',
85 -labelside=>'acrosstop',
86 -foreground=>$config{colors}{activehighlightcolor})
87 -> pack(-side=>'left', -fill=>'y', -anchor=>'w');
88 my $hlist;
89 $hlist = $labframe -> Scrolled('HList',
90 -scrollbars=>'osoe',
91 -columns=>1,
92 -header=>0,
93 -selectmode=>'single',
94 -width=>20,
95 -background=>'white',
96 -selectbackground=>$config{colors}{selected},
97 -browsecmd=>sub{athena_plot($hlist, $prjfile, \%athena_group)},
98 )
99 -> pack(-expand=>1, -fill=>'y');
100 $hlist->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background},
101 ($is_windows) ? () : (-width=>8));
102 $hlist->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background},
103 ($is_windows) ? () : (-width=>8));
104
105 $labframe = $ath -> Frame()
106 -> pack(-side=>'right', -expand=>1, -fill=>'both', -anchor=>'n');
107
108 $widgets{help_athena} = $labframe
109 -> Button(-text => "Document: Importing Athena project data", @button2_list,
110 -command=>sub{pod_display("artemis_athena.pod")},
111 -width=>65)
112 -> pack(-side=>'bottom', -fill=>'x', -padx=>2, -pady=>2);
113
114
115 my $fr = $labframe -> LabFrame(-label=>'Titles',
116 -labelside=>'acrosstop',
117 -foreground=>$config{colors}{activehighlightcolor})
118 -> pack(-side=>'top', -fill=>'x', -padx=>0, -pady=>0);
119 $widgets{athena_selected} = $fr;
120 $widgets{athena_titles} = $fr -> Scrolled('ROText',
121 -scrollbars => 'soe',
122 -wrap => 'none',
123 -height => 8,)
124 -> pack();
125 $widgets{athena_titles}->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background},
126 ($is_windows) ? () : (-width=>8));
127 $widgets{athena_titles}->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background},
128 ($is_windows) ? () : (-width=>8));
129
130
131 my @radio_args = (-foreground => $config{colors}{activehighlightcolor},
132 -activeforeground => $config{colors}{activehighlightcolor},
133 -selectcolor => $config{colors}{check},
134 -font => $config{fonts}{med},
135 -variable => \$ath_params{plot},
136 -command => sub{athena_plot($hlist, $prjfile, \%athena_group)});
137
138 $fr = $labframe -> LabFrame(-label=>'Plot as ... ',
139 -labelside=>'acrosstop',
140 -foreground=>$config{colors}{activehighlightcolor})
141 -> pack(-side=>'top', -fill=>'both', -pady=>4);
142 $fr -> Radiobutton(-text => 'chi(k)', @radio_args, -value => 'chi', )
143 -> grid(-row=>0, -column=>0, -padx=>2, -sticky=>'w');
144 $fr -> Radiobutton(-text => '|chi(R)|', @radio_args, -value => 'chir_mag',)
145 -> grid(-row=>0, -column=>1, -padx=>2, -sticky=>'w');
146 $fr -> Radiobutton(-text => '|chi(q)|', @radio_args, -value => 'chiq_mag', )
147 -> grid(-row=>0, -column=>2, -padx=>2, -sticky=>'w');
148 $fr -> Radiobutton(-text => 'Re[chi(R)]', @radio_args, -value => 'chir_re', )
149 -> grid(-row=>1, -column=>1, -padx=>2, -sticky=>'w');
150 $fr -> Radiobutton(-text => 'Re[chi(q)]', @radio_args, -value => 'chiq_re', )
151 -> grid(-row=>1, -column=>2, -padx=>2, -sticky=>'w');
152 $fr -> Radiobutton(-text => 'Im[chi(R)]', @radio_args, -value => 'chir_im', )
153 -> grid(-row=>2, -column=>1, -padx=>2, -sticky=>'w');
154 $fr -> Radiobutton(-text => 'Im[chi(q)]', @radio_args, -value => 'chiq_im', )
155 -> grid(-row=>2, -column=>2, -padx=>2, -sticky=>'w');
156
157
158 $fr = $labframe -> Frame()
159 -> pack(-side=>'top', -fill=>'x', -pady=>4, -padx=>4);
160 $fr -> Radiobutton(-text =>"Use parameters from Athena project",
161 -foreground => $config{colors}{activehighlightcolor},
162 -activeforeground => $config{colors}{activehighlightcolor},
163 -selectcolor => $config{colors}{check},
164 -font => $config{fonts}{med},
165 -variable => \$ath_params{params},
166 -value => 'project' )
167 -> pack(-side =>'top', -anchor=>'w');
168 $fr -> Radiobutton(-text =>"Use default parameters",
169 -foreground => $config{colors}{activehighlightcolor},
170 -activeforeground => $config{colors}{activehighlightcolor},
171 -selectcolor => $config{colors}{check},
172 -font => $config{fonts}{med},
173 -variable => \$ath_params{params},
174 -value => 'default' )
175 -> pack(-side=>'top', -anchor=>'w');
176
177
178 $labframe -> Button(-text=>"Import these data",
179 @button3_list,
180 -command=>sub{
181 $ath->packForget;
182 $current_canvas = "";
183 $edit_menu -> menu -> entryconfigure(13, -state=>'normal');
184 athena_import($hlist, $prjfile, $orig, $ath_params{params});
185 })
186 -> pack(-side=>'top', -fill=>'x', -pady=>10, -padx=>4);
187
188
189
190 my @groups = ();
191 my @group_lines = ();
192 my $old_group = "";
193 my $line_number = 1;
194
195 #foreach my $i (@athena_index) {
196 foreach my $g (sort {$athena_group{$a}{index} <=> $athena_group{$b}{index}} keys(%athena_group)) {
197 my $i = $athena_group{$g}{index};
198 my %args = athena_get_array($prjfile, $i, "args");
199 $args{label} =~ s{[\"\']}{}g;
200 next unless ($args{is_xmu} or $args{is_chi});
201 $hlist -> add($i, -data=>$i);
202 $hlist -> itemCreate($i, 0, -text=>$args{label});
203 $athena_group{$g}{hlist} = $i;
204 };
205 $hlist -> anchorSet($athena_index[0]);
206 $hlist -> selectionSet($athena_index[0]);
207 athena_plot($hlist, $prjfile, \%athena_group);
208
209 ## set_fit_button('fit');
210
211 };
212
213 ## This is, perhaps, a bit slow. It reads linearly through an athena
214 ## project file until it finds the specified group, then it imports
215 ## the requested array.
216
217 ## arg 0 is the project file name
218 ## arg 1 is the line in the file with that record (already found)
219 ## arg 2 is one of: args x y stddev i0
220 sub athena_get_array {
221 my ($prjfile, $index, $which) = @_;
222 my $cpt = new Safe;
223 my @array;
224 my $prj = gzopen($prjfile, "rb") or die "could not open $prjfile as an Athena project\n";
225 ##open A, $prjfile;
226 my $count = 0;
227 my $found = 0;
228 my $re = '@' . $which;
229 my $line = q{};
230 ##foreach my $line (<A>) {
231 while ($prj->gzreadline($line) > 0) {
232 ++$count;
233 $found = 1 if ($count == $index);
234 next unless $found;
235 last if ($line =~ /^\[record\]/);
236 if ($line =~ /^$re/) {
237 @ {$cpt->varglob('array')} = $cpt->reval( $line );
238 @array = @ {$cpt->varglob('array')};
239 last;
240 };
241 };
242 $prj->gzclose();
243 ##close A;
244 return @array;
245 };
246
247
248
249
250
251 sub athena_plot {
252
253 $top -> Busy;
254 my $n = $_[0]->info('anchor');
255 my $i = $_[0]->info('data', $n);
256 my $prjfile = $_[1];
257 my $r_athena_group = $_[2];
258 my $noplot = $_[3];
259 my $gname = "a___thena" ;
260 if ($noplot) {
261 $n = $r_athena_group->{$noplot}->{hlist};
262 $i = $_[0]->info('data', $n);
263 $gname = "st___andard";
264 };
265
266 ## get the args hash
267 my %args = athena_get_array($prjfile, $i, "args");
268 $args{fft_kw} ||= 2;
269
270 ## get the x- and y-axis arrays
271 my @x = athena_get_array($prjfile, $i, "x");
272 @x = map {$_ + $args{bkg_eshift}} @x;
273 my @y = athena_get_array($prjfile, $i, "y");
274
275 my %clamp = ("None" => 0, "Slight" => 3, "Weak" => 6, "Medium" =>12, "Strong" => 24, "Rigid" => 96);
276 my $title = $args{label};
277 $widgets{athena_selected} -> configure(-label=>"Header lines for " . $title);
278
279 $widgets{athena_titles} -> delete(qw(1.0 end));
280 foreach my $l (@{$args{titles}}) {
281 $widgets{athena_titles} -> insert('end', $l.$/);
282 };
283
284 $paths{data0}->dispose("erase \@group $gname\n");
285 $paths{data0}->dispose("##\n## reading Athena record \"$title\" into group $gname:", $dmode);
286 $paths{data0}->dispose("set \&status=0", $dmode);
287 if ($args{is_xmu}) {
288 Ifeffit::put_array($gname.".energy", \@x);
289 Ifeffit::put_array($gname.".xmu", \@y);
290 #Ifeffit::ifeffit("newplot($gname.energy, $gname.xmu)\n");
291 #print join(" ", %args), $/;
292 #sleep 5;
293 $args{bkg_clamp1} = $clamp{$args{bkg_clamp1}};
294 $args{bkg_clamp2} = $clamp{$args{bkg_clamp2}};
295
296 my $stan_string = q{};
297 if ($args{bkg_stan} ne 'None') {
298 athena_plot($_[0], $_[1], $r_athena_group, $args{bkg_stan});
299 $stan_string = "k_std=st___andard.k, chi_std=st___andard.chi, ";
300 ## need to remove background function from standard if standard
301 ## is mu(E) data!
302 };
303
304 my $spline = "$gname.energy, $gname.xmu, e0=$args{bkg_e0}, ";
305 $spline .= "rbkg=$args{bkg_rbkg}, kmin=$args{bkg_spl1}, ";
306 $spline .= "kmax=$args{bkg_spl2}, kweight=$args{bkg_kw}, ";
307 $spline .= "dk=$args{bkg_dk}, kwindow=$args{bkg_win}, pre1=$args{bkg_pre1}, ";
308 $spline .= "pre2=$args{bkg_pre2}, norm1=$args{bkg_nor1}, norm2=$args{bkg_nor2}, ";
309 $spline .= "clamp1=$args{bkg_clamp1}, clamp2=$args{bkg_clamp2}, nclamp=5, ";
310 $spline .= $stan_string;
311 $spline .= "interp=quad)\n";
312 $spline = wrap("spline(", " ", $spline);
313 ## remove the background and plot the data
314 Echo("Removing background from Athena record \"$title\"");
315 $paths{data0}->dispose($spline, $dmode);
316 my $status = Ifeffit::get_scalar('&status');
317 $paths{data0}->dispose($spline, $dmode) if ($status > 1);
318 #Ifeffit::ifeffit("newplot($gname.k, $gname.k*$gname.chi)\n");
319 #sleep 5;
320 $paths{data0}->dispose("set \&status=0", $dmode);
321 } else {
322 Ifeffit::put_array("$gname.k", \@x);
323 Ifeffit::put_array("$gname.chi", \@y);
324 };
325
326 $top -> Unbusy, return if $noplot;
327 my ($plot, $sp);
328 ## plot this in k-space
329 if ($ath_params{plot} eq 'chi') {
330 my $ylabel = "";
331 SWITCH: {
332 $ylabel = '\\gx(k)', last SWITCH if ($args{fft_kw} == 0);
333 $ylabel = 'k\\gx(k) (\\A\\u-1\\d)', last SWITCH if ($args{fft_kw} == 1);
334 $ylabel = 'k\\u' . $args{fft_kw} . '\\d\\gx(k) (\\A\\u-' . $args{fft_kw} . '\\d)';
335 };
336 $plot = "a___thena.k, a___thena.chi*a___thena.k**$args{fft_kw}, title=$title, ";
337 $plot .= "xlabel=\"k (\\A\\u-1\\d)\", ylabel=\"$ylabel\", ";
338 $plot .= "xmin=$plot_features{kmin}, xmax=$plot_features{kmax})\n";
339 $plot = wrap("newplot(", " ", $plot);
340 $sp = 'k';
341
342 ## fft then plot this in R-space
343 } elsif ($ath_params{plot} =~ /chir/) {
344 my $ylabel = '';
345 SWITCH: {
346 $ylabel = sprintf("|\\gx(R)| (\\A\\u-%s\\d)", $plot_features{kweight}+1),
347 last SWITCH if ($ath_params{plot} =~ /mag$/);
348 $ylabel = sprintf("Re[\\gx(R)] (\\A\\u-%s\\d)", $plot_features{kweight}+1),
349 last SWITCH if ($ath_params{plot} =~ /re$/);
350 $ylabel = sprintf("Im[\\gx(R)] (\\A\\u-%s\\d)", $plot_features{kweight}+1),
351 last SWITCH if ($ath_params{plot} =~ /im$/);
352 };
353 my $fft = "a___thena.chi, k=a___thena.k, kweight=$plot_features{kweight}, ";
354 $fft .= "kmin=$args{fft_kmin}, kmax=$args{fft_kmax}, ";
355 $fft .= "dk=$args{fft_dk}, kwindow=$args{fft_win})\n";
356 $fft = wrap("fftf(", " ", $fft);
357 $paths{data0}->dispose($fft, $dmode);
358 $plot = "a___thena.r, a___thena.$ath_params{plot}, title=$title, ";
359 $plot .= "xlabel=\"R (\\A)\", ylabel=\"$ylabel\", style=lines, ";
360 $plot .= "xmin=$plot_features{rmin}, xmax=$plot_features{rmax})\n";
361 $plot = wrap("newplot(", " ", $plot);
362 $sp = 'R';
363
364 ## fft, bft, then plot this in q-space
365 } else {
366 my $ylabel = '';
367 SWITCH: {
368 $ylabel = sprintf("|\\gx(q)| (\\A\\u-%s\\d)", $plot_features{kweight}),
369 last SWITCH if ($ath_params{plot} =~ /mag$/);
370 $ylabel = sprintf("Re[\\gx(q)] (\\A\\u-%s\\d)", $plot_features{kweight}),
371 last SWITCH if ($ath_params{plot} =~ /re$/);
372 $ylabel = sprintf("Im[\\gx(q)] (\\A\\u-%s\\d)", $plot_features{kweight}),
373 last SWITCH if ($ath_params{plot} =~ /im$/);
374 };
375 my $fft = "a___thena.chi, k=a___thena.k, kweight=$plot_features{kweight}, ";
376 $fft .= "kmin=$args{fft_kmin}, kmax=$args{fft_kmax}, ";
377 $fft .= "dk=$args{fft_dk}, kwindow=$args{fft_win})\n";
378 $fft = wrap("fftf(", " ", $fft);
379 $paths{data0}->dispose($fft, $dmode);
380 my $bft = "real=a___thena.chir_re, imag=a___thena.chir_im, ";
381 $bft .= "rmin=$args{bft_rmin}, rmax=$args{bft_rmax}, ";
382 $bft .= "dr=$args{bft_dr}, rwindow=$args{bft_win})\n";
383 $bft = wrap("fftr(", " ", $bft);
384 $paths{data0}->dispose($bft, $dmode);
385 $plot = "a___thena.q, a___thena.$ath_params{plot}, title=$title, ";
386 $plot .= "xlabel=\"q (\\A\\u-1\\d)\", ylabel=\"$ylabel\", ";
387 $plot .= "xmin=$plot_features{qmin}, xmax=$plot_features{qmax})\n";
388 $plot = wrap("newplot(", " ", $plot);
389 $sp = 'q';
390 };
391
392
393 Echo("Plotting Athena record \"$title\"");
394 $paths{data0}->dispose($plot, $dmode);
395
396 Echo("This is Athena record \"$title\" plotted in $sp-space");
397 $top -> Unbusy;
398 };
399
400 sub athena_import {
401
402 my ($group, $response) = ("", "New");
403 my @data = &every_data;
404 if ($#data or $paths{$paths{$current}->data}->get('file')) {
405 my $message = "Do you wish to read in a new data file (that is, to do multiple data set fitting), or do you wish to change the current data file (that is, to apply this fitting model to a different data set) ?";
406 my $dialog =
407 $top -> Dialog(-bitmap => 'questhead',
408 -text => $message,
409 -title => 'Athena: Reading data',
410 -buttons => [qw/Change New Cancel/],
411 -default_button => 'Change',
412 -font => $config{fonts}{med},
413 -popover => 'cursor');
414 &posted_Dialog;
415 $response = $dialog->Show();
416 if ($response eq 'Cancel') {
417 ## remove the index file
418 my $indexname = File::Spec->catfile($project_folder, "tmp", "index");
419 unlink $indexname if (-e $indexname);
420 $group = $list->info('anchor') || 'data0';
421 $current_canvas = "";
422 $list->see($group);
423 $list->anchorSet($group);
424 &display_properties(0);
425 Echo("Import of Athena record aborted");
426 return;
427 } elsif ($response eq 'Change') {
428 Echo("Changing data ...");
429 } else {
430 Echo("Importing new data ...");
431 };
432 };
433
434 $top->Busy;
435
436 my $n = $_[0]->info('anchor');
437 my $line = $_[0]->info('data', $n);
438 my $how_params = $_[3];
439
440 ## get the args hash
441 my %args = athena_get_array($_[1], $line, "args");
442 $args{fft_kw} ||= 2;
443 $args{label} =~ s{[\"\']}{}g;
444
445 my $i = 1;
446 my $erase = "";
447 foreach my $l (@{$args{titles}}) {
448 Ifeffit::put_string("athena_title_$i",$l);
449 $erase .= "erase \$athena_title_$i\n";
450 ++$i;
451 };
452 (my $fname = $args{label}) =~ s/[.,:@&\/\\ ]/_/g;
453 my $file = File::Spec->catfile($project_folder, "chi_data", $fname.".chi");
454 $paths{data0}->dispose("write_data(file=$file,\n a___thena.k, a___thena.chi, \$athena_title_*)", $dmode);
455 if ($args{is_xmu}) {
456 my $file = File::Spec->catfile($project_folder, "chi_data", $fname.".xmu");
457 $paths{data0}->dispose("write_data(file=$file,\n a___thena.energy, a___thena.xmu, \$athena_title_*)", $dmode);
458 };
459
460 $group = ($response eq 'Change') ?
461 read_data($paths{$current}->data, $file, 1) :
462 read_data(0, $file, 1);
463
464 if ($args{is_chi}) {
465 $paths{$group} -> make(is_xmu=>0, is_chi=>1);
466 } else {
467 $paths{$group} -> make(is_xmu=>1, is_chi=>0);
468 };
469 if ($how_params eq 'project') { # use project parameters
470 Echo("Setting parameters to values from Athena project");
471 my $rmin = $args{bft_rmin};
472 ($rmin = $args{bkg_rbkg}) if ($args{bkg_rbkg} > $args{bft_rmin});
473 $paths{$group} -> make(kmin => $args{fft_kmin},
474 kmax => $args{fft_kmax},
475 dk => $args{fft_dk},
476 kwindow => $args{fft_win},
477 rmin => $rmin,
478 rmax => $args{bft_rmax},
479 dr => $args{bft_dr},
480 rwindow => $args{bft_win},
481 lab => $args{label},
482 k1 => 0,
483 k2 => 0,
484 k3 => 0,
485 fs_absorber => $args{bkg_z},
486 fs_edge => $args{fft_edge},
487 );
488 $paths{$group} -> make(k1 => 1) if ($config{data}{kweight} == 1);
489 $paths{$group} -> make(k2 => 1) if ($config{data}{kweight} == 2);
490 $paths{$group} -> make(k3 => 1) if ($config{data}{kweight} == 3);
491 $paths{$group} -> make(k2 => 1) if not ( $paths{$group}->get('k1')
492 or $paths{$group}->get('k2')
493 or $paths{$group}->get('k3'));
494 } elsif ($response eq 'Change') { # replacing data, maintain params
495 Echo("Maintaining parameter values from previous data");
496 $paths{$group} -> make(lab => $args{label});
497 } else { # new data, use artemis defaults
498 Echo("Setting parameters to Artemis default values");
499 $paths{$group} -> make(kmin => $config{data}{kmin},
500 kmax => $config{data}{kmax},
501 dk => $config{data}{dk},
502 k1 => ($config{data}{kweight} == 1),
503 k2 => ($config{data}{kweight} == 2),
504 k3 => ($config{data}{kweight} == 3),
505 rmin => $config{data}{rmin},
506 rmax => $config{data}{rmax},
507 dr => $config{data}{dr},
508 kwindow => $config{data}{kwindow},
509 rwindow => $config{data}{rwindow},
510 lab => $args{label},
511 fs_absorber => $args{bkg_z},
512 fs_edge => $args{fft_edge},
513 );
514
515 # interpret the range parameters
516 if ($paths{$group}->get('kmax') == 0) {
517 $paths{$group}->make(kmax=>15);
518 my ($epsk, $epsr, $suggest) = $paths{$group}->chi_noise;
519 $suggest ||= 15;
520 $paths{$group}->make(kmax=>$suggest);
521 };
522 $paths{$group} -> fix_values();
523
524 };
525 ## parameters for the mu(E) tab
526 if ($paths{$group}->get("is_xmu")) {
527 foreach my $k (qw(e0 eshift kw rbkg dk pre1 pre2 nor1 nor2 spl1 spl2
528 slope int step fitted_step fixstep nc0
529 nc1 nc2 flatten stan clamp1 clamp2)) {
530 $paths{$group} -> make("bkg_".$k => $args{"bkg_".$k});
531 };
532 $paths{$group} -> make(do_xmu=>1, is_xmu=>1);
533 };
534 $list -> itemConfigure($group, 0, -text=>$args{label});
535 populate_op($group);
536 $plot_features{kweight} = $args{fft_kw};
537 plot('r', 0);
538 ##--bkg-- $widgets{data_notebook} -> raise('chi');
539 ##--bkg-- $widgets{data_notebook} -> pageconfigure('bkg', -state=>'normal') if $paths{$group}->get('is_xmu');
540
541 ## push the athena project onto the MRU list
542 &push_mru($_[2], 1, "athena");
543
544 ## remove the index file
545 my $indexname = File::Spec->catfile($project_folder, "tmp", "index");
546 unlink $indexname if (-e $indexname);
547
548 ## clean up ifeffit
549 $paths{$group}->dispose($erase, $dmode);
550 $paths{$group}->dispose("erase \@group a___thena\n", $dmode);
551
552 $top->Unbusy;
553 project_state(0);
554 Echo("Imported Athena record \"$args{label}\"");
555 };
556
557
558 ## sub build_index {
559 ## my $data_file = shift;
560 ## my $index_file = shift;
561 ## my $offset = 0;
562 ##
563 ## while (<$data_file>) {
564 ## print $index_file pack("N", $offset);
565 ## $offset = tell($data_file);
566 ## }
567 ## }
568 ##
569 ## # usage: line_with_index(*DATA_HANDLE, *INDEX_HANDLE, $LINE_NUMBER)
570 ## # returns line or undef if LINE_NUMBER was out of range
571 ## sub line_with_index {
572 ## my $data_file = shift;
573 ## my $index_file = shift;
574 ## my $line_number = shift;
575 ##
576 ## my $size; # size of an index entry
577 ## my $i_offset; # offset into the index of the entry
578 ## my $entry; # index entry
579 ## my $d_offset; # offset into the data file
580 ##
581 ## $size = length(pack("N", 0));
582 ## $i_offset = $size * ($line_number-1);
583 ## seek($index_file, $i_offset, 0) or return;
584 ## read($index_file, $entry, $size);
585 ## $d_offset = unpack("N", $entry);
586 ## seek($data_file, $d_offset, 0);
587 ## return scalar(<$data_file>);
588 ## }
589
590
591 sub clear_athena {
592 foreach my $k (qw(e0 eshift kw rbkg pre1 pre2 nor1 nor2 spl1 spl2 step)) {
593 my $key = "bkg_".$k;
594 $widgets{$key} -> configure(-validate=>'none');
595 $widgets{$key} -> delete(qw(0 end));
596 $widgets{$key} -> configure(-validate=>'key');
597 };
598 $temp{bkg_fixstep} = 0;
599 $temp{bkg_flatten} = 1;
600 $temp{bkg_clamp2} = 'None';
601 };
602
603 ## END OF THE ATHENA SUBSECTION
604