| 1 |
## -*- cperl -*- |
| 2 |
## |
| 3 |
## This file is part of Athena, copyright (c) 2001-2010 Bruce Ravel |
| 4 |
## |
| 5 |
## This section of the code contains subroutines associated with |
| 6 |
## reading in data and project files |
| 7 |
|
| 8 |
## file reading wrapper... |
| 9 |
## ## read from the command line? from the web? |
| 10 |
## ## unless (($_[0] and -e $_[0]) or ($_[0] and $_[0] =~ /^http:/)) { |
| 11 |
sub read_file { |
| 12 |
my $get_many = $_[0] || 0; |
| 13 |
my $read_arg = $_[1] || 0; |
| 14 |
($get_many =~ /HASH/) and ($get_many=0); |
| 15 |
$preprocess{ok} = 0; |
| 16 |
my $save_groupreplot = $config{general}{groupreplot}; |
| 17 |
$config{general}{groupreplot} = 'none'; |
| 18 |
my @data; |
| 19 |
if ($read_arg) { |
| 20 |
push @data, $read_arg; |
| 21 |
} elsif (($Tk::VERSION < 804) and ($get_many)) { |
| 22 |
@data = &get_file_list; |
| 23 |
} elsif ($Tk::VERSION < 804) { |
| 24 |
$data[0] = &get_single_file; |
| 25 |
} else { |
| 26 |
@data = &get_single_file; |
| 27 |
}; |
| 28 |
return unless ((@data) and ($data[0]) and ($data[0] !~ /^\s*$/)); |
| 29 |
$top -> Busy(-recurse=>1,); |
| 30 |
my ($raw, $cancel) = (undef, 0); |
| 31 |
#$prior_args = []; |
| 32 |
my ($first, $count) = ("", 1); |
| 33 |
my $errmsg; |
| 34 |
my $project_no_prompt = 0; |
| 35 |
DATA: foreach my $thisfile (@data) { |
| 36 |
next unless (($thisfile) and ($thisfile !~ /^\s*$/)); |
| 37 |
unless (-r $thisfile) { |
| 38 |
if (-e $thisfile) { |
| 39 |
$errmsg = "Could not read \"$thisfile\" (check permissions)"; |
| 40 |
$top -> Dialog(-bitmap => 'error', |
| 41 |
-text => $errmsg, |
| 42 |
-title => 'Athena: Error reading file', |
| 43 |
-buttons => ['OK'], |
| 44 |
-default_button => "OK" ) |
| 45 |
-> Show(); |
| 46 |
Error($errmsg); |
| 47 |
} else { |
| 48 |
$errmsg = "Could not read \"$thisfile\" (file does not exist)"; |
| 49 |
$top -> Dialog(-bitmap => 'error', |
| 50 |
-text => $errmsg, |
| 51 |
-title => 'Athena: Error reading file', |
| 52 |
-buttons => ['OK'], |
| 53 |
-default_button => "OK" ) |
| 54 |
-> Show(); |
| 55 |
Error($errmsg); |
| 56 |
}; |
| 57 |
$cancel = 1; |
| 58 |
next DATA |
| 59 |
}; |
| 60 |
|
| 61 |
Archive::Zip::setErrorHandler( \&is_zip_error_handler ); |
| 62 |
my $zip = Archive::Zip->new(); |
| 63 |
##print $zip->read($thisfile), $/; |
| 64 |
my $is_zipstyle = ($zip->read($thisfile) == AZ_OK) ? 1 : 0; |
| 65 |
my $is_artemis = ($is_zipstyle) ? $zip->membersMatching(/HORAE/) : 0; |
| 66 |
##print "$thisfile|$is_zipstyle|$is_artemis\n"; |
| 67 |
undef $zip; |
| 68 |
Archive::Zip::setErrorHandler( undef ); |
| 69 |
if ($is_artemis) { |
| 70 |
$errmsg = "Oops! $thisfile seems to be an Artemis project file."; |
| 71 |
$top -> Dialog(-bitmap => 'error', |
| 72 |
-text => $errmsg, |
| 73 |
-title => 'Athena: Error reading file', |
| 74 |
-buttons => ['OK'], |
| 75 |
-default_button => "OK" ) |
| 76 |
-> Show(); |
| 77 |
Error($errmsg); |
| 78 |
$cancel = 1; |
| 79 |
next DATA; |
| 80 |
}; |
| 81 |
if ($is_zipstyle) { |
| 82 |
$errmsg = "$thisfile is not a valid data file."; |
| 83 |
$top -> Dialog(-bitmap => 'error', |
| 84 |
-text => $errmsg, |
| 85 |
-title => 'Athena: Error reading file', |
| 86 |
-buttons => ['OK'], |
| 87 |
-default_button => "OK" ) |
| 88 |
-> Show(); |
| 89 |
Error($errmsg); |
| 90 |
$cancel = 1; |
| 91 |
next DATA; |
| 92 |
}; |
| 93 |
|
| 94 |
|
| 95 |
# does this one have mac line-endings? |
| 96 |
# my $was_mac = $groups{"Default Parameters"} -> |
| 97 |
# fix_mac($thisfile, $stash_dir, lc($config{general}{mac_eol}), $top); |
| 98 |
# Echo("\"$thisfile\" had Macintosh EOL characters and was skipped."), next DATA if ($was_mac eq '-1'); |
| 99 |
# Echo("\"$thisfile\" had Macintosh EOL characters and was fixed.") if ($was_mac eq '1'); |
| 100 |
my $is_record = (Ifeffit::Files->is_record($thisfile)); |
| 101 |
my ($is_mac, $tempfile) = (0, q{}); |
| 102 |
if (not $is_record) { |
| 103 |
local( $/, *FH ) ; |
| 104 |
open( FH, $thisfile ) or die "sudden flaming death\n"; |
| 105 |
my $snarf = <FH>; |
| 106 |
close(FH); |
| 107 |
if (($snarf !~ m{SSRL\s+\-?\s+EXAFS Data Collector}) and ($snarf =~ m{\r(?!\n)})) { # this matches Mac EOL but not Windows |
| 108 |
Echo("Correcting Mac line termination for $thisfile"); |
| 109 |
$tempfile = File::Spec->catfile($stash_dir, "unmacify_".basename($thisfile)); |
| 110 |
$snarf =~ s{\r(?!\n)}{\n}g; |
| 111 |
open TF, ">",$tempfile; |
| 112 |
print TF $snarf; |
| 113 |
close TF; |
| 114 |
$is_mac = 1; |
| 115 |
}; |
| 116 |
}; |
| 117 |
my $thisfile_notmac = ($is_mac) ? $tempfile : $thisfile; |
| 118 |
|
| 119 |
my @foo = %marked; |
| 120 |
my $empty = $#foo; |
| 121 |
my $safe_message_issued = 0; |
| 122 |
my %stash; |
| 123 |
my %map; |
| 124 |
if ($is_record) { |
| 125 |
my $fname = $thisfile_notmac; |
| 126 |
my %group_map = (); |
| 127 |
my ($imported, $total) = (0,0); |
| 128 |
my $frame = examine_project($fname, \%group_map, \$cancel, \$project_no_prompt); |
| 129 |
($frame == 0) or $frame -> waitWindow(); |
| 130 |
last DATA if ($cancel); |
| 131 |
my $nrecords = 0; |
| 132 |
$reading_project = 1; |
| 133 |
##open R, $fname or die "Could not open $thisfile_notmac as a record or project\n"; |
| 134 |
my $gz = gzopen($fname, "rb") or die "could not open $fname as an Athena project\n"; |
| 135 |
my $line; |
| 136 |
use vars qw($old_group @args @x @y @journal @stddev @i0 %foo); |
| 137 |
while ($gz->gzreadline($line) > 0) { |
| 138 |
next if ($line =~ /^\s*\#/); |
| 139 |
next if ($line =~ /^\s*$/); |
| 140 |
next if ($line =~ /^\s*1/); |
| 141 |
#if ($is_windows) { |
| 142 |
if ($always_false) { |
| 143 |
|
| 144 |
## eval each line directly -- NOT SAFE!! |
| 145 |
Echo("Reading project file with direct evaluations") unless $safe_message_issued; |
| 146 |
$safe_message_issued = 1; |
| 147 |
WINDOWS: { |
| 148 |
($line =~ /^\@journal/) and do { |
| 149 |
eval $line; |
| 150 |
foreach (@journal) { |
| 151 |
$notes{journal} -> insert('end', $line."\n", "text"); |
| 152 |
}; |
| 153 |
last WINDOWS; |
| 154 |
}; |
| 155 |
($line =~ /^\%plot_features/) and do { |
| 156 |
|
| 157 |
(my $this = $line) =~ s/^\%plot_features/\%foo/; |
| 158 |
eval $this; |
| 159 |
foreach my $k (keys %foo) { |
| 160 |
next unless ($k =~ /[ekqr]((_\w+)|(m(ax|in)))/); |
| 161 |
$plot_features{$k} = $foo{$k}; |
| 162 |
}; |
| 163 |
($plot_features{e_marked} = 'n') if ($plot_features{e_marked} eq 'd'); |
| 164 |
last WINDOWS; |
| 165 |
}; |
| 166 |
($line =~ /^\@indicator/) and do { |
| 167 |
(my $this = $line) =~ s/^\@indicator\s+=\s+//; |
| 168 |
my @indic = eval $this; |
| 169 |
foreach (1 .. $#indic) { |
| 170 |
$indicator[$_]->[1] = $indic[$_]->[1]; |
| 171 |
$indicator[$_]->[2] = $indic[$_]->[2]; |
| 172 |
}; |
| 173 |
#print Data::Dumper->Dump([\@indicator], [qw/indicator/]); |
| 174 |
last WINDOWS; |
| 175 |
}; |
| 176 |
($line =~ /^\%lcf_data/) and do { |
| 177 |
eval $line; |
| 178 |
last WINDOWS; |
| 179 |
}; |
| 180 |
($line =~ /^\$old_group/) and do { |
| 181 |
eval $line; |
| 182 |
last WINDOWS; |
| 183 |
}; |
| 184 |
($line =~ /^\@args/) and do { |
| 185 |
eval $line; |
| 186 |
last WINDOWS; |
| 187 |
}; |
| 188 |
($line =~ /^\@x/) and do { |
| 189 |
eval $line; |
| 190 |
last WINDOWS; |
| 191 |
}; |
| 192 |
($line =~ /^\@y/) and do { |
| 193 |
eval $line; |
| 194 |
last WINDOWS; |
| 195 |
}; |
| 196 |
($line =~ /^\@stddev/) and do { |
| 197 |
eval $line; |
| 198 |
last WINDOWS; |
| 199 |
}; |
| 200 |
($line =~ /^\@i0/) and do { |
| 201 |
eval $line; |
| 202 |
last WINDOWS; |
| 203 |
}; |
| 204 |
(($line =~ /^\[record\]/) or ($line =~ /^\&read_record/)) and do { |
| 205 |
my $memory_ok = $groups{"Default Parameters"} |
| 206 |
-> memory_check($top, \&Echo, \%groups, $max_heap, 0, 1); |
| 207 |
Echo ("Out of memory in Ifeffit"), last DATA if ($memory_ok == -1); |
| 208 |
my $gp = &read_record(0, $fname, $old_group, \@args, \@x, \@y, \@stddev, \@i0); |
| 209 |
$map{$old_group} = $gp; |
| 210 |
$first ||= $gp; |
| 211 |
++$nrecords; |
| 212 |
$old_group = ""; @args = (); @x = (); @y = (); @journal = (); @stddev = (); @i0 = (); %foo = (); |
| 213 |
last WINDOWS; |
| 214 |
}; |
| 215 |
1; |
| 216 |
}; |
| 217 |
|
| 218 |
} else { |
| 219 |
|
| 220 |
## read each line in a Safe compartment |
| 221 |
Echo("Reading project file in a safe compartment") unless $safe_message_issued; |
| 222 |
$safe_message_issued = 1; |
| 223 |
my $cpt = new Safe; |
| 224 |
NOT_WINDOWS: { |
| 225 |
($line =~ /^\@journal/) and do { |
| 226 |
@ {$cpt->varglob('journal')} = $cpt->reval($line); |
| 227 |
@journal = @ {$cpt->varglob('journal')}; |
| 228 |
foreach (@journal) { |
| 229 |
$notes{journal} -> insert('end', $_."\n", "text"); |
| 230 |
}; |
| 231 |
last NOT_WINDOWS; |
| 232 |
}; |
| 233 |
($line =~ /^\%plot_features/) and do { |
| 234 |
$line =~ s{^\%}{\@}; |
| 235 |
@ {$cpt->varglob('plot_features')} = $cpt->reval($line); |
| 236 |
my @list = @ {$cpt->varglob('plot_features')}; |
| 237 |
while (@list) { # only set the things in the plot |
| 238 |
my ($k, $v) = (shift @list, shift @list); # options area |
| 239 |
next unless ($k =~ /[ekqr]((_\w+)|(m(ax|in))|w)/); |
| 240 |
$plot_features{$k} = $v; |
| 241 |
}; |
| 242 |
($plot_features{e_marked} = 'n') if ($plot_features{e_marked} eq 'd'); |
| 243 |
delete $plot_features{project}; |
| 244 |
last NOT_WINDOWS; |
| 245 |
}; |
| 246 |
($line =~ /^\@indicator/) and do { |
| 247 |
@ {$cpt->varglob('indicator')} = $cpt->reval($line); |
| 248 |
my @indic = @ {$cpt->varglob('indicator')}; |
| 249 |
foreach (1 .. $#indic) { |
| 250 |
$indicator[$_]->[1] = $indic[$_]->[1]; |
| 251 |
$indicator[$_]->[2] = $indic[$_]->[2]; |
| 252 |
}; |
| 253 |
#print Data::Dumper->Dump([\@indicator], [qw/indicator/]); |
| 254 |
last NOT_WINDOWS; |
| 255 |
}; |
| 256 |
($line =~ /^\%lcf_data/) and do { |
| 257 |
my $this = $line; |
| 258 |
my $regex = join("|", (keys %map)); |
| 259 |
#print $regex; |
| 260 |
$this =~ s/\b($regex)\b/$map{$1}/g; |
| 261 |
% {$cpt->varglob('lcf_data')} = $cpt->reval($this); |
| 262 |
%lcf_data = % {$cpt->varglob('lcf_data')}; |
| 263 |
last NOT_WINDOWS; |
| 264 |
}; |
| 265 |
($line =~ /^\$old_group/) and do { |
| 266 |
$ {$cpt->varglob('old_group')} = $cpt->reval($line); |
| 267 |
$old_group = $ {$cpt->varglob('old_group')}; |
| 268 |
last NOT_WINDOWS; |
| 269 |
}; |
| 270 |
($line =~ /^\@args/) and do { |
| 271 |
@ {$cpt->varglob('args')} = $cpt->reval($line); |
| 272 |
@args = @ {$cpt->varglob('args')}; |
| 273 |
last NOT_WINDOWS; |
| 274 |
}; |
| 275 |
($line =~ /^\@x/) and do { |
| 276 |
@ {$cpt->varglob('x')} = $cpt->reval($line); |
| 277 |
@x = @ {$cpt->varglob('x')}; |
| 278 |
last NOT_WINDOWS; |
| 279 |
}; |
| 280 |
($line =~ /^\@y/) and do { |
| 281 |
@ {$cpt->varglob('y')} = $cpt->reval($line); |
| 282 |
@y = @ {$cpt->varglob('y')}; |
| 283 |
last NOT_WINDOWS; |
| 284 |
}; |
| 285 |
($line =~ /^\@stddev/) and do { |
| 286 |
@ {$cpt->varglob('stddev')} = $cpt->reval($line); |
| 287 |
@stddev = @ {$cpt->varglob('stddev')}; |
| 288 |
last NOT_WINDOWS; |
| 289 |
}; |
| 290 |
($line =~ /^\@i0/) and do { |
| 291 |
@ {$cpt->varglob('i0')} = $cpt->reval($line); |
| 292 |
@i0 = @ {$cpt->varglob('i0')}; |
| 293 |
last NOT_WINDOWS; |
| 294 |
}; |
| 295 |
(($line =~ /^\[record\]/) or ($line =~ /^\&read_record/)) and do { |
| 296 |
++$total; |
| 297 |
last NOT_WINDOWS if not $group_map{$old_group}; # from examine_project |
| 298 |
++$imported; |
| 299 |
my $memory_ok = $groups{"Default Parameters"} |
| 300 |
-> memory_check($top, \&Echo, \%groups, $max_heap, 0, 1); |
| 301 |
Echo ("Out of memory in Ifeffit"), last DATA if ($memory_ok == -1); |
| 302 |
my $gp = read_record(0, $fname, $old_group, \@args, \@x, \@y, \@stddev, \@i0); |
| 303 |
$map{$old_group} = $gp; |
| 304 |
$first ||= $gp; |
| 305 |
++$nrecords; |
| 306 |
$old_group = ""; @args = (); @x = (); @y = (); @journal = (); @stddev = (); @i0 = (); %foo = (); |
| 307 |
last NOT_WINDOWS; |
| 308 |
}; |
| 309 |
1; |
| 310 |
}; |
| 311 |
}; |
| 312 |
}; |
| 313 |
$reading_project = 0; |
| 314 |
$gz->gzclose(); |
| 315 |
##close R; |
| 316 |
unless ($nrecords) { |
| 317 |
$top->Unbusy; |
| 318 |
Echo("The project file \"$fname\" contained no records."); |
| 319 |
return; |
| 320 |
}; |
| 321 |
my $complete = ($total == $imported); |
| 322 |
&push_mru($thisfile, 1, 1, $complete); |
| 323 |
project_state(1) if ($empty == -1); |
| 324 |
|
| 325 |
|
| 326 |
&set_properties(1, $first||$current, 0); |
| 327 |
SWITCH: { |
| 328 |
($groups{$first}->{is_xmu}) and do { |
| 329 |
&plot_current_e; |
| 330 |
last SWITCH; |
| 331 |
}; |
| 332 |
($groups{$first}->{is_chi}) and do { |
| 333 |
my $str = sprintf('k%1d', $plot_features{kw}); #$groups{$first}->{fft_kw}); |
| 334 |
&plot_current_k; |
| 335 |
last SWITCH; |
| 336 |
}; |
| 337 |
}; |
| 338 |
|
| 339 |
## foreach my $g (keys %groups) { |
| 340 |
## next if ($g eq "Default Parameters"); |
| 341 |
## print $groups{$g}->{group}, " ", $groups{$g}->{old_group}, "\n"; |
| 342 |
## }; |
| 343 |
|
| 344 |
## restore purple mark buttons and fix up background standards, |
| 345 |
## reference channels, and lcf standards |
| 346 |
foreach my $k (keys %groups) { |
| 347 |
next if ($k eq "Default Parameters"); |
| 348 |
## mu_str |
| 349 |
if (exists($groups{$k}->{mu_str}) and $groups{$k}->{is_proj}) { |
| 350 |
my $mustr = $groups{$k}->{mu_str}; |
| 351 |
my $old = $groups{$k}->{old_group}; |
| 352 |
$mustr =~ s/\b$old\b/$k/g; |
| 353 |
$groups{$k}->MAKE(mu_str=>$mustr); |
| 354 |
}; |
| 355 |
## mark buttons |
| 356 |
if (exists($groups{$k}->{project_marked}) and |
| 357 |
$groups{$k}->{project_marked}) { |
| 358 |
$marked{$k} = 1; |
| 359 |
$groups{$k}->{checkbutton} -> select; |
| 360 |
}; |
| 361 |
## background standards |
| 362 |
unless ((exists $groups{$k}->{bkg_stan}) and |
| 363 |
($groups{$k}->{bkg_stan} eq 'None')) { |
| 364 |
STAN: foreach my $kk (keys %groups) { |
| 365 |
next if ($kk eq "Default Parameters"); |
| 366 |
##print join(" ", $k, $groups{$k}->{bkg_stan}, $kk, $groups{$kk}->{old_group}), $/; |
| 367 |
if ((exists $groups{$k}->{bkg_stan}) and |
| 368 |
(exists $groups{$kk}->{old_group}) and |
| 369 |
($groups{$k}->{bkg_stan} eq $groups{$kk}->{old_group})) { |
| 370 |
$groups{$k}->MAKE(bkg_stan=>$kk); |
| 371 |
last STAN; |
| 372 |
}; |
| 373 |
}; |
| 374 |
}; |
| 375 |
## reference channels |
| 376 |
if ($groups{$k}->{reference}) { |
| 377 |
my $found = 0; |
| 378 |
INNER: foreach my $o (keys %groups) { |
| 379 |
next if ($o eq "Default Parameters"); |
| 380 |
next if ($o eq $k); |
| 381 |
next unless exists $groups{$o}->{old_group}; |
| 382 |
if ((exists $groups{$k}->{reference}) and |
| 383 |
(exists $groups{$o}->{old_group}) and |
| 384 |
($groups{$k}->{reference} eq $groups{$o}->{old_group})) { |
| 385 |
$groups{$k}->MAKE(reference=>$o); |
| 386 |
$found = 1; |
| 387 |
last INNER; |
| 388 |
}; |
| 389 |
}; |
| 390 |
$groups{$k}->MAKE(reference=>0) if |
| 391 |
((not $found) and ## in case of partial project import |
| 392 |
(not exists($groups{$groups{$k}->{reference}}))); # already in project |
| 393 |
}; |
| 394 |
## linear combination fitting standards |
| 395 |
if ($groups{$k}->{lcf_fit}) { |
| 396 |
my @keys = (); |
| 397 |
foreach my $kk (&sorted_group_list) { |
| 398 |
($groups{$kk}->{is_xmu} or $groups{$kk}->{is_chi}) and push @keys, $kk; |
| 399 |
}; |
| 400 |
|
| 401 |
LCF: foreach my $o (keys %groups) { |
| 402 |
next if ($o eq "Default Parameters"); |
| 403 |
next if ($o eq $k); |
| 404 |
|
| 405 |
foreach my $i (1 .. $config{linearcombo}{maxspectra}) { |
| 406 |
next unless (exists $groups{$k}->{"lcf_standard$i"}); |
| 407 |
next if ($groups{$k}->{"lcf_standard$i"} eq 'None'); |
| 408 |
next unless (exists $groups{$o}->{old_group}); |
| 409 |
if ($groups{$k}->{"lcf_standard$i"} eq $groups{$o}->{old_group}) { |
| 410 |
my $ii = 0; |
| 411 |
foreach my $ke (@keys) { # find the index of this standard |
| 412 |
++$ii; |
| 413 |
last if ($ke eq $o); |
| 414 |
}; |
| 415 |
$groups{$k}->MAKE("lcf_standard$i" => $o, |
| 416 |
"lcf_standard_lab$i" => $ii . ": " . $groups{$o}->{label}); |
| 417 |
}; |
| 418 |
if ((exists $groups{$k}->{"lcf_standard$i"}) and |
| 419 |
(not exists $groups{$o}->{old_group})) { |
| 420 |
$groups{$k}->MAKE("lcf_standard$i" => 'None', |
| 421 |
"lcf_standard_lab$i" => '0: None', |
| 422 |
"lcf_e0$i" => 0, |
| 423 |
"lcf_e0val$i" => 0, |
| 424 |
"lcf_value$i" => 0, |
| 425 |
); |
| 426 |
}; |
| 427 |
##print "$i ", $groups{$k}->{label}, " ", $groups{$k}->{"lcf_standard_lab$i"}, $/; |
| 428 |
}; |
| 429 |
}; |
| 430 |
}; |
| 431 |
}; |
| 432 |
foreach my $o (keys %stash) { |
| 433 |
foreach my $k (%groups) { |
| 434 |
next unless (exists $groups{$k}->{old_group}); |
| 435 |
next unless ($groups{$k}->{old_group} eq $o); |
| 436 |
$lcf_data{$k} = $stash{$o}; |
| 437 |
}; |
| 438 |
# my @order = map { $map{$_} } @{ $stash{$o}{order} }; |
| 439 |
# $stash{$o}{order} = \@order; |
| 440 |
# my @results = @ {$stash{$o}{results}}; |
| 441 |
# my @fixed; |
| 442 |
# foreach my $r (@results) { |
| 443 |
# my $r->[0] |
| 444 |
# }; |
| 445 |
}; |
| 446 |
} else { |
| 447 |
#my $foo = $thisfile_notmac; |
| 448 |
($raw, $prior_string) = read_raw($thisfile_notmac, $thisfile, $prior_string, $prior_args, \$cancel, \$count); |
| 449 |
($raw == 0) or $raw -> waitWindow(); |
| 450 |
last DATA if ($cancel); |
| 451 |
++$count; |
| 452 |
$top->update; |
| 453 |
}; |
| 454 |
}; |
| 455 |
## unset extra import features |
| 456 |
#$rebin{do_rebin} = 0; |
| 457 |
$preprocess{standard} ||= 'None'; |
| 458 |
#$preprocess{mark_do} = 0; |
| 459 |
#$preprocess{trun_do} = 0; |
| 460 |
#$preprocess{deg_do} = 0; |
| 461 |
|
| 462 |
$preprocess{raised} ||= "reference"; |
| 463 |
$rebin{titles} = []; |
| 464 |
$preprocess{titles} = []; |
| 465 |
|
| 466 |
section_indicators(); |
| 467 |
|
| 468 |
$top->Unbusy, return if $cancel; |
| 469 |
$current and &set_properties(1, $first||$current,0); |
| 470 |
$config{general}{groupreplot} = $save_groupreplot; |
| 471 |
# finally adjust the view |
| 472 |
if (exists($groups{$current}->{text})) { |
| 473 |
my $here = ($list->bbox($groups{$current}->{text}))[1] - 5 || 0; |
| 474 |
($here < 0) and ($here = 0); |
| 475 |
my $full = ($list->bbox(@skinny_list))[3] + 5; |
| 476 |
$list -> yview('moveto', $here/$full); |
| 477 |
}; |
| 478 |
$top->Unbusy; |
| 479 |
}; |
| 480 |
|
| 481 |
|
| 482 |
## fetch a list of files using FileSelect |
| 483 |
sub get_file_list { |
| 484 |
## read from the command line? from the web? |
| 485 |
## unless (($_[0] and -e $_[0]) or ($_[0] and $_[0] =~ /^http:/)) { |
| 486 |
require Cwd; |
| 487 |
my $path = $current_data_dir || Cwd::cwd; |
| 488 |
my $FSel = $top->FileSelect(-title => 'Athena: open MANY data files', |
| 489 |
-width => 40, |
| 490 |
-directory=>$path); |
| 491 |
$FSel -> configure(-selectmode=>'extended'); |
| 492 |
my @data = $FSel->Show; |
| 493 |
return sort @data; |
| 494 |
}; |
| 495 |
|
| 496 |
## fetch a single file using getOpenFile |
| 497 |
sub get_single_file { |
| 498 |
## read from the command line? from the web? |
| 499 |
## unless (($_[0] and -e $_[0]) or ($_[0] and $_[0] =~ /^http:/)) { |
| 500 |
require Cwd; |
| 501 |
#local $Tk::FBox::a; |
| 502 |
#local $Tk::FBox::b; |
| 503 |
my $path = $current_data_dir || Cwd::cwd; |
| 504 |
my $types = [['All Files', '*'], |
| 505 |
['data files', ['.dat', '.xmu']], |
| 506 |
['chi(k) files', '.chi'], |
| 507 |
['Athena project files', '.prj'], |
| 508 |
]; |
| 509 |
if ($Tk::VERSION > 804) { |
| 510 |
my $file = $top -> getOpenFile(-filetypes=>$types, |
| 511 |
#(not $is_windows) ? |
| 512 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 513 |
-initialdir=>$path, |
| 514 |
-multiple => 1, |
| 515 |
-title => "Athena: Open one or more data files"); |
| 516 |
$file ||= []; |
| 517 |
return sort @$file; |
| 518 |
} else { |
| 519 |
my $file = $top -> getOpenFile(-filetypes=>$types, |
| 520 |
#(not $is_windows) ? |
| 521 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 522 |
-initialdir=>$path, |
| 523 |
-title => "Athena: Open a SINGLE data file"); |
| 524 |
$file ||= q{}; |
| 525 |
return $file; |
| 526 |
}; |
| 527 |
}; |
| 528 |
|
| 529 |
|
| 530 |
sub read_demo { |
| 531 |
require Cwd; |
| 532 |
#local $Tk::FBox::a; |
| 533 |
#local $Tk::FBox::b; |
| 534 |
my $path = $groups{"Default Parameters"} -> find('athena', 'demos'); |
| 535 |
my $types = [['Athena project files', '.prj'], |
| 536 |
['All Files', '*'], |
| 537 |
]; |
| 538 |
my $file = scalar $top -> getOpenFile(-filetypes=>$types, |
| 539 |
#(not $is_windows) ? |
| 540 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 541 |
-initialdir=>$path, |
| 542 |
-multiple => 0, |
| 543 |
-title => "Athena: Open a demo project"); |
| 544 |
if ($file) { |
| 545 |
read_file(0,$file); |
| 546 |
raise_palette('journal'); |
| 547 |
}; |
| 548 |
}; |
| 549 |
|
| 550 |
## read a file as raw data. This means to prompt for column selection. |
| 551 |
sub read_raw { |
| 552 |
|
| 553 |
my $red = $config{colors}{single}; |
| 554 |
|
| 555 |
my ($data, $orig, $prior_string, $prior_args, $r_cancel, $rcount) = @_; |
| 556 |
my $count = $$rcount; |
| 557 |
## look at first file in list to see |
| 558 |
## if this is a record or raw dat |
| 559 |
my $memory_ok = $groups{"Default Parameters"} |
| 560 |
-> memory_check($top, \&Echo, \%groups, $max_heap, 0, 1); |
| 561 |
Echo ("Out of memory in Ifeffit"), return (-1, $prior_string) if ($memory_ok == -1); |
| 562 |
|
| 563 |
## bad things happen if the data file name is longer than 128 |
| 564 |
## characters. when this happens, transfer the file to the stash |
| 565 |
## directory so ifeffit can read it from there. if the filename is |
| 566 |
## not too long, then $stash and $data will be the same |
| 567 |
my $stash = $data; |
| 568 |
my $is_binary = 0; |
| 569 |
|
| 570 |
PLUGINS: foreach my $p (sort {$a cmp $b} @plugins) { |
| 571 |
next PLUGINS unless $plugin_params{$p}{_enabled}; |
| 572 |
if (eval "Ifeffit::Plugins::Filetype::Athena::$p->is('$data')") { |
| 573 |
Echo("$data seems to be a $p data file."); |
| 574 |
$stash = eval "Ifeffit::Plugins::Filetype::Athena::$p->fix('$data', '$stash_dir', \$top, \$plugin_params{$p});"; |
| 575 |
if (not $stash) { |
| 576 |
$$r_cancel = 1; |
| 577 |
set_status(0); |
| 578 |
Echo("$data could not be read as a $p data file."); |
| 579 |
return (0, $prior_string); |
| 580 |
}; |
| 581 |
my $file = $groups{"Default Parameters"} -> find('athena', 'plugins'); |
| 582 |
tied( %plugin_params )->WriteConfig($file); |
| 583 |
eval "\$is_binary = \$Ifeffit::Plugins::Filetype::Athena::${p}::is_binary"; |
| 584 |
last PLUGINS; |
| 585 |
}; |
| 586 |
}; |
| 587 |
if ($stash =~ /\#/) { |
| 588 |
my ($nme, $pth, $suffix) = fileparse($stash); |
| 589 |
$nme =~ s/\#//g; |
| 590 |
my $new = File::Spec->catfile($stash_dir, $nme); |
| 591 |
($new = File::Spec->catfile($stash_dir, "toss")) if (length($new) > 127); |
| 592 |
copy($stash, $new); |
| 593 |
$stash = $new; |
| 594 |
}; |
| 595 |
if (length($stash) > 127) { |
| 596 |
my ($nme, $pth, $suffix) = fileparse($stash); |
| 597 |
my $new = File::Spec->catfile($stash_dir, $nme); |
| 598 |
($new = File::Spec->catfile($stash_dir, "toss")) if (length($new) > 127); |
| 599 |
copy($stash, $new); |
| 600 |
$stash = $new; |
| 601 |
}; |
| 602 |
|
| 603 |
my %label_map = (e=>'mu(E)', n=>'norm(E)', k=>'chi(k)', d=>'detector', |
| 604 |
x=>'xmu.dat', c=>'chi.dat', a=>'xanes(E)'); |
| 605 |
my ($name, $pth, $suffix) = fileparse($data, qw(\. \.dat \.chi \.xmu)); |
| 606 |
my $databox; |
| 607 |
#my $group = $name; |
| 608 |
my $group = $name.$suffix; |
| 609 |
my $label; |
| 610 |
($group, $label) = group_name($group); |
| 611 |
##$groups{$current} -> dispose("read_data(file=\"$data\", group=$group)\n", $dmode); |
| 612 |
my $is_xmudat = Ifeffit::Files->is_xmudat($stash, $top); |
| 613 |
my $is_pixel = ($config{pixel}{do_pixel_check}) ? |
| 614 |
Ifeffit::Files->is_pixel($stash) : 0; |
| 615 |
my $is_xanes = 0; |
| 616 |
($is_xanes = Ifeffit::Files->is_xanes($stash, 100)) if $config{xanes}{cutoff}; |
| 617 |
if ($stash ne $data) { |
| 618 |
$groups{"Default Parameters"} -> dispose("## actual file: $data\n"); |
| 619 |
$groups{"Default Parameters"} -> dispose("## transfered to stash file: $stash\n"); |
| 620 |
}; |
| 621 |
$groups{"Default Parameters"} -> dispose("\n## Reading a data file in the column selection dialog\n"); |
| 622 |
if ($is_xmudat) { |
| 623 |
$groups{"Default Parameters"} -> dispose("read_data(file=\"$stash\", group=$group, type=xmu.dat, no_sort)\n", $dmode); |
| 624 |
} else { |
| 625 |
$groups{"Default Parameters"} -> dispose("read_data(file=\"$stash\", group=$group, no_sort)\n", $dmode); |
| 626 |
}; |
| 627 |
unless (Ifeffit::Files->is_datafile) { |
| 628 |
$top -> Dialog(-bitmap => 'error', |
| 629 |
-text => "\`$data\' could not be read by ifeffit as a data file", |
| 630 |
-title => 'Athena: Error reading file', |
| 631 |
-buttons => ['OK'], |
| 632 |
-default_button => "OK" ) |
| 633 |
-> Show(); |
| 634 |
## delete title lines from ifeffit for $group |
| 635 |
$$r_cancel = 0; |
| 636 |
set_status(0); |
| 637 |
return (0, $prior_string); |
| 638 |
}; |
| 639 |
my $str = &column_string; |
| 640 |
my $suff = (split(" ", $str))[0]; |
| 641 |
$groups{"Default Parameters"} -> dispose("set ___n = npts($group.$suff)", $dmode); |
| 642 |
my $nn = Ifeffit::get_scalar("___n"); |
| 643 |
if ($nn <= $config{general}{minpts}) { |
| 644 |
$top -> Dialog(-bitmap => 'error', |
| 645 |
-text => "\`$data\' has fewer than " . |
| 646 |
$config{general}{minpts} . " data points.", |
| 647 |
-title => 'Athena: Error reading file', |
| 648 |
-buttons => ['OK'], |
| 649 |
-default_button => "OK" ) |
| 650 |
-> Show(); |
| 651 |
## delete title lines from ifeffit for $group |
| 652 |
$$r_cancel = 0; |
| 653 |
set_status(0); |
| 654 |
--$count; |
| 655 |
return (0, $prior_string); |
| 656 |
}; |
| 657 |
|
| 658 |
&push_mru($orig, 1); |
| 659 |
|
| 660 |
## the heuristic for deciding if the interpretation of the columns |
| 661 |
## has changed is the value of ifeffit's column_label variable. I |
| 662 |
## presume that if this is unchanged between successive files, then |
| 663 |
## I can interpret the columns identically. This is a decent |
| 664 |
## heuristic for data with labeled columns, but can be trouble for |
| 665 |
## unlabeled columns. In that case, the arrays are called $group.1, |
| 666 |
## $group.2, etc. |
| 667 |
my $col_string = &column_string; |
| 668 |
## this is trouble -- need to know difference between one file and many files |
| 669 |
if (($count > 1) and ($col_string eq $prior_string)) { |
| 670 |
construct_xmu(0, $group, $label, $data, $stash, $prior_args); |
| 671 |
return (0, $col_string); |
| 672 |
}; |
| 673 |
## If the column lables are different, then go ahead and set up the |
| 674 |
## column selection palette... |
| 675 |
my @cols = split(" ", $col_string); |
| 676 |
my $raw = $top->Toplevel(-class=>'horae'); |
| 677 |
$raw -> geometry($1) if $colsel_geometry =~ /([-+]\d+[-+]\d+)/; |
| 678 |
$raw -> title('Athena: data columns'); |
| 679 |
$raw -> protocol(WM_DELETE_WINDOW => sub{$colsel_geometry = $raw->geometry; $$r_cancel = 1; $raw->destroy; return (-1, $prior_string)}); |
| 680 |
$raw -> packPropagate(1); |
| 681 |
$raw -> bind('<Control-q>' => sub{$colsel_geometry = $raw->geometry; $$r_cancel = 1; $raw->destroy; return (-1, $prior_string)}); |
| 682 |
$raw -> bind('<Control-d>' => sub{$colsel_geometry = $raw->geometry; $$r_cancel = 1; $raw->destroy; return (-1, $prior_string)}); |
| 683 |
my ($fnlabel, $enlabel, $unlabel); |
| 684 |
my $grey= '#9c9583'; |
| 685 |
my $active_color = $config{colors}{activehighlightcolor}; |
| 686 |
##my $preproc_state = (scalar(keys %groups) == 1) ? 'disabled' : 'normal'; |
| 687 |
my $preproc_state = 'normal'; |
| 688 |
my $preproc_number = scalar(keys %groups); |
| 689 |
#($preproc_state = 'disabled') if ($current eq "Default Parameters"); |
| 690 |
my ($energy, %numerator, %denominator, $mustr, $enstr, %widg, %reference); |
| 691 |
my ($j, $do_ln, $invert, $multi, $xmustring, $space, $space_label, $evkev, $sort, $sorted) = |
| 692 |
(1, 0, 0, 0, "1", 'e', "mu(E)", 'ev', 1, ""); |
| 693 |
%reference = (numerator=>0, denominator=>0, ln=>1, same=>1); |
| 694 |
## build a grid of radio and check |
| 695 |
## buttons for selecting columns from |
| 696 |
## which to construct mu(E) |
| 697 |
my $left = $raw -> Frame() -> pack(-side=>'left', -anchor=>'n'); |
| 698 |
my $right = $raw -> Frame() -> pack(-side=>'right', -anchor=>'n', -expand=>1, -fill=>'both'); |
| 699 |
($widg{left}, $widg{right}, $widg{raw}) = ($left, $right, $raw); |
| 700 |
|
| 701 |
my $fr = $left -> Scrolled('Pane', -relief=>'groove', -borderwidth=>2, |
| 702 |
-gridded=>'xy', |
| 703 |
-scrollbars=>'os', -sticky => 'we',) |
| 704 |
-> pack(-expand=>1, -fill=>'x'); |
| 705 |
$fr->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}); |
| 706 |
$fr -> Label(-text=>' ', -foreground=>$config{colors}{activehighlightcolor}) |
| 707 |
-> grid(-row=>0, -column=>0, -sticky=>'e'); |
| 708 |
$fr -> Label(-text=>'Energy', -foreground=>$config{colors}{activehighlightcolor}) |
| 709 |
-> grid(-row=>1, -column=>0, -sticky=>'e'); |
| 710 |
$fr -> Label(-text=>'Numerator', -foreground=>$config{colors}{activehighlightcolor}) |
| 711 |
-> grid(-row=>2, -column=>0, -sticky=>'e'); |
| 712 |
$fr -> Label(-text=>'Denominator', -foreground=>$config{colors}{activehighlightcolor}) |
| 713 |
-> grid(-row=>3, -column=>0, -sticky=>'e'); |
| 714 |
my @toss; |
| 715 |
## regexes that attempt to recognize common labels for the i0, it, and if |
| 716 |
## channels |
| 717 |
my %re = (i0 => $config{general}{i0_regex}, |
| 718 |
it => $config{general}{transmission_regex}, |
| 719 |
if => $config{general}{fluorescence_regex}, ); |
| 720 |
if ($config{general}{match_as} eq 'glob') { |
| 721 |
$re{i0} = glob_to_regex($config{general}{i0_regex}); |
| 722 |
$re{it} = glob_to_regex($config{general}{transmission_regex}); |
| 723 |
$re{if} = glob_to_regex($config{general}{fluorescence_regex}); |
| 724 |
}; |
| 725 |
my %parts = (0=>0, t=>0, f=>0); |
| 726 |
## $Data::Dumper::Indent = 2; |
| 727 |
## print Data::Dumper->Dump([$prior_args],[qw(*prior_args)]); |
| 728 |
## $Data::Dumper::Indent = 0; |
| 729 |
my $match = 0; |
| 730 |
foreach (@cols) { |
| 731 |
my $this = $group.".".$_; |
| 732 |
($numerator{$this}, $denominator{$this}) = (0,0); |
| 733 |
|
| 734 |
if ($$prior_args{old}) { # check to see if column labels are |
| 735 |
# the same as the previous group |
| 736 |
my $old = $$prior_args{old}; |
| 737 |
$old = (split(/\./, $old))[0]; |
| 738 |
## the keys of the hashes are of the form |
| 739 |
## group.col rather than just col |
| 740 |
(my $that = $this) =~ s/$group/$old/; |
| 741 |
($energy = $this) if ($that eq $$prior_args{old}); |
| 742 |
$numerator{$this} = $$prior_args{numerator}->{$that} || 0; |
| 743 |
$denominator{$this} = $$prior_args{denominator}->{$that} || 0; |
| 744 |
$match += $numerator{$this} + $denominator{$this}; |
| 745 |
|
| 746 |
($reference{numerator} = $this) if ($$prior_args{ref}->{numerator} eq $that); |
| 747 |
($reference{denominator} = $this) if ($$prior_args{ref}->{denominator} eq $that); |
| 748 |
|
| 749 |
}; |
| 750 |
|
| 751 |
$fr -> Label(-text=>$_) |
| 752 |
-> grid(-row=>0, -column=>$j); |
| 753 |
my $jj = $j; # need a counter that is scoped HERE |
| 754 |
$fr -> Radiobutton(-variable=>\$energy, -value=>$this, -selectcolor=>$red, |
| 755 |
-command => |
| 756 |
sub{ |
| 757 |
$$prior_args{old} = $energy; |
| 758 |
$$prior_args{numerator} = \%numerator; |
| 759 |
$$prior_args{denominator} = \%denominator; |
| 760 |
$$prior_args{do_ln} = $do_ln; |
| 761 |
$$prior_args{invert} = $invert; |
| 762 |
$$prior_args{space} = $space; |
| 763 |
$$prior_args{evkev} = $evkev; |
| 764 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 765 |
$$prior_args{sort} = $sort; |
| 766 |
$$prior_args{multi} = $multi; |
| 767 |
$$prior_args{ref} = \%reference; |
| 768 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 769 |
$sort=$jj; |
| 770 |
}) |
| 771 |
-> grid(-row=>1, -column=>$j,); |
| 772 |
$fr -> Checkbutton(-variable=>\$numerator{$this}, -selectcolor=>$red, -command=> |
| 773 |
sub{ |
| 774 |
$$prior_args{old} = $energy; |
| 775 |
$$prior_args{numerator} = \%numerator; |
| 776 |
$$prior_args{denominator} = \%denominator; |
| 777 |
$$prior_args{do_ln} = $do_ln; |
| 778 |
$$prior_args{invert} = $invert; |
| 779 |
$$prior_args{space} = $space; |
| 780 |
$$prior_args{evkev} = $evkev; |
| 781 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 782 |
$$prior_args{sort} = $sort; |
| 783 |
$$prior_args{multi} = $multi; |
| 784 |
$$prior_args{ref} = \%reference; |
| 785 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 786 |
my $sum = 0; |
| 787 |
foreach my $v (values %numerator) {$sum += $v}; |
| 788 |
$widg{multi} -> configure(-state=>($sum > 1)?'normal':'disabled'); |
| 789 |
}) |
| 790 |
-> grid(-row=>2, -column=>$j,); |
| 791 |
$fr -> Checkbutton(-variable=>\$denominator{$this}, -selectcolor=>$red, -command=> |
| 792 |
sub{ |
| 793 |
$$prior_args{old} = $energy; |
| 794 |
$$prior_args{numerator} = \%numerator; |
| 795 |
$$prior_args{denominator} = \%denominator; |
| 796 |
$$prior_args{do_ln} = $do_ln; |
| 797 |
$$prior_args{invert} = $invert; |
| 798 |
$$prior_args{space} = $space; |
| 799 |
$$prior_args{evkev} = $evkev; |
| 800 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 801 |
$$prior_args{sort} = $sort; |
| 802 |
$$prior_args{multi} = $multi; |
| 803 |
$$prior_args{ref} = \%reference; |
| 804 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy) |
| 805 |
}) |
| 806 |
-> grid(-row=>3, -column=>$j,); |
| 807 |
++$j; |
| 808 |
}; |
| 809 |
|
| 810 |
## $match>0 means that the columns used in the last imported file match this |
| 811 |
## file. If there is no match, then need to rely upon the regexes for |
| 812 |
## i0, it, if |
| 813 |
#if ($match) { |
| 814 |
if ($col_string eq $prior_string) { |
| 815 |
$do_ln = $$prior_args{do_ln} || 0; |
| 816 |
$invert = $$prior_args{invert} || 0; |
| 817 |
$space = $$prior_args{space} || 'e'; |
| 818 |
$space_label = $label_map{$space}; |
| 819 |
$evkev = $$prior_args{evkev} || 'ev'; |
| 820 |
$sort = $$prior_args{sort} || 1; |
| 821 |
$multi = $$prior_args{multi} || 0; |
| 822 |
%reference = (numerator => $reference{numerator} || $$prior_args{ref}{numerator} || 0, |
| 823 |
denominator => $reference{denominator} || $$prior_args{ref}{denominator} || 0, |
| 824 |
ln => $$prior_args{ref}->{ln}, |
| 825 |
same => $$prior_args{ref}->{same}, |
| 826 |
); |
| 827 |
$sorted = $$prior_args{sorted} || ""; |
| 828 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 829 |
} else { |
| 830 |
|
| 831 |
## reset all the preprocessing stuff if this one is different |
| 832 |
$rebin{do_rebin} = 0; |
| 833 |
$preprocess{standard} = 'None'; |
| 834 |
$preprocess{mark_do} = 0; |
| 835 |
$preprocess{trun_do} = 0; |
| 836 |
$preprocess{deg_do} = 0; |
| 837 |
$preprocess{raised} = 'reference'; |
| 838 |
|
| 839 |
%reference = (numerator=>0, denominator=>0, ln=>1, same=>1); |
| 840 |
$$prior_args{evkev} = 'ev'; |
| 841 |
foreach (@cols) { |
| 842 |
my $this = $group.".".$_; |
| 843 |
(/^(e|en|energy)/i) and ($energy = $this); |
| 844 |
(/^[Kk]$/) and ($energy = $this); |
| 845 |
(/$re{i0}/i) and ($parts{0} = $this); |
| 846 |
if (/$re{it}/i) {$parts{t} = $this} |
| 847 |
elsif (/$re{if}/i) {$parts{f} = $this}; |
| 848 |
}; |
| 849 |
$energy ||= $group.".".$cols[0]; # set it if not already set |
| 850 |
|
| 851 |
if ($parts{t}) { |
| 852 |
$denominator{$parts{t}} = 1; |
| 853 |
($parts{0}) and ($numerator{$parts{0}} = 1); |
| 854 |
$do_ln = 1; |
| 855 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 856 |
} elsif ($parts{f}) { |
| 857 |
$numerator{$parts{f}} = 1; |
| 858 |
($parts{0}) and ($denominator{$parts{0}} = 1); |
| 859 |
$do_ln = 0; |
| 860 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 861 |
} |
| 862 |
}; |
| 863 |
|
| 864 |
$energy ||= $group.".".$cols[0]; # set it if not already set |
| 865 |
if ($#cols == 1) { # mu(E) or chi(k) data |
| 866 |
$$prior_args{evkev} = 'ev'; |
| 867 |
$numerator{$group.".".$cols[1]} = 1; |
| 868 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 869 |
} elsif (($#cols == 3) and ($cols[1] eq 'chi')) { # probably a chi.dat file |
| 870 |
$numerator{$group.".".$cols[1]} = 1; |
| 871 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 872 |
} elsif ($is_xmudat) { |
| 873 |
$$prior_args{evkev} = 'ev'; |
| 874 |
$numerator{"$group.mu"} = 1; |
| 875 |
$energy = $group.".".$cols[0]; |
| 876 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy); |
| 877 |
}; |
| 878 |
## try to guess if this is chi(k) data. |
| 879 |
if (($#cols == 3) and ($cols[1] eq 'chi')) { |
| 880 |
($space, $space_label, $evkev) = ('c', 'chi.dat', 'ev'); |
| 881 |
} elsif (($cols[0] eq 'k') or ($cols[1] =~ /chi/)) { |
| 882 |
($space, $space_label, $evkev) = ('k', 'chi(K)', 'ev'); |
| 883 |
} elsif ($is_xmudat) { |
| 884 |
($space, $space_label, $evkev) = ('x', 'xmu.dat', 'ev'); |
| 885 |
} elsif ($is_pixel) { |
| 886 |
($space, $space_label, $evkev) = ('e', 'mu(E)', 'pixel'); |
| 887 |
(($space, $space_label) = ('a','xanes(E)')) if $is_xanes; |
| 888 |
} else { |
| 889 |
(($space, $space_label) = ('a','xanes(E)')) if $is_xanes; |
| 890 |
my @cols = split(" ", $col_string); |
| 891 |
my @en = Ifeffit::get_array("$group.$cols[0]"); |
| 892 |
($#en > 0) || (@en = Ifeffit::get_array($group.'.1')); |
| 893 |
$evkev = ($en[0] < 100) ? 'kev' : 'ev'; |
| 894 |
}; |
| 895 |
$space ||= 'm'; # fall back |
| 896 |
$space_label = $label_map{$space}; |
| 897 |
$evkev ||= 'ev'; |
| 898 |
|
| 899 |
## Formulas |
| 900 |
$fr = $left -> Frame(-relief=>'flat', -borderwidth=>0,) |
| 901 |
-> pack(-expand=>1, -fill=>'x'); |
| 902 |
## take the natural log? |
| 903 |
$fr -> Checkbutton(-text=>"Natural log", |
| 904 |
-variable=>\$do_ln, |
| 905 |
-selectcolor=>$red, |
| 906 |
-onvalue=>1, |
| 907 |
-command=> |
| 908 |
sub{ |
| 909 |
$$prior_args{old} = $energy; |
| 910 |
$$prior_args{numerator} = \%numerator; |
| 911 |
$$prior_args{denominator} = \%denominator; |
| 912 |
$$prior_args{do_ln} = $do_ln; |
| 913 |
$$prior_args{invert} = $invert; |
| 914 |
$$prior_args{space} = $space; |
| 915 |
$$prior_args{evkev} = $evkev; |
| 916 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 917 |
$$prior_args{sort} = $sort; |
| 918 |
$$prior_args{multi} = $multi; |
| 919 |
$$prior_args{ref} = \%reference; |
| 920 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy) |
| 921 |
}) |
| 922 |
-> pack(-side=>'left', -anchor=>'w'); |
| 923 |
$widg{multi} = $fr -> Checkbutton(-text=>"Save each channel as a group", |
| 924 |
-variable=>\$multi, -selectcolor=>$red, |
| 925 |
-onvalue=>1, -offvalue=>0, |
| 926 |
-state=>'disabled') |
| 927 |
-> pack(-side=>'right', -anchor=>'w'); |
| 928 |
$fr = $left -> Frame(-relief=>'flat', -borderwidth=>0,) |
| 929 |
-> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 930 |
$fr -> Checkbutton(-text=>"Negate", |
| 931 |
-variable=>\$invert, |
| 932 |
-selectcolor=>$red, |
| 933 |
-onvalue=>1, |
| 934 |
-command=> |
| 935 |
sub{ |
| 936 |
$$prior_args{old} = $energy; |
| 937 |
$$prior_args{numerator} = \%numerator; |
| 938 |
$$prior_args{denominator} = \%denominator; |
| 939 |
$$prior_args{do_ln} = $do_ln; |
| 940 |
$$prior_args{invert} = $invert; |
| 941 |
$$prior_args{space} = $space; |
| 942 |
$$prior_args{evkev} = $evkev; |
| 943 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 944 |
$$prior_args{sort} = $sort; |
| 945 |
$$prior_args{multi} = $multi; |
| 946 |
$$prior_args{ref} = \%reference; |
| 947 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy) |
| 948 |
}) |
| 949 |
-> pack(-side=>'left', -anchor=>'w'); |
| 950 |
$fr -> Button(-text=>"Replot", |
| 951 |
-borderwidth=>1, |
| 952 |
-command=>sub{make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy)}, |
| 953 |
) |
| 954 |
-> pack(-side=>'right', -anchor=>'w'); |
| 955 |
|
| 956 |
$fr = $left -> Frame(-relief=>'flat', -borderwidth=>0,) |
| 957 |
-> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 958 |
$enlabel = $fr -> Label(-text=>"Energy:", |
| 959 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 960 |
-> pack(-side=>'left', -padx=>2); |
| 961 |
$enstr = $fr -> Label(-textvariable=>\$energy, -justify=>'left') |
| 962 |
-> pack(-side=>'left', -padx=>2, -expand=>1, -fill=>'x', -anchor=>'w'); |
| 963 |
|
| 964 |
$fr = $left -> Frame(-relief=>'flat', -borderwidth=>0) |
| 965 |
-> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 966 |
$fnlabel = $fr -> Label(-text=>($is_xmudat) ? "theory:" : "mu(E):", |
| 967 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 968 |
-width=>6) |
| 969 |
-> pack(-side=>'left', -padx=>2); |
| 970 |
$mustr = $fr -> Scrolled("Entry", -text=>\$xmustring, -justify=>'left', -width=>35, |
| 971 |
(($Tk::VERSION >= 804) ? (-disabledforeground=>$config{colors}{foreground}) : ()), |
| 972 |
-state=>'disabled') |
| 973 |
-> pack(-side=>'left', -padx=>2, -expand=>1, -fill=>'x'); |
| 974 |
$mustr->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}, |
| 975 |
($is_windows) ? () : (-width=>8)); |
| 976 |
|
| 977 |
$fr = $left -> Frame(-relief=>'flat', -borderwidth=>2, -height=>2) |
| 978 |
-> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 979 |
|
| 980 |
|
| 981 |
my $frm = $left -> Frame(-relief=>'flat', -borderwidth=>2) |
| 982 |
-> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 983 |
## -> grid(-row=>5, -column=>0, -sticky=>'ew', -columnspan=>$#cols+2); |
| 984 |
## choose the data type (mu || norm || chi || xmu.dat || chi.dat || detector) |
| 985 |
my $f1 = $frm -> Frame() -> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 986 |
#my $f2 = $frm -> Frame() -> pack(-side=>'bottom', -expand=>1, -fill=>'x'); |
| 987 |
$f1 -> Label(-text=>'Data type: ', -foreground=>$config{colors}{activehighlightcolor}) |
| 988 |
-> pack(-side=>'left'); |
| 989 |
my $om = $f1 -> Optionmenu(-font=>$config{fonts}{small}, |
| 990 |
-borderwidth=>1, |
| 991 |
-textvariable=>\$space_label, -width=>7) |
| 992 |
-> pack(-side=>'left'); |
| 993 |
$om ->command(-label=>'mu(E)', |
| 994 |
-command=>sub{$space='e'; $space_label='mu(E)'; |
| 995 |
$widg{evkev}->configure(-state=>'normal'); |
| 996 |
#$widg{pre}->configure(-state=>$preproc_state); |
| 997 |
$enlabel -> configure(-text=>'Energy:'); |
| 998 |
$fnlabel -> configure(-text=>'mu(E):'); |
| 999 |
$unlabel -> configure(-foreground=>$active_color); }); |
| 1000 |
$om ->command(-label=>'norm(E)', |
| 1001 |
-command=>sub{$space='n'; $space_label='norm(E)'; |
| 1002 |
$widg{evkev}->configure(-state=>'normal'); |
| 1003 |
#$widg{pre}->configure(-state=>$preproc_state); |
| 1004 |
$enlabel -> configure(-text=>'Energy:'); |
| 1005 |
$fnlabel -> configure(-text=>'norm(E):'); |
| 1006 |
$unlabel -> configure(-foreground=>$active_color); }); |
| 1007 |
$om ->command(-label=>'xanes(E)', |
| 1008 |
-command=>sub{$space='a'; $space_label='xanes(E)'; |
| 1009 |
$widg{evkev}->configure(-state=>'normal'); |
| 1010 |
#$widg{pre}->configure(-state=>$preproc_state); |
| 1011 |
$enlabel -> configure(-text=>'Energy:'); |
| 1012 |
$fnlabel -> configure(-text=>'mu(E):'); |
| 1013 |
$unlabel -> configure(-foreground=>$active_color); }); |
| 1014 |
$om ->command(-label=>'chi(k)', |
| 1015 |
-command=>sub{$space='k'; $space_label='chi(k)'; |
| 1016 |
$widg{evkev}->configure(-state=>'disabled'); |
| 1017 |
#$widg{pre}->configure(-state=>'disabled'); |
| 1018 |
$enlabel -> configure(-text=>'wavenumber:'); |
| 1019 |
$fnlabel -> configure(-text=>'chi(k):'); |
| 1020 |
$unlabel -> configure(-foreground=>$grey); }); |
| 1021 |
$om ->command(-label=>'detector', |
| 1022 |
-command=>sub{$space='d'; $space_label='detector'; |
| 1023 |
$widg{evkev}->configure(-state=>'normal'); |
| 1024 |
#$widg{pre}->configure(-state=>$preproc_state); |
| 1025 |
$enlabel -> configure(-text=>'Energy:'); |
| 1026 |
$fnlabel -> configure(-text=>'det(E):'); |
| 1027 |
$unlabel -> configure(-foreground=>$active_color);}); |
| 1028 |
$om ->command(-label=>'xmu.dat', |
| 1029 |
-command=>sub{$space='x'; $space_label='xmu.dat'; |
| 1030 |
$widg{evkev}->configure(-state=>'normal'); |
| 1031 |
#$widg{pre}->configure(-state=>'disabled'); |
| 1032 |
$enlabel -> configure(-text=>'Energy:'); |
| 1033 |
$fnlabel -> configure(-text=>'theory:'); |
| 1034 |
$unlabel -> configure(-foreground=>$active_color); }); |
| 1035 |
$om ->command(-label=>'chi.dat', |
| 1036 |
-command=>sub{$space='c'; $space_label='chi.dat'; |
| 1037 |
$widg{evkev}->configure(-state=>'disabled'); |
| 1038 |
#$widg{pre}->configure(-state=>'disabled'); |
| 1039 |
$enlabel -> configure(-text=>'wavenumber:'); |
| 1040 |
$fnlabel -> configure(-text=>'theory:'); |
| 1041 |
$unlabel -> configure(-foreground=>$grey); }); |
| 1042 |
|
| 1043 |
$f1 -> Frame(-width=>10) |
| 1044 |
-> pack(-side=>'left'); |
| 1045 |
$unlabel = $f1 -> Label(-text=>'Energy units: ', |
| 1046 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 1047 |
-> pack(-side=>'left'); |
| 1048 |
$widg{evkev} = $f1 -> Optionmenu(-font=>$config{fonts}{small}, |
| 1049 |
-borderwidth=>1, |
| 1050 |
-textvariable=>\$evkev, -width=>6) |
| 1051 |
-> pack(-side=>'left'); |
| 1052 |
$widg{evkev} -> command(-label =>'eV', |
| 1053 |
-command=>sub{$evkev = 'ev'; |
| 1054 |
#$widg{extras} -> raise(($preproc_number>1) ? 'preprocessing' : 'reference'); |
| 1055 |
$$prior_args{old} = $energy; |
| 1056 |
$$prior_args{numerator} = \%numerator; |
| 1057 |
$$prior_args{denominator} = \%denominator; |
| 1058 |
$$prior_args{do_ln} = $do_ln; |
| 1059 |
$$prior_args{invert} = $invert; |
| 1060 |
$$prior_args{space} = $space; |
| 1061 |
$$prior_args{evkev} = $evkev; |
| 1062 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 1063 |
$$prior_args{sort} = $sort; |
| 1064 |
$$prior_args{multi} = $multi; |
| 1065 |
$$prior_args{ref} = \%reference; |
| 1066 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy) |
| 1067 |
}); |
| 1068 |
$widg{evkev} -> command(-label =>'keV', |
| 1069 |
-command=>sub{$evkev = 'kev'; |
| 1070 |
#$widg{extras} -> raise(($preproc_number>1) ? 'preprocessing' : 'reference'); |
| 1071 |
$$prior_args{old} = $energy; |
| 1072 |
$$prior_args{numerator} = \%numerator; |
| 1073 |
$$prior_args{denominator} = \%denominator; |
| 1074 |
$$prior_args{do_ln} = $do_ln; |
| 1075 |
$$prior_args{invert} = $invert; |
| 1076 |
$$prior_args{space} = $space; |
| 1077 |
$$prior_args{evkev} = $evkev; |
| 1078 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 1079 |
$$prior_args{sort} = $sort; |
| 1080 |
$$prior_args{multi} = $multi; |
| 1081 |
$$prior_args{ref} = \%reference; |
| 1082 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy) |
| 1083 |
}); |
| 1084 |
$widg{evkev} -> command(-label =>'pixel', |
| 1085 |
-command=>sub{$evkev = 'pixel'; |
| 1086 |
#$widg{extras} -> raise(($preproc_number>1) ? 'preprocessing' : 'reference'); |
| 1087 |
$$prior_args{old} = $energy; |
| 1088 |
$$prior_args{numerator} = \%numerator; |
| 1089 |
$$prior_args{denominator} = \%denominator; |
| 1090 |
$$prior_args{do_ln} = $do_ln; |
| 1091 |
$$prior_args{invert} = $invert; |
| 1092 |
$$prior_args{space} = $space; |
| 1093 |
$$prior_args{evkev} = $evkev; |
| 1094 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 1095 |
$$prior_args{sort} = $sort; |
| 1096 |
$$prior_args{multi} = $multi; |
| 1097 |
$$prior_args{ref} = \%reference; |
| 1098 |
($xmustring, @toss) = make_xmu_string(\%numerator, \%denominator, $do_ln, $invert, $energy) |
| 1099 |
}, |
| 1100 |
-state=>($config{pixel}{do_pixel_check}) ? 'normal' : 'disabled'); |
| 1101 |
if ($space =~ /[ck]/) { |
| 1102 |
$widg{evkev}->configure(-state=>'disabled'); |
| 1103 |
$enlabel -> configure(-text=>'wavenumber:'); |
| 1104 |
$unlabel -> configure(-foreground=>$grey); |
| 1105 |
}; |
| 1106 |
FN: { |
| 1107 |
$fnlabel -> configure(-text=>'mu(E):'), last FN if ($space eq 'e'); |
| 1108 |
$fnlabel -> configure(-text=>'norm(E):'), last FN if ($space eq 'n'); |
| 1109 |
$fnlabel -> configure(-text=>'mu(E):'), last FN if ($space eq 'a'); |
| 1110 |
$fnlabel -> configure(-text=>'chi(k):'), last FN if ($space eq 'k'); |
| 1111 |
$fnlabel -> configure(-text=>'det(E):'), last FN if ($space eq 'd'); |
| 1112 |
$fnlabel -> configure(-text=>'theory:'), last FN if ($space eq 'x'); |
| 1113 |
$fnlabel -> configure(-text=>'theory:'), last FN if ($space eq 'c'); |
| 1114 |
}; |
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
$preprocess{raised} ||= "reference"; |
| 1120 |
$widg{extras} = $left -> NoteBook(-background=>$config{colors}{background}, |
| 1121 |
-backpagecolor=>$config{colors}{background}, |
| 1122 |
-inactivebackground=>$config{colors}{inactivebackground}, |
| 1123 |
-font=>$config{fonts}{small}, |
| 1124 |
) |
| 1125 |
-> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 1126 |
$widg{pre_card} = $widg{extras} -> |
| 1127 |
add("preprocessing", -label=>'Preprocess', -anchor=>'center', |
| 1128 |
-state=>$preproc_state); |
| 1129 |
set_preprocessing(\%widg) |
| 1130 |
-> pack(-expand=>1, -fill=>'x'); |
| 1131 |
$widg{bin_card} = $widg{extras} -> |
| 1132 |
add("bin", -label=>'Bin' , -anchor=>'center', |
| 1133 |
-state=>($$prior_args{space} eq 'k') ? 'disabled' : 'normal'); |
| 1134 |
set_bin(\%widg) |
| 1135 |
-> pack(-anchor=>'n', -fill=>'x'); |
| 1136 |
$widg{ref_card} = $widg{extras} -> |
| 1137 |
add("reference", -label=>'Reference', -anchor=>'center',); |
| 1138 |
set_reference($widg{ref_card}, $group, \@cols, \%widg, \%reference, \$energy) |
| 1139 |
-> pack(-anchor=>'n', -fill=>'x'); |
| 1140 |
## $widg{fav_card} = $widg{extras} |
| 1141 |
## -> add("favorites", -label=>'Favorites', -anchor=>'center',); |
| 1142 |
## set_favorites(\%widg) |
| 1143 |
## -> pack(-anchor=>'n', -fill=>'x'); |
| 1144 |
$widg{extras} -> raise($preprocess{raised}); |
| 1145 |
|
| 1146 |
$$prior_args{extra_shown} = 1; # 0; |
| 1147 |
## $widg{extra_button} = $left -> Button(-text=>'Show extra features', @button_list, |
| 1148 |
## -command=> |
| 1149 |
## sub{ |
| 1150 |
## my ($h,$w) = ($left->height(), $raw->width()); |
| 1151 |
## $reference{preproc_state} = $preproc_state; |
| 1152 |
## $widg{extra_button} -> packForget; |
| 1153 |
## $top -> update; # needed so $raw resizes correctly |
| 1154 |
## $widg{extras} -> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 1155 |
## $right->pack(-expand=>1, -fill=>'both', |
| 1156 |
## -side=>'right', -anchor=>'n'); |
| 1157 |
## $databox->pack(-expand=>1, -fill=>'both', |
| 1158 |
## -padx=>4, -pady=>2); |
| 1159 |
## $widg{extras} -> raise(($preproc_number>1 eq 'normal') ? 'preprocessing' : 'reference'); |
| 1160 |
## $$prior_args{extra_shown} = 1; |
| 1161 |
## }) |
| 1162 |
## -> pack(-expand=>1, -fill=>'x', -pady=>0); |
| 1163 |
|
| 1164 |
|
| 1165 |
## help button |
| 1166 |
#$left -> Button(-text=>'Document section: importing data', @button_list, |
| 1167 |
# -command=>sub{pod_display("import::index.pod")}) |
| 1168 |
# -> pack(-side=>'bottom', -fill=>'x', -pady=>2); |
| 1169 |
|
| 1170 |
$fr = $left -> Frame(-relief=>'flat', -borderwidth=>0) |
| 1171 |
-> pack(-pady=>2, -expand=>1, -fill=>'x', -side=>'bottom'); |
| 1172 |
$widg{ok}= $fr -> Button(-text=>'OK', @button_list, |
| 1173 |
-command=> |
| 1174 |
sub { |
| 1175 |
$widg{ok} -> configure(-state=>'disabled'); |
| 1176 |
if (($rebin{do_rebin}) and ($rebin{abs} =~ /^\s*$/)) { |
| 1177 |
my $dialog = |
| 1178 |
$raw -> Dialog(-bitmap => 'error', |
| 1179 |
-text => "You did not specify an absorber. The on-the-fly rebinning algorithm needs to know the absorber species.", |
| 1180 |
-title => 'Athena: Problem with rebinning parameters', |
| 1181 |
-buttons => ['Go back', 'Import without rebinning'], |
| 1182 |
-default_button => 'Go back', |
| 1183 |
-popover => 'cursor'); |
| 1184 |
$dialog->raise; |
| 1185 |
my $response = $dialog->Show(); |
| 1186 |
if ($response eq 'Go back') { |
| 1187 |
$widg{ok} -> configure(-state=>'normal'); |
| 1188 |
$raw->raise; |
| 1189 |
$widg{extras} -> raise("bin"); |
| 1190 |
$widget{rebin_abs} -> focus; |
| 1191 |
return (-1, $prior_string); |
| 1192 |
}; |
| 1193 |
}; |
| 1194 |
if (($rebin{do_rebin}) and (lc($rebin{abs}) !~ /^$Ifeffit::Files::elem_regex$/)) { |
| 1195 |
my $dialog = |
| 1196 |
$raw -> Dialog(-bitmap => 'error', |
| 1197 |
-text => "Your absorber, $rebin{abs}, is not a valid element symbol. The on-the-fly rebinning cannot continue.", |
| 1198 |
-title => 'Athena: Problem with rebinning parameters', |
| 1199 |
-buttons => ['Go back', 'Import without rebinning'], |
| 1200 |
-default_button => 'Go back', |
| 1201 |
-popover => 'cursor'); |
| 1202 |
my $response = $dialog->Show(); |
| 1203 |
if ($response eq 'Go back') { |
| 1204 |
$widg{ok} -> configure(-state=>'normal'); |
| 1205 |
$raw->raise; |
| 1206 |
$widget{rebin_abs} -> focus; |
| 1207 |
return (-1, $prior_string); |
| 1208 |
}; |
| 1209 |
}; |
| 1210 |
$preprocess{raised} = $widg{extras}->raised(); |
| 1211 |
$colsel_geometry = $raw->geometry; |
| 1212 |
$$prior_args{old} = $energy; |
| 1213 |
$$prior_args{numerator} = \%numerator; |
| 1214 |
$$prior_args{denominator} = \%denominator; |
| 1215 |
$$prior_args{do_ln} = $do_ln; |
| 1216 |
$$prior_args{invert} = $invert; |
| 1217 |
$$prior_args{space} = $space; |
| 1218 |
$$prior_args{evkev} = $evkev; |
| 1219 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 1220 |
$$prior_args{sort} = $sort; |
| 1221 |
$$prior_args{multi} = $multi; |
| 1222 |
my $ret = &construct_xmu($raw, $group, $label, |
| 1223 |
$data, $stash, $prior_args |
| 1224 |
); |
| 1225 |
$$prior_args{ref} = \%reference; |
| 1226 |
if ($ret < 0) {$$r_cancel = 1; $raw->destroy; |
| 1227 |
return (-1, $col_string)}; |
| 1228 |
$widg{ok} -> configure(-state=>'normal') if ($ret == 0); |
| 1229 |
}) |
| 1230 |
-> pack(-expand=>1, -fill=>'x', -pady=>2, -side=>'left'); |
| 1231 |
$fr -> Button(-text=>'Cancel', @button_list, |
| 1232 |
-command=>sub{$colsel_geometry = $raw->geometry; |
| 1233 |
$$r_cancel = 1; $raw->destroy; return (-1, $prior_string)}) |
| 1234 |
-> pack(-expand=>1, -fill=>'x', -pady=>2, -side=>'right'); |
| 1235 |
|
| 1236 |
|
| 1237 |
## setup the display of the data file text |
| 1238 |
my $h = $left->height(); |
| 1239 |
$databox = $right -> Scrolled(qw/ROText -relief sunken -borderwidth 2 |
| 1240 |
-wrap none -scrollbars se -width 50/, |
| 1241 |
-font=>$config{fonts}{fixed}) |
| 1242 |
-> pack(-expand=>1, -fill=>'both', -padx=>4, -pady=>2); |
| 1243 |
$databox -> tagConfigure("text", -font=>$config{fonts}{fixedsm}); |
| 1244 |
$widg{databox} = $databox; |
| 1245 |
BindMouseWheel($databox); |
| 1246 |
$databox->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}); |
| 1247 |
$databox->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background}); |
| 1248 |
my $to_display = ($is_binary) ? $stash : $data; |
| 1249 |
open F, $to_display or die "Could not open $to_display\n"; |
| 1250 |
while (<F>) { |
| 1251 |
s/\r//; |
| 1252 |
$databox -> insert('end', $_, 'text'); |
| 1253 |
}; |
| 1254 |
close F; |
| 1255 |
## display the multi-element button properly |
| 1256 |
my $sum; |
| 1257 |
foreach my $v (values %numerator) {$sum += $v}; |
| 1258 |
$widg{multi} -> configure(-state=>($sum > 1)?'normal':'disabled'); |
| 1259 |
|
| 1260 |
|
| 1261 |
## show the reference dialog if the reference channels are set, which only |
| 1262 |
## happens if this is similar to the prior data and the prior had reference |
| 1263 |
## channels |
| 1264 |
## print Data::Dumper->Dump([\%reference], [qw(*reference)]); |
| 1265 |
if ($reference{numerator} or $reference{denominator}) { |
| 1266 |
$reference{preproc_state} = $preproc_state; |
| 1267 |
##$widg{extra_button} -> packForget; |
| 1268 |
$top -> update; # needed so $raw resizes correctly |
| 1269 |
$widg{extras} -> pack(-pady=>2, -expand=>1, -fill=>'x'); |
| 1270 |
$right->pack(-expand=>1, -fill=>'both', -side=>'right', -anchor=>'n'); |
| 1271 |
$databox->pack(-expand=>1, -fill=>'both', -padx=>4, -pady=>2); |
| 1272 |
#$widg{extras} -> raise('reference'); |
| 1273 |
$$prior_args{extra_shown} = 1; |
| 1274 |
}; |
| 1275 |
|
| 1276 |
$widg{ok} -> focus; |
| 1277 |
##$raw -> raise; |
| 1278 |
$raw -> grab; |
| 1279 |
##$top -> update; |
| 1280 |
##$update -> grabRelease; |
| 1281 |
$$prior_args{old} = $energy; |
| 1282 |
$$prior_args{numerator} = \%numerator; |
| 1283 |
$$prior_args{denominator} = \%denominator; |
| 1284 |
$$prior_args{do_ln} = $do_ln; |
| 1285 |
$$prior_args{invert} = $invert; |
| 1286 |
$$prior_args{space} = $space; |
| 1287 |
$$prior_args{evkev} = $evkev; |
| 1288 |
$$prior_args{is_xmudat} = $is_xmudat; |
| 1289 |
$$prior_args{sort} = $sort; |
| 1290 |
$$prior_args{multi} = $multi; |
| 1291 |
$$prior_args{ref} = \%reference; |
| 1292 |
return ($raw, $col_string); |
| 1293 |
}; |
| 1294 |
|
| 1295 |
|
| 1296 |
sub column_string { |
| 1297 |
my $col_string = q{}; |
| 1298 |
my $i = 1; |
| 1299 |
my $this = Ifeffit::get_string('$column_label'.$i); |
| 1300 |
while ($this !~ m{^\s*$}) { |
| 1301 |
$col_string .= $this . ' '; |
| 1302 |
++$i; |
| 1303 |
$this = Ifeffit::get_string('$column_label'.$i) |
| 1304 |
}; |
| 1305 |
# $col_string =~ s{^nergy}{energy}i; |
| 1306 |
return $col_string; |
| 1307 |
}; |
| 1308 |
|
| 1309 |
## this suppresses a nattering message that warns, in cryptic fashion, |
| 1310 |
## when you attempt to read a non-zip file as a zip file. since that |
| 1311 |
## is the only way to test for zippiness of a file using Archive::Zip, |
| 1312 |
## simply suppressing the message seems appropriate. |
| 1313 |
sub is_zip_error_handler { 1; }; |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
## $w takes the column selection Toplevel or 0 if this is a repeated file |
| 1318 |
sub construct_xmu { |
| 1319 |
my ($w, $group, $label, $file, $stash, $prior_args) = @_; |
| 1320 |
#$en, $rn, $rd, $ln, $inv, $space, $evkev, $is_xmudat, $sort, $multi, $reference, $sorted) = @_; |
| 1321 |
#print join(" ", $group, $file, $en, $rn, $rd, $ln, $space, $evkev, |
| 1322 |
# $is_xmudat, $sort, $multi), $/; |
| 1323 |
|
| 1324 |
my $en = $$prior_args{old}; # 0 |
| 1325 |
my $rn = $$prior_args{numerator}; # 1 |
| 1326 |
my $rd = $$prior_args{denominator}; # 2 |
| 1327 |
my $ln = $$prior_args{do_ln}; # 3 |
| 1328 |
my $inv = $$prior_args{invert}; # 4 |
| 1329 |
my $space = $$prior_args{space}; # 5 |
| 1330 |
my $evkev = $$prior_args{evkev}; # 6 |
| 1331 |
my $is_xmudat = $$prior_args{is_xmudat}; # 7 |
| 1332 |
my $sort = $$prior_args{sort}; # 8 |
| 1333 |
my $multi = $$prior_args{multi}; # 9 |
| 1334 |
my $reference = $$prior_args{ref}; # 10 |
| 1335 |
my $sorted = $$prior_args{sorted}; # 11 |
| 1336 |
|
| 1337 |
#print join(" ", %$reference), $/; |
| 1338 |
unless (($group) and ($en) and ($rd) and ($rn)) { |
| 1339 |
($w == 0) or $w -> destroy(); # get rid of column palette |
| 1340 |
Echo("Group undefined!"), return 0 unless $group; |
| 1341 |
Echo("Energy array undefined!"), return 0 unless $en; |
| 1342 |
Echo("Numerator hash undefined!"), return 0 unless $rn; |
| 1343 |
Echo("Denominator hash undefined!"), return 0 unless $rd; |
| 1344 |
}; |
| 1345 |
## must take care when reading multiple files that the arguments |
| 1346 |
## from the previous run have the current group name substituted |
| 1347 |
## in. The following regex is unnecessary (but not incorrect) when |
| 1348 |
## reading a single data file, but is essential when reading a set |
| 1349 |
## of data files |
| 1350 |
## |
| 1351 |
## The regex is anything that is not an alphanumeric, an underscore, |
| 1352 |
## or a question mark then followed by a dot, but the dot is matched |
| 1353 |
## by a non-consuming look-ahead, so it does not get substituted |
| 1354 |
## |
| 1355 |
## Matt sez (mail 17 Jan. 2003) "the first character for scalars and |
| 1356 |
## group prefix must be 'a-z_&', and 'a-z0-9_&' for group suffixes, |
| 1357 |
## and that subsequent characters can be any of 'a-z0-9_&:?@~' ". I |
| 1358 |
## am actually only using _ and ? as nonalphanumerics |
| 1359 |
$en =~ s/[A-Za-z0-9_?]+(?=\.)/$group/g; |
| 1360 |
$space = lc($space); |
| 1361 |
$evkev = lc($evkev); |
| 1362 |
($evkev =~ /(kev|pixel)/) or ($evkev = 'ev'); |
| 1363 |
($is_xmudat) and ($space = 'e'); # n for normalizaed |
| 1364 |
($space eq 'c') and ($space = 'k'); |
| 1365 |
($space eq 'k') and ($evkev = ''); |
| 1366 |
#$prior_args = [$en, $rn, $rd, $ln, $inv, $space, $evkev, $is_xmudat, $sort, $multi, $reference, $sorted]; |
| 1367 |
($w == 0) or $w -> grabRelease; # column palette gives up grab |
| 1368 |
($label .= "_pixel") if ($evkev eq 'pixel'); |
| 1369 |
|
| 1370 |
|
| 1371 |
my ($str, $num, $den, $i0) = make_xmu_string($rn, $rd, $ln, $inv, 0); |
| 1372 |
if (($str eq "1") or ($str eq "ln(abs(1))")) { |
| 1373 |
my $message = "You have not selected any data columns!"; |
| 1374 |
my $dialog = |
| 1375 |
$w -> Dialog(-bitmap => 'questhead', |
| 1376 |
-text => $message, |
| 1377 |
-title => 'Athena: oops!', |
| 1378 |
-buttons => [qw/OK/], |
| 1379 |
-default_button => 'OK'); |
| 1380 |
my $response = $dialog->Show(); |
| 1381 |
#$w -> raise(); |
| 1382 |
$top -> update; |
| 1383 |
return 0; |
| 1384 |
}; |
| 1385 |
|
| 1386 |
unless ($num) { |
| 1387 |
#($w == 0) or $w -> destroy(); # get rid of column palette |
| 1388 |
Echo("Data string was not selected.") and return 0; |
| 1389 |
}; |
| 1390 |
## clean up the strings to use the current group's group name |
| 1391 |
$str =~ s/[A-Za-z0-9_?]+(?=\.)/$group/g; # same regex as above |
| 1392 |
$num =~ s/[A-Za-z0-9_?]+(?=\.)/$group/g; |
| 1393 |
$den =~ s/[A-Za-z0-9_?]+(?=\.)/$group/g; |
| 1394 |
$i0 =~ s/[A-Za-z0-9_?]+(?=\.)/$group/g; |
| 1395 |
my $was_backwards = 0; # Ifeffit::Files->backwards_data($group, $en); |
| 1396 |
my ($isnt_monotonic, @points) = Ifeffit::Files->monotonic_data($group, $en, $evkev); # (0, ()); |
| 1397 |
if ($isnt_monotonic) { |
| 1398 |
my $xaxis = "energy"; |
| 1399 |
($space eq 'k') and ($xaxis = "wavenumber"); |
| 1400 |
my $response = ""; |
| 1401 |
# if ($sorted) { |
| 1402 |
# $response = $sorted; |
| 1403 |
# } else { |
| 1404 |
# my $message = "This file:\n\n $file\n\n"; |
| 1405 |
# $message .= "contains data that are not monotonically increasing in $xaxis.\n"; |
| 1406 |
# if ($#points) { |
| 1407 |
# $message .= "(check data points " . join(", ", @points) . ")"; |
| 1408 |
# } else { |
| 1409 |
# $message .= "(check data point $points[0])"; |
| 1410 |
# }; |
| 1411 |
# $message .= "\n\n\nAthena cannot import data in this state."; |
| 1412 |
# $message .= " You may sort these data by $xaxis,"; |
| 1413 |
# $message .= " discarding repeated points,"; |
| 1414 |
# $message .= " or you may simply cancel the import of these data."; |
| 1415 |
# my $dialog = |
| 1416 |
# $top -> Dialog(-bitmap => 'warning', |
| 1417 |
# -text => $message, |
| 1418 |
# -title => 'Athena: Non-monotonic data file', |
| 1419 |
# -buttons => ['Sort data', 'Cancel'], |
| 1420 |
# -default_button => 'Sort data'); |
| 1421 |
# ($w == 0) or $w -> lower; # the dialog sometimes is hard to see on the screen! |
| 1422 |
# $response = $dialog->Show(-popover => 'cursor' ); |
| 1423 |
# }; |
| 1424 |
$response = "Sort data"; |
| 1425 |
if ($response eq 'Cancel') { # discard non-monotonic data |
| 1426 |
#($w == 0) or $w -> destroy(); # get rid of column palette |
| 1427 |
$setup -> dispose("erase \@group $group"); |
| 1428 |
Echo("Canceling import of \"$file\""); |
| 1429 |
return -1; |
| 1430 |
} else { # fix non-monotonic data |
| 1431 |
$$prior_args{sorted} = $response; |
| 1432 |
Echo("Sorting data for $label"); |
| 1433 |
|
| 1434 |
## This block is a complicated bit. The idea is to store all |
| 1435 |
## the data in a list of lists. In this way, I can sort all the |
| 1436 |
## data in one swoop by sorting off the energy part of the list |
| 1437 |
## of lists. After sorting, I check the data for repeated |
| 1438 |
## points and remove them. Finally, I reload the data into |
| 1439 |
## ifeffit and carry on like normal data |
| 1440 |
|
| 1441 |
## This gets a list of column labels |
| 1442 |
my @cols = split(" ", &column_string); |
| 1443 |
my @lol; |
| 1444 |
## energy value is zeroth in each anon list |
| 1445 |
my @array = get_array("$en"); |
| 1446 |
map {push @{$lol[$_]}, $array[$_]} (0 .. $#array); |
| 1447 |
foreach my $c (@cols) { |
| 1448 |
## load other cols (including energy col) into anon. lists |
| 1449 |
my @array = get_array("$group.$c"); |
| 1450 |
map {push @{$lol[$_]}, $array[$_]} (0 .. $#array); |
| 1451 |
}; |
| 1452 |
## sort the anon. lists by energy (i.e. zeroth element) |
| 1453 |
@lol = sort {$a->[0] <=> $b->[0]} @lol; |
| 1454 |
|
| 1455 |
## now fish thru lol looking for repeated energy points |
| 1456 |
my $ii = 0; |
| 1457 |
while ($ii < $#lol) { |
| 1458 |
($lol[$ii+1]->[0] > $lol[$ii]->[0]) ? ++$ii : splice(@lol, $ii+1, 1); |
| 1459 |
}; |
| 1460 |
|
| 1461 |
## now feed columns back to ifeffit |
| 1462 |
foreach my $c (0 .. $#cols) { |
| 1463 |
my @array; |
| 1464 |
map {push @array, $_->[$c+1]} @lol; |
| 1465 |
$setup->dispose("erase $group.$cols[$c]", $dmode); |
| 1466 |
Ifeffit::put_array("$group.$cols[$c]", \@array); |
| 1467 |
}; |
| 1468 |
$setup->dispose("## Athena reloaded arrays after sorting non-monotonic data\n", $dmode); |
| 1469 |
}; |
| 1470 |
}; |
| 1471 |
## for multi-element data fed to separate groups -- loop over |
| 1472 |
## channels. For all other data, this is a "loop" over a list 1 |
| 1473 |
## item long |
| 1474 |
my @channel_list = ($num); |
| 1475 |
if ($multi) { |
| 1476 |
(my $channels = $num) =~ s/[()]//g; |
| 1477 |
@channel_list = split(/\s*\+\s*/, $channels); |
| 1478 |
}; |
| 1479 |
foreach my $c (@channel_list) { |
| 1480 |
my $this_str = $str; |
| 1481 |
my $grp = $group; |
| 1482 |
if ($multi) { |
| 1483 |
my $suff = (split(/\./, $c))[1]; |
| 1484 |
($grp, $label) = group_name(basename($file) . "_" . $suff); |
| 1485 |
($this_str, my $num, my $den, my $i0) = make_xmu_string({$c => 1}, $rd, $ln, $inv, 0); |
| 1486 |
} |
| 1487 |
|
| 1488 |
++$line_count; |
| 1489 |
$i0 =~ s/[\(\)]//g; |
| 1490 |
$groups{$grp} = Ifeffit::Group -> new(group=>$grp, label=>$label, |
| 1491 |
is_rsp=>0, is_qsp=>0, line=>$line_count, |
| 1492 |
is_rec=>0, file=>$file, en_str=>$en, mu_str=>$this_str, |
| 1493 |
is_raw=>1, numerator=>$c, denominator=>$den, |
| 1494 |
i0=>$i0); |
| 1495 |
|
| 1496 |
$groups{$grp} -> dispose("\n## Importing a new file\n"); |
| 1497 |
if ($sort_available) { |
| 1498 |
if ($isnt_monotonic and (not $is_xmudat)) { |
| 1499 |
$groups{$grp} -> |
| 1500 |
dispose("## uncomment the following line in a macro to have ifeffit sort the data\n", $dmode); |
| 1501 |
$groups{$grp} -> |
| 1502 |
dispose("## read_data(file=\"$stash\", group=$grp, sort=$sort)\n", $dmode); |
| 1503 |
}; |
| 1504 |
}; |
| 1505 |
|
| 1506 |
if ($space =~ /[enx]/) { |
| 1507 |
$groups{$grp} -> make(is_xmu=>1, is_chi=>0, is_xmudat=>$is_xmudat); |
| 1508 |
($space =~ /[nx]/) and ($groups{$grp} -> make(is_nor=>1)); |
| 1509 |
if ($evkev eq 'ev') { |
| 1510 |
$groups{$grp} -> dispose("set $grp.energy = $en\n", $dmode); |
| 1511 |
} elsif ($evkev eq 'pixel') { |
| 1512 |
$groups{$grp} -> make(is_pixel=>1); |
| 1513 |
$groups{$grp} -> dispose("set $grp.energy = $en\n", $dmode); |
| 1514 |
} else { # keV |
| 1515 |
$groups{$grp} -> dispose("set $grp.energy = 1000*$en\n", $dmode); |
| 1516 |
}; |
| 1517 |
$rebin{do_rebin} and perform_rebinning($grp); |
| 1518 |
if (length($this_str) < 251) { |
| 1519 |
$groups{$grp} -> dispose("set $grp.xmu = $this_str\n", $dmode); |
| 1520 |
} else { |
| 1521 |
&long_string($grp, "$grp.xmu", $this_str); |
| 1522 |
}; |
| 1523 |
} elsif ($space =~ /[ck]/) { |
| 1524 |
$groups{$grp} -> make(is_xmu=>0, is_chi=>1); |
| 1525 |
$groups{$grp} -> dispose("set $grp.k = $en\n", $dmode); |
| 1526 |
$groups{$grp} -> dispose("set $grp.chi = $this_str\n", $dmode); |
| 1527 |
if (($space eq 'k') and (not Ifeffit::Files->uniform_k_grid($grp))) { |
| 1528 |
$setup->dispose("## this seems to be chi(k) data in need of fixing...\nfix_chik($grp)", |
| 1529 |
$dmode); |
| 1530 |
}; |
| 1531 |
} elsif ($space eq 'd') { |
| 1532 |
$groups{$grp} -> make(not_data=>1, is_xmu=>0, is_chi=>0, is_rsp=>0, is_qsp=>0); |
| 1533 |
if ($evkev eq 'ev') { |
| 1534 |
$groups{$grp} -> dispose("set $grp.energy = $en\n", $dmode); |
| 1535 |
} elsif ($evkev eq 'pixel') { |
| 1536 |
$groups{$grp} -> make(is_pixel=>1); |
| 1537 |
$groups{$grp} -> dispose("set $grp.energy = $en\n", $dmode); |
| 1538 |
} else { |
| 1539 |
$groups{$grp} -> dispose("set $grp.energy = 1000*$en\n", $dmode); |
| 1540 |
}; |
| 1541 |
$rebin{do_rebin} and perform_rebinning($grp); |
| 1542 |
if (length($this_str) < 251) { |
| 1543 |
$groups{$grp} -> dispose("set $grp.det = $this_str\n", $dmode); |
| 1544 |
} else { |
| 1545 |
&long_string($grp, "$grp.det", $this_str); |
| 1546 |
}; |
| 1547 |
} elsif ($space eq 'a') { |
| 1548 |
$groups{$grp} -> make(not_data=>0, is_xmu=>1, is_xanes=>1, |
| 1549 |
is_chi=>0, is_rsp=>0, is_qsp=>0, bkg_nnorm=>2); |
| 1550 |
if ($evkev eq 'ev') { |
| 1551 |
$groups{$grp} -> dispose("set $grp.energy = $en\n", $dmode); |
| 1552 |
} elsif ($evkev eq 'pixel') { |
| 1553 |
$groups{$grp} -> make(is_pixel=>1); |
| 1554 |
$groups{$grp} -> dispose("set $grp.energy = $en\n", $dmode); |
| 1555 |
} else { |
| 1556 |
$groups{$grp} -> dispose("set $grp.energy = 1000*$en\n", $dmode); |
| 1557 |
}; |
| 1558 |
$rebin{do_rebin} and perform_rebinning($grp); |
| 1559 |
if (length($this_str) < 251) { |
| 1560 |
$groups{$grp} -> dispose("set $grp.xmu = $this_str\n", $dmode); |
| 1561 |
} else { |
| 1562 |
&long_string($grp, "$grp.xmu", $this_str); |
| 1563 |
}; |
| 1564 |
}; |
| 1565 |
|
| 1566 |
set_defaults($grp, $space, $is_xmudat); |
| 1567 |
$preprocess{evkev} = $evkev; |
| 1568 |
$preprocess{ok} and perform_preprocessing($grp); |
| 1569 |
|
| 1570 |
fill_skinny($list, $grp, 1); |
| 1571 |
if ($$reference{numerator} or $$reference{denominator}) { |
| 1572 |
Echo("Importing reference channel for $label ..."); |
| 1573 |
my ($ref, $ref_label) = group_name(" Ref " . $label); |
| 1574 |
$groups{$grp} -> make(reference=>$ref); |
| 1575 |
++$line_count; |
| 1576 |
$$reference{numerator} ||= 1; |
| 1577 |
$$reference{denominator} ||= 1; |
| 1578 |
$this_str = join("/", $$reference{numerator}, $$reference{denominator}); |
| 1579 |
($this_str = "ln(abs($this_str))") if $$reference{ln}; |
| 1580 |
$this_str =~ s/[A-Za-z0-9_?]+(?=\.)/$grp/g; # same regex as above |
| 1581 |
$groups{$ref} = Ifeffit::Group -> new(group => $ref, |
| 1582 |
label => $ref_label, |
| 1583 |
is_xmu => 1, |
| 1584 |
is_chi => 0, |
| 1585 |
is_nor => 0, |
| 1586 |
is_rsp => 0, |
| 1587 |
is_qsp => 0, |
| 1588 |
is_rec => 0, |
| 1589 |
is_raw => 1, |
| 1590 |
en_str => $en, |
| 1591 |
mu_str => $this_str, |
| 1592 |
numerator => $$reference{numerator}, |
| 1593 |
denominator => $$reference{denominator}, |
| 1594 |
reference => $grp, |
| 1595 |
is_ref => 1, |
| 1596 |
bkg_eshift => $groups{$grp}->{bkg_eshift}); |
| 1597 |
$groups{$ref} -> make(bkg_eshift=>0) unless ($groups{$ref}->{bkg_eshift} =~ /-?(\d+\.?\d*|\.\d+)/); |
| 1598 |
$groups{$ref} -> make(line => $line_count, |
| 1599 |
file => "reference channel for " . $groups{$grp}->{label}); |
| 1600 |
$groups{$ref} -> set_to_another($groups{$grp}); |
| 1601 |
|
| 1602 |
if ($$reference{same}) { |
| 1603 |
$groups{$grp} -> make(refsame=>1); |
| 1604 |
$groups{$ref} -> make(bkg_z=>$groups{$grp}->{bkg_z}, |
| 1605 |
fft_edge=>$groups{$grp}->{fft_edge}, |
| 1606 |
refsame=>1, |
| 1607 |
); |
| 1608 |
}; |
| 1609 |
$groups{$ref} -> dispose("set $ref.energy = $grp.energy\n", $dmode); |
| 1610 |
$groups{$ref} -> dispose("set $ref.xmu = $this_str\n", $dmode); |
| 1611 |
$groups{$ref} -> dispose("pre_edge($ref.energy, $ref.xmu)\n", $dmode); |
| 1612 |
$groups{$ref} -> make(bkg_e0 => Ifeffit::get_scalar("e0"), |
| 1613 |
is_xanes => $groups{$grp}->{is_xanes}); |
| 1614 |
if (not $$reference{same}) { |
| 1615 |
$groups{$grp} -> make(refsame=>0); |
| 1616 |
my ($z, $edge) = find_edge($groups{$ref}->{bkg_e0}); |
| 1617 |
$groups{$ref} -> make(bkg_z=>$z, |
| 1618 |
fft_edge=>$edge, |
| 1619 |
refsame=>0, |
| 1620 |
); |
| 1621 |
}; |
| 1622 |
fill_skinny($list, $ref, 1); |
| 1623 |
Echo("Importing reference channel for $label ... done!"); |
| 1624 |
}; |
| 1625 |
clean_unused_columns($grp, $en, $num, $den); |
| 1626 |
|
| 1627 |
my $stan = $preprocess{standard}; |
| 1628 |
if ($preprocess{al_do} and ($stan !~ /None/) and exists($groups{$stan})) { |
| 1629 |
my $eshift; |
| 1630 |
if ($groups{$stan}->{reference} and $groups{$grp}->{reference}) { |
| 1631 |
$groups{$grp} -> dispose("## Aligning $groups{$grp}->{label} using reference", $dmode); |
| 1632 |
Echo("Aligning $groups{$grp}->{label} using reference"); |
| 1633 |
$eshift = auto_align($groups{$stan}->{reference}, $groups{$grp}->{reference}, 'd'); |
| 1634 |
} else { |
| 1635 |
$groups{$grp} -> dispose("## Aligning $groups{$grp}->{label} using data", $dmode); |
| 1636 |
Echo("Aligning $groups{$grp}->{label} using data", 0); |
| 1637 |
$eshift = auto_align($stan, $grp, 'd'); |
| 1638 |
}; |
| 1639 |
$groups{$grp} -> dispose("## need to re-get e0 after doing the preprocessing auto-alignment...\npre_edge(\"$grp.energy+$eshift\", $grp.xmu)\n", $dmode); |
| 1640 |
$groups{$grp} -> make(bkg_e0 => Ifeffit::get_scalar("e0")) unless $preprocess{par_do}; |
| 1641 |
$groups{$grp} -> make(bkg_eshift => $eshift); |
| 1642 |
my $ref = $groups{$grp}->{reference}; |
| 1643 |
if ($ref) { |
| 1644 |
$groups{$ref} -> make(bkg_eshift => $eshift); |
| 1645 |
$groups{$ref} -> dispose("pre_edge($ref.energy, $ref.xmu)\n", $dmode); |
| 1646 |
$groups{$ref} -> make(bkg_e0 => Ifeffit::get_scalar("e0")); |
| 1647 |
}; |
| 1648 |
push @{$preprocess{titles}}, "^^ alignment to $groups{$stan}->{label}"; |
| 1649 |
}; |
| 1650 |
|
| 1651 |
## marking proprocessing |
| 1652 |
Echo("Marking $groups{$grp}->{label}", 0); |
| 1653 |
($marked{$grp} = 1) if $preprocess{mark_do}; |
| 1654 |
|
| 1655 |
## capture title lines from the data file and from the extra import features |
| 1656 |
$groups{$grp} -> get_titles; |
| 1657 |
foreach (@{$rebin{titles}}) { |
| 1658 |
push @{$groups{$grp}->{titles}}, $_; |
| 1659 |
}; |
| 1660 |
foreach (@{$preprocess{titles}}) { |
| 1661 |
push @{$groups{$grp}->{titles}}, $_; |
| 1662 |
}; |
| 1663 |
push @{$groups{$grp}->{titles}}, "^^ Imported with reference channel" |
| 1664 |
if ($$reference{numerator} or $$reference{denominator}); |
| 1665 |
|
| 1666 |
my @titles = (); |
| 1667 |
foreach (@{$groups{$grp}->{titles}}) { |
| 1668 |
next if ($_ =~ /^\s*$/); |
| 1669 |
my $str = (length($_) > 254) ? substr($_, 0, 254) : $_; |
| 1670 |
my $count = 0; |
| 1671 |
foreach my $i (0..length($str)) { |
| 1672 |
++$count if (substr($str, $i, 1) eq '('); |
| 1673 |
--$count if ($count and (substr($str, $i, 1) eq ')')); |
| 1674 |
}; |
| 1675 |
## close all unmatched parens by appending close_parens to the string |
| 1676 |
$str .= ')' x $count; |
| 1677 |
## ! % and # in title lines seem to be a problem on Windows |
| 1678 |
$str =~ s/[!\%\#]//g; |
| 1679 |
push @titles, $str; |
| 1680 |
}; |
| 1681 |
$groups{$grp} -> make(titles=>\@titles); |
| 1682 |
$groups{$grp} -> put_titles; |
| 1683 |
|
| 1684 |
## and show some eye candy... |
| 1685 |
set_properties(1, $grp,0); |
| 1686 |
unless ($w == 0) { |
| 1687 |
&set_key_params; |
| 1688 |
SWITCH: { |
| 1689 |
$groups{$grp} -> plotE('em', $dmode,\%plot_features, \@indicator), last SWITCH if ($is_xmudat); |
| 1690 |
$groups{$grp} -> plotE('em', $dmode,\%plot_features, \@indicator), last SWITCH if ($space eq 'd'); |
| 1691 |
$groups{$grp} -> plotE('em', $dmode,\%plot_features, \@indicator), last SWITCH if ($space eq 'a'); |
| 1692 |
$groups{$grp} -> plotE('emz', $dmode,\%plot_features, \@indicator), last SWITCH if ($space eq 'e'); |
| 1693 |
$groups{$grp} -> plotE('emzn',$dmode,\%plot_features, \@indicator), last SWITCH if ($space eq 'n'); |
| 1694 |
$groups{$grp} -> plotk('k1', $dmode,\%plot_features, \@indicator), last SWITCH if ($space eq 'k'); |
| 1695 |
}; |
| 1696 |
$last_plot = $space; |
| 1697 |
($last_plot = 'e') if (($space eq 'a') or ($space eq 'n')); |
| 1698 |
$plotsel->raise($last_plot) unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 1699 |
my $pl_str = 'emz'; |
| 1700 |
if ($space =~ /k/) { |
| 1701 |
$pointfinder{space} -> configure(-text=>"The last plot was in k"); |
| 1702 |
} else { |
| 1703 |
$pointfinder{space} -> configure(-text=>"The last plot was in Energy"); |
| 1704 |
}; |
| 1705 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 1706 |
$pointfinder{$_} -> configure(-state=>'normal'); |
| 1707 |
}; |
| 1708 |
($space eq 'k') and ($pl_str = 'k1'); |
| 1709 |
($space eq 'n') and ($pl_str = 'emzn'); |
| 1710 |
($is_xmudat) and ($pl_str = 'em'); |
| 1711 |
$last_plot_params = [$grp, 'group', $space, $pl_str]; |
| 1712 |
## this seems to be necessary... |
| 1713 |
($is_xmudat) and $groups{$grp}->make(update_bkg=>1); |
| 1714 |
}; # end of plotting SWITCH |
| 1715 |
unless ($config{fft}{kmax}){ |
| 1716 |
$groups{$grp} -> dispose("___x = ceil($groups{$grp}->{group}.k)\n", 1); |
| 1717 |
$groups{$grp} -> make(fft_kmax=>Ifeffit::get_scalar("___x")); |
| 1718 |
$groups{$grp} -> kmax_suggest(\%plot_features); |
| 1719 |
}; |
| 1720 |
|
| 1721 |
}; # end of loop over data channels |
| 1722 |
($w == 0) or $w -> destroy(); # get rid of column palette |
| 1723 |
|
| 1724 |
$was_backwards and |
| 1725 |
Echo("Notice: Athena had to reverse the data in this file as it was in descending order"); |
| 1726 |
return 1; |
| 1727 |
}; |
| 1728 |
|
| 1729 |
## construct the string that tells ifeffit how to make mu(E) out of |
| 1730 |
## columns of data |
| 1731 |
sub make_xmu_string { |
| 1732 |
my ($rn, $rd, $ln, $inv, $en) = @_; |
| 1733 |
my $num = "("; # build the numerator string: |
| 1734 |
map {$$rn{$_} and ($num .= $_ . " + ")} (sort keys %$rn); |
| 1735 |
$num = substr($num, 0, -3) . ")"; |
| 1736 |
($num eq ')') and ($num = "1"); |
| 1737 |
my $str = $num; |
| 1738 |
my $den = "("; # build the denominator string: |
| 1739 |
map {$$rd{$_} and ($den .= $_ . " + ")} (sort keys %$rd); |
| 1740 |
$den = substr($den, 0, -3) . ")"; |
| 1741 |
($den eq ')') and ($den = ""); |
| 1742 |
($den) and $str .= " / " . $den; |
| 1743 |
($ln) and ($str = "ln(abs(" . $str . "))"); # transmission data |
| 1744 |
($inv) and ($str = "-1*" . $str); # invert |
| 1745 |
|
| 1746 |
## autoplot as columns are selected |
| 1747 |
if ($en and $config{general}{autoplot}) { |
| 1748 |
&set_key_params; |
| 1749 |
my $command = "\n## Autoplot in the file selection dialog:\n"; |
| 1750 |
$command .= "set t___oss.y = $str\n"; |
| 1751 |
$command .= "newplot(x=$en, y=t___oss.y, "; |
| 1752 |
$command .= "color=$config{plot}{c0}, title=\"current column selection\", xlabel=x, ylabel=y)\n"; |
| 1753 |
$command .= "erase \@group t___oss\n"; |
| 1754 |
$groups{"Default Parameters"}->dispose($command, $dmode); |
| 1755 |
}; |
| 1756 |
my $i0 = ($ln) ? $num : $den; |
| 1757 |
($i0 = "") unless $den; |
| 1758 |
|
| 1759 |
## return full string, numerator part, denominator part |
| 1760 |
return ($str, $num, $den, $i0); |
| 1761 |
}; |
| 1762 |
|
| 1763 |
|
| 1764 |
## deal with a very long string as the expression for setting a vector |
| 1765 |
## assume it is of the form (a + b + c + ...) / i0 |
| 1766 |
sub long_string { |
| 1767 |
my ($g, $xmu, $string) = @_; |
| 1768 |
my ($num, $den) = split(/\s*\/\s*/, $string); |
| 1769 |
$num =~ s/[()]//g; |
| 1770 |
my @channels = split(/\s*\+\s*/, $num); |
| 1771 |
$groups{$g} -> dispose("set ___npts = npts($g.energy)", $dmode); |
| 1772 |
$groups{$g} -> dispose("set $xmu = zeros(___npts)", $dmode); |
| 1773 |
foreach my $ch (@channels) { |
| 1774 |
$groups{$g} -> dispose("set $xmu = $xmu + $ch/$den", $dmode); |
| 1775 |
}; |
| 1776 |
}; |
| 1777 |
|
| 1778 |
sub clean_unused_columns { |
| 1779 |
my ($group, $en, $num, $den) = @_; |
| 1780 |
my @col_string = split(" ", &column_string); |
| 1781 |
my @words = split(/[() \t+]+/, $num); |
| 1782 |
push @words, split(/[() \t+]+/, $den); |
| 1783 |
if ($groups{$group}->{reference}) { |
| 1784 |
my $str = $groups{$groups{$group}->{reference}}->{numerator}; |
| 1785 |
push @words, split(/[() \t+]+/, $str); |
| 1786 |
$str = $groups{$groups{$group}->{reference}}->{denominator}; |
| 1787 |
push @words, split(/[() \t+]+/, $str); |
| 1788 |
}; |
| 1789 |
my @used = ((split(/\./,$en))[1]); # put energy suffix in the list |
| 1790 |
foreach my $w (@words) { # of used columns |
| 1791 |
next if ($w =~ /^\s*$/); |
| 1792 |
push @used, (split(/\./, $w))[1]; # put suffixes used in numerator |
| 1793 |
}; # and denominator in list |
| 1794 |
## see Perl Cookbook recipe 4.7 p. 104 |
| 1795 |
my %seen; # lookup table |
| 1796 |
my @csonly; # only in @col_string |
| 1797 |
@seen{@used} = (); # perl-y magic! |
| 1798 |
foreach my $i (@col_string) { |
| 1799 |
push(@csonly, $i) unless exists $seen{$i}; |
| 1800 |
}; |
| 1801 |
## print "col_string: ", join(" ", @col_string), $/; |
| 1802 |
## print "used: ", join(" ", @used), $/; |
| 1803 |
## print "unused: ", join(" ", @csonly), $/; |
| 1804 |
foreach my $suff (@csonly) { # erase the unused columns |
| 1805 |
$groups{$group} -> dispose("erase $group.$suff", $dmode); |
| 1806 |
}; |
| 1807 |
}; |
| 1808 |
|
| 1809 |
|
| 1810 |
## open a Toplevel with a palette for setting preprocessing |
| 1811 |
## parameters, including parameters for deglitching, truncating, |
| 1812 |
## interpolating, and aligning data sets as they are read in. A |
| 1813 |
## standard, i.e. a record already read in, must be chosen for all |
| 1814 |
## these actions. |
| 1815 |
sub set_preprocessing { |
| 1816 |
my $widg = $_[0]; |
| 1817 |
my $ppp = $$widg{pre_card}; |
| 1818 |
my $parent = $ppp -> Frame(-borderwidth=>0, -relief=>'flat'); |
| 1819 |
my $how_many = scalar(keys %groups); |
| 1820 |
|
| 1821 |
## set some variables |
| 1822 |
my $red = $config{colors}{single}; |
| 1823 |
my $blue= $config{colors}{activehighlightcolor}; |
| 1824 |
my $grey= '#9c9583'; |
| 1825 |
#my $pre = $top->Toplevel(-class=>'horae'); |
| 1826 |
#$pre -> title('Athena: preprocess data'); |
| 1827 |
my (%widgets, %labels, %grab); |
| 1828 |
|
| 1829 |
$parent -> Label(-text=>'Preprocessing parameters', |
| 1830 |
-font=>$config{fonts}{bold}, |
| 1831 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 1832 |
-> pack(-pady=>3); |
| 1833 |
## choose a standard |
| 1834 |
my $frame = $parent -> Frame(-relief=>'flat', -borderwidth=>0) |
| 1835 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 1836 |
|
| 1837 |
my $exists = 0; |
| 1838 |
foreach my $k (&sorted_group_list) { $exists = 1, last if ($k eq $preprocess{standard}); }; |
| 1839 |
$exists or (($preprocess{standard},$preprocess{standard_lab}) = ('None','0: None')); |
| 1840 |
$preprocess{ok} = ($preprocess{standard} eq 'None') ? 0 : 1; |
| 1841 |
my $initial_state = ($preprocess{standard} eq 'None') ? 'disabled' : 'normal'; |
| 1842 |
$frame -> Label(-text=>'Standard', -foreground=>$config{colors}{activehighlightcolor}) |
| 1843 |
-> pack(-side=>'left'); |
| 1844 |
|
| 1845 |
$preprocess{keys} = ['None', &sorted_group_list]; |
| 1846 |
$widgets{standard} = $frame -> BrowseEntry(-variable => \$preprocess{standard_lab}, |
| 1847 |
@browseentry_list, |
| 1848 |
-browsecmd => sub { |
| 1849 |
my $text = $_[1]; |
| 1850 |
my $this = $1 if ($text =~ /^(\d+):/); |
| 1851 |
#Echo("Failed to match in browsecmd. Yikes! Complain to Bruce."), return unless $this; |
| 1852 |
#$this -= 1; |
| 1853 |
$preprocess{standard} = $preprocess{keys}->[$this]; |
| 1854 |
#if ($this == 0) { # choose None |
| 1855 |
if ($preprocess{standard} eq 'None') { # choose None |
| 1856 |
foreach (keys %widgets) { |
| 1857 |
$preprocess{ok} = 0; |
| 1858 |
next if ($_ eq 'standard'); |
| 1859 |
next if ($_ =~ /^int/); |
| 1860 |
#next if ($_ eq 'deg_check'); |
| 1861 |
#next if ($_ eq 'trun_check'); |
| 1862 |
next if ($_ =~ /^(deg|mark|trun)/); |
| 1863 |
$widgets{$_}->configure(-state=>'disabled'); |
| 1864 |
($_ =~ /check$/) or |
| 1865 |
($widgets{$_}->configure(-foreground=>$grey)); |
| 1866 |
}; |
| 1867 |
foreach (keys %labels) { |
| 1868 |
next if ($_ =~ /^(deg|mark|trun)/); |
| 1869 |
$labels{$_}->configure(-foreground=>$grey); |
| 1870 |
}; |
| 1871 |
foreach (keys %grab) { |
| 1872 |
next if ($_ =~ /^(deg|trun)/); |
| 1873 |
$grab{$_}->configure(-state=>'disabled'); |
| 1874 |
}; |
| 1875 |
foreach (qw(deg_do trun_do int_do al_do par_do)) { |
| 1876 |
$preprocess{$_} = 0; |
| 1877 |
}; |
| 1878 |
} else { # choose a group |
| 1879 |
my $x = $preprocess{standard}; |
| 1880 |
$preprocess{ok} = 1; |
| 1881 |
$widgets{mark_check}-> configure(-state=>'normal'); |
| 1882 |
$widgets{deg_check} -> configure(-state=>'normal'); |
| 1883 |
$widgets{trun_check}-> configure(-state=>'normal'); |
| 1884 |
#$widgets{int_check}-> configure(-state=>'normal'); |
| 1885 |
$widgets{al_check} -> configure(-state=>'normal'); |
| 1886 |
$widgets{par_check} -> configure(-state=>'normal'); |
| 1887 |
$groups{$x}->dispose("___x = ceil($x.energy)\n", 1); |
| 1888 |
my $minE = $groups{$x}->{bkg_nor1}+$groups{$x}->{bkg_e0}; |
| 1889 |
my $maxE = Ifeffit::get_scalar("___x"); |
| 1890 |
my $toler = sprintf("%.4f", $groups{$x}->{bkg_step} * $config{deglitch}{margin}); |
| 1891 |
$preprocess{deg_emin} = $groups{$x}->{deg_emin} || $minE; |
| 1892 |
$preprocess{deg_emax} = $groups{$x}->{deg_emax} || $maxE+$config{deglitch}{emax}; |
| 1893 |
$preprocess{deg_tol} = ($groups{$x}->{deg_tol} > 0) ? $groups{$x}->{deg_tol} : $toler; |
| 1894 |
$preprocess{trun_e} = $maxE; |
| 1895 |
$preprocess{al_emin} = -50; |
| 1896 |
$preprocess{al_emax} = 150; |
| 1897 |
$groups{$x} -> make(deg_emin=>$minE, deg_emax=>$maxE, deg_tol=>$toler); |
| 1898 |
&set_key_params; |
| 1899 |
$groups{$x} -> plotE('emtg',$dmode); |
| 1900 |
$groups{$x} -> dispose("___x = floor($x.xmu)\n", 1); |
| 1901 |
$preprocess{ymin} = 0.95 * Ifeffit::get_scalar("___x"); |
| 1902 |
$groups{$x} -> dispose("___x = ceil($x.xmu)\n", 1); |
| 1903 |
$preprocess{ymax} = 1.05 * Ifeffit::get_scalar("___x"); |
| 1904 |
$groups{$x} -> plot_vertical_line($preprocess{trun_e}, $preprocess{ymin}, |
| 1905 |
$preprocess{ymax}, $dmode, "truncate", |
| 1906 |
$groups{$x}->{plot_yoffset}); |
| 1907 |
if ($preprocess{trun_do}) { |
| 1908 |
$widgets{"pp_trun_".$_} -> configure(-state=>'normal') foreach (qw(e beforeafter)); |
| 1909 |
$grab{pp_trun_e}->configure(-state=>'normal'); |
| 1910 |
$labels{trun_e}->configure(-foreground=>$blue); |
| 1911 |
$widgets{pp_trun_e}->configure(-foreground=>'black'); |
| 1912 |
}; |
| 1913 |
if ($preprocess{deg_do}) { |
| 1914 |
foreach (qw(deg_emin deg_emax deg_tol)) { |
| 1915 |
$labels{$_}->configure(-foreground=>$blue); |
| 1916 |
$widgets{$_}->configure(-state=>'normal', |
| 1917 |
-foreground=>'black'); |
| 1918 |
$grab{'pp_'.$_}->configure(-state=>'normal'); |
| 1919 |
}; |
| 1920 |
}; |
| 1921 |
}; |
| 1922 |
}) |
| 1923 |
-> pack(-side=>'right', -expand=>1, -fill=>'x', -padx=>1); |
| 1924 |
my $i = 1; |
| 1925 |
$widgets{standard} -> insert("end", "0: None"); |
| 1926 |
foreach my $s (&sorted_group_list) { |
| 1927 |
$widgets{standard} -> insert("end", "$i: $groups{$s}->{label}"); |
| 1928 |
++$i; |
| 1929 |
}; |
| 1930 |
|
| 1931 |
## $widgets{standard} = $frame -> Optionmenu(-textvariable => \$preprocess{standard_lab}, |
| 1932 |
## -borderwidth=>1, ) |
| 1933 |
## -> pack(-side=>'right', -expand=>1, -fill=>'x', -padx=>1); |
| 1934 |
## $widgets{standard} -> command(-label => 'None', |
| 1935 |
## -command=>sub{$preprocess{standard}='None'; |
| 1936 |
## $preprocess{standard_lab}='0: None'; |
| 1937 |
## foreach (keys %widgets) { |
| 1938 |
## $preprocess{ok} = 0; |
| 1939 |
## next if ($_ eq 'standard'); |
| 1940 |
## next if ($_ =~ /^int/); |
| 1941 |
## #next if ($_ eq 'deg_check'); |
| 1942 |
## #next if ($_ eq 'trun_check'); |
| 1943 |
## next if ($_ =~ /^(deg|trun)/); |
| 1944 |
## $widgets{$_}->configure(-state=>'disabled'); |
| 1945 |
## ($_ =~ /check$/) or |
| 1946 |
## ($widgets{$_}->configure(-foreground=>$grey)); }; |
| 1947 |
## foreach (keys %labels) { |
| 1948 |
## next if ($_ =~ /^(deg|trun)/); |
| 1949 |
## $labels{$_}->configure(-foreground=>$grey); }; |
| 1950 |
## foreach (keys %grab) { |
| 1951 |
## next if ($_ =~ /^(deg|trun)/); |
| 1952 |
## $grab{$_}->configure(-state=>'disabled'); }; |
| 1953 |
## foreach (qw(deg_do trun_do int_do al_do par_do)){ |
| 1954 |
## $preprocess{$_} = 0; }; |
| 1955 |
## }); |
| 1956 |
## foreach my $x (&sorted_group_list) { |
| 1957 |
## $widgets{standard} -> |
| 1958 |
## command(-label => $groups{$x}->{label}, |
| 1959 |
## -command=> |
| 1960 |
## sub{ # set preprocess parameters based on this group |
| 1961 |
## $preprocess{standard}=$x; |
| 1962 |
## $preprocess{standard_lab}=$groups{$x}->{label}; |
| 1963 |
## $preprocess{ok} = 1; |
| 1964 |
## $widgets{deg_check}->configure(-state=>'normal'); |
| 1965 |
## $widgets{trun_check}->configure(-state=>'normal'); |
| 1966 |
## #$widgets{int_check}->configure(-state=>'normal'); |
| 1967 |
## $widgets{al_check}->configure(-state=>'normal'); |
| 1968 |
## $widgets{par_check}->configure(-state=>'normal'); |
| 1969 |
## $groups{$x}->dispose("___x = ceil($x.energy)\n", 1); |
| 1970 |
## my $minE = $groups{$x}->{bkg_nor1}+$groups{$x}->{bkg_e0}; |
| 1971 |
## my $maxE = Ifeffit::get_scalar("___x"); |
| 1972 |
## my $toler = sprintf("%.4f", $groups{$x}->{bkg_step} * $config{deglitch}{margin}); |
| 1973 |
## $preprocess{deg_emin} = $groups{$x}->{deg_emin} || $minE; |
| 1974 |
## $preprocess{deg_emax} = $groups{$x}->{deg_emax} || $maxE+$config{deglitch}{emax}; |
| 1975 |
## $preprocess{deg_tol} = ($groups{$x}->{deg_tol} > 0) ? $groups{$x}->{deg_tol} : $toler; |
| 1976 |
## $preprocess{trun_e} = $maxE; |
| 1977 |
## $preprocess{al_emin} = -50; |
| 1978 |
## $preprocess{al_emax} = 150; |
| 1979 |
## $groups{$x} -> make(deg_emin=>$minE, deg_emax=>$maxE, deg_tol=>$toler); |
| 1980 |
## &set_key_params; |
| 1981 |
## $groups{$x} -> plotE('emtg',$dmode); |
| 1982 |
## $groups{$x} -> dispose("___x = floor($x.xmu)\n", 1); |
| 1983 |
## $preprocess{ymin} = 0.95 * Ifeffit::get_scalar("___x"); |
| 1984 |
## $groups{$x} -> dispose("___x = ceil($x.xmu)\n", 1); |
| 1985 |
## $preprocess{ymax} = 1.05 * Ifeffit::get_scalar("___x"); |
| 1986 |
## $groups{$x} -> plot_vertical_line($preprocess{trun_e}, $preprocess{ymin}, |
| 1987 |
## $preprocess{ymax}, $dmode, "truncate", |
| 1988 |
## $groups{$x}->{plot_yoffset}); |
| 1989 |
## if ($preprocess{trun_do}) { |
| 1990 |
## $widgets{"pp_trun_".$_} -> configure(-state=>'normal') foreach (qw(e beforeafter)); |
| 1991 |
## $grab{pp_trun_e}->configure(-state=>'normal'); |
| 1992 |
## $labels{trun_e}->configure(-foreground=>$blue); |
| 1993 |
## $widgets{pp_trun_e}->configure(-foreground=>'black'); |
| 1994 |
## }; |
| 1995 |
## if ($preprocess{deg_do}) { |
| 1996 |
## foreach (qw(deg_emin deg_emax deg_tol)) { |
| 1997 |
## $labels{$_}->configure(-foreground=>$blue); |
| 1998 |
## $widgets{$_}->configure(-state=>'normal', |
| 1999 |
## -foreground=>'black'); |
| 2000 |
## $grab{'pp_'.$_}->configure(-state=>'normal'); |
| 2001 |
## }; |
| 2002 |
## }; |
| 2003 |
## }); |
| 2004 |
## }; |
| 2005 |
|
| 2006 |
## mark? ===================================================== |
| 2007 |
my $outer = $parent -> Frame(-relief=>'groove', -borderwidth=>2) |
| 2008 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2009 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2010 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2011 |
$widgets{mark_check} = $frame -> Checkbutton(-text=>"Mark each data set when imported", |
| 2012 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 2013 |
-variable=>\$preprocess{mark_do}, |
| 2014 |
-selectcolor=>$red, |
| 2015 |
) |
| 2016 |
-> pack(-pady=>2, -side=>'left'); |
| 2017 |
|
| 2018 |
|
| 2019 |
## truncate? ================================================= |
| 2020 |
#=$preprocess{trun_do} = 0; |
| 2021 |
#=$preprocess{trun_e} = 0; |
| 2022 |
$outer = $parent -> Frame(-relief=>'groove', -borderwidth=>2) |
| 2023 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2024 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2025 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2026 |
$widgets{trun_check} = $frame -> Checkbutton(-text=>"Truncate each data set", |
| 2027 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 2028 |
-variable=>\$preprocess{trun_do}, |
| 2029 |
-selectcolor=>$red, |
| 2030 |
-command=>sub{ |
| 2031 |
$preprocess{ok} = 1; |
| 2032 |
my $stst = ($config{general}{autoplot}) ? 'normal' : 'disabled'; |
| 2033 |
my ($color, $text, $state, $button) = $preprocess{trun_do} ? |
| 2034 |
($blue, 'black', 'normal', $stst) : |
| 2035 |
($grey, $grey, 'disabled', 'disabled'); |
| 2036 |
$labels{trun_e}->configure(-foreground=>$color); |
| 2037 |
$widgets{pp_trun_e}->configure(-state=>$state, |
| 2038 |
-foreground=>$text); |
| 2039 |
$grab{pp_trun_e}->configure(-state=>$button); |
| 2040 |
$widgets{pp_trun_beforeafter}->configure(-state=>$state); |
| 2041 |
}) |
| 2042 |
-> pack(-pady=>2, -side=>'left'); |
| 2043 |
# truncate emax |
| 2044 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2045 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2046 |
$grab{pp_trun_e} = $frame -> Button(@pluck_button, @pluck, |
| 2047 |
-command=>sub{$last_plot ||= 'e'; |
| 2048 |
pluck('pp_trun_e'); |
| 2049 |
my $x = $preprocess{standard}; |
| 2050 |
return unless exists $groups{$x}; |
| 2051 |
$groups{$x} -> plotE('emtg',$dmode); |
| 2052 |
$groups{$x} -> plot_vertical_line($preprocess{trun_e}, $preprocess{ymin}, |
| 2053 |
$preprocess{ymax}, $dmode, "truncate", |
| 2054 |
$groups{$x}->{plot_yoffset}); |
| 2055 |
},) |
| 2056 |
-> pack(-side=>'right'); |
| 2057 |
$widgets{pp_trun_e} = $frame->Entry(-width => 8, |
| 2058 |
-textvariable => \$preprocess{trun_e}, |
| 2059 |
-foreground => $grey,) |
| 2060 |
-> pack(-side=>'right'); |
| 2061 |
$widgets{pp_trun_beforeafter} = $frame -> Optionmenu(-variable=>\$preprocess{trun_beforeafter}, |
| 2062 |
-textvariable=>\$preprocess{trun_beforeafter}, |
| 2063 |
-borderwidth=>1, |
| 2064 |
-options=>['before', 'after'],) |
| 2065 |
-> pack(-side=>'right'); |
| 2066 |
$labels{trun_e} = $frame -> Label(-text=>'Truncate ') |
| 2067 |
-> pack(-side=>'right'); |
| 2068 |
|
| 2069 |
## deglitch? =================================================== |
| 2070 |
#=$preprocess{deg_do} = 0; |
| 2071 |
#=$preprocess{deg_emin} = 0; |
| 2072 |
#=$preprocess{deg_emax} = 0; |
| 2073 |
#=$preprocess{deg_tol} = 0; |
| 2074 |
$outer = $parent -> Frame(-relief=>'groove', -borderwidth=>2) |
| 2075 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2076 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2077 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2078 |
$widgets{deg_check} = $frame -> Checkbutton(-text=>"Deglitch each data set", |
| 2079 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 2080 |
-variable=>\$preprocess{deg_do}, |
| 2081 |
-selectcolor=>$red, |
| 2082 |
-command=>sub{ |
| 2083 |
$preprocess{ok} = 1; |
| 2084 |
my $stst = ($config{general}{autoplot}) ? 'normal' : 'disabled'; |
| 2085 |
my ($color, $text, $state, $button) = $preprocess{deg_do} ? |
| 2086 |
($blue, 'black', 'normal', $stst) : |
| 2087 |
($grey, $grey, 'disabled', 'disabled'); |
| 2088 |
foreach (qw(deg_emin deg_emax deg_tol)) { |
| 2089 |
$labels{$_}->configure(-foreground=>$color); |
| 2090 |
$widgets{$_}->configure(-state=>$state, |
| 2091 |
-foreground=>$text); |
| 2092 |
next if ($_ eq 'deg_tol'); |
| 2093 |
$grab{'pp_'.$_}->configure(-state=>$button); |
| 2094 |
}; |
| 2095 |
}) |
| 2096 |
-> pack(-pady=>2, -side=>'left', -anchor=>'w'); |
| 2097 |
# deglitch emin |
| 2098 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2099 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2100 |
$grab{pp_deg_emin} = $frame -> Button(@pluck_button, @pluck, |
| 2101 |
-command=>sub{$last_plot ||= 'e'; |
| 2102 |
pluck('pp_deg_emin'); |
| 2103 |
my $x = $preprocess{standard}; |
| 2104 |
return unless $x; |
| 2105 |
$groups{$x} -> make(deg_emin=>$preprocess{deg_emin}); |
| 2106 |
$groups{$x} -> plotE('emtg',$dmode); |
| 2107 |
$groups{$x} -> plot_vertical_line($preprocess{trun_e}, $preprocess{ymin}, |
| 2108 |
$preprocess{ymax}, $dmode, "truncate", |
| 2109 |
$groups{$x}->{plot_yoffset}); |
| 2110 |
},) |
| 2111 |
-> pack(-side=>'right'); |
| 2112 |
$widgets{deg_emin} = $frame->Entry(-width=>8, -textvariable=>\$preprocess{deg_emin}, |
| 2113 |
-foreground=>$grey) |
| 2114 |
-> pack(-side=>'right'); |
| 2115 |
$labels{deg_emin} = $frame -> Label(-text=>'Emin') |
| 2116 |
-> pack(-side=>'right'); |
| 2117 |
# deglitch emax |
| 2118 |
#$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2119 |
# -> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2120 |
$frame -> Frame(-width=>5) |
| 2121 |
-> pack(-side=>'right'); |
| 2122 |
$grab{pp_deg_emax} = $frame -> Button(@pluck_button, @pluck, |
| 2123 |
-command=>sub{pluck('pp_deg_emax'); |
| 2124 |
my $x = $preprocess{standard}; |
| 2125 |
return unless $x; |
| 2126 |
$groups{$x} -> make(deg_emin=>$preprocess{deg_emax}); |
| 2127 |
$groups{$x} -> plotE('emtg',$dmode); |
| 2128 |
$groups{$x} -> plot_vertical_line($preprocess{trun_e}, $preprocess{ymin}, |
| 2129 |
$preprocess{ymax}, $dmode, "truncate", |
| 2130 |
$groups{$x}->{plot_yoffset}); |
| 2131 |
},) |
| 2132 |
-> pack(-side=>'right'); |
| 2133 |
$widgets{deg_emax} = $frame->Entry(-width=>8, -textvariable=>\$preprocess{deg_emax}, |
| 2134 |
-foreground=>$grey) |
| 2135 |
-> pack(-side=>'right'); |
| 2136 |
$labels{deg_emax} = $frame -> Label(-text=>'Emax') |
| 2137 |
-> pack(-side=>'right'); |
| 2138 |
# deglitch tolerance |
| 2139 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2140 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2141 |
$widgets{deg_tol} = $frame->Entry(-width=>8, -textvariable=>\$preprocess{deg_tol}, |
| 2142 |
-foreground=>$grey) |
| 2143 |
-> pack(-side=>'right'); |
| 2144 |
$labels{deg_tol} = $frame -> Label(-text=>'Tolerance') |
| 2145 |
-> pack(-side=>'right'); |
| 2146 |
|
| 2147 |
## interpolate? ================================================= |
| 2148 |
#=$preprocess{int_do} = 0; |
| 2149 |
## $outer = $parent -> Frame(-relief=>'groove', -borderwidth=>2) |
| 2150 |
## -> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2151 |
## $frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2152 |
## -> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2153 |
## $widgets{int_check} = $frame -> Checkbutton(-text=>"Interpolate to the standard", |
| 2154 |
## -foreground=>$config{colors}{activehighlightcolor}, |
| 2155 |
## -variable=>\$preprocess{int_do}, |
| 2156 |
## -selectcolor=>$red, |
| 2157 |
## -command=>sub{ |
| 2158 |
## my $state = ($preprocess{int_do}) ? |
| 2159 |
## 'normal' : 'disabled'; |
| 2160 |
## ##$widgets{al_check} -> configure(-state=>$state); |
| 2161 |
## }) |
| 2162 |
## -> pack(-pady=>2, -side=>'left'); |
| 2163 |
|
| 2164 |
## align? ================================================= |
| 2165 |
#=$preprocess{al_do} = 0; |
| 2166 |
$outer = $parent -> Frame(-relief=>'groove', -borderwidth=>2) |
| 2167 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2168 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2169 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2170 |
$widgets{al_check} = $frame -> Checkbutton(-text=>"Align to the standard", |
| 2171 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 2172 |
-variable=>\$preprocess{al_do}, |
| 2173 |
-selectcolor=>$red,) |
| 2174 |
#-command=>sub{ |
| 2175 |
#my ($color, $text, $state) = $preprocess{al_do} ? |
| 2176 |
# ($blue, 'black', 'normal') : |
| 2177 |
# ($grey, $grey, 'disabled'); |
| 2178 |
#foreach (qw(al_emin al_emax)) { |
| 2179 |
# $labels{$_}->configure(-foreground=>$color); |
| 2180 |
# $widgets{$_}->configure(-state=>$state, |
| 2181 |
# -foreground=>$color); |
| 2182 |
# $grab{'pp_'.$_}->configure(-state=>$state); |
| 2183 |
#}; |
| 2184 |
#}) |
| 2185 |
-> pack(-pady=>2, -side=>'left'); |
| 2186 |
# alignment emin |
| 2187 |
#$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2188 |
# -> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2189 |
#$grab{pp_al_emin} = $frame -> Button(@pluck_button, @pluck, |
| 2190 |
# -command=>sub{Echo("Preprocessing pluck not yet working")},) |
| 2191 |
# -> pack(-side=>'right'); |
| 2192 |
#$widgets{al_emin} = $frame->Entry(-width=>8, -textvariable=>\$preprocess{al_emin}, |
| 2193 |
# -foreground=>$grey) |
| 2194 |
# -> pack(-side=>'right'); |
| 2195 |
#$labels{al_emin} = $frame -> Label(-text=>'Emin') |
| 2196 |
# -> pack(-side=>'right'); |
| 2197 |
# alignment emax |
| 2198 |
#$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2199 |
# -> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2200 |
#$grab{pp_al_emax} = $frame -> Button(@pluck_button, @pluck, |
| 2201 |
# -command=>sub{Echo("Preprocessing pluck not yet working")},) |
| 2202 |
# -> pack(-side=>'right'); |
| 2203 |
#$widgets{al_emax} = $frame->Entry(-width=>8, -textvariable=>\$preprocess{al_emax}, |
| 2204 |
# -foreground=>$grey) |
| 2205 |
# -> pack(-side=>'right'); |
| 2206 |
#$labels{al_emax} = $frame -> Label(-text=>'Emax') |
| 2207 |
# -> pack(-side=>'right'); |
| 2208 |
|
| 2209 |
## params? =================================================== |
| 2210 |
#=$preprocess{par_do} = 0; |
| 2211 |
$outer = $parent -> Frame(-relief=>'groove', -borderwidth=>2) |
| 2212 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2213 |
$frame = $outer -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2214 |
-> pack(-side=>'top', -expand=>1, -fill=>'x'); |
| 2215 |
$widgets{par_check} = $frame -> Checkbutton(-text=>"Set parameters to the standard", |
| 2216 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 2217 |
-variable=>\$preprocess{par_do}, |
| 2218 |
-selectcolor=>$red, |
| 2219 |
) |
| 2220 |
-> pack(-pady=>2, -side=>'left'); |
| 2221 |
|
| 2222 |
|
| 2223 |
## buttons =================================================== |
| 2224 |
$frame = $parent -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2225 |
-> pack(-expand=>1, -fill=>'x'); |
| 2226 |
$frame -> Button(-text=>'Replot standard', -width=>5, @button_list, |
| 2227 |
-command=>sub{ |
| 2228 |
my $x = $preprocess{standard}; |
| 2229 |
$groups{$x} -> make(deg_emin=>$preprocess{deg_emin}, |
| 2230 |
deg_emax=>$preprocess{deg_emax}, |
| 2231 |
deg_tol =>$preprocess{deg_tol}); |
| 2232 |
&set_key_params; |
| 2233 |
$groups{$x} -> plotE('emtg',$dmode); |
| 2234 |
$groups{$x} -> plot_vertical_line($preprocess{trun_e}, $preprocess{ymin}, |
| 2235 |
$preprocess{ymax}, $dmode, "truncate", |
| 2236 |
$groups{$x}->{plot_yoffset}); |
| 2237 |
}) |
| 2238 |
-> pack(-expand=>1, -fill=>'x', -padx=>1, -pady=>2, -side=>'left'); |
| 2239 |
##$frame -> Button(-text=>'Dismiss extras', -width=>5, @button_list, |
| 2240 |
## -command => sub{remove_extras($widg)} ) |
| 2241 |
## -> pack(-expand=>1, -fill=>'x', -padx=>1, -pady=>2, -side=>'right'); |
| 2242 |
|
| 2243 |
## initial setup |
| 2244 |
my $notnone = $config{colors}{activehighlightcolor}; |
| 2245 |
foreach (qw(deg_emin deg_emax deg_tol)) { |
| 2246 |
my $active = (($preprocess{standard} ne 'None') and $preprocess{deg_do}); |
| 2247 |
$labels{$_}->configure(-foreground=> $active ? '#9c9583' : $notnone); |
| 2248 |
}; |
| 2249 |
foreach (qw(trun_e)) { |
| 2250 |
my $active = (($preprocess{standard} ne 'None') and $preprocess{trun_do}); |
| 2251 |
$labels{$_}->configure(-foreground=> $active ? '#9c9583' : $notnone); |
| 2252 |
}; |
| 2253 |
foreach (keys %widgets) { |
| 2254 |
next if ($_ eq 'standard'); # or ($_ =~ /(deg|trun)_check/)); |
| 2255 |
$widgets{$_}->configure(-state=>$initial_state); |
| 2256 |
}; |
| 2257 |
foreach (keys %grab) { |
| 2258 |
$grab{$_}->configure(-state=>$initial_state); |
| 2259 |
}; |
| 2260 |
$widgets{standard} -> configure(-state=>'disabled') if $how_many == 1; |
| 2261 |
map { $widgets{$_} -> configure(-state=>'normal') } (qw(mark_check trun_check deg_check)); |
| 2262 |
#$pre -> grab; |
| 2263 |
return $parent; |
| 2264 |
}; |
| 2265 |
|
| 2266 |
|
| 2267 |
## evkev for deglitching?? wait til someone complains |
| 2268 |
sub perform_preprocessing { |
| 2269 |
if ($preprocess{standard} eq 'None') { |
| 2270 |
return 0 unless ($preprocess{trun_do} or $preprocess{deg_do}); |
| 2271 |
}; |
| 2272 |
my $group = $_[0]; |
| 2273 |
my $stan = $preprocess{standard}; |
| 2274 |
my $eshift = 0; |
| 2275 |
$preprocess{titles} = ["^^ Preprocessing chores performed:"]; |
| 2276 |
Echo("Performing preprocessing chores on $groups{$group}->{label} ... "); |
| 2277 |
if ($preprocess{trun_do}) { |
| 2278 |
Echo("Truncating $groups{$group}->{label}", 0); |
| 2279 |
my $factor = ($preprocess{evkev} eq 'kev') ? 1000 : 1; |
| 2280 |
$groups{$group}->make(etruncate=>$preprocess{trun_e}*$factor); |
| 2281 |
push @{$preprocess{titles}}, "^^ truncation at $preprocess{trun_e}"; |
| 2282 |
truncate_data($group, 1, $preprocess{trun_beforeafter}, 'mu(E)'); |
| 2283 |
}; |
| 2284 |
if ($preprocess{deg_do}) { |
| 2285 |
Echo("Deglitching $groups{$group}->{label}", 0); |
| 2286 |
$groups{$group}->make(deg_emin=>$preprocess{deg_emin}, |
| 2287 |
deg_emax=>$preprocess{deg_emax}, |
| 2288 |
deg_tol =>$preprocess{deg_tol}); |
| 2289 |
$groups{$group}->dispatch_bkg($dmode); |
| 2290 |
my $cmd = sprintf("set %s.postline = %g+%g*%s.energy+%g*%s.energy**2\n", |
| 2291 |
$group, $groups{$group}->{bkg_nc0}, $groups{$group}->{bkg_nc1}, |
| 2292 |
$group, $groups{$group}->{bkg_nc2}, $group); |
| 2293 |
$groups{$group}->dispose($cmd, $dmode); |
| 2294 |
remove_glitches($group, 1); # remove em, but don't plot yet |
| 2295 |
push @{$preprocess{titles}}, "^^ deglitching with margins $preprocess{deg_emin}, $preprocess{deg_emax}, and $preprocess{deg_tol}"; |
| 2296 |
}; |
| 2297 |
if ($preprocess{int_do}) { |
| 2298 |
Echo("Interpolating $groups{$group}->{label}", 0); |
| 2299 |
$groups{$stan} -> interpolate($groups{$group}, 'e', $dmode); |
| 2300 |
push @{$preprocess{titles}}, "^^ interpolation onto grid of $groups{$stan}->{label}"; |
| 2301 |
}; |
| 2302 |
|
| 2303 |
## need to do alignment a bit later in case we want to align using |
| 2304 |
## the reference channels |
| 2305 |
|
| 2306 |
if ($preprocess{par_do}) { |
| 2307 |
Echo("Setting parameters for $groups{$group}->{label}", 0); |
| 2308 |
$groups{$group} -> set_to_another($groups{$stan}); |
| 2309 |
push @{$preprocess{titles}}, "^^ constraint of parameters to $groups{$stan}->{label}"; |
| 2310 |
}; |
| 2311 |
Echo("Finished with preprocessing!", 0); |
| 2312 |
}; |
| 2313 |
|
| 2314 |
|
| 2315 |
sub perform_rebinning { |
| 2316 |
return 0 unless $rebin{do_rebin}; |
| 2317 |
#Error("You forgot to specify an absorber for rebinning."), |
| 2318 |
return 0 if ($rebin{abs} =~ /^\s*$/); |
| 2319 |
#Error("\"$rebin{abs}\" is not a valid element symbol."), |
| 2320 |
return 0 unless (lc($rebin{abs}) =~ /^$Ifeffit::Files::elem_regex$/); |
| 2321 |
## make sure these are all defined |
| 2322 |
$rebin{emin} ||= $config{rebin}{emin}; |
| 2323 |
$rebin{emax} ||= $config{rebin}{emax}; |
| 2324 |
$rebin{pre} ||= $config{rebin}{pre}; |
| 2325 |
$rebin{xanes} ||= $config{rebin}{xanes}; |
| 2326 |
$rebin{exafs} ||= $config{rebin}{exafs}; |
| 2327 |
## these must be positive or bad stuff will happen |
| 2328 |
$rebin{pre} = abs($rebin{pre}); |
| 2329 |
$rebin{xanes} = abs($rebin{xanes}); |
| 2330 |
$rebin{exafs} = abs($rebin{exafs}); |
| 2331 |
## check if emin, emax out of order |
| 2332 |
(($rebin{emin}, $rebin{emax}) = ($rebin{emax}, $rebin{emin})) if |
| 2333 |
($rebin{emin} > $rebin{emax}); |
| 2334 |
|
| 2335 |
my $group = $_[0]; |
| 2336 |
|
| 2337 |
my @e = Ifeffit::get_array("$group.energy"); |
| 2338 |
my ($efirst, $elast) = ($e[0], $e[$#e]); |
| 2339 |
my ($ek, $el1, $el2, $el3) = (Xray::Absorption->get_energy($rebin{abs}, 'K'), |
| 2340 |
Xray::Absorption->get_energy($rebin{abs}, 'L1'), |
| 2341 |
Xray::Absorption->get_energy($rebin{abs}, 'L2'), |
| 2342 |
Xray::Absorption->get_energy($rebin{abs}, 'L3')); |
| 2343 |
my ($e0, $edge); |
| 2344 |
SWITCH: { |
| 2345 |
(($e0, $edge) = ($ek, 'K')), last SWITCH if (($ek > $efirst) and ($ek < $elast)); |
| 2346 |
(($e0, $edge) = ($el3, 'L3')), last SWITCH if (($el3 > $efirst) and ($el3 < $elast)); |
| 2347 |
(($e0, $edge) = ($el2, 'L2')), last SWITCH if (($el2 > $efirst) and ($el2 < $elast)); |
| 2348 |
(($e0, $edge) = ($el1, 'L1')), last SWITCH if (($el1 > $efirst) and ($el1 < $elast)); |
| 2349 |
Error("These data cannot be of absorber $rebin{abs}! No edge of that element lies within the energy range."), return; |
| 2350 |
}; |
| 2351 |
Echo("Rebinning data $groups{$group}->{label} ($rebin{abs} $edge-edge) ..."); |
| 2352 |
$groups{$group}->dispose("## Rebinning group $group:", $dmode); |
| 2353 |
my @bingrid; |
| 2354 |
my $ee = $efirst; |
| 2355 |
while ($ee < $rebin{emin}+$e0) { |
| 2356 |
push @bingrid, $ee; |
| 2357 |
$ee += $rebin{pre}; |
| 2358 |
}; |
| 2359 |
$ee = $rebin{emin}+$e0; |
| 2360 |
while ($ee < $rebin{emax}+$e0) { |
| 2361 |
push @bingrid, $ee; |
| 2362 |
$ee += $rebin{xanes}; |
| 2363 |
}; |
| 2364 |
$ee = $rebin{emax}+$e0; |
| 2365 |
my $kk = $groups{$group}->e2k($rebin{emax}); |
| 2366 |
while ($ee < $elast) { |
| 2367 |
push @bingrid, $ee; |
| 2368 |
$kk += $rebin{exafs}; |
| 2369 |
$ee = $e0 + $groups{$group}->k2e($kk); |
| 2370 |
}; |
| 2371 |
push @bingrid, $elast; |
| 2372 |
Ifeffit::put_array("$group.xxx", \@bingrid); |
| 2373 |
foreach my $y (split(" ", &column_string)) { |
| 2374 |
next if ($y eq 'energy'); |
| 2375 |
## also do not want to rebin, say, $g.1 if "1" is the energy column |
| 2376 |
$groups{$group}->dispose("set $group.rebin = rebin($group.energy, $group.$y, $group.xxx)", $dmode); |
| 2377 |
$groups{$group}->dispose("set $group.$y = $group.rebin", $dmode); |
| 2378 |
}; |
| 2379 |
$groups{$group}->dispose("set $group.energy = $group.xxx", $dmode); |
| 2380 |
$groups{$group}->dispose("erase $group.xxx $group.rebin", $dmode); |
| 2381 |
#$groups{$group}->dispose("erase $group.rebin", $dmode); |
| 2382 |
$rebin{titles} = |
| 2383 |
["^^ Rebinned data onto grid [$rebin{emin}:$rebin{emax}] with steps ($rebin{pre},$rebin{xanes},$rebin{exafs})"]; |
| 2384 |
|
| 2385 |
Echo("Rebinning data $groups{$group}->{label} ($rebin{abs} $edge-edge) ... done!"); |
| 2386 |
}; |
| 2387 |
|
| 2388 |
sub set_reference { |
| 2389 |
my $parent = $_[0] -> Frame(-borderwidth=>0, -relief=>'flat'); |
| 2390 |
my $group = $_[1]; |
| 2391 |
my $cols = $_[2]; |
| 2392 |
my $widg = $_[3]; |
| 2393 |
my $reference = $_[4]; |
| 2394 |
my $energy = $_[5]; |
| 2395 |
|
| 2396 |
## set some variables |
| 2397 |
my $red = $config{colors}{single}; |
| 2398 |
my $blue= $config{colors}{activehighlightcolor}; |
| 2399 |
my $grey= '#9c9583'; |
| 2400 |
|
| 2401 |
$parent -> Label(-text=>'Reference channel', |
| 2402 |
-font=>$config{fonts}{bold}, |
| 2403 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2404 |
-> pack(); |
| 2405 |
$parent -> Label(-text=>'The reference uses the same energy array as the data.', |
| 2406 |
-relief=>'groove', |
| 2407 |
) |
| 2408 |
-> pack(-ipadx=>2, -ipady=>2); |
| 2409 |
my $fr = $parent -> Scrolled('Pane', -relief=>'flat', -borderwidth=>2, |
| 2410 |
-gridded=>'xy', |
| 2411 |
-scrollbars=>'os', -sticky => 'ew',) |
| 2412 |
-> pack(-expand=>1, -fill=>'x'); |
| 2413 |
$fr->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}); |
| 2414 |
$fr -> Label(-text=>' ', -foreground=>$config{colors}{activehighlightcolor}) |
| 2415 |
-> grid(-row=>0, -column=>0, -sticky=>'e'); |
| 2416 |
$fr -> Label(-text=>'Numerator', -foreground=>$config{colors}{activehighlightcolor}) |
| 2417 |
-> grid(-row=>1, -column=>0, -sticky=>'e'); |
| 2418 |
$fr -> Label(-text=>'Denominator', -foreground=>$config{colors}{activehighlightcolor}) |
| 2419 |
-> grid(-row=>2, -column=>0, -sticky=>'e'); |
| 2420 |
my $j = 1; |
| 2421 |
foreach (@$cols) { |
| 2422 |
my $this = $group.".".$_; |
| 2423 |
#my $this = $_; |
| 2424 |
|
| 2425 |
$fr -> Label(-text=>$_) |
| 2426 |
-> grid(-row=>0, -column=>$j); |
| 2427 |
my $jj = $j; # need a counter that is scoped HERE |
| 2428 |
$fr -> Radiobutton(-variable=>\$$reference{numerator}, |
| 2429 |
-value=>$this, |
| 2430 |
-text=>"", |
| 2431 |
-selectcolor=>$red, |
| 2432 |
) |
| 2433 |
-> grid(-row=>1, -column=>$j,); |
| 2434 |
$fr -> Radiobutton(-variable=>\$$reference{denominator}, |
| 2435 |
-value=>$this, |
| 2436 |
-text=>"", |
| 2437 |
-selectcolor=>$red, |
| 2438 |
) |
| 2439 |
-> grid(-row=>2, -column=>$j,); |
| 2440 |
++$j; |
| 2441 |
}; |
| 2442 |
|
| 2443 |
$fr = $parent -> Frame() |
| 2444 |
-> pack(); |
| 2445 |
$fr -> Checkbutton(-text=>"Natural log", -variable=>\$$reference{ln}, -selectcolor=>$red,) |
| 2446 |
-> pack(-side=>'left', -fill=>'x', -anchor=>'w'); |
| 2447 |
$fr -> Checkbutton(-text=>"Same element", -variable=>\$$reference{same}, -selectcolor=>$red,) |
| 2448 |
-> pack(-side=>'left', -fill=>'x', -anchor=>'w', -padx=>2); |
| 2449 |
$fr -> Button(-text=>"Plot reference", |
| 2450 |
-borderwidth=>1, |
| 2451 |
-command=>sub{ |
| 2452 |
Echo("Not enough information to plot reference"), return unless |
| 2453 |
($$reference{numerator} or $$reference{denominator}); |
| 2454 |
my $str = "$$reference{numerator}/$$reference{denominator}"; |
| 2455 |
$str = "ln(abs( $str ))" if $$reference{ln}; |
| 2456 |
my $en = $$energy; |
| 2457 |
my $command = "\n## Plot reference in the file selection dialog:\n"; |
| 2458 |
$command .= "set t___oss.y = $str\n"; |
| 2459 |
$command .= "newplot(x=$en, y=t___oss.y, "; |
| 2460 |
$command .= "color=$config{plot}{c0}, title=\"current reference selection\", xlabel=x, ylabel=y)\n"; |
| 2461 |
$command .= "erase \@group t___oss\n"; |
| 2462 |
$groups{"Default Parameters"}->dispose($command, $dmode); |
| 2463 |
}, |
| 2464 |
) |
| 2465 |
-> pack(-side=>'left', -fill=>'x', -anchor=>'w', -padx=>2); |
| 2466 |
$fr = $parent -> Frame() |
| 2467 |
-> pack(-side=>'bottom', -anchor=>'w', -pady=>4); |
| 2468 |
$fr -> Button(-text=>'Clear reference channels', @button_list, |
| 2469 |
-command=>sub{$$reference{numerator} = 0; |
| 2470 |
$$reference{denominator} = 0; |
| 2471 |
$$reference{ln} = 1; |
| 2472 |
$$reference{same} = 1; |
| 2473 |
}) |
| 2474 |
-> pack(-side=>'left', -fill=>'x', -padx=>8, -anchor=>'e'); |
| 2475 |
##$fr -> Button(-text=>'Dismiss extras', @button_list, |
| 2476 |
## -command=>sub{remove_extras($widg)}) |
| 2477 |
## -> pack(-side=>'left', -fill=>'x', -padx=>8, -anchor=>'e'); |
| 2478 |
return $parent; |
| 2479 |
}; |
| 2480 |
|
| 2481 |
|
| 2482 |
sub set_bin { |
| 2483 |
my $widg = $_[0]; |
| 2484 |
my $ppp = $$widg{bin_card}; |
| 2485 |
my $parent = $ppp -> Frame(-borderwidth=>0, -relief=>'flat'); |
| 2486 |
|
| 2487 |
$parent -> Label(-text=>'Data rebinning', |
| 2488 |
-font=>$config{fonts}{bold}, |
| 2489 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2490 |
-> pack(); |
| 2491 |
$parent -> Checkbutton(-text=>"Perform rebinning", |
| 2492 |
-variable=>\$rebin{do_rebin}) |
| 2493 |
-> pack(-pady=>4); |
| 2494 |
|
| 2495 |
my $frame = $parent -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2496 |
-> pack(-expand=>1, -fill=>'x'); |
| 2497 |
$frame -> Label(-text=>'Absorber:', |
| 2498 |
-foreground=>$config{colors}{activehighlightcolor},) |
| 2499 |
-> grid(-row=>0, -column=>0, -sticky=>'e'); |
| 2500 |
$widget{rebin_abs} = $frame -> Entry(-width=>5, -textvariable=>\$rebin{abs}) |
| 2501 |
-> grid(-row=>0, -column=>1, -sticky=>'w', -padx=>2); |
| 2502 |
|
| 2503 |
$frame -> Label(-text=>'Edge region from:', |
| 2504 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2505 |
-> grid(-row=>1, -column=>0, -sticky=>'e'); |
| 2506 |
$frame -> Entry(-width=>5, -textvariable=>\$rebin{emin}, |
| 2507 |
-validate=>'key', |
| 2508 |
-validatecommand=>[\&set_variable, 'rebin']) |
| 2509 |
-> grid(-row=>1, -column=>1, -sticky=>'w', -padx=>2); |
| 2510 |
$frame -> Label(-text=>' to ', |
| 2511 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2512 |
-> grid(-row=>1, -column=>2); |
| 2513 |
$frame -> Entry(-width=>5, -textvariable=>\$rebin{emax}, |
| 2514 |
-validate=>'key', |
| 2515 |
-validatecommand=>[\&set_variable, 'rebin']) |
| 2516 |
-> grid(-row=>1, -column=>3, -sticky=>'w', -padx=>2); |
| 2517 |
$frame -> Label(-text=>'eV', |
| 2518 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2519 |
-> grid(-row=>1, -column=>4); |
| 2520 |
|
| 2521 |
$frame -> Label(-text=>'Pre edge grid:', |
| 2522 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2523 |
-> grid(-row=>2, -column=>0, -sticky=>'e'); |
| 2524 |
$frame -> Entry(-width=>5, -textvariable=>\$rebin{pre}, |
| 2525 |
-validate=>'key', |
| 2526 |
-validatecommand=>[\&set_variable, 'rebin']) |
| 2527 |
-> grid(-row=>2, -column=>1, -sticky=>'w', -padx=>2); |
| 2528 |
$frame -> Label(-text=>'eV', |
| 2529 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2530 |
-> grid(-row=>2, -column=>2, -sticky=>'w',); |
| 2531 |
|
| 2532 |
$frame -> Label(-text=>'XANES grid:', |
| 2533 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2534 |
-> grid(-row=>3, -column=>0, -sticky=>'e'); |
| 2535 |
$frame -> Entry(-width=>5, -textvariable=>\$rebin{xanes}, |
| 2536 |
-validate=>'key', |
| 2537 |
-validatecommand=>[\&set_variable, 'rebin']) |
| 2538 |
-> grid(-row=>3, -column=>1, -sticky=>'w', -padx=>2); |
| 2539 |
$frame -> Label(-text=>'eV', |
| 2540 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2541 |
-> grid(-row=>3, -column=>2, -sticky=>'w',); |
| 2542 |
|
| 2543 |
$frame -> Label(-text=>'EXAFS grid:', |
| 2544 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2545 |
-> grid(-row=>4, -column=>0, -sticky=>'e'); |
| 2546 |
$frame -> Entry(-width=>5, -textvariable=>\$rebin{exafs}, |
| 2547 |
-validate=>'key', |
| 2548 |
-validatecommand=>[\&set_variable, 'rebin']) |
| 2549 |
-> grid(-row=>4, -column=>1, -sticky=>'w', -padx=>2); |
| 2550 |
$frame -> Label(-text=>'invAng', |
| 2551 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 2552 |
-> grid(-row=>4, -column=>2, -sticky=>'w',); |
| 2553 |
|
| 2554 |
$frame = $parent -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2555 |
-> pack(-expand=>1, -fill=>'x', -pady=>4); |
| 2556 |
##$frame -> Button(-text=>'Dismiss extras', -width=>5, @button_list, |
| 2557 |
## -command => sub{remove_extras($widg)} ) |
| 2558 |
## -> pack(-expand=>1, -fill=>'x', -padx=>1, -pady=>2, -side=>'right'); |
| 2559 |
|
| 2560 |
return $parent; |
| 2561 |
}; |
| 2562 |
|
| 2563 |
## sub set_favorites { |
| 2564 |
## my $widg = $_[0]; |
| 2565 |
## my $ppp = $$widg{fav_card}; |
| 2566 |
## my $parent = $ppp -> Frame(-borderwidth=>0, -relief=>'flat'); |
| 2567 |
## |
| 2568 |
## $parent -> Label(-text=>'Favorite file types', |
| 2569 |
## -font=>$config{fonts}{bold}, |
| 2570 |
## -foreground=>$config{colors}{activehighlightcolor}) |
| 2571 |
## -> pack(); |
| 2572 |
## |
| 2573 |
## my $text = $parent -> ROText(-wrap=>'word', -width=>1, -height=>10, -relief=>'flat') |
| 2574 |
## -> pack(-expand=>1, -fill=>'both'); |
| 2575 |
## $text -> insert('end', "This space will contain an as-yet unimplemented, user-definable list of file types. Selecting one will serve as a short cut to setting the column checkboxes for the numerator and denominator, allowing you to quickly specify common column selections."); |
| 2576 |
## |
| 2577 |
## my $frame = $parent -> Frame(-relief=>'flat', -borderwidth=>0) |
| 2578 |
## -> pack(-expand=>1, -fill=>'x'); |
| 2579 |
## $frame -> Button(-text=>'Dismiss extras', -width=>5, @button_list, |
| 2580 |
## -command => sub{remove_extras($widg)} ) |
| 2581 |
## -> pack(-expand=>1, -fill=>'x', -padx=>1, -pady=>2, -side=>'right'); |
| 2582 |
## |
| 2583 |
## return $parent; |
| 2584 |
## }; |
| 2585 |
|
| 2586 |
|
| 2587 |
sub remove_extras { |
| 2588 |
my $widg = $_[0]; |
| 2589 |
$$widg{extras} -> packForget; |
| 2590 |
$top -> update; # needed so $raw resizes correctly |
| 2591 |
$$widg{extra_button} -> pack(-expand=>1, -fill=>'x', -pady=>0); |
| 2592 |
$$widg{right}->pack(-expand=>1, -fill=>'both', |
| 2593 |
-side=>'right', -anchor=>'n'); |
| 2594 |
$$widg{databox}->pack(-expand=>1, -fill=>'both', |
| 2595 |
-padx=>4, -pady=>2); |
| 2596 |
$$prior_args{extra_shown} = 0; |
| 2597 |
## removing this frame says that the user does not want to do any of these |
| 2598 |
## chores, so turn them all off |
| 2599 |
$preprocess{ok}=0; |
| 2600 |
} |
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
## save data in the selected space (a misnomer, since mu(E) can also |
| 2608 |
## be saved by this subroutine |
| 2609 |
sub save_chi { |
| 2610 |
Echo('No data!'), return unless ($current); |
| 2611 |
my ($space, $in_loop, $dir) = @_; |
| 2612 |
$space = lc($space); |
| 2613 |
Echo("You cannot save chi for the Default Parameters"), return 0 |
| 2614 |
if ($current eq "Default Parameters"); |
| 2615 |
$top -> Busy; |
| 2616 |
my $this = $in_loop || $current; |
| 2617 |
my ($suffix, $text) = ('chi', 'chi(k)'); |
| 2618 |
SWITCH: { |
| 2619 |
(($suffix, $text) = ('chi1', 'k*chi(k)')), last SWITCH if ($space eq 'k1'); |
| 2620 |
(($suffix, $text) = ('chi2', 'k^2*chi(k)')), last SWITCH if ($space eq 'k2'); |
| 2621 |
(($suffix, $text) = ('chi3', 'k^3*chi(k)')), last SWITCH if ($space eq 'k3'); |
| 2622 |
(($suffix, $text) = ('chie', 'chi(E)')), last SWITCH if ($space eq 'ke'); |
| 2623 |
(($suffix, $text) = ('xmu', 'mu(E)')), last SWITCH if ($space eq 'e'); |
| 2624 |
(($suffix, $text) = ('nor', 'normalized mu(E)')), last SWITCH if ($space eq 'n'); |
| 2625 |
(($suffix, $text) = ('der', 'derivative mu(E)')), last SWITCH if ($space eq 'd'); |
| 2626 |
(($suffix, $text) = ('bkg', 'bkg(E)')), last SWITCH if ($space eq 'b'); |
| 2627 |
(($suffix, $text) = ('rsp', 'chi(R)')), last SWITCH if ($space eq 'r'); |
| 2628 |
(($suffix, $text) = ('qsp', 'chi(q)')), last SWITCH if ($space eq 'q'); |
| 2629 |
}; |
| 2630 |
Echo("Saving $text data ...", 0); |
| 2631 |
#local $Tk::FBox::a; |
| 2632 |
#local $Tk::FBox::b; |
| 2633 |
my $path = $current_data_dir || Cwd::cwd; |
| 2634 |
my $types = [["EXAFS $text data", ".".$suffix], |
| 2635 |
['All + hidden', '*']]; |
| 2636 |
##(my $initial = join(".", $this, $suffix)) =~ s/\?/_/g; |
| 2637 |
my $initial = join(".", $groups{$this}->{label}, $suffix); |
| 2638 |
# spaces are common in filenames on Mac and Win, but not on un*x |
| 2639 |
($initial =~ s/\s+/_/g) unless ($is_windows or $is_darwin); |
| 2640 |
($initial =~ s/[\\:\/\*\?\'<>\|]/_/g);# if ($is_windows); |
| 2641 |
my $file = q{}; |
| 2642 |
if ($in_loop) { |
| 2643 |
$file = File::Spec->catfile($dir, $initial); |
| 2644 |
} else { |
| 2645 |
$file = $top -> getSaveFile(-defaultextension=>$suffix, |
| 2646 |
-filetypes=>$types, |
| 2647 |
#(not $is_windows) ? |
| 2648 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 2649 |
-initialdir=>$path, |
| 2650 |
-initialfile=>$initial, |
| 2651 |
-title => "Athena: Save $text data"); |
| 2652 |
}; |
| 2653 |
if ($file) { |
| 2654 |
## make sure I can write to $file |
| 2655 |
open F, ">".$file or do { |
| 2656 |
$top -> Unbusy; |
| 2657 |
Error("You cannot write to \"$file\"."); |
| 2658 |
return |
| 2659 |
}; |
| 2660 |
close F; |
| 2661 |
my ($name, $pth, $suffix) = fileparse($file); |
| 2662 |
$current_data_dir = $pth; |
| 2663 |
##&push_mru($file); |
| 2664 |
my $stdev = ""; |
| 2665 |
if ($groups{$this}->{is_merge} eq $space) { |
| 2666 |
$stdev = ", $this.stddev" |
| 2667 |
}; |
| 2668 |
refresh_titles($groups{$this}); # make sure titles are up-to-date |
| 2669 |
$groups{$this}->dispose("\$id_line = \"Athena data file -- Athena version $VERSION\""); |
| 2670 |
#$groups{$this}->dispose("\$id2_line = \"Saving $groups{$this}->{label} (group=$groups{$this}->{group}) as $text\""); |
| 2671 |
$groups{$this}->dispose("\$id2_line = \"Saving $groups{$this}->{label} as $text\""); |
| 2672 |
my $i = 0; |
| 2673 |
foreach my $l (split(/\n/, $groups{$this}->param_summary)) { |
| 2674 |
++$i; |
| 2675 |
$groups{$this}->dispose("\$param_line_$i = \"$l\""); |
| 2676 |
}; |
| 2677 |
|
| 2678 |
SWITCH: { # what about mu(E), mu0(E), pre(E), |
| 2679 |
# post(E), window(?) |
| 2680 |
(($space eq 'e') and ($groups{$this}->{not_data})) and do { |
| 2681 |
my $esh = $groups{$this}->{bkg_eshift}; |
| 2682 |
$groups{$this}->dispose("set $this.ee = $this.energy+$esh", $dmode); |
| 2683 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.ee, $this.det)\n", $dmode); |
| 2684 |
$groups{$this}->dispose("erase $this.ee", $dmode); |
| 2685 |
last SWITCH; |
| 2686 |
}; |
| 2687 |
($space eq 'e') and do { |
| 2688 |
$groups{$this}->dispatch_bkg($dmode); |
| 2689 |
my $suff = ($groups{$this}->{bkg_cl}) ? "f2" : "bkg"; |
| 2690 |
my $esh = $groups{$this}->{bkg_eshift}; |
| 2691 |
my $i0 = ($groups{$this}->{i0}) ? ", $this.i0" : ""; |
| 2692 |
$groups{$this}->dispose("set $this.ee = $this.energy+$esh", $dmode); |
| 2693 |
$groups{$this}->dispose("set $this.der = deriv($this.xmu)/deriv($this.energy)", $dmode); |
| 2694 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.ee, $this.xmu, $this.$suff, $this.der $stdev$i0, $this.preline, $this.postline)\n", $dmode); |
| 2695 |
$groups{$this}->dispose("erase $this.ee $this.der", $dmode); |
| 2696 |
last SWITCH; |
| 2697 |
}; |
| 2698 |
($space eq 'n') and do { |
| 2699 |
##($groups{$this}->{update_bkg}) and |
| 2700 |
$groups{$this}->dispatch_bkg($dmode); |
| 2701 |
my $suff = "f2norm"; |
| 2702 |
my $esh = $groups{$this}->{bkg_eshift}; |
| 2703 |
my $i0 = ($groups{$this}->{i0}) ? ", $this.i0" : ""; |
| 2704 |
unless ($groups{$this}->{bkg_cl}) { |
| 2705 |
$groups{$this}->dispose("$this.bkg_norm=($this.bkg-$this.preline)/$groups{$this}->{bkg_step}", $dmode); |
| 2706 |
$suff = "bkg_norm"; |
| 2707 |
}; |
| 2708 |
$groups{$this}->dispose("set $this.der_norm = deriv($this.norm)/deriv($this.energy)", $dmode); |
| 2709 |
$groups{$this}->dispose("set $this.ee = $this.energy+$esh", $dmode); |
| 2710 |
if ($groups{$this}->{bkg_flatten}) { |
| 2711 |
my $label = "energy norm"; |
| 2712 |
$label .= " bkg_norm" if (not $groups{$this}->{is_xanes}); |
| 2713 |
$label .= " der_norm"; |
| 2714 |
$label .= " stddev" if $groups{$this}->{is_merge}; |
| 2715 |
$label .= " i0" if $groups{$this}->{i0}; |
| 2716 |
my $fbkg = ($groups{$this}->{is_xanes}) ? "" : ", $this.fbkg"; |
| 2717 |
$groups{$this}->dispose("write_data(file=\"$file\", label=\"$label\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.ee, $this.flat $fbkg, $this.der_norm $stdev $i0)\n", $dmode); |
| 2718 |
} else { |
| 2719 |
my $fbkg = ($groups{$this}->{is_xanes}) ? "" : ", $this.$suff"; |
| 2720 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.ee, $this.norm $fbkg, $this.der_norm $stdev $i0)\n", $dmode); |
| 2721 |
}; |
| 2722 |
$groups{$this}->dispose("erase $this.ee", $dmode); |
| 2723 |
($groups{$this}->{bkg_cl}) or |
| 2724 |
$groups{$this}->dispose("erase $this.bkg_norm $this.der_norm", $dmode); |
| 2725 |
last SWITCH; |
| 2726 |
}; |
| 2727 |
($space eq 'd') and do { |
| 2728 |
my $esh = $groups{$this}->{bkg_eshift}; |
| 2729 |
$groups{$this}->dispatch_bkg($dmode); |
| 2730 |
$groups{$this}->dispose("set $this.ee = $this.energy+$esh", $dmode); |
| 2731 |
$groups{$this}->dispose("set $this.deriv = deriv($this.xmu)/deriv($this.energy)", $dmode); |
| 2732 |
my $i0 = ($groups{$this}->{i0}) ? ", $this.i0" : ""; |
| 2733 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.ee, $this.deriv $i0)\n", $dmode); |
| 2734 |
$groups{$this}->dispose("erase $this.ee $this.deriv", $dmode); |
| 2735 |
last SWITCH; |
| 2736 |
}; |
| 2737 |
($space eq 'b') and do { |
| 2738 |
my $suff = ($groups{$this}->{bkg_cl}) ? "f2norm" : "bkg"; |
| 2739 |
my $esh = $groups{$this}->{bkg_eshift}; |
| 2740 |
($groups{$this}->{update_bkg}) and $groups{$this}->dispatch_bkg($dmode); |
| 2741 |
$groups{$this}->dispose("set $this.ee = $this.energy+$esh", $dmode); |
| 2742 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.ee, $this.$suff)\n", $dmode); |
| 2743 |
$groups{$this}->dispose("erase $this.ee", $dmode); |
| 2744 |
last SWITCH; |
| 2745 |
}; |
| 2746 |
($space eq 'k') and do { |
| 2747 |
($groups{$this}->{update_bkg}) and $groups{$this}->dispatch_bkg($dmode); |
| 2748 |
($groups{$this}->{update_fft}) and $groups{$this}->do_fft($dmode, \%plot_features); |
| 2749 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.k, $this.chi $stdev, $this.win)\n", $dmode); |
| 2750 |
last SWITCH; |
| 2751 |
}; |
| 2752 |
($space =~ /k(\d)/) and do { # k-weighted chi(k) output (note stddev not to scale) |
| 2753 |
my $kw = $1; |
| 2754 |
($groups{$this}->{update_bkg}) and $groups{$this}->dispatch_bkg($dmode); |
| 2755 |
($groups{$this}->{update_fft}) and $groups{$this}->do_fft($dmode, \%plot_features); |
| 2756 |
$groups{$this}->dispose("set $this.chik = $this.chi * $this.k**$kw", $dmode); |
| 2757 |
ifeffit("set ___x = ceil($this.chik)"); # scale window to plot |
| 2758 |
my $scale = 1.05 * Ifeffit::get_scalar("___x"); |
| 2759 |
$groups{$this}->dispose("set $this.winout = $scale*$this.win"); |
| 2760 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.k, $this.chik $stdev, $this.winout)\n", $dmode); |
| 2761 |
$groups{$this}->dispose("erase $this.chik $this.winout", $dmode); |
| 2762 |
last SWITCH; |
| 2763 |
}; |
| 2764 |
($space eq 'r') and do { |
| 2765 |
($groups{$this}->{update_bkg}) and $groups{$this}->dispatch_bkg($dmode); |
| 2766 |
($groups{$this}->{update_fft}) and $groups{$this}->do_fft($dmode, \%plot_features); |
| 2767 |
($groups{$this}->{update_bft}) and $groups{$this}->do_bft($dmode); |
| 2768 |
ifeffit("set ___x = ceil($this.chir_mag)"); # scale window to plot |
| 2769 |
my $scale = 1.05 * Ifeffit::get_scalar("___x"); |
| 2770 |
$groups{$this}->dispose("set $this.winout = $scale*$this.rwin"); |
| 2771 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*,\n $this.r, $this.chir_re, $this.chir_im, $this.chir_mag, $this.chir_pha, $this.winout)\n", $dmode); |
| 2772 |
$groups{$this}->dispose("erase $this.winout", $dmode); |
| 2773 |
last SWITCH; |
| 2774 |
}; |
| 2775 |
($space eq 'ke') and do { |
| 2776 |
($groups{$this}->{update_bkg}) and $groups{$this}->dispatch_bkg($dmode); |
| 2777 |
my $e0 = $groups{$this}->{bkg_e0}; |
| 2778 |
my $command = "$this.eee = $this.k^2/etok+$e0$/\n"; |
| 2779 |
$command .= "write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.eee, $this.chi)\n"; |
| 2780 |
$groups{$this}->dispose($command, $dmode); |
| 2781 |
last SWITCH; |
| 2782 |
}; |
| 2783 |
($space eq 'q') and do { |
| 2784 |
($groups{$this}->{update_bkg}) and $groups{$this}->dispatch_bkg($dmode); |
| 2785 |
($groups{$this}->{update_fft}) and $groups{$this}->do_fft($dmode, \%plot_features); |
| 2786 |
($groups{$this}->{update_bft}) and $groups{$this}->do_bft($dmode); |
| 2787 |
$groups{$this}->dispose("write_data(file=\"$file\", \$id_line, \$id2_line, \$param_line_\*, \$${this}_title_\*, $this.q, $this.chiq_re, $this.chiq_im, $this.chiq_mag, $this.chiq_pha)\n", $dmode); |
| 2788 |
last SWITCH; |
| 2789 |
}; |
| 2790 |
}; |
| 2791 |
Echo("Saving $text data to $file ... done", 0); |
| 2792 |
my $memory_ok = $groups{$this}->memory_check($top, \&Echo, \%groups, $max_heap, 0, 0); |
| 2793 |
Echo ("WARNING: Ifeffit is out of memory!") if ($memory_ok == -1); |
| 2794 |
} else { |
| 2795 |
Echo("Saving $text data ... canceled", 0); |
| 2796 |
}; |
| 2797 |
$top -> Unbusy; |
| 2798 |
return $text; |
| 2799 |
}; |
| 2800 |
|
| 2801 |
|
| 2802 |
sub save_marked { |
| 2803 |
my $m = 0; |
| 2804 |
map {$m += $_} values %marked; |
| 2805 |
Error("Saving file aborted. There are no marked groups."), return 1 unless ($m); |
| 2806 |
my $maxcol = Ifeffit::get_scalar('&max_output_cols') || 16; |
| 2807 |
--$maxcol; |
| 2808 |
Error("You cannot save more than $maxcol groups to a single file."), return if ($m>$maxcol); |
| 2809 |
my $sp = $_[0]; |
| 2810 |
##local $Tk::FBox::a; |
| 2811 |
##local $Tk::FBox::b; |
| 2812 |
|
| 2813 |
my ($x, $y, $mess) = ('','',''); |
| 2814 |
SWITCH: { |
| 2815 |
($x, $y, $mess) = ('energy','xmu', "mu(E)"), last SWITCH if ($sp eq 'e'); |
| 2816 |
($x, $y, $mess) = ('energy','norm', "normalized mu(E)"), last SWITCH if ($sp eq 'n'); |
| 2817 |
($x, $y, $mess) = ('energy','deriv', "derivative mu(E)"), last SWITCH if ($sp eq 'd'); |
| 2818 |
($x, $y, $mess) = ('energy','nderiv', "derivative norm(E)"), last SWITCH if ($sp eq 'nd'); |
| 2819 |
($x, $y, $mess) = ('k','chi', "chi(k)"), last SWITCH if ($sp eq 'k'); |
| 2820 |
($x, $y, $mess) = ('k','chi1', "k*chi(k)"), last SWITCH if ($sp eq 'k1'); |
| 2821 |
($x, $y, $mess) = ('k','chi2', "k^2*chi(k)"), last SWITCH if ($sp eq 'k2'); |
| 2822 |
($x, $y, $mess) = ('k','chi3', "k^3*chi(k)"), last SWITCH if ($sp eq 'k3'); |
| 2823 |
($x, $y, $mess) = ('energy','chi', "chi(E)"), last SWITCH if ($sp eq 'ke'); |
| 2824 |
($x, $y, $mess) = ('r','chir_mag', "the magnitude of chi(R)"), last SWITCH if ($sp eq 'rm'); |
| 2825 |
($x, $y, $mess) = ('r','chir_re', "the real part of chi(R)"), last SWITCH if ($sp eq 'rr'); |
| 2826 |
($x, $y, $mess) = ('r','chir_im', "the imaginary part of chi(R)"), last SWITCH if ($sp eq 'ri'); |
| 2827 |
($x, $y, $mess) = ('q','chiq_mag', "the magnitude of chi(q)"), last SWITCH if ($sp eq 'qm'); |
| 2828 |
($x, $y, $mess) = ('q','chiq_re', "the real part of chi(q)"), last SWITCH if ($sp eq 'qr'); |
| 2829 |
($x, $y, $mess) = ('q','chiq_im', "the imaginary part of chi(q)"), last SWITCH if ($sp eq 'qi'); |
| 2830 |
}; |
| 2831 |
my $types = [['All Files', '*'],[$x, '.'.$y]]; |
| 2832 |
my $path = $current_data_dir || Cwd::cwd; |
| 2833 |
my $file = $top -> getSaveFile(-filetypes=>$types, |
| 2834 |
#(not $is_windows) ? |
| 2835 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 2836 |
-initialdir=>$path, |
| 2837 |
-initialfile=>"marked.".$y, |
| 2838 |
-title => "Athena: Save marked groups as $mess"); |
| 2839 |
return unless $file; |
| 2840 |
## make sure I can write to $file |
| 2841 |
open F, ">".$file or do { |
| 2842 |
Error("You cannot write to \"$file\"."); return |
| 2843 |
}; |
| 2844 |
close F; |
| 2845 |
my ($name, $pth, $suffix) = fileparse($file); |
| 2846 |
$current_data_dir = $pth; |
| 2847 |
#&push_mru($file); |
| 2848 |
Echo("Saving $mess for each marked group ..."); |
| 2849 |
$top -> Busy; |
| 2850 |
|
| 2851 |
$groups{$current} -> dispose("\n## saving marked groups as columns in a file", $dmode); |
| 2852 |
my @list = (&sorted_group_list); |
| 2853 |
## determine first marked group so we can use its energy array |
| 2854 |
my $first; |
| 2855 |
foreach (@list) { |
| 2856 |
($first = $_), last if $marked{$_}; |
| 2857 |
}; |
| 2858 |
my ($label, $alt_label) = ($x, $x); |
| 2859 |
my $command = "file=\"$file\", \$marked_title_\*, "; |
| 2860 |
$groups{$current}->dispose("\$marked_title_1 = \"Athena multicolumn data file -- Athena version $VERSION\""); |
| 2861 |
my $erase = "erase \$marked_title_1\n"; |
| 2862 |
$groups{$current}->dispose("\$marked_title_2 = \"This file contains $mess from:\""); |
| 2863 |
$erase .= "erase \$marked_title_2\n"; |
| 2864 |
if ($x eq "energy") { |
| 2865 |
$groups{$first}->dispose("set $first.ee = $first.energy+$groups{$first}->{bkg_eshift}", $dmode); |
| 2866 |
$command .= "$first.ee"; |
| 2867 |
$erase .= "erase $first.ee\n"; |
| 2868 |
} else { |
| 2869 |
$command .= "$first.$x"; |
| 2870 |
}; |
| 2871 |
my $ncol = 0; |
| 2872 |
my $stan; |
| 2873 |
foreach my $g (@list) { |
| 2874 |
next unless $marked{$g}; |
| 2875 |
next if (($x ne 'energy') and ($groups{$g}->{not_data})); |
| 2876 |
next if (($x eq 'energy') and (($groups{$g}->{is_chi}) or ($groups{$g}->{is_rsp}) or |
| 2877 |
($groups{$g}->{is_qsp}))); |
| 2878 |
next if (($x eq 'k') and (($groups{$g}->{is_rsp}) or ($groups{$g}->{is_qsp}))); |
| 2879 |
next if (($x eq 'r') and ($groups{$g}->{is_qsp})); |
| 2880 |
## bring up to date if needed |
| 2881 |
$groups{$g}->dispatch_bkg($dmode) if $groups{$g}->{update_bkg}; |
| 2882 |
$groups{$g}->do_fft($dmode, \%plot_features) if (($x =~ /^[qr]$/) and $groups{$g}->{update_fft}); |
| 2883 |
$groups{$g}->do_bft($dmode) if (($x eq 'q') and $groups{$g}->{update_bft}); |
| 2884 |
## column label |
| 2885 |
(my $this_lab = $groups{$g}->{label}) =~ s/[^A-Za-z0-9_&:?@~]+/_/g; |
| 2886 |
$label .= " $this_lab"; |
| 2887 |
## interpolate if energy and not the first column |
| 2888 |
my $yy = $y; |
| 2889 |
($ncol) or ($stan = $g); |
| 2890 |
if (($ncol) and ($y eq 'deriv')) { |
| 2891 |
my ($e0stan, $e0g) = ($groups{$stan}->{bkg_eshift},$groups{$g}->{bkg_eshift}); |
| 2892 |
$yy = sprintf "deriv_%s", $ncol+1; |
| 2893 |
$groups{$g}->dispose("set $g.$yy = deriv($g.xmu)/deriv($g.energy)", $dmode); |
| 2894 |
$groups{$g}->dispose("set $g.$yy = qinterp($g.energy+$e0g, $g.$yy, $stan.energy+$e0stan)", |
| 2895 |
$dmode); |
| 2896 |
$erase .= "erase $g.$yy\n"; |
| 2897 |
} elsif ($y eq 'nderiv') { |
| 2898 |
my ($e0stan, $e0g) = ($groups{$stan}->{bkg_eshift},$groups{$g}->{bkg_eshift}); |
| 2899 |
$yy = sprintf "nderiv_%s", $ncol+1; |
| 2900 |
$groups{$g}->dispose("set $g.$yy = deriv($g.norm)/deriv($g.energy)", $dmode); |
| 2901 |
$groups{$g}->dispose("set $g.$yy = qinterp($g.energy+$e0g, $g.$yy, $stan.energy+$e0stan)", |
| 2902 |
$dmode); |
| 2903 |
$erase .= "erase $g.$yy\n"; |
| 2904 |
} elsif (($ncol) and ($x eq 'energy')) { |
| 2905 |
my ($e0stan, $e0g) = ($groups{$stan}->{bkg_eshift},$groups{$g}->{bkg_eshift}); |
| 2906 |
$yy = sprintf "%s_%s", $y, $ncol+1; |
| 2907 |
if (($y eq 'norm') and $groups{$g}->{bkg_flatten}) { |
| 2908 |
$groups{$g}->dispose("set $g.$yy = qinterp($g.energy+$e0g, $g.flat, $stan.energy+$e0stan)", |
| 2909 |
$dmode); |
| 2910 |
} else { |
| 2911 |
$groups{$g}->dispose("set $g.$yy = qinterp($g.energy+$e0g, $g.$y, $stan.energy+$e0stan)", |
| 2912 |
$dmode); |
| 2913 |
}; |
| 2914 |
$erase .= "erase $g.yy\n"; |
| 2915 |
} elsif ($y =~ /chi(\d)/) { |
| 2916 |
$yy = sprintf "%s_%s", $y, $ncol+1; |
| 2917 |
my $kw = $1; |
| 2918 |
$groups{$g}->dispose("set $g.$yy = $g.chi * $g.k**$kw", $dmode); |
| 2919 |
$erase .= "erase $g.$yy\n"; |
| 2920 |
} else { |
| 2921 |
$yy = sprintf "%s_%s", $y, $ncol+1; |
| 2922 |
if ($y eq 'deriv') { |
| 2923 |
$groups{$g}->dispose("set $g.$yy = deriv($g.xmu)/deriv($g.energy)", $dmode); |
| 2924 |
} elsif (($y eq 'norm') and ($groups{$g}->{bkg_flatten})) { |
| 2925 |
$groups{$g}->dispose("set $g.$yy = $g.flat", $dmode); |
| 2926 |
} else { |
| 2927 |
$groups{$g}->dispose("set $g.$yy = $g.$y", $dmode); |
| 2928 |
}; |
| 2929 |
$erase .= "erase $g.$yy\n"; |
| 2930 |
}; |
| 2931 |
$command .= ", $g.$yy"; |
| 2932 |
++$ncol; |
| 2933 |
$alt_label .= " $ncol"; |
| 2934 |
my $nmess = $ncol+1; |
| 2935 |
my $ntit = $ncol+2; |
| 2936 |
$groups{$g}->dispose("\$marked_title_$ntit = \"$groups{$g}->{label} (column $nmess)\""); |
| 2937 |
$erase .= "erase \$marked_title_$ntit\n" |
| 2938 |
}; |
| 2939 |
$Text::Wrap::huge = 'overflow'; |
| 2940 |
## extremely long column label strings can lead to weirdness as the ifeffit |
| 2941 |
## string gets written past the end. if it's too long, use he alt_label, |
| 2942 |
## which is boring and non-descriptive, but safe |
| 2943 |
if (length($label) < 255) { |
| 2944 |
$command .= ", label=\"$label\""; |
| 2945 |
} else { |
| 2946 |
$command .= ", label=\"$alt_label\""; |
| 2947 |
}; |
| 2948 |
$command = wrap("write_data(", " ", $command.")"); |
| 2949 |
##$command .= ",\n label=\"$label\")"; |
| 2950 |
$groups{$current} -> dispose($command, $dmode); |
| 2951 |
$groups{$current} -> dispose($erase, $dmode); # clean up the mess |
| 2952 |
$top -> Unbusy; |
| 2953 |
Echo("Saving $mess for each marked group ... done!"); |
| 2954 |
}; |
| 2955 |
|
| 2956 |
sub save_each { |
| 2957 |
my ($sp) = @_; |
| 2958 |
my $m = 0; |
| 2959 |
map {$m += $_} values %marked; |
| 2960 |
Error("Saving files aborted. There are no marked groups."), return 1 unless ($m); |
| 2961 |
|
| 2962 |
my $d = $top->DialogBox(-title => "Artemis: Save each marked group to a directory", |
| 2963 |
-buttons => ["Select", "Cancel"], |
| 2964 |
##-popover => 'cursor' |
| 2965 |
); |
| 2966 |
|
| 2967 |
my $curr_dir = $current_data_dir; |
| 2968 |
my $label = $d -> add('Label', -textvariable=>\$curr_dir) |
| 2969 |
-> pack(-fill => "x", -expand => 1); |
| 2970 |
my $fr = $d -> add('Frame') -> pack(-fill => "both", -expand => 1); |
| 2971 |
## ----> need a create new directory button <---- |
| 2972 |
my $dt = $fr->Scrolled('DirTree', |
| 2973 |
-scrollbars => 'osoe', |
| 2974 |
-width => 55, |
| 2975 |
-height => 20, |
| 2976 |
-selectmode => 'browse', |
| 2977 |
-exportselection => 1, |
| 2978 |
-directory => $current_data_dir, |
| 2979 |
-browsecmd => sub { $curr_dir = shift }, |
| 2980 |
|
| 2981 |
# With this version of -command a double-click will |
| 2982 |
# select the directory |
| 2983 |
##-command => sub { $ok = 1 }, |
| 2984 |
|
| 2985 |
# With this version of -command a double-click will |
| 2986 |
# open a directory. Selection is only possible with |
| 2987 |
# the Ok button. |
| 2988 |
#-command => sub { $d->opencmd($_[0]) }, |
| 2989 |
) |
| 2990 |
->pack(-fill => "both", -expand => 1); |
| 2991 |
my $this = $d -> Show(); |
| 2992 |
Echo("Not saving each marked file"), return if ($this eq 'Cancel'); |
| 2993 |
|
| 2994 |
my $text = q{}; |
| 2995 |
my @list = (&sorted_group_list); |
| 2996 |
foreach my $g (@list) { |
| 2997 |
next if not $marked{$g}; |
| 2998 |
Echonow("Saving $groups{$g}->{label} in \"$curr_dir\" ..."); |
| 2999 |
$text = save_chi($sp, $g, $curr_dir); |
| 3000 |
}; |
| 3001 |
Echo("Saved $text data to \"$curr_dir\" ..."); |
| 3002 |
}; |
| 3003 |
|
| 3004 |
|
| 3005 |
sub set_defaults { |
| 3006 |
my ($group, $space, $is_xmudat) = @_; |
| 3007 |
SWITCH:{ |
| 3008 |
($space =~ /[aenx]/) and do { |
| 3009 |
## set e0, kmax, Emax values |
| 3010 |
if ($is_xmudat) { # for an xmu.dat file use computed e0 |
| 3011 |
my @x = Ifeffit::get_array("$group.energy"); |
| 3012 |
my $omega = $x[0]; |
| 3013 |
@x = Ifeffit::get_array("$group.e_wrt0"); |
| 3014 |
$omega -= $x[0]; |
| 3015 |
$omega += $is_xmudat; |
| 3016 |
##print "omega = $omega\n"; |
| 3017 |
$groups{$group} -> make(bkg_e0=>$omega, bkg_spl1=>0, update_bkg=>1, |
| 3018 |
bkg_flatten=>1, bkg_fixstep=>1, bkg_step=>1.0); |
| 3019 |
} else { # else look for max first deriv |
| 3020 |
$groups{$group} -> |
| 3021 |
dispose("## need to get e0 to set defaults...\npre_edge(\"$group.energy+$groups{$group}->{bkg_eshift}\", $group.xmu)\n", $dmode); |
| 3022 |
my $e0 = Ifeffit::get_scalar("e0"); |
| 3023 |
unless ($e0) { # deal with situation where pre_edge |
| 3024 |
$groups{$group} -> # fails to return an e0 value |
| 3025 |
dispose("## failed to find e0 with the pre_edge command, take max of derivative", |
| 3026 |
$dmode); |
| 3027 |
my $sets = "set($group.derv = deriv($group.xmu)/deriv($group.energy),\n"; |
| 3028 |
$sets .= " i___i = ceil($group.derv),\n"; |
| 3029 |
$sets .= " i___i = nofx($group.derv, i___i))\n"; |
| 3030 |
$groups{$group} -> dispose($sets, $dmode); |
| 3031 |
$e0 = Ifeffit::get_scalar("i___i"); |
| 3032 |
if ($e0 < 5) { |
| 3033 |
$e0 = 15; |
| 3034 |
$groups{$group} -> dispose("## max of derivative was very close to the beginning of the data, e0 set to 15th data point", $dmode); |
| 3035 |
}; |
| 3036 |
my @array = Ifeffit::get_array("$group.energy"); |
| 3037 |
$e0 = $array[$e0-1]; |
| 3038 |
$groups{$group} -> dispose("erase i___i $group.derv", $dmode); |
| 3039 |
}; |
| 3040 |
$groups{$group} -> make(bkg_e0=>$e0); |
| 3041 |
}; |
| 3042 |
|
| 3043 |
## set defaults of the various range parameters |
| 3044 |
my ($pre1, $pre2, $nor1, $nor2, $spl1, $spl2, $kmin, $kmax) = |
| 3045 |
set_range_params($group); |
| 3046 |
$groups{$group} -> make( |
| 3047 |
bkg_pre1 => $pre1, |
| 3048 |
bkg_pre2 => $pre2, |
| 3049 |
bkg_nor1 => $nor1, |
| 3050 |
bkg_nor2 => $nor2, |
| 3051 |
bkg_spl1 => $spl1, |
| 3052 |
bkg_spl2 => $spl2, |
| 3053 |
bkg_spl1e => $groups{$group}->k2e($spl1), |
| 3054 |
bkg_spl2e => $groups{$group}->k2e($spl2), |
| 3055 |
fft_kmin => $kmin, |
| 3056 |
fft_kmax => $kmax, |
| 3057 |
update_bkg => 1, |
| 3058 |
); |
| 3059 |
if ($groups{$group}->{is_xmudat}) { |
| 3060 |
$groups{$group}->make(bkg_nor2=>$groups{$group}->{bkg_spl2e}); |
| 3061 |
}; |
| 3062 |
if ($groups{$group}->{fft_kmax} == 999) { |
| 3063 |
if ($groups{$group}->{is_xanes}) { |
| 3064 |
$groups{$group}->make(fft_kmax=>$groups{$group}->e2k($config{xanes}{cutoff})); |
| 3065 |
} else { |
| 3066 |
$groups{$group} -> kmax_suggest(\%plot_features); |
| 3067 |
## if ($groups{$group}->{fft_kmax} < EPSI) { |
| 3068 |
## $groups{$group} -> dispose("set ___x = ceil($group.k)\n", 1); |
| 3069 |
## $groups{$group} -> make(fft_kmax=>Ifeffit::get_scalar("___x")); |
| 3070 |
## }; |
| 3071 |
}; |
| 3072 |
}; |
| 3073 |
last SWITCH; |
| 3074 |
}; |
| 3075 |
($space eq 'd') and do { |
| 3076 |
my @en = Ifeffit::get_array("$group.energy"); |
| 3077 |
$groups{$group} -> make(bkg_e0=>$en[0]-$plot_features{emin}); |
| 3078 |
last SWITCH; |
| 3079 |
}; |
| 3080 |
($space eq 'k') and do { |
| 3081 |
$groups{$group}->dispose("___x = ceil($group.k)\n", 1); |
| 3082 |
my $maxk = Ifeffit::get_scalar("___x"); |
| 3083 |
## need to set fft_kmax correctly |
| 3084 |
$groups{$group} -> make(fft_kmax=>$maxk, update_bkg=>0, fft_pc=>'off'); |
| 3085 |
last SWITCH; |
| 3086 |
}; |
| 3087 |
}; |
| 3088 |
}; |
| 3089 |
|
| 3090 |
|
| 3091 |
sub set_range_params { |
| 3092 |
my $group = $_[0]; |
| 3093 |
## PRE1 |
| 3094 |
my @en = Ifeffit::get_array("$group.energy"); |
| 3095 |
my $firstE = ($en[1] - $groups{$group}->{bkg_e0}); |
| 3096 |
my $secondE = ($en[2] - $groups{$group}->{bkg_e0}); |
| 3097 |
#my $pre1 = $groups{$group}->{bkg_pre1}; |
| 3098 |
my $pre1 = $groups{$group}->Default('bkg_pre1') || $config{bkg}{pre1}; |
| 3099 |
($pre1 *= 1000) if (($pre1 > -1) and ($pre1 < 1)); |
| 3100 |
PRE1: { |
| 3101 |
($pre1 = $firstE+$pre1), last PRE1 if ($pre1 > 0); |
| 3102 |
($pre1 = $secondE), last PRE1 if ($pre1 == 0); |
| 3103 |
($pre1 = $secondE), last PRE1 if ($pre1 < $secondE); |
| 3104 |
}; |
| 3105 |
|
| 3106 |
## PRE2 |
| 3107 |
#my $pre2 = $groups{$group}->{bkg_pre2}; |
| 3108 |
my $pre2 = $groups{$group}->Default('bkg_pre2') || $config{bkg}{pre2}; |
| 3109 |
($pre2 *= 1000) if (($pre2 > -1) and ($pre2 < 1)); |
| 3110 |
PRE2: { |
| 3111 |
($pre2 = $firstE+$pre2), last PRE2 if ($pre2 > 0); |
| 3112 |
($pre2 = $secondE/2), last PRE2 if ($pre2 < $secondE); |
| 3113 |
}; |
| 3114 |
(($pre1,$pre2) = ($pre2,$pre1)) if ($pre1 > $pre2); |
| 3115 |
#($pre2 = ($pre1>30) ? $pre1+30 : $pre1/2) if ($pre1 < $pre2); |
| 3116 |
|
| 3117 |
## NOR1 |
| 3118 |
my $lastE = ($en[$#en] - $groups{$group}->{bkg_e0}); |
| 3119 |
#my $nor1 = $groups{$group}->{bkg_nor1}; |
| 3120 |
my $nor1 = $groups{$group}->Default('bkg_nor1') || $config{bkg}{nor1}; |
| 3121 |
($nor1 *= 1000) if (($nor1 > 0) and ($nor1 < 5)); |
| 3122 |
NOR1: { |
| 3123 |
if ($groups{$group}->{is_xanes}) { |
| 3124 |
$nor1 = $config{xanes}{nor1}; |
| 3125 |
($nor1 += $lastE) if ($nor1 < 0); |
| 3126 |
last NOR1; |
| 3127 |
}; |
| 3128 |
($nor1 = $lastE/5), last NOR1 if ($nor1 > $lastE); |
| 3129 |
($nor1 = $lastE+$nor1), last NOR1 if ($nor1 < 0); |
| 3130 |
}; |
| 3131 |
|
| 3132 |
## NOR2 |
| 3133 |
my $nor2 = $groups{$group}->Default('bkg_nor2') || $groups{$group}->{bkg_nor2}; |
| 3134 |
($nor2 *= 1000) if (($nor2 > -5) and ($nor2 < 5)); |
| 3135 |
NOR2: { |
| 3136 |
if ($groups{$group}->{is_xanes}) { |
| 3137 |
$nor2 = $config{xanes}{nor2}; |
| 3138 |
if ($nor2 < 0) { $nor2 += $lastE } |
| 3139 |
elsif ($nor2 == 0) { $nor2 = $lastE } |
| 3140 |
elsif ($nor2 > $lastE) { $nor2 = $lastE }; |
| 3141 |
last NOR2; |
| 3142 |
}; |
| 3143 |
($nor2 = $lastE), last NOR2 if ($nor2 > $lastE); |
| 3144 |
($nor2 = $lastE), last NOR2 if ($nor2 == 0); |
| 3145 |
($nor2 = $lastE+$nor2), last NOR2 if ($nor2 < 0); |
| 3146 |
}; |
| 3147 |
($nor1 > $nor2) and (($nor1, $nor2) = ($nor2, $nor1)); |
| 3148 |
|
| 3149 |
## SPL1 |
| 3150 |
my $lastk = $groups{$group}->e2k($lastE); |
| 3151 |
my $spl1 = $groups{$group}->Default('bkg_spl1') || $groups{$group}->{bkg_spl1}; |
| 3152 |
SPL1: { |
| 3153 |
($spl1 = 0.5), last SPL1 if ($groups{$group}->{is_xanes}); |
| 3154 |
($spl1 = 0.5), last SPL1 if ($spl1 > $lastk); |
| 3155 |
($spl1 = $lastk+$spl1), last SPL1 if ($spl1 < 0); |
| 3156 |
}; |
| 3157 |
|
| 3158 |
## SPL2 |
| 3159 |
my $spl2 = $groups{$group}->Default('bkg_spl2') || $groups{$group}->{bkg_spl2}; |
| 3160 |
SPL2: { |
| 3161 |
($spl2 = $lastk), last SPL2 if ($groups{$group}->{is_xanes}); |
| 3162 |
($spl2 = $lastk), last SPL2 if ($spl2 > $lastk); |
| 3163 |
($spl2 = $lastk), last SPL2 if ($spl2 == 0); |
| 3164 |
($spl2 = $lastk+$spl2), last SPL2 if ($spl2 < 0); |
| 3165 |
}; |
| 3166 |
($spl1 > $spl2) and (($spl1, $spl2) = ($spl1, $lastk)); |
| 3167 |
|
| 3168 |
## FFT_KMIN |
| 3169 |
my $kmin = $groups{$group}->Default('fft_kmin') || $groups{$group}->{fft_kmin}; |
| 3170 |
KMIN: { |
| 3171 |
($kmin = 2), last KMIN if ($groups{$group}->{is_xanes}); |
| 3172 |
($kmin = 2), last KMIN if ($kmin > $lastk); |
| 3173 |
($kmin = $lastk+$kmin), last KMIN if ($kmin < 0); |
| 3174 |
}; |
| 3175 |
|
| 3176 |
## FFT_KMAX |
| 3177 |
my $kmax = $groups{$group}->Default('fft_kmax') || $groups{$group}->{fft_kmax}; |
| 3178 |
KMAX: { |
| 3179 |
($kmax = $lastk), last KMAX if ($groups{$group}->{is_xanes}); |
| 3180 |
($kmax = 999), last KMAX if (not $kmax); |
| 3181 |
($kmax = $lastk), last KMAX if ($kmax > $lastk); |
| 3182 |
($kmax = $lastk+$kmax), last KMAX if ($kmax < 0); |
| 3183 |
}; |
| 3184 |
#($kmax = $lastk) if ($kmax < EPSI); |
| 3185 |
($kmin > $kmax) and (($kmin, $kmax) = ($kmax, $kmin)); |
| 3186 |
##print "in set_range: $group $kmax\n"; |
| 3187 |
|
| 3188 |
($pre2 = $pre1+5) if ($pre2 < $pre1); |
| 3189 |
($nor2 = $nor1+50) if ($nor2 < $nor1); |
| 3190 |
($spl2 = $spl1+50) if ($spl2 < $spl1); |
| 3191 |
($kmax = $kmin+5) if ($kmax < $kmin); |
| 3192 |
return ($pre1, $pre2, $nor1, $nor2, $spl1, $spl2, $kmin, $kmax); |
| 3193 |
}; |
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
## first arg is 1 when this is called from the Help menu, 0 otherwise |
| 3198 |
## second arg is 1 if called after reading a file, 0 otherwise |
| 3199 |
sub memory_check { |
| 3200 |
my ($just_checking, $reading_file) = @_; |
| 3201 |
Echo ("Cannot check memory with this version of Ifeffit"), return 0 if ($max_heap == -1); |
| 3202 |
my $free = Ifeffit::get_scalar("\&heap_free"); |
| 3203 |
my $used = $max_heap - $free; |
| 3204 |
my $ngr = keys %groups; |
| 3205 |
--$ngr; |
| 3206 |
Echo("You have not used any memory yet."), return 0 unless $ngr; |
| 3207 |
my $per = ($ngr) ? $used / $ngr : 0; |
| 3208 |
my $more = ($ngr) ? int($free / $per) : 0; |
| 3209 |
$per = int($per/1024); |
| 3210 |
$free = int($free/1024); |
| 3211 |
$used = int($used/1024); |
| 3212 |
my $net = int($max_heap / 1024); |
| 3213 |
my $report = "\n\nNumber of groups: $ngr |
| 3214 |
Memory used per group: $per kB |
| 3215 |
Memory space used: $used kB |
| 3216 |
Memory space free: $free kB |
| 3217 |
Total memory space: $net kB |
| 3218 |
Approximate number of groups available: $more |
| 3219 |
"; |
| 3220 |
if ($just_checking) { |
| 3221 |
my $message = "Ifeffit's current memory usage:$report"; |
| 3222 |
my $dialog = |
| 3223 |
$top -> Dialog(-bitmap => 'info', |
| 3224 |
-text => $message, |
| 3225 |
-title => 'Athena: memory check', |
| 3226 |
-buttons => ['OK'], |
| 3227 |
-default_button => 'OK'); |
| 3228 |
my $response = $dialog->Show(); |
| 3229 |
return 0; |
| 3230 |
} elsif ($more < 2) { |
| 3231 |
my $message = "Ifeffit is nearly out of memory space!!! |
| 3232 |
Athena will not read more data until you |
| 3233 |
delete some groups.\n\n$report"; |
| 3234 |
my $dialog = |
| 3235 |
$top -> Dialog(-bitmap => 'error', |
| 3236 |
-text => $message, |
| 3237 |
-title => 'Athena: Out of memory space', |
| 3238 |
-buttons => ['OK'], |
| 3239 |
-default_button => 'OK'); |
| 3240 |
my $response = $dialog->Show(); |
| 3241 |
return -1; |
| 3242 |
} elsif (($more < 5) and $reading_file) { |
| 3243 |
my $message = "You are running out of Ifeffit memory space!!! |
| 3244 |
Reading this data group is probably ok, but you |
| 3245 |
need to delete some groups before reading |
| 3246 |
more data.\n\n$report"; |
| 3247 |
my $dialog = |
| 3248 |
$top -> Dialog(-bitmap => 'warning', |
| 3249 |
-text => $message, |
| 3250 |
-title => 'Athena: memory space running low', |
| 3251 |
-buttons => ['OK'], |
| 3252 |
-default_button => 'OK'); |
| 3253 |
my $response = $dialog->Show(); |
| 3254 |
return 1; |
| 3255 |
} elsif (($more < 10) and (not $reading_file)) { |
| 3256 |
my $message = "You are running out of Ifeffit memory space!!! |
| 3257 |
You should probably delete some groups to |
| 3258 |
free up space before continuing with any |
| 3259 |
operation.\n\n$report"; |
| 3260 |
my $dialog = |
| 3261 |
$top -> Dialog(-bitmap => 'warning', |
| 3262 |
-text => $message, |
| 3263 |
-title => 'Athena: memory space running low', |
| 3264 |
-buttons => ['OK'], |
| 3265 |
-default_button => 'OK'); |
| 3266 |
my $response = $dialog->Show(); |
| 3267 |
return 1; |
| 3268 |
}; |
| 3269 |
return 1; |
| 3270 |
}; |
| 3271 |
|
| 3272 |
|
| 3273 |
sub fetch_url { |
| 3274 |
my $remote = ""; |
| 3275 |
my $label = "URL of the remote file: "; |
| 3276 |
my $dialog = get_string($dmode, $label, \$remote, \@web_buffer); |
| 3277 |
$dialog -> waitWindow; # the get_string dialog will be |
| 3278 |
# destroyed once the user hits ok, |
| 3279 |
# then we can move on... |
| 3280 |
Echo("Aborting web fetch of data."), return unless ($remote); |
| 3281 |
Echo("Fetching $remote ..."); |
| 3282 |
$top -> Busy; |
| 3283 |
my @parts = split(/\//, $remote); |
| 3284 |
(-d $webdir) or mkpath($webdir); |
| 3285 |
my $local = File::Spec->catfile($webdir, $parts[$#parts]); |
| 3286 |
my $response = getstore($remote, $local); |
| 3287 |
$top -> Unbusy; |
| 3288 |
Echo("$remote: HTTP status $response -- " . status_message($response)); |
| 3289 |
return unless (-e $local); |
| 3290 |
push @web_buffer, $remote; |
| 3291 |
&read_file(0, $local); |
| 3292 |
}; |
| 3293 |
|
| 3294 |
sub purge_web_cache { |
| 3295 |
return unless -d $webdir; |
| 3296 |
opendir C, $webdir; |
| 3297 |
map { my $f = File::Spec->catfile($webdir, $_); -f $f and unlink $f} |
| 3298 |
(grep !/^\.{1,2}$/, readdir C); |
| 3299 |
closedir C; |
| 3300 |
Echo("Purged web cache: $webdir"); |
| 3301 |
}; |
| 3302 |
|
| 3303 |
|
| 3304 |
## this wacko sub is to satisfy the Aussie contingent. The output |
| 3305 |
## file is something that can be read in by Xfit. The idea is for |
| 3306 |
## someone to use Athena for data processing and Xfit for data |
| 3307 |
## analysis. Whatever. |
| 3308 |
sub write_xfit_file { |
| 3309 |
Error("Only mu(E) data can be saved as an xfit file."), return unless |
| 3310 |
($groups{$current}->{is_xmu}); |
| 3311 |
|
| 3312 |
#local $Tk::FBox::a; |
| 3313 |
#local $Tk::FBox::b; |
| 3314 |
my $path = $current_data_dir || Cwd::cwd; |
| 3315 |
my $types = [["Xfit data", ".xfit"], ['All', '*']]; |
| 3316 |
my $initial = join(".", $groups{$current}->{label}, "xfit"); |
| 3317 |
# spaces are common in filenames on Mac and Win, but not on un*x |
| 3318 |
($initial =~ s/\s+/_/g) unless ($is_windows or $is_darwin); |
| 3319 |
($initial =~ s/[\\:\/\*\?\'<>\|]/_/g);# if ($is_windows); |
| 3320 |
my $file = $top -> getSaveFile(-filetypes=>$types, |
| 3321 |
#(not $is_windows) ? |
| 3322 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 3323 |
-initialdir=>$path, |
| 3324 |
-initialfile=>$initial, |
| 3325 |
-title => "Athena: Save Xfit data"); |
| 3326 |
Echo("Saving Xfit data ... canceled", 0), return unless ($file); |
| 3327 |
|
| 3328 |
my ($com,$sep) = ("", ","); # xfit-able |
| 3329 |
#my ($com,$sep) = ("#", " "); # readable by gnuplot |
| 3330 |
#Error("Cannot write to $file"), return unless (-w $file); |
| 3331 |
open F, ">".$file; |
| 3332 |
## write boilerplate headers |
| 3333 |
printf F ("%sAVERAGE |
| 3334 |
%s ABSORBER %s |
| 3335 |
%s EDGE %s |
| 3336 |
%s E0 %.2f eV |
| 3337 |
%s |
| 3338 |
", |
| 3339 |
$com, |
| 3340 |
$com, ucfirst(Chemistry::Elements::get_name($groups{$current}->{bkg_z})), |
| 3341 |
$com, $groups{$current}->{fft_edge}, |
| 3342 |
$com, $groups{$current}->{bkg_e0}, |
| 3343 |
$com |
| 3344 |
); |
| 3345 |
printf F ("%sSPLINE |
| 3346 |
%s ABSORBER %s |
| 3347 |
%s EDGE %s |
| 3348 |
%s E0 %.2f eV |
| 3349 |
%s WEIGHT K**%.1f |
| 3350 |
%s WINDOW %.2f-%.2f (0.20) angstrom**-1 |
| 3351 |
%s BACKGROUND |
| 3352 |
%s SPLINE |
| 3353 |
%s CORRECTION OFF |
| 3354 |
%s |
| 3355 |
", |
| 3356 |
$com, |
| 3357 |
$com, ucfirst(Chemistry::Elements::get_name($groups{$current}->{bkg_z})), |
| 3358 |
$com, $groups{$current}->{fft_edge}, |
| 3359 |
$com, $groups{$current}->{bkg_e0}, |
| 3360 |
$com, $groups{$current}->{bkg_kw}, |
| 3361 |
$com, $groups{$current}->{bkg_spl1}, |
| 3362 |
$groups{$current}->{bkg_spl2}, |
| 3363 |
$com, $com, $com, $com); |
| 3364 |
print F $com . "DATA |
| 3365 |
$com EV ENERGY |
| 3366 |
$com EV X-ray energy in eV |
| 3367 |
$com RAW ABSORBANCE |
| 3368 |
$com RAW Sample absorbance |
| 3369 |
$com FOIL Foil absorbance |
| 3370 |
$com BACKGROUND PREEDGE |
| 3371 |
$com BACKGROUND Background absorbance |
| 3372 |
$com NORMAL Normalised absorbance |
| 3373 |
$com SPLINE Polynomial spline |
| 3374 |
$com K K-SCALE |
| 3375 |
$com K Photoelectron momentum |
| 3376 |
$com XAFS EXAFS |
| 3377 |
$com XAFS X-ray absorption fine structure |
| 3378 |
$com |
| 3379 |
$com EV RAW BACKGROUND NORMAL SPLINE K XAFS |
| 3380 |
"; |
| 3381 |
## columns: energy, mu, pre-edge, norm, normbkg, k, chik |
| 3382 |
## k is converted from E, negative values set to 0 |
| 3383 |
## comma separated |
| 3384 |
my $gp = $groups{$current}->{group}; |
| 3385 |
my @e = Ifeffit::get_array("$gp.energy"); |
| 3386 |
my @x = Ifeffit::get_array("$gp.xmu"); |
| 3387 |
my @b = Ifeffit::get_array("$gp.bkg"); |
| 3388 |
my @n = Ifeffit::get_array("$gp.norm"); |
| 3389 |
my $e0 = $groups{$current}->{bkg_e0}; |
| 3390 |
foreach my $i (0 .. $#e) { |
| 3391 |
my $pre = $groups{$current}->{bkg_int} + |
| 3392 |
$groups{$current}->{bkg_slope}*($e[$i] + $groups{$current}->{bkg_eshift}); |
| 3393 |
my $normbkg = ($b[$i] - $pre)/$groups{$current}->{bkg_step}; |
| 3394 |
my $k = ($e[$i] < $e0) ? "0" : sprintf("%.5f",sqrt(ETOK * ($e[$i]-$e0))); |
| 3395 |
my $chik = $n[$i] - $normbkg; |
| 3396 |
printf F " %.5f%s%.11f%s%.11f%s%.11f%s%.11f%s%s%s%.11f\n", |
| 3397 |
$e[$i], $sep, $x[$i], $sep, $pre, $sep, $n[$i], $sep, |
| 3398 |
$normbkg, $sep, $k, $sep, $chik; |
| 3399 |
}; |
| 3400 |
|
| 3401 |
close F; |
| 3402 |
Echo("Wrote $groups{$current}->{label} to an Xfit file."); |
| 3403 |
}; |
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
## END OF DATA INPUT SUBSECTION |
| 3409 |
########################################################################################## |