| 1 |
# -*- cperl -*- |
| 2 |
## This file is part of Artemis, copyright (c) 2002-2006 Bruce Ravel |
| 3 |
## |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
###=================================================================== |
| 8 |
### record description subsystem |
| 9 |
###=================================================================== |
| 10 |
|
| 11 |
sub read_record { |
| 12 |
my $file = $_[0]; |
| 13 |
|
| 14 |
open PROJ, $file or die "could not open $file as a project file\n"; |
| 15 |
|
| 16 |
my $cpt = new Safe; |
| 17 |
use vars qw($old_path @args @strings @journal @plot_features @parameter); |
| 18 |
my $from_version = 0; |
| 19 |
while (<PROJ>) { |
| 20 |
if (/^\s*\#\s*Artemis project/) { |
| 21 |
my @list = split(" ",$_); |
| 22 |
$from_version = $list[$#list]; |
| 23 |
@list = split(/\./, $from_version); |
| 24 |
$from_version = $#list ? $list[0] . "." . $list[1] . $list[2] : "DR".$list[0]; |
| 25 |
$from_version =~ s/rc//; |
| 26 |
next; |
| 27 |
}; |
| 28 |
next if (/^\s*\#/); |
| 29 |
next if (/^\s*$/); |
| 30 |
|
| 31 |
SWITCH: { |
| 32 |
(/^\@parameter/) and do { |
| 33 |
@ {$cpt->varglob('parameter')} = $cpt->reval($_); |
| 34 |
@parameter = @ {$cpt->varglob('parameter')}; |
| 35 |
push @gds, Ifeffit::Parameter->new(name => $parameter[0], |
| 36 |
type => $parameter[1], |
| 37 |
mathexp => $parameter[2], |
| 38 |
note => $parameter[3], |
| 39 |
autonote => $parameter[4], |
| 40 |
); |
| 41 |
$gds[$#gds]->make(bestfit => $parameter[2]) if ($parameter[1] eq 'guess'); |
| 42 |
last SWITCH; |
| 43 |
}; |
| 44 |
(/^\@journal/) and do { |
| 45 |
## as of 0.7.004 the journal is saved in a file separate from |
| 46 |
## the description file. so this block is merely to read the |
| 47 |
## journal from the project file from before 0.7.004 |
| 48 |
@ {$cpt->varglob('journal')} = $cpt->reval($_); |
| 49 |
@journal = @ {$cpt->varglob('journal')}; |
| 50 |
$notes{journal} -> delete(qw(1.0 end)); |
| 51 |
foreach (@journal) { |
| 52 |
$notes{journal} -> insert('end', $_."\n"); |
| 53 |
}; |
| 54 |
open J, ">".File::Spec->catfile($project_folder, "descriptions", "journal.artemis"); |
| 55 |
map { print J $_, $/ } (@journal); |
| 56 |
print J $/; |
| 57 |
close J; |
| 58 |
last SWITCH; |
| 59 |
}; |
| 60 |
(/^\%plot_features/) and do { |
| 61 |
% {$cpt->varglob('plot_features')} = $cpt->reval($_); |
| 62 |
while (my ($k, $v) = each % {$cpt->varglob('plot_features')}) { |
| 63 |
$plot_features{$k} = $v; |
| 64 |
}; |
| 65 |
last SWITCH; |
| 66 |
}; |
| 67 |
(/^\@extra/) and do { |
| 68 |
@ {$cpt->varglob('extra')} = $cpt->reval($_); |
| 69 |
my @this = @ {$cpt->varglob('extra')}; |
| 70 |
@extra[0..6] = @this[0..6]; |
| 71 |
foreach (7 .. $#this) { |
| 72 |
$extra[$_]->[1] = $this[$_]->[0]; |
| 73 |
$extra[$_]->[2] = $this[$_]->[1]; |
| 74 |
}; |
| 75 |
#{ no warnings; |
| 76 |
# print join(" ", @extra), $/;}; |
| 77 |
last SWITCH; |
| 78 |
}; |
| 79 |
(/^\%props/) and do { |
| 80 |
% {$cpt->varglob('props')} = $cpt->reval($_); |
| 81 |
while (my ($k, $v) = each % {$cpt->varglob('props')}) { |
| 82 |
next if ($k eq 'Environment'); |
| 83 |
next if ($k eq 'Project location'); |
| 84 |
next if ($k eq 'Information content'); |
| 85 |
$props{$k} = $v; |
| 86 |
}; |
| 87 |
last SWITCH; |
| 88 |
}; |
| 89 |
(/^\$old_path/) and do { |
| 90 |
$ {$cpt->varglob('old_path')} = $cpt->reval($_); |
| 91 |
$old_path = $ {$cpt->varglob('old_path')}; |
| 92 |
@args = (); |
| 93 |
@strings = (); |
| 94 |
last SWITCH; |
| 95 |
}; |
| 96 |
(/^\@args/) and do { |
| 97 |
@ {$cpt->varglob('args')} = $cpt->reval($_); |
| 98 |
@args = @ {$cpt->varglob('args')}; |
| 99 |
last SWITCH; |
| 100 |
}; |
| 101 |
(/^\@strings/) and do { |
| 102 |
@ {$cpt->varglob('strings')} = $cpt->reval($_); |
| 103 |
@strings = @ {$cpt->varglob('strings')}; |
| 104 |
last SWITCH; |
| 105 |
}; |
| 106 |
(/^\[record\]/) and do { |
| 107 |
last SWITCH unless @args; |
| 108 |
&read_path(\$old_path, \@args, \@strings); |
| 109 |
last SWITCH; |
| 110 |
}; |
| 111 |
|
| 112 |
}; |
| 113 |
|
| 114 |
}; |
| 115 |
|
| 116 |
close PROJ; |
| 117 |
return $from_version; |
| 118 |
}; |
| 119 |
|
| 120 |
sub read_record_on_windows { |
| 121 |
my $file = $_[0]; |
| 122 |
|
| 123 |
open PROJ, $file or die "could not open $file as a project file\n"; |
| 124 |
|
| 125 |
my $cpt = new Safe; |
| 126 |
use vars qw($old_path @args @strings @journal @plot_features @parameter %foo); |
| 127 |
my $from_version = 0; |
| 128 |
while (<PROJ>) { |
| 129 |
if (/^\s*\#\s*Artemis project/) { |
| 130 |
my @list = split(" ",$_); |
| 131 |
$from_version = $list[$#list]; |
| 132 |
@list = split(/\./, $from_version); |
| 133 |
$from_version = $#list ? $list[0] . "." . $list[1] . $list[2] : "DR".$list[0]; |
| 134 |
$from_version =~ s/rc//; |
| 135 |
next; |
| 136 |
}; |
| 137 |
next if (/^\s*\#/); |
| 138 |
next if (/^\s*$/); |
| 139 |
|
| 140 |
SWITCH: { |
| 141 |
(/^\@parameter/) and do { |
| 142 |
eval $_; |
| 143 |
push @gds, Ifeffit::Parameter->new(name => $parameter[0], |
| 144 |
type => $parameter[1], |
| 145 |
mathexp => $parameter[2], |
| 146 |
note => $parameter[3], |
| 147 |
autonote => $parameter[4], |
| 148 |
); |
| 149 |
$gds[$#gds]->make(bestfit => $parameter[2]) if ($parameter[1] eq 'guess'); |
| 150 |
last SWITCH; |
| 151 |
}; |
| 152 |
(/^\@journal/) and do { |
| 153 |
## as of 0.7.004 the journal is saved in a file separate from |
| 154 |
## the description file. so this block is merely to read the |
| 155 |
## journal from the project file from before 0.7.004 |
| 156 |
eval $_; |
| 157 |
$notes{journal} -> delete(qw(1.0 end)); |
| 158 |
foreach (@journal) { |
| 159 |
$notes{journal} -> insert('end', $_."\n"); |
| 160 |
}; |
| 161 |
open J, ">".File::Spec->catfile($project_folder, "descriptions", "journal.artemis"); |
| 162 |
map { print J $_, $/ } (@journal); |
| 163 |
print J $/; |
| 164 |
close J; |
| 165 |
last SWITCH; |
| 166 |
}; |
| 167 |
(/^\%plot_features/) and do { |
| 168 |
(my $this = $_) =~ s/^\%plot_features/\%foo/; |
| 169 |
eval $this; |
| 170 |
foreach my $k (keys %foo) { |
| 171 |
$plot_features{$k} = $foo{$k}; |
| 172 |
}; |
| 173 |
last SWITCH; |
| 174 |
}; |
| 175 |
(/^\@extra/) and do { |
| 176 |
(my $this = $_) =~ s/^\@extra\s+=\s+//; |
| 177 |
my @this = eval $this; |
| 178 |
@extra[0..6] = @this[0..6]; |
| 179 |
foreach (7 .. $#this) { |
| 180 |
$extra[$_]->[1] = $this[$_]->[0]; |
| 181 |
$extra[$_]->[2] = $this[$_]->[1]; |
| 182 |
}; |
| 183 |
last SWITCH; |
| 184 |
}; |
| 185 |
(/^\%props/) and do { |
| 186 |
(my $this = $_) =~ s/^\%props/\%foo/; |
| 187 |
eval $this; |
| 188 |
foreach my $k (keys %foo) { |
| 189 |
##next if ($k eq 'Last fit'); |
| 190 |
($props{$k} = $foo{$k}) unless ($k eq 'Environment'); |
| 191 |
}; |
| 192 |
last SWITCH; |
| 193 |
}; |
| 194 |
(/^\$old_path/) and do { |
| 195 |
eval $_; |
| 196 |
@args = (); |
| 197 |
@strings = (); |
| 198 |
last SWITCH; |
| 199 |
}; |
| 200 |
(/^\@args/) and do { |
| 201 |
eval $_; |
| 202 |
last SWITCH; |
| 203 |
}; |
| 204 |
(/^\@strings/) and do { |
| 205 |
eval $_; |
| 206 |
last SWITCH; |
| 207 |
}; |
| 208 |
(/^\[record\]/) and do { |
| 209 |
last SWITCH unless @args; |
| 210 |
&read_path(\$old_path, \@args, \@strings); |
| 211 |
last SWITCH; |
| 212 |
}; |
| 213 |
|
| 214 |
}; |
| 215 |
|
| 216 |
}; |
| 217 |
|
| 218 |
close PROJ; |
| 219 |
return $from_version; |
| 220 |
}; |
| 221 |
|
| 222 |
|
| 223 |
sub read_athena_record { |
| 224 |
my ($file, $from_project, $change) = @_; |
| 225 |
&push_mru($file, 1, "record"); |
| 226 |
use vars qw/$old_group @args @x @y @stddev/; |
| 227 |
open F, $file or die "could not open $file as an Athena record\n"; |
| 228 |
while (<F>) { |
| 229 |
next if (/^\s*\#/); # skip blank and commented lines |
| 230 |
next if (/^\s*$/); |
| 231 |
next if (/^\s*1/); |
| 232 |
my $cpt = new Safe; |
| 233 |
SWITCH: { |
| 234 |
(/^\$old_group/) and do { |
| 235 |
$ {$cpt->varglob('old_group')} = $cpt->reval($_); |
| 236 |
$old_group = $ {$cpt->varglob('old_group')}; |
| 237 |
last SWITCH; |
| 238 |
}; |
| 239 |
(/^\@args/) and do { |
| 240 |
@ {$cpt->varglob('args')} = $cpt->reval($_); |
| 241 |
@args = @ {$cpt->varglob('args')}; |
| 242 |
last SWITCH; |
| 243 |
}; |
| 244 |
(/^\@x/) and do { |
| 245 |
@ {$cpt->varglob('x')} = $cpt->reval($_); |
| 246 |
@x = @ {$cpt->varglob('x')}; |
| 247 |
last SWITCH; |
| 248 |
}; |
| 249 |
(/^\@y/) and do { |
| 250 |
@ {$cpt->varglob('y')} = $cpt->reval($_); |
| 251 |
@y = @ {$cpt->varglob('y')}; |
| 252 |
last SWITCH; |
| 253 |
}; |
| 254 |
(/^\@stddev/) and do { |
| 255 |
@ {$cpt->varglob('stddev')} = $cpt->reval($_); |
| 256 |
@stddev = @ {$cpt->varglob('stddev')}; |
| 257 |
last SWITCH; |
| 258 |
}; |
| 259 |
##(/^\$old_group\s*=\s*\'([^\']*)\';$/) and do { |
| 260 |
## $old_group = $1; |
| 261 |
## last SWITCH; |
| 262 |
##}; |
| 263 |
((/^\[record\]/) or (/^\&read_record/)) and do { |
| 264 |
#my $memory_ok = &memory_check(0, 1); |
| 265 |
#Echo ("Out of memory in Ifeffit"), last DATA if ($memory_ok == -1); |
| 266 |
last SWITCH; |
| 267 |
}; |
| 268 |
1; |
| 269 |
}; |
| 270 |
}; |
| 271 |
close F; |
| 272 |
|
| 273 |
## read the args |
| 274 |
my %args; |
| 275 |
while (@args) { |
| 276 |
my ($key, $val) = (shift @args, shift @args); |
| 277 |
$args{$key} = $val; |
| 278 |
}; |
| 279 |
Echo("$file is not an Athena chi(k) record and cannot be imported."), |
| 280 |
return unless $args{is_chi}; |
| 281 |
|
| 282 |
my ($name, $pth, $suffix) = fileparse($file); |
| 283 |
$current_data_dir = $pth; |
| 284 |
$name = (split(/\./, $name))[0]; |
| 285 |
map {($_ =~ /^op/) and $widgets{$_}->configure(-state=>'normal')} (keys %widgets); |
| 286 |
map {$grab{$_}->configure(-state=>'normal')} (keys %grab); |
| 287 |
|
| 288 |
## extract the useful parts of @args |
| 289 |
my $group = ($change) ? $paths{$current}->data : 'data'.&next_data; |
| 290 |
my $fit = $group . '.0'; |
| 291 |
|
| 292 |
## fill the data arrays |
| 293 |
Ifeffit::put_array("$group.k", \@x); |
| 294 |
Ifeffit::put_array("$group.chi", \@y); |
| 295 |
++$n_data; |
| 296 |
|
| 297 |
if (($change) or (not $current)) { |
| 298 |
$paths{$group} -> make(group =>$group, file =>$file, lab=>$name, |
| 299 |
is_rec =>1,); |
| 300 |
$list -> entryconfigure($paths{$group}->get('id'), -text=>$name); |
| 301 |
} else { |
| 302 |
$paths{$group} = Ifeffit::Path -> new(id => $group, |
| 303 |
group => $group, |
| 304 |
type => 'data', |
| 305 |
sameas => 0, |
| 306 |
file => $file, |
| 307 |
lab => $name, |
| 308 |
family => \%paths,); |
| 309 |
$list -> add($group, -text=>$name, -style=>$list_styles{enabled}); |
| 310 |
$list -> setmode($group, 'none'); |
| 311 |
|
| 312 |
$list -> add($group.".0", -text=>'Fit', -style=>$list_styles{enabled},); |
| 313 |
$list -> setmode($group.'.0', 'close'); |
| 314 |
$list -> hide('entry', $group.".0"); |
| 315 |
}; |
| 316 |
$from_project or |
| 317 |
$paths{$group} -> make(kmin =>$args{fft_kmin}, kmax =>$args{fft_kmax}, |
| 318 |
dk =>$args{fft_dk}, kwindow=>$args{fft_win}, |
| 319 |
rmin =>$args{bft_rmin}, rmax =>$args{bft_rmax}, |
| 320 |
dr =>$args{bft_dr}, rwindow=>$args{bft_win}, |
| 321 |
pcedge =>$args{fft_edge}, pcelem =>$args{bkg_z}); |
| 322 |
SWITCH: { |
| 323 |
$paths{$group} -> make(k1=>1), last SWITCH if ($args{fft_kw} eq 1); |
| 324 |
$paths{$group} -> make(k2=>1), last SWITCH if ($args{fft_kw} eq 2); |
| 325 |
$paths{$group} -> make(k3=>1), last SWITCH if ($args{fft_kw} eq 3); |
| 326 |
$paths{$group} -> make(karb_use=>1, karb=>$args{fft_kw}); |
| 327 |
}; |
| 328 |
$paths{$fit} = Ifeffit::Path -> new(id => $group.".0", |
| 329 |
type => 'fit', |
| 330 |
group => $fit, |
| 331 |
sameas => $group, |
| 332 |
parent => 0, |
| 333 |
family => \%paths); |
| 334 |
my $titles = ""; |
| 335 |
map { $titles .= $_ . "\n" } @{$args{titles}}; |
| 336 |
$paths{$group} -> make(titles=>$titles); |
| 337 |
## pc left off by default |
| 338 |
## $paths{$group} -> make(pcplot=>(lc($args{fft_pc}) eq 'on') ? 'Yes' : 'No'); |
| 339 |
|
| 340 |
## display data |
| 341 |
display_page($group); |
| 342 |
$file_menu->menu->entryconfigure($save_index, -state=>'normal'); # data |
| 343 |
&plot('r', 0) unless $from_project; |
| 344 |
Echo("Opened record file \`$file\'."); |
| 345 |
project_state(0); |
| 346 |
|
| 347 |
}; |
| 348 |
|
| 349 |
sub read_athena_record_on_windows { |
| 350 |
my ($file, $from_project, $change) = @_; |
| 351 |
&push_mru($file, 1, "record"); |
| 352 |
use vars qw/$old_group @args @x @y @stddev/; |
| 353 |
open F, $file or die "could not open $file as an Athena record\n"; |
| 354 |
while (<F>) { |
| 355 |
next if (/^\s*\#/); # skip blank and commented lines |
| 356 |
next if (/^\s*$/); |
| 357 |
next if (/^\s*1/); |
| 358 |
SWITCH: { |
| 359 |
(/^\$old_group/) and do { |
| 360 |
$old_group = eval $_; |
| 361 |
last SWITCH; |
| 362 |
}; |
| 363 |
(/^\@args/) and do { |
| 364 |
@args = eval $_; |
| 365 |
last SWITCH; |
| 366 |
}; |
| 367 |
(/^\@x/) and do { |
| 368 |
@x = eval $_; |
| 369 |
last SWITCH; |
| 370 |
}; |
| 371 |
(/^\@y/) and do { |
| 372 |
@y = eval $_; |
| 373 |
last SWITCH; |
| 374 |
}; |
| 375 |
(/^\@stddev/) and do { |
| 376 |
@stddev = eval $_; |
| 377 |
last SWITCH; |
| 378 |
}; |
| 379 |
##(/^\$old_group\s*=\s*\'([^\']*)\';$/) and do { |
| 380 |
## $old_group = $1; |
| 381 |
## last SWITCH; |
| 382 |
##}; |
| 383 |
((/^\[record\]/) or (/^\&read_record/)) and do { |
| 384 |
#my $memory_ok = &memory_check(0, 1); |
| 385 |
#Echo ("Out of memory in Ifeffit"), last DATA if ($memory_ok == -1); |
| 386 |
last SWITCH; |
| 387 |
}; |
| 388 |
1; |
| 389 |
}; |
| 390 |
}; |
| 391 |
close F; |
| 392 |
|
| 393 |
## read the args |
| 394 |
my %args; |
| 395 |
while (@args) { |
| 396 |
my ($key, $val) = (shift @args, shift @args); |
| 397 |
$args{$key} = $val; |
| 398 |
}; |
| 399 |
Echo("$file is not an Athena chi(k) record and cannot be imported."), |
| 400 |
return unless $args{is_chi}; |
| 401 |
|
| 402 |
my ($name, $pth, $suffix) = fileparse($file); |
| 403 |
$current_data_dir = $pth; |
| 404 |
$name = (split(/\./, $name))[0]; |
| 405 |
map {($_ =~ /^op/) and $widgets{$_}->configure(-state=>'normal')} (keys %widgets); |
| 406 |
map {$grab{$_}->configure(-state=>'normal')} (keys %grab); |
| 407 |
|
| 408 |
## extract the useful parts of @args |
| 409 |
my $group = ($change) ? $paths{$current}->data : 'data'.&next_data; |
| 410 |
my $fit = $group . '.0'; |
| 411 |
|
| 412 |
## fill the data arrays |
| 413 |
Ifeffit::put_array("$group.k", \@x); |
| 414 |
Ifeffit::put_array("$group.chi", \@y); |
| 415 |
++$n_data; |
| 416 |
|
| 417 |
if (($change) or (not $current)) { |
| 418 |
$paths{$group} -> make(group =>$group, file =>$file, lab=>$name, |
| 419 |
is_rec =>1,); |
| 420 |
$list -> entryconfigure($paths{$group}->get('id'), -text=>$name); |
| 421 |
} else { |
| 422 |
$paths{$group} = Ifeffit::Path -> new(id => $group, |
| 423 |
group => $group, |
| 424 |
type => 'data', |
| 425 |
sameas => 0, |
| 426 |
file => $file, |
| 427 |
lab => $name, |
| 428 |
family => \%paths,); |
| 429 |
$list -> add($group, -text=>$name, -style=>$list_styles{enabled}); |
| 430 |
$list -> setmode($group, 'none'); |
| 431 |
|
| 432 |
$list -> add($group.".0", -text=>'Fit', -style=>$list_styles{enabled},); |
| 433 |
$list -> setmode($group.'.0', 'close'); |
| 434 |
$list -> hide('entry', $group.".0"); |
| 435 |
}; |
| 436 |
$from_project or |
| 437 |
$paths{$group} -> make(kmin =>$args{fft_kmin}, kmax =>$args{fft_kmax}, |
| 438 |
dk =>$args{fft_dk}, kwindow=>$args{fft_win}, |
| 439 |
rmin =>$args{bft_rmin}, rmax =>$args{bft_rmax}, |
| 440 |
dr =>$args{bft_dr}, rwindow=>$args{bft_win}, |
| 441 |
pcedge =>$args{fft_edge}, pcelem =>$args{bkg_z}); |
| 442 |
SWITCH: { |
| 443 |
$paths{$group} -> make(k1=>1), last SWITCH if ($args{fft_kw} eq 1); |
| 444 |
$paths{$group} -> make(k2=>1), last SWITCH if ($args{fft_kw} eq 2); |
| 445 |
$paths{$group} -> make(k3=>1), last SWITCH if ($args{fft_kw} eq 3); |
| 446 |
$paths{$group} -> make(karb_use=>1, karb=>$args{fft_kw}); |
| 447 |
}; |
| 448 |
$paths{$fit} = Ifeffit::Path -> new(id => $group.".0", |
| 449 |
type => 'fit', |
| 450 |
group => $fit, |
| 451 |
sameas => $group, |
| 452 |
parent => 0, |
| 453 |
family => \%paths); |
| 454 |
my $titles = ""; |
| 455 |
map { $titles .= $_ . "\n" } @{$args{titles}}; |
| 456 |
$paths{$group} -> make(titles=>$titles); |
| 457 |
## pc left off by default |
| 458 |
## $paths{$group} -> make(pcplot=>(lc($args{fft_pc}) eq 'on') ? 'Yes' : 'No'); |
| 459 |
|
| 460 |
## display data |
| 461 |
display_page($group); |
| 462 |
$file_menu->menu->entryconfigure($save_index, -state=>'normal'); # data |
| 463 |
&plot('r', 0) unless $from_project; |
| 464 |
Echo("Opened record file \`$file\'."); |
| 465 |
project_state(0); |
| 466 |
|
| 467 |
}; |