| 1 |
## -*- cperl -*- |
| 2 |
## |
| 3 |
## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel |
| 4 |
## |
| 5 |
## This section of the code contains subroutines associated with |
| 6 |
## Athena's interactions with the Ifeffit/PGPLOT plotting system. |
| 7 |
|
| 8 |
sub plot_merge { |
| 9 |
my ($group, $space) = @_; |
| 10 |
my $color = $plot_features{c1}; |
| 11 |
my $label = $groups{$group}->{label}; |
| 12 |
my $propsp = "color=$color, key=\"$label+std.dev.\", style=lines"; |
| 13 |
my $propsm = "color=$color, key=\"$label-std.dev.\", style=lines"; |
| 14 |
my $kstr = ($plot_features{k_w} eq 'w') ? 'kw' : 'k'.$plot_features{k_w}; |
| 15 |
my $kexp = ($plot_features{k_w} eq 'w') ? $groups{$group}->{fft_arbkw} : $plot_features{k_w}; |
| 16 |
my $yoffset = $groups{$group}->{plot_yoffset}; |
| 17 |
PLOT: { |
| 18 |
($space eq 'k') and do { |
| 19 |
if ($config{merge}{plot} eq 'stddev') { |
| 20 |
$groups{$group} -> plotk($kstr,$dmode,\%plot_features, \@indicator); |
| 21 |
my $string = "plot($group.k, \"($group.chi+$group.stddev)*$group.k**$kexp+$yoffset\", $propsp)"; |
| 22 |
$groups{$group} -> dispose($string, $dmode); |
| 23 |
$string = "plot($group.k, \"($group.chi-$group.stddev)*$group.k**$kexp+$yoffset\", $propsm)"; |
| 24 |
$groups{$group} -> dispose($string, $dmode); |
| 25 |
} else { |
| 26 |
&plot_marked_k; |
| 27 |
}; |
| 28 |
$plotsel->raise('k') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 29 |
last PLOT; |
| 30 |
}; |
| 31 |
($space =~ /[end]/) and do { |
| 32 |
if ($config{merge}{plot} eq 'stddev') { |
| 33 |
my $str = ($space eq 'e') ? 'em' : 'emn'; |
| 34 |
$groups{$group} -> plotE($str,$dmode,\%plot_features, \@indicator); |
| 35 |
my $esh = $groups{$group}->{bkg_eshift}; |
| 36 |
my $suff = ($space eq 'e') ? 'xmu' : 'norm'; |
| 37 |
($suff = "det") if ($space eq 'd'); |
| 38 |
($groups{$group}->{is_nor}) and ($suff = 'xmu'); |
| 39 |
my $string = "plot($group.energy+$esh, \"$group.$suff+$group.stddev+$yoffset\", $propsp)"; |
| 40 |
$groups{$group} -> dispose($string, $dmode); |
| 41 |
$string = "plot($group.energy+$esh, \"$group.$suff-$group.stddev+$yoffset\", $propsm)"; |
| 42 |
$groups{$group} -> dispose($string, $dmode); |
| 43 |
} else { |
| 44 |
&plot_marked_e; |
| 45 |
}; |
| 46 |
$plotsel->raise('e') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 47 |
last PLOT; |
| 48 |
}; |
| 49 |
($space =~ /[rq]/) and do { |
| 50 |
if ($config{merge}{plot} eq 'stddev') { |
| 51 |
Echo("Plotting merge+std.dev. in R and q spaces does not work yet."); |
| 52 |
} elsif ($space eq 'r') { |
| 53 |
&plot_marked_r; |
| 54 |
$plotsel->raise('r') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 55 |
} elsif ($space eq 'q') { |
| 56 |
&plot_marked_q; |
| 57 |
$plotsel->raise('q') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 58 |
}; |
| 59 |
last PLOT; |
| 60 |
}; |
| 61 |
}; |
| 62 |
|
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
sub plot_i0 { |
| 67 |
my $plot_mu = $_[0]; |
| 68 |
$top -> Busy; |
| 69 |
my $with = ($plot_mu) ? " $groups{$current}->{label} and" : ""; |
| 70 |
my $how = ($plot_mu) ? " (scaled to the size of mu)" : " for $groups{$current}->{label}"; |
| 71 |
Echonow("Plotting$with I0$how ..."); |
| 72 |
my $plot = ($plot_mu) ? "plot" : "newplot"; |
| 73 |
my $title = ($plot_mu) ? "" : ",xlabel=\"energy (eV)\", ylabel=I0, title=\"I0 of $groups{$current}->{label}\""; |
| 74 |
my ($scale, $color) = ("", $config{plot}{c0}); |
| 75 |
my $i0 = $groups{$current}->{i0}; |
| 76 |
my $eshift = $groups{$current}->{bkg_eshift}; |
| 77 |
if ($plot_mu) { |
| 78 |
$groups{$current}->dispose("## plotting data and I0, scaled to the size of mu(E)\n", $dmode); |
| 79 |
$groups{$current}->plotE('em', $dmode, \%plot_features, \@indicator); |
| 80 |
$color = $config{plot}{c1}; |
| 81 |
$groups{$current}->dispose("set ___x = ceil($current.xmu) / ceil($i0)\n", $dmode); |
| 82 |
$scale = sprintf("%.6g*", abs(Ifeffit::get_scalar("___x"))); |
| 83 |
}; |
| 84 |
my $cmd = "$plot(\"$current.energy+$eshift\", $scale$i0, key=I0, color=$color,\n"; |
| 85 |
$cmd .= " " x length($plot) . " style=lines$title,\n"; |
| 86 |
my ($emin, $emax) = ($plot_features{emin}+$groups{$current}->{bkg_e0}, $plot_features{emax}+$groups{$current}->{bkg_e0}); |
| 87 |
$cmd .= " " x length($plot) . " xmin=$emin, xmax=$emax)\n"; |
| 88 |
$groups{$current}->dispose($cmd, $dmode); |
| 89 |
|
| 90 |
if ($indicator[0]) { |
| 91 |
my $eshift = $groups{$current}->{bkg_eshift}; |
| 92 |
$groups{$current}->dispose("set(i___ndic.y = $scale$i0, i___ndic.x = $current.energy+$eshift)"); |
| 93 |
my @x = Ifeffit::get_array("i___ndic.x"); |
| 94 |
my @y = Ifeffit::get_array("i___ndic.y"); |
| 95 |
my ($ymin, $ymax) = Ifeffit::Group->floor_ceil(\@x, \@y, \%plot_features, 'e', $groups{$current}->{bkg_e0}); |
| 96 |
#print join("|", $not_data, $ymin, $ymax), $/; |
| 97 |
#(($ymin, $ymax) = ($plot_scale*$ymin, $plot_scale*$ymax)) if ($not_data); |
| 98 |
my $diff = $ymax-$ymin; |
| 99 |
$ymin -= $diff/20; |
| 100 |
$ymax += $diff/20; |
| 101 |
foreach my $i (@indicator) { |
| 102 |
last if ($i =~ /^0$/); |
| 103 |
next if ($i =~ /^1$/); |
| 104 |
next if (lc($i->[1]) =~ /[r\s]/); |
| 105 |
my $val = $i->[2]; |
| 106 |
($val = $groups{$current}->k2e($val)+$groups{$current}->{bkg_e0}) if (lc($i->[1]) =~ /[kq]/); |
| 107 |
next if ($val < 0); |
| 108 |
$groups{$current}->plot_vertical_line($val, $ymin, $ymax, $dmode, "", 0, 0, 1) |
| 109 |
}; |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
$last_plot='e'; |
| 114 |
$top -> Unbusy; |
| 115 |
Echonow("Plotting$with I0$how ... done!"); |
| 116 |
}; |
| 117 |
|
| 118 |
sub plot_i0_marked { |
| 119 |
my $plot = "newplot"; |
| 120 |
my $i = 0; |
| 121 |
my $title = ",xlabel=\"energy (eV)\", ylabel=I0, title=\"I0 of marked groups\""; |
| 122 |
my ($yn, $yx) = (1e10, -1e10); |
| 123 |
foreach my $k (&sorted_group_list) { |
| 124 |
next unless $marked{$k}; |
| 125 |
next unless $groups{$k}->{i0}; |
| 126 |
my $eshift = $groups{$k}->{bkg_eshift}; |
| 127 |
my $key = $groups{$k}->{label}; |
| 128 |
my $color = $config{plot}{"c".$i}; |
| 129 |
my ($emin, $emax) = ($plot_features{emin}+$groups{$k}->{bkg_e0}, $plot_features{emax}+$groups{$k}->{bkg_e0}); |
| 130 |
my $limits = ($plot eq "newplot") ? ",\n xmin=$emin, xmax=$emax" : ""; |
| 131 |
$groups{$current}->dispose("$plot(\"$k.energy+$eshift\", $groups{$k}->{i0}, key=$key, color=$color, style=lines$title$limits)\n", $dmode); |
| 132 |
$plot = "plot"; |
| 133 |
$title = ""; |
| 134 |
++$i; |
| 135 |
($i = 0) if ($i > 9); # wrap colors |
| 136 |
|
| 137 |
$groups{$k}->dispose("set(i___ndic.y = $groups{$k}->{i0}, set i___ndic.x = $current.energy+$eshift)"); |
| 138 |
my @x = Ifeffit::get_array("i___ndic.x"); |
| 139 |
my @y = Ifeffit::get_array("i___ndic.y"); |
| 140 |
my ($ymin, $ymax) = Ifeffit::Group->floor_ceil(\@x, \@y, \%plot_features, 'e', $groups{$k}->{bkg_e0}); |
| 141 |
($yn = $ymin) if ($ymin<$yn); |
| 142 |
($yx = $ymax) if ($ymax>$yx); |
| 143 |
}; |
| 144 |
my $diff = $yx-$yn; |
| 145 |
$yn -= $diff/20; |
| 146 |
$yx += $diff/20; |
| 147 |
foreach my $i (@indicator) { |
| 148 |
last if ($i =~ /^0$/); |
| 149 |
next if ($i =~ /^1$/); |
| 150 |
next if (lc($i->[1]) =~ /[r\s]/); |
| 151 |
my $val = $i->[2]; |
| 152 |
($val = $groups{$current}->k2e($val)+$groups{$current}->{bkg_e0}) if (lc($i->[1]) =~ /[kq]/); |
| 153 |
next if ($val < 0); |
| 154 |
$groups{$current}->plot_vertical_line($val, $yn, $yx, $dmode, "", 0, 0, 1) |
| 155 |
}; |
| 156 |
$last_plot='e'; |
| 157 |
}; |
| 158 |
|
| 159 |
sub redo_plot { |
| 160 |
Echo ("You have not yet plotted anything"), return unless $last_plot_params; |
| 161 |
my ($curr, $type, $sp, $str) = @$last_plot_params; |
| 162 |
SWITCH: { # dispatch plot request to the correct method |
| 163 |
$groups{$curr}->plot_marked($str,$dmode,\%groups,\%marked,\%plot_features, $list, \@indicator), last SWITCH |
| 164 |
if ($type eq 'marked'); |
| 165 |
$groups{$curr}->plotE($str,$dmode,\%plot_features, \@indicator), last SWITCH if ($sp eq 'e'); |
| 166 |
$groups{$curr}->plotk($str,$dmode,\%plot_features, \@indicator), last SWITCH if ($sp eq 'k'); |
| 167 |
$groups{$curr}->plotR($str,$dmode,\%plot_features, \@indicator), last SWITCH if ($sp eq 'r'); |
| 168 |
$groups{$curr}->plotq($str,$dmode,\%plot_features, \@indicator), last SWITCH if ($sp eq 'q'); |
| 169 |
}; |
| 170 |
}; |
| 171 |
|
| 172 |
sub replot { |
| 173 |
Echo('No data'), return unless $current; |
| 174 |
my $mode = $_[0]; # 0=replot, 1=write gif, 2=write ps, |
| 175 |
# 3=send to printer |
| 176 |
Echo("You have not yet plotted anything."), return 0 unless ($Ifeffit::Group::last_plot); |
| 177 |
my ($title, $suf, $dev); |
| 178 |
SWITCH: { |
| 179 |
($mode eq 'replot') and do { |
| 180 |
$setup->dispose($Ifeffit::Group::last_plot, 1); |
| 181 |
Echo("Unzoomed."); |
| 182 |
return; |
| 183 |
}; |
| 184 |
($mode =~ /(gif|png|ppm)/) and do { |
| 185 |
($title, $suf, $dev) = ('Athena: '.uc($1).' file name', $1, $mode ); |
| 186 |
last SWITCH; |
| 187 |
}; |
| 188 |
($mode =~ /ps/) and do { |
| 189 |
($title, $suf, $dev) = ('Athena: Postscript file name', 'ps', $mode); |
| 190 |
last SWITCH; |
| 191 |
}; |
| 192 |
($mode =~ /latex/) and do { |
| 193 |
($title, $suf, $dev) = ('Athena: LaTeX picture mode file name', 'tex', $mode); |
| 194 |
last SWITCH; |
| 195 |
}; |
| 196 |
($mode eq 'print') and do { |
| 197 |
($title, $suf, $dev) = ('', 'ps', $config{general}{ps_device}); |
| 198 |
last SWITCH; |
| 199 |
}; |
| 200 |
($title, $suf, $dev) = ('Athena: Image file name', 'img', $mode); |
| 201 |
}; |
| 202 |
my $path = $current_data_dir || Cwd::cwd; |
| 203 |
if ($mode eq 'print') { |
| 204 |
if ($is_windows) { |
| 205 |
Echo("Printing under Windows is not yet supported"); |
| 206 |
} else { |
| 207 |
## this is alarmingly crufty! |
| 208 |
my $tmp = '...athena.tmp'; |
| 209 |
$setup->dispose("plot(device=\"$dev\", file=\"$tmp\")\n", 7); |
| 210 |
local $| = 1; |
| 211 |
Echo("Sending image to printer with " . |
| 212 |
$config{general}{print_spooler}); |
| 213 |
open OUT, "| ".$config{general}{print_spooler} or |
| 214 |
die "could not open pipe to ".$config{general}{print_spooler}."\n"; |
| 215 |
open IN, $tmp or die "could not open temp file for printing"; |
| 216 |
while (<IN>) { print OUT; }; |
| 217 |
close IN; close OUT; unlink $tmp; |
| 218 |
Echo("Image spooled."); |
| 219 |
}; |
| 220 |
return; |
| 221 |
} else { |
| 222 |
##local $Tk::FBox::a; |
| 223 |
##local $Tk::FBox::b; |
| 224 |
my $types = [["$suf image files", $suf], |
| 225 |
['All Files', '*'],]; |
| 226 |
my $file = $top -> getSaveFile(-defaultextension=>$suf, |
| 227 |
-filetypes=>$types, |
| 228 |
##(not $is_windows) ? |
| 229 |
## (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 230 |
-initialdir=>$path, |
| 231 |
-initialfile=>"athena.$suf", |
| 232 |
-title => $title); |
| 233 |
if ($file) { |
| 234 |
## make sure I can write to $file |
| 235 |
open F, ">".$file or do { |
| 236 |
Error("You cannot write to \"$file\"."); return |
| 237 |
}; |
| 238 |
close F; |
| 239 |
my ($name, $path, $suffix) = fileparse($file); |
| 240 |
$current_data_dir = $path; |
| 241 |
Echo("saving image to $file"); |
| 242 |
$setup->dispose("plot(device=\"$dev\", file=\"$file\")\n", 7); |
| 243 |
#$setup->dispose("plot(device=\"/xserve\", file=\"\")\n", 7); |
| 244 |
}; |
| 245 |
}; |
| 246 |
}; |
| 247 |
|
| 248 |
|
| 249 |
sub autoreplot { |
| 250 |
## this could be a direct call or it could be a callback from some widget |
| 251 |
my $arg = (ref($_[0]) =~ /Tk/) ? $_[1] : $_[0]; |
| 252 |
#print join(" ", @_), $/, "arg=$arg\n"; |
| 253 |
## replot a specific space |
| 254 |
plot_current_e(), return if (lc($arg) eq 'e'); |
| 255 |
plot_current_k(), return if (lc($arg) eq 'k'); |
| 256 |
plot_current_r(), return if (lc($arg) eq 'r'); |
| 257 |
plot_current_q(), return if (lc($arg) eq 'q'); |
| 258 |
## replot the most recent space |
| 259 |
plot_current_e(), return if ($last_plot eq 'e'); |
| 260 |
plot_current_k(), return if ($last_plot eq 'k'); |
| 261 |
plot_current_r(), return if ($last_plot eq 'r'); |
| 262 |
plot_current_q(), return if ($last_plot eq 'q'); |
| 263 |
}; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
sub pluck { |
| 268 |
my $widg = $_[0]; |
| 269 |
my $parent = $_[1] || $top; |
| 270 |
my $this = $current || "Default Parameters"; |
| 271 |
Echo("You have not made a plot yet."), return 0 unless ($last_plot); |
| 272 |
if ($widg =~ /^lr/) { |
| 273 |
1; |
| 274 |
} elsif ($widg =~ /^pp/) { |
| 275 |
1; |
| 276 |
} elsif (($last_plot =~ /[ek]/) and (($widg =~ /^bft/) or ($widg eq 'bkg_rbkg'))) { |
| 277 |
Echonow("You cannot pluck an R value from the last plot."); |
| 278 |
return 0; |
| 279 |
## } elsif (($last_plot eq 'ke') and ($widg !~ /bkg/)) { |
| 280 |
## Echonow("Your last plot was an energy plot."); |
| 281 |
## return 0; |
| 282 |
} elsif (($last_plot eq 'k') and ($widg =~ /pre/)) { |
| 283 |
Echonow("You cannot pluck an pre-edge parameter value from a k plot."); |
| 284 |
return 0; |
| 285 |
} elsif (($last_plot eq 'r') and (($widg !~ /^bft/) and ($widg ne 'bkg_rbkg'))) { |
| 286 |
Echonow("Your last plot was an R plot."); |
| 287 |
return 0; |
| 288 |
}; |
| 289 |
Echonow("Select a value for $widg from the plot..."); |
| 290 |
my ($cursor_x, $cursor_y) = (0,0); |
| 291 |
my $to_grab = $grab{$widg} || $parent; |
| 292 |
$to_grab -> grab(); |
| 293 |
$groups{$this}->dispose("cursor(crosshair=true)\n", 1); |
| 294 |
($cursor_x, $cursor_y) = (Ifeffit::get_scalar("cursor_x"), |
| 295 |
Ifeffit::get_scalar("cursor_y")); |
| 296 |
$to_grab -> grabRelease(); |
| 297 |
my $value; |
| 298 |
if ($widg =~ /^(bkg_(e0|nor[12]|pre[12]|spl(1e|2e)))$/) { # need an E value |
| 299 |
if (($last_plot eq 'e') or ($last_plot eq 'ke')) { |
| 300 |
$value = $cursor_x; |
| 301 |
} else { |
| 302 |
$value = $groups{$this}->k2e($cursor_x); |
| 303 |
}; |
| 304 |
($widg !~ /e0/) and $value -= $groups{$this}->{bkg_e0}; |
| 305 |
} elsif ($widg =~ /^(deg|diff|etrun|lcf|peak)/) { |
| 306 |
$value = $cursor_x; |
| 307 |
} elsif ($widg =~ /^(bkg_spl[12]|fft_km(ax|in))$/) { # need a k value |
| 308 |
if (($last_plot eq 'e') or ($last_plot eq 'ke')) { |
| 309 |
$value = $groups{$this}->e2k($cursor_x); |
| 310 |
($widg =~ /(nor|pre)/) and $value -= $groups{$this}->{bkg_e0}; |
| 311 |
} else { |
| 312 |
$value = $cursor_x; |
| 313 |
}; |
| 314 |
} elsif ($widg =~ /^(b(ft_rm(ax|in)|kg_rbkg))$/) { # need an R value |
| 315 |
$value = $cursor_x; |
| 316 |
} elsif ($widg =~ /^lr/) { # need an R value |
| 317 |
$value = $cursor_x; |
| 318 |
} elsif ($widg =~ /^pp_(.+)/) { |
| 319 |
$value = sprintf("%.3f", $cursor_x); |
| 320 |
$preprocess{$1} = $value; |
| 321 |
Echonow("Plucked the value of $value for $widg."); |
| 322 |
return 1; |
| 323 |
} else { |
| 324 |
return -1; |
| 325 |
}; |
| 326 |
$value = sprintf("%.3f", $value); |
| 327 |
set_variable($widg, $value, 1); |
| 328 |
my $v = $groups{$this}->{$widg}; |
| 329 |
$widget{$widg} -> configure(-validate=>'none'); |
| 330 |
$widget{$widg} -> delete(qw/0 end/); |
| 331 |
$widget{$widg} -> insert(0, $v); |
| 332 |
$widget{$widg} -> configure(-validate=>'key'); |
| 333 |
##$parent->raise; |
| 334 |
my $how = $_[2] || "e"; |
| 335 |
($how = 'r') if ($widg =~ /^fft/); |
| 336 |
($how = 'q') if ($widg =~ /^bft/); |
| 337 |
$widget{peak_plot}->invoke if ($widg =~ /^peak/); |
| 338 |
autoreplot($how) unless |
| 339 |
( |
| 340 |
(($widg =~ /^fft/) and not ($config{fft}{pluck_replot})) |
| 341 |
or |
| 342 |
($widg =~ /^(peak)/) |
| 343 |
or |
| 344 |
($widg =~ /^(lcf)/) |
| 345 |
); |
| 346 |
Echonow("Plucked the value of $v for $widg."); |
| 347 |
#($widg =~ /^deg/) and $groups{$current} -> plotE('emg',$dmode,\%plot_features, \@indicator); |
| 348 |
return 1; |
| 349 |
}; |
| 350 |
|
| 351 |
|
| 352 |
sub zoom { |
| 353 |
if ($fat_showing ne 'teach_ft') { |
| 354 |
Echo('No data'), return unless $current; |
| 355 |
Echo("You have not yet plotted anything."), return unless $last_plot; |
| 356 |
}; |
| 357 |
Echonow('Click corners to zoom'); |
| 358 |
my $mode = $dmode; |
| 359 |
($mode & 8) and ($mode -= 8); |
| 360 |
$setup->dispose('zoom(show)', $mode); |
| 361 |
Echo('Zooming done!'); |
| 362 |
}; |
| 363 |
|
| 364 |
sub cursor { |
| 365 |
Echo('No data'), return unless $current; |
| 366 |
Echo("You have not yet plotted anything."), return unless $last_plot; |
| 367 |
my $old = $echo_pause; |
| 368 |
$echo_pause = 0; |
| 369 |
Echonow('Click on a point'); |
| 370 |
$echo_pause = $old; |
| 371 |
my $mode = $dmode; |
| 372 |
($mode & 8) and ($mode -= 8); |
| 373 |
$setup->dispose('cursor(show, crosshair=true)', $mode); |
| 374 |
Echonow(sprintf("You selected x=%f y=%f", |
| 375 |
Ifeffit::get_scalar("cursor_x"), |
| 376 |
Ifeffit::get_scalar("cursor_y"))); |
| 377 |
}; |
| 378 |
|
| 379 |
|
| 380 |
## return 1 if all relevant ranges are correct, return 0 and do an |
| 381 |
## Echo if there is a problem |
| 382 |
sub verify_ranges { |
| 383 |
my ($this, $space, $multi) = @_; |
| 384 |
if ($groups{$this}->{is_xmu} and (not $groups{$this}->{is_nor}) and |
| 385 |
($groups{$this}->{bkg_pre1} > $groups{$this}->{bkg_pre2})) { |
| 386 |
Echo("ERROR: The minimum value of the pre-edge range exceeds the maximum value."); |
| 387 |
set_properties (1, $this, 0) if ($multi); |
| 388 |
return 0; |
| 389 |
}; |
| 390 |
if ($groups{$this}->{is_xmu} and (not $groups{$this}->{is_nor}) and |
| 391 |
($groups{$this}->{bkg_nor1} > $groups{$this}->{bkg_nor2})) { |
| 392 |
Echo("ERROR: The minimum value of the normalization range exceeds the maximum value."); |
| 393 |
set_properties (1, $this, 0) if ($multi); |
| 394 |
return 0; |
| 395 |
}; |
| 396 |
if ($groups{$this}->{is_xmu} and ($groups{$this}->{bkg_spl1} > $groups{$this}->{bkg_spl2})) { |
| 397 |
Echo("ERROR: The minimum value of the spline range exceeds the maximum value."); |
| 398 |
set_properties (1, $this, 0) if ($multi); |
| 399 |
return 0; |
| 400 |
}; |
| 401 |
return 1 if $groups{$this}->{is_xanes}; |
| 402 |
return 1 if $groups{$this}->{not_data}; |
| 403 |
if (($space =~ /[rq]/) and (not $groups{$this}->{is_qsp})) { |
| 404 |
if ($groups{$this}->{fft_kmin} > $groups{$this}->{fft_kmax}) { |
| 405 |
Echo("ERROR: The minimum value of the forward Fourier transform range exceeds the maximum value."); |
| 406 |
set_properties (1, $this, 0) if ($multi); |
| 407 |
return 0; |
| 408 |
}; |
| 409 |
}; |
| 410 |
return 1 if $groups{$this}->{is_qsp}; |
| 411 |
if ($space =~ /q/) { |
| 412 |
if ($groups{$this}->{bft_rmin} > $groups{$this}->{bft_rmax}) { |
| 413 |
Echo("ERROR: The minimum value of the backward Fourier transform range exceeds the maximum value."); |
| 414 |
set_properties (1, $this, 0) if ($multi); |
| 415 |
return 0; |
| 416 |
}; |
| 417 |
}; |
| 418 |
return 1; |
| 419 |
}; |
| 420 |
|
| 421 |
sub plot_current_e { |
| 422 |
my $str = "e"; |
| 423 |
Echo('No data!'), return unless ($current); |
| 424 |
return unless &verify_ranges($current, 'e'); |
| 425 |
$top -> Busy(-recurse=>1,); |
| 426 |
update_hook(); |
| 427 |
map {$str .= $plot_features{$_}} (qw/e_mu e_mu0 e_pre e_post e_norm e_der/); |
| 428 |
($str eq "e") and ($str = "emz"); |
| 429 |
($str eq "en") and ($str = "emzn"); |
| 430 |
($str eq "ed") and ($str = "emdsss"); |
| 431 |
($str =~ "d") and ($str .= "s" x $plot_features{smoothderiv}); |
| 432 |
&set_key_params; |
| 433 |
$groups{$current}->plotE($str,$dmode,\%plot_features, \@indicator); |
| 434 |
&refresh_properties; |
| 435 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'e'); |
| 436 |
$last_plot='e'; |
| 437 |
$last_plot_params = [$current, 'group', 'e', $str]; |
| 438 |
$plotsel->raise('e') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 439 |
section_indicators(); |
| 440 |
$pointfinder{space} -> configure(-text=>"The last plot was in Energy"); |
| 441 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 442 |
$pointfinder{$_} -> configure(-state=>'normal'); |
| 443 |
}; |
| 444 |
Error("The edge step is negative! You probably need to adjust the normalization parameters.") |
| 445 |
if ($groups{$current}->{bkg_step} < 0); |
| 446 |
$top->Unbusy; |
| 447 |
}; |
| 448 |
|
| 449 |
|
| 450 |
sub plot_current_k { |
| 451 |
my $str = "k"; |
| 452 |
Echo('No data!'), return unless ($current); |
| 453 |
return unless &verify_ranges($current, 'k'); |
| 454 |
$top -> Busy(-recurse=>1,); |
| 455 |
update_hook(); |
| 456 |
map {$str .= $plot_features{$_}} (qw/k_w k_win/); |
| 457 |
&set_key_params; |
| 458 |
$groups{$current}->plotk($str,$dmode,\%plot_features, \@indicator); |
| 459 |
&refresh_properties; |
| 460 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'k'); |
| 461 |
$last_plot='k'; |
| 462 |
$last_plot_params = [$current, 'group', 'k', $str]; |
| 463 |
$plotsel->raise('k') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 464 |
section_indicators(); |
| 465 |
$pointfinder{space} -> configure(-text=>"The last plot was in k"); |
| 466 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 467 |
$pointfinder{$_} -> configure(-state=>'normal'); |
| 468 |
}; |
| 469 |
Error("The edge step is negative! You probably need to adjust the normalization parameters.") |
| 470 |
if ($groups{$current}->{bkg_step} < 0); |
| 471 |
$top->Unbusy; |
| 472 |
}; |
| 473 |
|
| 474 |
sub plot_current_r { |
| 475 |
my $str = "r"; |
| 476 |
Echo('No data!'), return unless ($current); |
| 477 |
return unless &verify_ranges($current, 'r'); |
| 478 |
$top -> Busy(-recurse=>1,); |
| 479 |
update_hook(); |
| 480 |
map {$str .= $plot_features{$_}} (qw/r_mag r_env r_re r_im r_pha r_win/); |
| 481 |
($str eq "r") and ($str = "rm"); |
| 482 |
&set_key_params; |
| 483 |
$groups{$current}->plotR($str,$dmode,\%plot_features, \@indicator); |
| 484 |
&refresh_properties; |
| 485 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'r'); |
| 486 |
$last_plot='r'; |
| 487 |
$last_plot_params = [$current, 'group', 'r', $str]; |
| 488 |
$plotsel->raise('r') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 489 |
section_indicators(); |
| 490 |
$pointfinder{space} -> configure(-text=>"The last plot was in R"); |
| 491 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 492 |
$pointfinder{$_} -> configure(-state=>'normal'); |
| 493 |
}; |
| 494 |
Error("The edge step is negative! You probably need to adjust the normalization parameters.") |
| 495 |
if ($groups{$current}->{bkg_step} < 0); |
| 496 |
$top->Unbusy; |
| 497 |
}; |
| 498 |
|
| 499 |
sub plot_current_q { # } |
| 500 |
my $str = "q"; |
| 501 |
Echo('No data!'), return unless ($current); |
| 502 |
return unless &verify_ranges($current, 'q'); |
| 503 |
$top -> Busy(-recurse=>1,); |
| 504 |
update_hook(); |
| 505 |
map {$str .= $plot_features{$_}} (qw/q_mag q_env q_re q_im q_pha q_win/); |
| 506 |
($str eq "q") and ($str = "qi"); |
| 507 |
&set_key_params; |
| 508 |
$groups{$current}->plotq($str,$dmode,\%plot_features, \@indicator); |
| 509 |
&refresh_properties; |
| 510 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'q'); |
| 511 |
$last_plot='q'; |
| 512 |
$last_plot_params = [$current, 'group', 'q', $str]; |
| 513 |
$plotsel->raise('q') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 514 |
section_indicators(); |
| 515 |
$pointfinder{space} -> configure(-text=>"The last plot was in q"); |
| 516 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 517 |
$pointfinder{$_} -> configure(-state=>'normal'); |
| 518 |
}; |
| 519 |
Error("The edge step is negative! You probably need to adjust the normalization parameters.") |
| 520 |
if ($groups{$current}->{bkg_step} < 0); |
| 521 |
$top->Unbusy; |
| 522 |
}; |
| 523 |
|
| 524 |
|
| 525 |
sub keyboard_plot { |
| 526 |
my $who = $top->focusCurrent; |
| 527 |
$multikey = ""; |
| 528 |
Echo("Plot Current group: specify plot space (e k r q)"); |
| 529 |
$echo -> focus(); |
| 530 |
$echo -> grab; |
| 531 |
$echo -> waitVariable(\$multikey); |
| 532 |
$echo -> grabRelease; |
| 533 |
$who -> focus; |
| 534 |
Echo("$multikey is not a plot space!"), return unless (lc($multikey) =~ /^[ekqr]$/); |
| 535 |
SWITCH: { |
| 536 |
&plot_current_e, last SWITCH if (lc($multikey) eq 'e'); |
| 537 |
&plot_current_k, last SWITCH if (lc($multikey) eq 'k'); |
| 538 |
&plot_current_r, last SWITCH if (lc($multikey) eq 'r'); |
| 539 |
&plot_current_q, last SWITCH if (lc($multikey) eq 'q'); # , |
| 540 |
}; |
| 541 |
}; |
| 542 |
|
| 543 |
|
| 544 |
sub plot_marked_e { |
| 545 |
my $str = $plot_features{e_marked}; |
| 546 |
Echo('No data!'), return unless ($current); |
| 547 |
$top -> Busy(-recurse=>1,); |
| 548 |
update_hook(); |
| 549 |
&set_key_params; |
| 550 |
$groups{$current}->plot_marked($str, $dmode, \%groups, \%marked, \%plot_features, $list, \@indicator); |
| 551 |
&refresh_properties; |
| 552 |
$last_plot='e'; |
| 553 |
$last_plot_params = [$current, 'marked', 'e', $str]; |
| 554 |
$plotsel->raise('e') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 555 |
section_indicators(); |
| 556 |
$pointfinder{space} -> configure(-text=>"The last plot was a marked plot"); |
| 557 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 558 |
$pointfinder{$_} -> configure(-state=>'disabled'); |
| 559 |
}; |
| 560 |
my $bad_step = 0; |
| 561 |
foreach my $k (keys %marked) { |
| 562 |
next unless $marked{$k}; |
| 563 |
++$bad_step if ($groups{$k}->{bkg_step} < 0); |
| 564 |
}; |
| 565 |
Error("The edge step of one or more groups is negative! You probably need to adjust the normalization parameters.") |
| 566 |
if $bad_step; |
| 567 |
$top->Unbusy; |
| 568 |
}; |
| 569 |
|
| 570 |
sub plot_marked_k { |
| 571 |
#my $str = $plot_features{k_w}; |
| 572 |
my $str = $plot_features{kw}; |
| 573 |
Echo('No data!'), return unless ($current); |
| 574 |
$top -> Busy(-recurse=>1,); |
| 575 |
update_hook(); |
| 576 |
&set_key_params; |
| 577 |
$groups{$current}->plot_marked($str, $dmode, \%groups, \%marked, \%plot_features, $list, \@indicator); |
| 578 |
&refresh_properties; |
| 579 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'k'); |
| 580 |
$last_plot='k'; |
| 581 |
$last_plot_params = [$current, 'marked', 'k', $str]; |
| 582 |
$plotsel->raise('k') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 583 |
section_indicators(); |
| 584 |
$pointfinder{space} -> configure(-text=>"The last plot was a marked plot"); |
| 585 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 586 |
$pointfinder{$_} -> configure(-state=>'disabled'); |
| 587 |
}; |
| 588 |
my $bad_step = 0; |
| 589 |
foreach my $k (keys %marked) { |
| 590 |
next unless $marked{$k}; |
| 591 |
++$bad_step if ($groups{$k}->{bkg_step} < 0); |
| 592 |
}; |
| 593 |
Error("The edge step of one or more groups is negative! You probably need to adjust the normalization parameters.") |
| 594 |
if $bad_step; |
| 595 |
$top->Unbusy; |
| 596 |
}; |
| 597 |
|
| 598 |
sub plot_marked_r { |
| 599 |
#tie my $timer, 'Time::Stopwatch'; |
| 600 |
my $str = $plot_features{r_marked}; |
| 601 |
Echo('No data!'), return unless ($current); |
| 602 |
$top -> Busy(-recurse=>1,); |
| 603 |
update_hook(); |
| 604 |
&set_key_params; |
| 605 |
$groups{$current}->plot_marked($str, $dmode, \%groups, \%marked, \%plot_features, $list, \@indicator); |
| 606 |
&refresh_properties; |
| 607 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'r'); |
| 608 |
$last_plot='r'; |
| 609 |
$last_plot_params = [$current, 'marked', 'r', $str]; |
| 610 |
$plotsel->raise('r') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 611 |
section_indicators(); |
| 612 |
$pointfinder{space} -> configure(-text=>"The last plot was a marked plot"); |
| 613 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 614 |
$pointfinder{$_} -> configure(-state=>'disabled'); |
| 615 |
}; |
| 616 |
my $bad_step = 0; |
| 617 |
foreach my $k (keys %marked) { |
| 618 |
next unless $marked{$k}; |
| 619 |
++$bad_step if ($groups{$k}->{bkg_step} < 0); |
| 620 |
}; |
| 621 |
Error("The edge step of one or more groups is negative! You probably need to adjust the normalization parameters.") |
| 622 |
if $bad_step; |
| 623 |
$top->Unbusy; |
| 624 |
#my $elapsed = $timer; |
| 625 |
#undef $timer; |
| 626 |
#$elapsed = sprintf("Deletion took %.0f min, %.0f sec", $elapsed/60, $elapsed%60); |
| 627 |
#Echo($elapsed); |
| 628 |
}; |
| 629 |
|
| 630 |
sub plot_marked_q { |
| 631 |
my $str = $plot_features{q_marked}; # } |
| 632 |
Echo('No data!'), return unless ($current); |
| 633 |
$top -> Busy(-recurse=>1,); |
| 634 |
update_hook(); |
| 635 |
&set_key_params; |
| 636 |
$groups{$current}->plot_marked($str, $dmode, \%groups, \%marked, \%plot_features, $list, \@indicator); |
| 637 |
&refresh_properties; |
| 638 |
($pointfinder{xvalue}, $pointfinder{yvalue}) = ("", "") unless ($last_plot eq 'q'); |
| 639 |
$last_plot='q'; |
| 640 |
$last_plot_params = [$current, 'marked', 'q', $str]; |
| 641 |
$plotsel->raise('q') unless ($plotsel->raised() =~ /(Stack|Ind|PF)/); |
| 642 |
section_indicators(); |
| 643 |
$pointfinder{space} -> configure(-text=>"The last plot was a marked plot"); |
| 644 |
foreach (qw(x xpluck xfind y ypluck clear)) { |
| 645 |
$pointfinder{$_} -> configure(-state=>'disabled'); |
| 646 |
}; |
| 647 |
my $bad_step = 0; |
| 648 |
foreach my $k (keys %marked) { |
| 649 |
next unless $marked{$k}; |
| 650 |
++$bad_step if ($groups{$k}->{bkg_step} < 0); |
| 651 |
}; |
| 652 |
Error("The edge step of one or more groups is negative! You probably need to adjust the normalization parameters.") |
| 653 |
if $bad_step; |
| 654 |
$top->Unbusy; |
| 655 |
}; |
| 656 |
|
| 657 |
|
| 658 |
sub keyboard_plot_marked { |
| 659 |
my $who = $top->focusCurrent; |
| 660 |
$multikey = ""; |
| 661 |
Echo("Plot marked groups: specify plot space (e k r q)"); |
| 662 |
$echo -> focus(); |
| 663 |
$echo -> grab; |
| 664 |
$echo -> waitVariable(\$multikey); |
| 665 |
$echo -> grabRelease; |
| 666 |
$who -> focus; |
| 667 |
Echo("$multikey is not a plot space!"), return unless (lc($multikey) =~ /^[ekqr]$/); |
| 668 |
SWITCH: { |
| 669 |
&plot_marked_e, last SWITCH if (lc($multikey) eq 'e'); |
| 670 |
&plot_marked_k, last SWITCH if (lc($multikey) eq 'k'); |
| 671 |
&plot_marked_r, last SWITCH if (lc($multikey) eq 'r'); |
| 672 |
&plot_marked_q, last SWITCH if (lc($multikey) eq 'q'); # , |
| 673 |
}; |
| 674 |
}; |
| 675 |
|
| 676 |
|
| 677 |
sub set_key_params { |
| 678 |
Ifeffit::put_scalar('&plot_key_x', $config{plot}{'key_x'}); |
| 679 |
Ifeffit::put_scalar('&plot_key_y0', $config{plot}{'key_y'}); |
| 680 |
Ifeffit::put_scalar('&plot_key_dy', $config{plot}{'key_dy'}); |
| 681 |
}; |
| 682 |
|
| 683 |
|
| 684 |
sub hide_show_plot_options { |
| 685 |
if ($plot_features{options_showing}) { |
| 686 |
$plotsel->packForget; |
| 687 |
$plot_features{options_showing} = 0; |
| 688 |
$po_left -> configure(-text=>'^'); |
| 689 |
$po_right -> configure(-text=>'^'); |
| 690 |
} else { |
| 691 |
$plotsel->pack(-fill => 'x', -side => 'bottom', -anchor=>'s'); |
| 692 |
$plot_features{options_showing} = 1; |
| 693 |
$po_left -> configure(-text=>'v'); |
| 694 |
$po_right -> configure(-text=>'v'); |
| 695 |
}; |
| 696 |
}; |
| 697 |
|
| 698 |
sub detach_plot { |
| 699 |
#eval {Tk::Wm->release}; |
| 700 |
$plot_menu->menu->entryconfigure(12, -state=>'disabled'); |
| 701 |
#$top->update; |
| 702 |
#$detached_plot->deiconify; |
| 703 |
#$detached_plot->raise; |
| 704 |
#$b_frame -> pack(-in=>$detached_plot); |
| 705 |
$b_frame->packForget; |
| 706 |
$b_frame->wmRelease; |
| 707 |
$b_frame->raise; |
| 708 |
$b_frame->MainWindow::protocol('WM_DELETE_WINDOW', \&reattach_plot); |
| 709 |
$b_frame->MainWindow::title('Athena: plot buttons'); |
| 710 |
$b_frame->MainWindow::iconimage($iconimage); |
| 711 |
$replace = $b_frame -> |
| 712 |
Button(-text=>'Replace', |
| 713 |
-font=>$config{fonts}{smbold}, @button_list, |
| 714 |
-command => \&reattach_plot) |
| 715 |
-> pack(-expand=>1, -fill=>'x', -padx=>4, -pady=>4); |
| 716 |
$b_frame->MainWindow::deiconify; |
| 717 |
}; |
| 718 |
|
| 719 |
sub reattach_plot { |
| 720 |
Echonow("Replacing the plot buttons may take a few seconds..."); |
| 721 |
$replace -> packForget; |
| 722 |
$b_frame -> wmCapture; |
| 723 |
$b_frame -> pack(-after=>$po, -anchor=>'n', -fill=>'x'); |
| 724 |
$plot_menu->menu->entryconfigure(12, -state=>'normal'); |
| 725 |
$top -> update; |
| 726 |
Echonow("Replaced plot buttons!"); |
| 727 |
}; |
| 728 |
|
| 729 |
## END OF PLOTTING SUBSECTION |
| 730 |
########################################################################################## |