| 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 |
## writing project files |
| 7 |
|
| 8 |
|
| 9 |
sub save_project { |
| 10 |
Echo('No data!'), return unless ($current); |
| 11 |
my $save = lc($_[0]); |
| 12 |
if ($save eq 'marked') { |
| 13 |
my $m = 0; |
| 14 |
map {$m += $_} values %marked; |
| 15 |
Error("Saving marked groups aborted. There are no marked groups."), return 1 unless ($m); |
| 16 |
}; |
| 17 |
my $file; |
| 18 |
my $curr = $current; |
| 19 |
my $how = 2; |
| 20 |
if (($save ne 'all quick') or ($project_name =~ /^\s*$/)) { |
| 21 |
my $path = $current_data_dir || Cwd::cwd; |
| 22 |
my $init = 'athena.prj'; |
| 23 |
if ($project_name !~ /^\s*$/) { |
| 24 |
my $suff; |
| 25 |
($init, $path, $suff) = fileparse($project_name); |
| 26 |
}; |
| 27 |
local $Tk::FBox::a; |
| 28 |
local $Tk::FBox::b; |
| 29 |
my $types = [['Athena project files', '.prj'], |
| 30 |
['All Files', '*'],]; |
| 31 |
$file = $top -> getSaveFile(-defaultextension=>'.prj', |
| 32 |
-filetypes=>$types, |
| 33 |
#(not $is_windows) ? |
| 34 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 35 |
-initialdir=>$path, |
| 36 |
-initialfile=>$init, |
| 37 |
-title => "Athena: Save project"); |
| 38 |
return unless $file; |
| 39 |
#my ($name, $pth, $suffix) = fileparse($file); |
| 40 |
#$current_data_dir = $pth; |
| 41 |
if ($save eq 'marked') { |
| 42 |
&push_mru($file, 1, 0); |
| 43 |
} else { |
| 44 |
&push_mru($file, 1, 1, 1); |
| 45 |
}; |
| 46 |
} else { |
| 47 |
$file = $project_name; |
| 48 |
}; |
| 49 |
##open REC, '>'.$file or die $!; |
| 50 |
open REC, '>'.$file or do { |
| 51 |
Error("You cannot write to \"$file\"."); return |
| 52 |
}; |
| 53 |
$top -> Busy(-recurse=>1,); |
| 54 |
local $| = 1; |
| 55 |
print REC "# Athena project file -- Athena version $VERSION\n"; |
| 56 |
print REC $groups{$current} -> project_header; |
| 57 |
close REC; |
| 58 |
my $save_groupreplot = $config{general}{groupreplot}; |
| 59 |
$config{general}{groupreplot} = 'none'; |
| 60 |
my @keys = &sorted_group_list; |
| 61 |
foreach (@keys) { |
| 62 |
next if ($_ eq "Default Parameters"); |
| 63 |
next if (($save eq 'marked') and (not $marked{$_})); |
| 64 |
set_properties(0, $_, 1); |
| 65 |
save_record($file, $how++, 0, $save); |
| 66 |
}; |
| 67 |
open REC, '>>'.$file or die $!; |
| 68 |
my $journal = $notes{journal} -> get(qw(1.0 end)); |
| 69 |
my $eol = $/; |
| 70 |
my $colon = ":"; |
| 71 |
my $end = "End"; |
| 72 |
my $lv = ucfirst("local "); |
| 73 |
my @journal = split(/$eol/, $journal); |
| 74 |
print REC Data::Dumper->Dump([\@journal], [qw/*journal/]), "\n\n"; |
| 75 |
print REC Data::Dumper->Dump([\%plot_features], [qw/*plot_features/]), "\n\n"; |
| 76 |
my @indic = (0); |
| 77 |
foreach (1 .. $#indicator) { |
| 78 |
push @indic, ["", $indicator[$_]->[1], $indicator[$_]->[2]] |
| 79 |
}; |
| 80 |
print REC Data::Dumper->Dump([\@indic], [qw/*indicator/]), "\n\n"; |
| 81 |
print REC Data::Dumper->Dump([\%lcf_data], [qw/*lcf_data/]), "\n\n"; |
| 82 |
$lv .= "Var" . "iables"; |
| 83 |
print REC "\n1;\n\n# $lv$colon\n# truncate-lines$colon t\n# End$colon\n"; |
| 84 |
close REC; |
| 85 |
if ($config{general}{compress_prj}) { |
| 86 |
Echo("Compressing $file"); |
| 87 |
my $stash = File::Spec->catfile($stash_dir, basename($file)); |
| 88 |
move($file, $stash); |
| 89 |
my $gz = gzopen($stash, 'rb'); |
| 90 |
my $gzout = gzopen($file, 'wb9'); |
| 91 |
my $buffer; |
| 92 |
$gzout->gzwrite($buffer) while $gz->gzread($buffer) > 0 ; |
| 93 |
$gz->gzclose; |
| 94 |
$gzout->gzclose; |
| 95 |
unlink $stash; |
| 96 |
}; |
| 97 |
set_properties(1, $curr, 1); |
| 98 |
$config{general}{groupreplot} = $save_groupreplot; |
| 99 |
project_state(1) unless ($save eq 'marked'); |
| 100 |
($save =~ /all/) and Echo("Saved entire project to $file", 0); |
| 101 |
($save eq 'marked') and Echo("Saved all marked groups to $file", 0); |
| 102 |
$top->Unbusy; |
| 103 |
}; |
| 104 |
|
| 105 |
sub read_record { |
| 106 |
my ($plot, $file, $old_group, $ra, $rx, $ry, $rstddev, $ri0) = @_; |
| 107 |
my $gp = ""; |
| 108 |
my @args = @$ra; my @x = @$rx; my @y = @$ry; my @stddev = @$rstddev; my @i0 = @$ri0; |
| 109 |
|
| 110 |
## deal with backward compatibility issues in the parameters |
| 111 |
## |
| 112 |
## need to accommodate the change to (groupname != listentry) in |
| 113 |
## 0.8.009 without breaking old project files. search ahead in |
| 114 |
## @args for the label string and use it, if found. otherwise use |
| 115 |
## the old group name as the argument to group_name |
| 116 |
## |
| 117 |
## there is a chance that a project file comes from a version of |
| 118 |
## athena between when I introduced peak fitting and when I made the |
| 119 |
## main window modal. I need to check that values of "fit |
| 120 |
## amplitude" and "set amplitude" (from peak fitting) are changed to |
| 121 |
## "fit amp." and "set amp." |
| 122 |
## |
| 123 |
## then in 0.8.028 I change "arctangent" to "atan" and so on. |
| 124 |
my $old_label = $old_group; |
| 125 |
my $is_frozen = 0; |
| 126 |
foreach (0 .. $#args) { |
| 127 |
next unless defined $args[$_]; # undef is a possible value in @args |
| 128 |
if ($args[$_] eq 'label') { |
| 129 |
$old_label = $args[$_+1]; |
| 130 |
next; |
| 131 |
} elsif ($args[$_] =~ /(fit|set) amplitude(.*)/) { |
| 132 |
$args[$_] = $1 . " amp." . $2; |
| 133 |
} elsif ($args[$_] =~ /peak_step/) { # this is to accommodate a |
| 134 |
$args[$_] =~ s/step/function/; # small change to peakfitting |
| 135 |
# for 0.8.018 |
| 136 |
} elsif (lc($args[$_]) =~ /arctangent/) { |
| 137 |
$args[$_] = 'atan'; |
| 138 |
} elsif (lc($args[$_]) =~ /error/) { |
| 139 |
$args[$_] = 'erf'; |
| 140 |
} elsif (lc($args[$_]) =~ /gauss/) { |
| 141 |
$args[$_] = 'gauss'; |
| 142 |
} elsif (lc($args[$_]) =~ /loren/) { |
| 143 |
$args[$_] = 'loren'; |
| 144 |
} elsif ($args[$_] eq 'frozen') { # need to turn off frozen-ness until the |
| 145 |
$is_frozen = $args[$_+1]; # record is imported |
| 146 |
$args[$_+1] = 0; |
| 147 |
}; |
| 148 |
}; |
| 149 |
|
| 150 |
my ($group, $label) = group_name($old_label); |
| 151 |
$label =~ s{[\"\']}{}g; |
| 152 |
++$line_count; |
| 153 |
$groups{$group} = Ifeffit::Group -> new(file=>$file, group=>$group, label=>$label); |
| 154 |
$groups{$group} -> make(@args); |
| 155 |
$groups{$group} -> make(line=>$line_count, old_group=>$old_group); |
| 156 |
$groups{$group} -> make(is_rec=>1, is_raw=>0, update_bkg=>1, is_proj=>1); |
| 157 |
$groups{$group} -> make(i0 => "$group.i0") if (@i0); |
| 158 |
$groups{$group} -> put_titles; |
| 159 |
my ($x, $y, $z) = (0, 0, 0); |
| 160 |
SWITCH: { |
| 161 |
($x,$y) = ('.energy', '.det'), last SWITCH if $groups{$group}->{not_data}; |
| 162 |
($x,$y) = ('.energy', '.xmu'), last SWITCH if $groups{$group}->{is_xmu}; |
| 163 |
($x,$y) = ('.k', '.chi'), last SWITCH if $groups{$group}->{is_chi}; |
| 164 |
($x,$y,$z) = ('.r', '.chir_re', '.chir_im'), last SWITCH if $groups{$group}->{is_rsp}; |
| 165 |
($x,$y,$z) = ('.q', '.chiq_re', '.chiq_im'), last SWITCH if $groups{$group}->{is_qsp}; |
| 166 |
}; |
| 167 |
Ifeffit::put_array($group.$x, \@x); |
| 168 |
Ifeffit::put_array($group.$y, \@y); |
| 169 |
Ifeffit::put_array("$group.stddev", \@stddev) if (@stddev); |
| 170 |
Ifeffit::put_array("$group.i0", \@i0) if (@i0); |
| 171 |
##($z) and Ifeffit::put_array($group.$z, \@z); |
| 172 |
|
| 173 |
## fill_skinny unsets this parameter and it needs to be dealt with |
| 174 |
## after the entire project is read |
| 175 |
my $save_stan = $groups{$group}->{bkg_stan}; |
| 176 |
fill_skinny($list, $group, 1); |
| 177 |
$groups{$group}->make(bkg_stan=>$save_stan); |
| 178 |
if ($is_frozen) { # turn frozen-ness back on |
| 179 |
$groups{$group}->freeze; |
| 180 |
freeze_chores($group); |
| 181 |
}; |
| 182 |
($gp) or ($gp = $group); |
| 183 |
return $group unless $plot; |
| 184 |
# what about reading r or q records? |
| 185 |
SWITCH: { |
| 186 |
($groups{$gp}->{is_xmu}) and do { |
| 187 |
$groups{$gp} -> plotE('emz',$dmode,\%plot_features, \@indicator); |
| 188 |
$last_plot = 'e'; |
| 189 |
$last_plot_params = [$gp, 'group', 'e', 'emz']; |
| 190 |
last SWITCH; |
| 191 |
}; |
| 192 |
($groups{$gp}->{is_chi}) and do { |
| 193 |
#my $str = sprintf('k%1d', $groups{$gp}->{fft_kw}); |
| 194 |
my $str = sprintf('k%1d', $plot_features{kw}); |
| 195 |
$groups{$gp} -> plotk($str,$dmode,\%plot_features, \@indicator); |
| 196 |
$last_plot = 'k'; |
| 197 |
$last_plot_params = [$gp, 'group', 'k', $str]; |
| 198 |
last SWITCH; |
| 199 |
}; |
| 200 |
}; |
| 201 |
return $group; |
| 202 |
}; |
| 203 |
|
| 204 |
|
| 205 |
## the call to save_record takes three arguments: |
| 206 |
## 1st: filename or nil to prompt for filename |
| 207 |
## 2nd: 0=open file to overwite, 1=open file to append |
| 208 |
## 3rd: 0=save record as record type, 1=force saving as chi(k) |
| 209 |
|
| 210 |
## save a record as a Data::Dumper file. This contains four lvalues, |
| 211 |
## 1) the group name from this session, 2) an array of parameters, 3) |
| 212 |
## an x-array, 4) a y-array. The x- and y-arrays are appropriate to |
| 213 |
## the initial state of the data (i.e. the intial state of raw data is |
| 214 |
## energy/xmu and the initial state of merged chi(k) data is k/chi). |
| 215 |
sub save_record { |
| 216 |
Echo('No data!'), return unless ($current); |
| 217 |
Echo("Saving records is unsupported for R- and q-space data", 0), return |
| 218 |
if (($groups{$current}->{is_rsp}) or ($groups{$current}->{is_qsp})); |
| 219 |
Echonow("Saving record for group \"$groups{$current}->{label}\"", 0); |
| 220 |
my ($file, $how, $force_chik, $save) = @_; |
| 221 |
#my $how = ((defined $_[1]) and $_[1]) ? $_[1] : 0; |
| 222 |
#if (defined $_[0] and $_[0]) { |
| 223 |
# $file = $_[0]; # File::Spec->catfile($current_data_dir, $_[0].".rec"); |
| 224 |
#} else { |
| 225 |
unless ($file) { |
| 226 |
local $Tk::FBox::a; |
| 227 |
local $Tk::FBox::b; |
| 228 |
my $path = $current_data_dir || Cwd::cwd; |
| 229 |
my $fname = ($force_chik) ? $current . "_chik.rec" : "$current.rec"; |
| 230 |
my $types = [['Athena record files', '.rec'], |
| 231 |
['All Files', '*'],]; |
| 232 |
$file = $top -> getSaveFile(-defaultextension=>'rec', |
| 233 |
-filetypes=>$types, |
| 234 |
#(not $is_windows) ? |
| 235 |
# (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 236 |
-initialdir=>$path, |
| 237 |
-initialfile=>$fname, |
| 238 |
-title => "Athena: Save record"); |
| 239 |
Echonow("Saving record for group \"$groups{$current}->{label}\" ... canceled", 0), return |
| 240 |
unless $file; |
| 241 |
my ($name, $pth, $suffix) = fileparse($file); |
| 242 |
$current_data_dir = $pth; |
| 243 |
##&push_mru($file, 1); |
| 244 |
}; |
| 245 |
refresh_titles($groups{$current}); # make sure titles are up-to-date |
| 246 |
my @args = (); |
| 247 |
foreach (sort keys(%{$groups{$current}})) { |
| 248 |
next if ($_ =~ /\b([ex]col|check(button)?|group|id|rect|text)\b/); |
| 249 |
next if ($_ eq 'made_pixel'); |
| 250 |
next if ($_ =~ /^update/); |
| 251 |
next if ($_ eq "project_marked"); |
| 252 |
##next if ($_ =~ /^title/); |
| 253 |
if (($save eq 'marked') and ($_ eq 'reference') and ($groups{$current}->{reference})) { |
| 254 |
my $ref = $groups{$current}->{reference}; |
| 255 |
next unless $marked{$ref}; |
| 256 |
}; |
| 257 |
push @args, $_, $groups{$current}->{$_}; |
| 258 |
}; |
| 259 |
push @args, "project_marked", $marked{$current}; |
| 260 |
## need to update from titles palette |
| 261 |
## my @titles = @{$groups{$current}->{titles}}; |
| 262 |
my (@x, @y, @z, @stddev, @i0); |
| 263 |
SWITCH: { |
| 264 |
($force_chik) and do { |
| 265 |
$groups{$current}->dispatch_bkg($dmode) if $groups{$current}->{update_bkg}; |
| 266 |
@x = Ifeffit::get_array($current.".k"); |
| 267 |
@y = Ifeffit::get_array($current.".chi"); |
| 268 |
## need to flag this as a chi record -- appending new values to |
| 269 |
## the end of @args is cheesy, but it works |
| 270 |
push @args, qw(is_chi 1 is_bkg 0 is_xmu 0 is_nor 0 is_merge 0); |
| 271 |
last SWITCH; |
| 272 |
}; |
| 273 |
($groups{$current}->{not_data}) and do { |
| 274 |
@x = Ifeffit::get_array($current.".energy"); |
| 275 |
## @x = map {$_ + $groups{$current}->{bkg_eshift}} @x; |
| 276 |
@y = Ifeffit::get_array($current.".det"); |
| 277 |
last SWITCH; |
| 278 |
}; |
| 279 |
($groups{$current}->{is_xmu}) and do { |
| 280 |
@x = Ifeffit::get_array($current.".energy"); |
| 281 |
## @x = map {$_ + $groups{$current}->{bkg_eshift}} @x; |
| 282 |
@y = Ifeffit::get_array($current.".xmu"); |
| 283 |
@i0 = Ifeffit::get_array($groups{$current}->{i0}) if ($groups{$current}->{i0}); |
| 284 |
last SWITCH; |
| 285 |
}; |
| 286 |
($groups{$current}->{is_chi}) and do { |
| 287 |
@x = Ifeffit::get_array($current.".k"); |
| 288 |
@y = Ifeffit::get_array($current.".chi"); |
| 289 |
last SWITCH; |
| 290 |
}; |
| 291 |
($groups{$current}->{is_rsp}) and do { |
| 292 |
@x = Ifeffit::get_array($current.".r"); |
| 293 |
@y = Ifeffit::get_array($current.".chir_re"); |
| 294 |
@z = Ifeffit::get_array($current.".chir_im"); |
| 295 |
last SWITCH; |
| 296 |
}; |
| 297 |
($groups{$current}->{is_qsp}) and do { |
| 298 |
@x = Ifeffit::get_array($current.".q"); |
| 299 |
@y = Ifeffit::get_array($current.".chiq_re"); |
| 300 |
@z = Ifeffit::get_array($current.".chiq_im"); |
| 301 |
last SWITCH; |
| 302 |
}; |
| 303 |
}; |
| 304 |
## what about chi(k) records with stddev??? |
| 305 |
if ((not $force_chik) and $groups{$current}->{is_merge}) { |
| 306 |
@stddev = Ifeffit::get_array($current.".stddev"); |
| 307 |
}; |
| 308 |
my $open = ($how > 1) ? '>>' : '>'; |
| 309 |
my $arg = (($how == 0) or ($how == 2)) ? 1 : 0; |
| 310 |
open REC, $open.$file or do { |
| 311 |
Error("You cannot write to \"$file\"."); return |
| 312 |
}; |
| 313 |
($how) or print REC "# Athena record file -- Athena version $VERSION\n"; |
| 314 |
($how) or print REC $groups{$current} -> project_header(); |
| 315 |
print REC |
| 316 |
Data::Dumper->Dump([$current], [qw/old_group/]), "\n", |
| 317 |
Data::Dumper->Dump([\@args], [qw/*args/]), "\n", |
| 318 |
Data::Dumper->Dump([\@x], [qw/*x/]), "\n", |
| 319 |
Data::Dumper->Dump([\@y], [qw/*y/]), "\n"; |
| 320 |
print REC Data::Dumper->Dump([\@stddev],[qw/*stddev/]), "\n" if @stddev; |
| 321 |
print REC Data::Dumper->Dump([\@i0], [qw/*i0/]), "\n" if $groups{$current}->{i0}; |
| 322 |
print REC "[record] # create object and set arrays in ifeffit\n\n"; |
| 323 |
unless ($how) { |
| 324 |
|
| 325 |
my $colon = ":"; |
| 326 |
my $end = "End"; |
| 327 |
my $lv = ucfirst("local "); |
| 328 |
$lv .= "Var" . "iables"; |
| 329 |
print REC "\n1;\n\n# $lv$colon\n# truncate-lines$colon t\n# End$colon\n"; |
| 330 |
}; |
| 331 |
close REC; |
| 332 |
Echonow("Wrote record to $file", 0); |
| 333 |
}; |
| 334 |
|
| 335 |
|
| 336 |
sub close_project { |
| 337 |
reset_window($which_showing, $fat_showing, 0) unless ($fat_showing eq 'normal'); |
| 338 |
delete_many($list, $dmode, 0); |
| 339 |
project_state(1); |
| 340 |
$plot_features{project} = q{}; |
| 341 |
}; |
| 342 |
|
| 343 |
sub clear_project_name { |
| 344 |
$plot_features{project} = q{}; |
| 345 |
$project_name = q{}; |
| 346 |
project_state(0); |
| 347 |
}; |
| 348 |
|
| 349 |
## state=0 -> project needs to be saved state=1 -> project has been saved |
| 350 |
sub project_state { |
| 351 |
return unless $current; |
| 352 |
##$_[0] || print join(" ", caller), $/; |
| 353 |
$project_saved = $_[0]; |
| 354 |
$lab -> configure(-text => ($_[0]) ? "" : "modified",); |
| 355 |
return if ($current eq "Default Parameters"); |
| 356 |
autoreplot() if $config{general}{autoreplot}; |
| 357 |
section_indicators(); |
| 358 |
}; |
| 359 |
|
| 360 |
|
| 361 |
sub examine_project { |
| 362 |
my ($prjfile, $r_hash, $r_cancel, $r_project_no_prompt) = @_; |
| 363 |
my @athena_index = (); |
| 364 |
my @athena_groups = (); |
| 365 |
my $titles; |
| 366 |
|
| 367 |
my $prj = $top->Toplevel(-class=>'horae'); |
| 368 |
$prj -> withdraw; |
| 369 |
$prj -> title("Athena: import from project file"); |
| 370 |
$prj -> protocol(WM_DELETE_WINDOW => sub{$$r_cancel = 1; $prj->destroy; return}); |
| 371 |
$prj -> packPropagate(1); |
| 372 |
$prj -> bind('<Control-q>' => sub{$$r_cancel = 1; $prj->destroy; return}); |
| 373 |
$prj -> bind('<Control-d>' => sub{$$r_cancel = 1; $prj->destroy; return}); |
| 374 |
|
| 375 |
$prj -> Label(-text => $prjfile, |
| 376 |
-foreground => $config{colors}{activehighlightcolor}, |
| 377 |
-font => $config{fonts}{bold}, |
| 378 |
-borderwidth=> 2, |
| 379 |
-relief => 'ridge', |
| 380 |
) |
| 381 |
-> pack(-side=>'top', -fill=>'x', -padx=>0, -pady=>0); |
| 382 |
|
| 383 |
my $labframe = $prj -> LabFrame(-label=>'Project groups', |
| 384 |
-labelside=>'acrosstop', |
| 385 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 386 |
-> pack(-side=>'left', -expand=>1, -fill=>'both', -anchor=>'w'); |
| 387 |
|
| 388 |
my $hlist; |
| 389 |
$hlist = $labframe -> Scrolled('HList', |
| 390 |
-scrollbars => 'osoe', |
| 391 |
-columns => 1, |
| 392 |
-header => 0, |
| 393 |
-selectmode => 'extended', |
| 394 |
-width => 25, |
| 395 |
-height => 30, |
| 396 |
-background => $config{colors}{hlist}, |
| 397 |
#-highlightcolor => $config{colors}{hlist}, |
| 398 |
-selectbackground => $config{colors}{current}, |
| 399 |
-browsecmd => |
| 400 |
sub { |
| 401 |
## only plot if this selection is |
| 402 |
## also the anchor |
| 403 |
return if $hlist->info('anchor') ne $_[0]; |
| 404 |
project_plot($hlist, $titles, $prjfile); |
| 405 |
}, |
| 406 |
) |
| 407 |
-> pack(-expand=>1, -fill=>'both'); |
| 408 |
$hlist->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}, |
| 409 |
($is_windows) ? () : (-width=>8)); |
| 410 |
$hlist->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background}, |
| 411 |
($is_windows) ? () : (-width=>8)); |
| 412 |
BindMouseWheel($hlist); |
| 413 |
|
| 414 |
my $fr = $prj -> Frame() |
| 415 |
-> pack(-side=>'right', -expand=>1, -fill=>'both', -anchor=>'n'); |
| 416 |
$labframe = $fr -> LabFrame(-label=>'Journal', |
| 417 |
-labelside=>'acrosstop', |
| 418 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 419 |
-> pack(-side=>'top', -fill=>'both', -padx=>0, -pady=>0); |
| 420 |
my $journal = $labframe -> Scrolled('ROText', |
| 421 |
-scrollbars => 'osoe', |
| 422 |
-wrap => 'none', |
| 423 |
-height => 12,) |
| 424 |
-> pack(-expand=>1, -fill=>'both'); |
| 425 |
$journal->Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}, |
| 426 |
($is_windows) ? () : (-width=>8)); |
| 427 |
$journal->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background}, |
| 428 |
($is_windows) ? () : (-width=>8)); |
| 429 |
$journal -> tagConfigure("text", -font=>$config{fonts}{fixedsm}); |
| 430 |
BindMouseWheel($journal); |
| 431 |
disable_mouse3($journal->Subwidget("rotext")); |
| 432 |
|
| 433 |
## selection buttons |
| 434 |
my $button_frame = $fr -> LabFrame(-label=>'Select groups', |
| 435 |
-labelside=>'acrosstop', |
| 436 |
-foreground=>$config{colors}{activehighlightcolor}) |
| 437 |
-> pack(-side=>'top', -expand=>1, -fill=>'x', -padx=>0, -pady=>0); |
| 438 |
$button_frame -> Button(-text => "All", |
| 439 |
@button_list, |
| 440 |
-width => 8, |
| 441 |
-borderwidth => 1, |
| 442 |
-command => sub{ $hlist->selectionSet(@athena_index[0,-1]) }, |
| 443 |
) |
| 444 |
-> pack(-side=>'left', -expand=>1, -fill=>'x', -padx=>4, -pady=>4); |
| 445 |
$button_frame -> Button(-text => "None", |
| 446 |
@button_list, |
| 447 |
-width => 8, |
| 448 |
-borderwidth => 1, |
| 449 |
-command => sub{{$hlist->selectionClear(); |
| 450 |
$hlist->anchorClear();} }, |
| 451 |
) |
| 452 |
-> pack(-side=>'left', -expand=>1, -fill=>'x', -padx=>4, -pady=>4); |
| 453 |
$button_frame -> Button(-text => "Invert", |
| 454 |
@button_list, |
| 455 |
-width => 8, |
| 456 |
-borderwidth => 1, |
| 457 |
-command => |
| 458 |
sub{ |
| 459 |
foreach my $i (@athena_index) { |
| 460 |
($hlist->selectionIncludes($i)) ? |
| 461 |
$hlist->selectionClear($i) : |
| 462 |
$hlist->selectionSet($i); |
| 463 |
}; |
| 464 |
}, |
| 465 |
) |
| 466 |
-> pack(-side=>'left', -expand=>1, -fill=>'x', -padx=>4, -pady=>4); |
| 467 |
|
| 468 |
$labframe = $fr -> LabFrame(-label => 'Selected group titles', |
| 469 |
-labelside => 'acrosstop', |
| 470 |
-foreground => $config{colors}{activehighlightcolor}) |
| 471 |
-> pack(-side=>'top', -expand=>1, -fill=>'both', -padx=>0, -pady=>0); |
| 472 |
$titles = $labframe -> Scrolled('ROText', |
| 473 |
-scrollbars => 'osoe', |
| 474 |
-wrap => 'none', |
| 475 |
-height => 12,) |
| 476 |
-> pack(-expand=>1, -fill=>'both'); |
| 477 |
$titles -> Subwidget("xscrollbar")->configure(-background=>$config{colors}{background}, |
| 478 |
($is_windows) ? () : (-width=>8)); |
| 479 |
$titles -> Subwidget("yscrollbar")->configure(-background=>$config{colors}{background}, |
| 480 |
($is_windows) ? () : (-width=>8)); |
| 481 |
$titles -> tagConfigure("text", -font=>$config{fonts}{fixedsm}); |
| 482 |
$titles -> tagConfigure("explain", -font=>$config{fonts}{fixedsm}, -foreground=>$config{colors}{button}); |
| 483 |
BindMouseWheel($titles); |
| 484 |
disable_mouse3($titles->Subwidget("rotext")); |
| 485 |
|
| 486 |
|
| 487 |
## ok/cancel buttons |
| 488 |
$button_frame = $fr -> Frame() |
| 489 |
-> pack(-side=>'bottom', -fill=>'x', -padx=>0, -pady=>0); |
| 490 |
$button_frame -> Button(-text => "Import", |
| 491 |
@button_list, |
| 492 |
-width => 8, |
| 493 |
-borderwidth => 1, |
| 494 |
-command => |
| 495 |
sub { |
| 496 |
my $n_selected = 0; |
| 497 |
## import bkg removal standards as well |
| 498 |
foreach my $i (@athena_index) { |
| 499 |
next if not $hlist->selectionIncludes($i); |
| 500 |
my %args = project_get_array($prjfile, $i, "args"); |
| 501 |
next if ($args{bkg_stan} eq 'None'); |
| 502 |
my $j = 0; |
| 503 |
foreach my $og (@athena_groups) { |
| 504 |
if ($og eq $args{bkg_stan}) { |
| 505 |
$hlist->selectionSet($athena_index[$j]); |
| 506 |
last; |
| 507 |
}; |
| 508 |
++$j; |
| 509 |
}; |
| 510 |
}; |
| 511 |
foreach my $i (@athena_index) { |
| 512 |
++$n_selected if $hlist->selectionIncludes($i); |
| 513 |
}; |
| 514 |
$hlist->selectionSet(@athena_index[0,-1]) if not $n_selected; |
| 515 |
if (($n_selected == 0) or ($n_selected == $#athena_index+1)) { |
| 516 |
$$r_project_no_prompt = 1; |
| 517 |
}; |
| 518 |
my $c = 0; |
| 519 |
foreach my $i (@athena_index) { |
| 520 |
$$r_hash{$athena_groups[$c]} = ($hlist->selectionIncludes($i)) ? 1 : 0; |
| 521 |
++$c; |
| 522 |
}; |
| 523 |
$$r_cancel = 0; |
| 524 |
$prj->destroy; |
| 525 |
return(()); |
| 526 |
}, |
| 527 |
) |
| 528 |
-> pack(-side=>'left', -expand=>1, -fill=>'x', -padx=>4, -pady=>4) |
| 529 |
-> focus; |
| 530 |
$button_frame -> Button(-text => "Quick help", |
| 531 |
@button_list, |
| 532 |
-width => 8, |
| 533 |
-borderwidth => 1, |
| 534 |
-command => sub{project_quick_help($titles)}, |
| 535 |
) |
| 536 |
-> pack(-side=>'left', -expand=>1, -fill=>'x', -padx=>4, -pady=>4); |
| 537 |
$button_frame -> Button(-text => "Cancel", |
| 538 |
@button_list, |
| 539 |
-width => 8, |
| 540 |
-borderwidth => 1, |
| 541 |
-command => sub{$$r_cancel = 1; $prj->destroy; return(())}, |
| 542 |
) |
| 543 |
-> pack(-side=>'right', -expand=>1, -fill=>'x', -padx=>4, -pady=>4); |
| 544 |
|
| 545 |
|
| 546 |
my $athena_fh = gzopen($prjfile, "rb") or die "could not open $prjfile as an Athena project\n"; |
| 547 |
|
| 548 |
my $nline = 0; |
| 549 |
my $line = q{}; |
| 550 |
##while (<ORIG>) { |
| 551 |
my $cpt = new Safe; |
| 552 |
my $bytesread; |
| 553 |
PRJ: while (($bytesread = $athena_fh->gzreadline($line)) > 0) { |
| 554 |
my $error = $athena_fh->gzerror; |
| 555 |
++$nline; |
| 556 |
if ($line =~ /^\@journal/) { |
| 557 |
@ {$cpt->varglob('journal')} = $cpt->reval( $line ); |
| 558 |
my @journal = @ {$cpt->varglob('journal')}; |
| 559 |
map { $journal -> insert('end', $_."\n", 'text') } @journal; |
| 560 |
}; |
| 561 |
##print $bytesread, " ", $error, $/; |
| 562 |
if ( (($bytesread < 0) or $error) and ($gzerrno != Z_STREAM_END) ) { |
| 563 |
pop @athena_groups; |
| 564 |
pop @athena_index; |
| 565 |
project_error($titles, $error); |
| 566 |
Error("An error was found while reading \"$prjfile\"."); |
| 567 |
last PRJ; |
| 568 |
}; |
| 569 |
next unless ($line =~ /^\$old_group/); |
| 570 |
push @athena_index, $nline; |
| 571 |
$ {$cpt->varglob('old_group')} = $cpt->reval($line); |
| 572 |
my $old_group = $ {$cpt->varglob('old_group')}; |
| 573 |
push @athena_groups, $old_group; |
| 574 |
$$r_hash{$old_group} = 0; |
| 575 |
}; |
| 576 |
$athena_fh->gzclose(); |
| 577 |
undef $cpt; |
| 578 |
|
| 579 |
foreach my $i (@athena_index) { |
| 580 |
my %args = project_get_array($prjfile, $i, "args"); |
| 581 |
$args{label} =~ s{[\"\']}{}g; |
| 582 |
$hlist -> add($i, -data=>$i); |
| 583 |
$hlist -> itemCreate($i, 0, -text=>$args{label}); |
| 584 |
}; |
| 585 |
|
| 586 |
if ($$r_project_no_prompt) { |
| 587 |
$hlist->selectionSet(@athena_index[0,-1]); |
| 588 |
my $c = 0; |
| 589 |
foreach my $i (@athena_index) { |
| 590 |
$$r_hash{$athena_groups[$c]} = ($hlist->selectionIncludes($i)) ? 1 : 0; |
| 591 |
++$c; |
| 592 |
}; |
| 593 |
$$r_cancel = 0; |
| 594 |
$prj->destroy; |
| 595 |
return 0; |
| 596 |
} else { |
| 597 |
$prj->deiconify; |
| 598 |
$prj->raise; |
| 599 |
}; |
| 600 |
return $prj; |
| 601 |
|
| 602 |
}; |
| 603 |
|
| 604 |
|
| 605 |
sub project_error { |
| 606 |
my ($titles, $error) = @_; |
| 607 |
$titles->delete(qw(1.0 end)); |
| 608 |
$titles->insert('end', " !!! WARNING !!!\n", 'explain'); |
| 609 |
my $message = " |
| 610 |
An error has been encountered reading this project file. It is |
| 611 |
likely that the file has been corrupted in some way. All data |
| 612 |
after the point of failure has been excluded from the groups list. |
| 613 |
|
| 614 |
The error returned by zlib is: |
| 615 |
$error |
| 616 |
"; |
| 617 |
$titles->insert('end', $message, 'explain'); |
| 618 |
}; |
| 619 |
|
| 620 |
|
| 621 |
sub project_get_array { |
| 622 |
my ($prjfile, $index, $which) = @_; |
| 623 |
my $cpt = new Safe; |
| 624 |
my @array; |
| 625 |
my $prj = gzopen($prjfile, "rb") or die "could not open $prjfile as an Athena project\n"; |
| 626 |
##open A, $prjfile; |
| 627 |
my $count = 0; |
| 628 |
my $found = 0; |
| 629 |
my $re = '@' . $which; |
| 630 |
my $line = q{}; |
| 631 |
##foreach my $line (<A>) { |
| 632 |
while ($prj->gzreadline($line) > 0) { |
| 633 |
++$count; |
| 634 |
$found = 1 if ($count == $index); |
| 635 |
next unless $found; |
| 636 |
last if ($line =~ /^\[record\]/); |
| 637 |
if ($line =~ /^$re/) { |
| 638 |
@ {$cpt->varglob('array')} = $cpt->reval( $line ); |
| 639 |
@array = @ {$cpt->varglob('array')}; |
| 640 |
last; |
| 641 |
}; |
| 642 |
}; |
| 643 |
$prj->gzclose(); |
| 644 |
##close A; |
| 645 |
return @array; |
| 646 |
}; |
| 647 |
|
| 648 |
sub project_plot { |
| 649 |
my ($hlist, $titles, $prjfile) = @_; |
| 650 |
$top -> Busy; |
| 651 |
my $n = $hlist->info('anchor'); |
| 652 |
my $i = $hlist->info('data', $n); |
| 653 |
my ($xlabel, $ylabel) = ("Energy (eV)", "x\\gm(E)"); |
| 654 |
|
| 655 |
## get the args hash |
| 656 |
my %args = project_get_array($prjfile, $i, "args"); |
| 657 |
if ($args{is_chi}) { |
| 658 |
($xlabel, $ylabel) = ("wavenumber (\\A\\u-1\\d)", "\\gx(k)*k\\u2\\d" ); |
| 659 |
} elsif ($args{not_data}) { |
| 660 |
($xlabel, $ylabel) = ("Energy (eV)", "data" ); |
| 661 |
} elsif ($args{is_bkg}) { |
| 662 |
($xlabel, $ylabel) = ("Energy (eV)", "background(E)" ); |
| 663 |
} elsif ($args{is_pixel}) { |
| 664 |
($xlabel, $ylabel) = ("pixel", "x\\gm(E)" ); |
| 665 |
}; |
| 666 |
|
| 667 |
## fill titles |
| 668 |
$titles->configure(-foreground=>$config{colors}{foreground}); |
| 669 |
$titles->delete(qw(1.0 end)); |
| 670 |
foreach my $t (@{ $args{titles} }) { |
| 671 |
$titles->insert('end', $t."\n", 'text'); |
| 672 |
}; |
| 673 |
|
| 674 |
## get the x- and y-axis arrays |
| 675 |
my @x = project_get_array($prjfile, $i, "x"); |
| 676 |
@x = map {$_ + $args{bkg_eshift}} @x if not $args{is_chi}; |
| 677 |
my @y = project_get_array($prjfile, $i, "y"); |
| 678 |
Ifeffit::put_array("p___rj.x", \@x); |
| 679 |
Ifeffit::put_array("p___rj.y", \@y); |
| 680 |
my $plot = ($args{is_chi}) # plot k^2 weighted chi(k) |
| 681 |
? "newplot(p___rj.x, \"p___rj.y*p___rj.x**2\"," |
| 682 |
: "newplot(p___rj.x, p___rj.y,"; |
| 683 |
$plot .= " title=\"$args{label}\", color=blue,"; |
| 684 |
$plot .= " xlabel=\"$xlabel\", ylabel=\"$ylabel\")\n"; |
| 685 |
|
| 686 |
Echo("Plotting group from project \"$args{label}\""); |
| 687 |
$groups{"Default Parameters"}->dispose($plot, $dmode); |
| 688 |
|
| 689 |
Echo("Plotting groups from project \"$args{label}\" ... done!"); |
| 690 |
$top -> Unbusy; |
| 691 |
} |
| 692 |
|
| 693 |
sub project_quick_help { |
| 694 |
my ($titles) = @_; |
| 695 |
my @hints = ("Click on a group to select and plot.", |
| 696 |
"Control-click to add a group to the selection.", |
| 697 |
"Shift-click or click-drag to select multiple groups.", |
| 698 |
"All groups will be imported if none are selected.",); |
| 699 |
|
| 700 |
$titles->delete(qw(1.0 end)); |
| 701 |
$titles->insert('end', "\n", 'explain'); |
| 702 |
foreach my $h (@hints) { |
| 703 |
$titles->insert('end', $h."\n\n", 'explain'); |
| 704 |
}; |
| 705 |
}; |
| 706 |
|
| 707 |
sub section_indicators { |
| 708 |
return unless $current; |
| 709 |
return unless (exists $groups{$current}); |
| 710 |
my ($blue, $cyan, $grey) = ($config{colors}{activehighlightcolor}, |
| 711 |
$config{colors}{requiresupdate}, |
| 712 |
$config{colors}{disabledforeground}); |
| 713 |
#($blue, $cyan) = ($config{colors}{frozen}, $config{colors}{frozenrequiresupdate}) if $groups{$current}->{frozen}; |
| 714 |
|
| 715 |
SWITCH:{ |
| 716 |
($groups{$current}->{is_xanes}) and do { |
| 717 |
$header{bkg} -> configure(-foreground=>($groups{$current}->{update_bkg}) ? $cyan : $blue); |
| 718 |
$header{bkg_secondary} -> configure(-foreground=>($groups{$current}->{update_bkg}) ? $cyan : $blue); |
| 719 |
$header{fft} -> configure(-foreground=>$grey); |
| 720 |
$header{bft} -> configure(-foreground=>$grey); |
| 721 |
last SWITCH; |
| 722 |
}; |
| 723 |
($groups{$current}->{is_xmu}) and do { |
| 724 |
$header{bkg} -> configure(-foreground=>($groups{$current}->{update_bkg}) ? $cyan : $blue); |
| 725 |
$header{bkg_secondary} -> configure(-foreground=>($groups{$current}->{update_bkg}) ? $cyan : $blue); |
| 726 |
$header{fft} -> configure(-foreground=>($groups{$current}->{update_fft}) ? $cyan : $blue); |
| 727 |
$header{bft} -> configure(-foreground=>($groups{$current}->{update_bft}) ? $cyan : $blue); |
| 728 |
last SWITCH; |
| 729 |
}; |
| 730 |
($groups{$current}->{is_chi}) and do { |
| 731 |
$header{bkg} -> configure(-foreground=>$grey); |
| 732 |
$header{bkg_secondary} -> configure(-foreground=>$grey); |
| 733 |
$header{fft} -> configure(-foreground=>($groups{$current}->{update_fft}) ? $cyan : $blue); |
| 734 |
$header{bft} -> configure(-foreground=>($groups{$current}->{update_bft}) ? $cyan : $blue); |
| 735 |
last SWITCH; |
| 736 |
}; |
| 737 |
($groups{$current}->{is_rsp}) and do { |
| 738 |
$header{bkg} -> configure(-foreground=>$grey); |
| 739 |
$header{bkg_secondary} -> configure(-foreground=>$grey); |
| 740 |
$header{fft} -> configure(-foreground=>$grey); |
| 741 |
$header{bft} -> configure(-foreground=>($groups{$current}->{update_bft}) ? $cyan : $blue); |
| 742 |
last SWITCH; |
| 743 |
}; |
| 744 |
($groups{$current}->{is_qsp}) and do { |
| 745 |
$header{bkg} -> configure(-foreground=>$grey); |
| 746 |
$header{bkg_secondary} -> configure(-foreground=>$grey); |
| 747 |
$header{fft} -> configure(-foreground=>$grey); |
| 748 |
$header{bft} -> configure(-foreground=>$grey); |
| 749 |
last SWITCH; |
| 750 |
}; |
| 751 |
($groups{$current}->{not_data}) and do { |
| 752 |
$header{bkg} -> configure(-foreground=>$grey); |
| 753 |
$header{bkg_secondary} -> configure(-foreground=>$grey); |
| 754 |
$header{fft} -> configure(-foreground=>$grey); |
| 755 |
$header{bft} -> configure(-foreground=>$grey); |
| 756 |
last SWITCH; |
| 757 |
}; |
| 758 |
}; |
| 759 |
|
| 760 |
}; |
| 761 |
|
| 762 |
## END OF PROJECT FILE SUBSECTION |
| 763 |
########################################################################################## |