| 1 |
# -*- cperl -*- |
| 2 |
## This file is part of Artemis, copyright (c) 2002-2006 Bruce Ravel |
| 3 |
## |
| 4 |
|
| 5 |
###=================================================================== |
| 6 |
### histogram import subsystem |
| 7 |
###=================================================================== |
| 8 |
|
| 9 |
sub histogram { |
| 10 |
|
| 11 |
my $path = $_[0]; |
| 12 |
my %histo_params = (this_path => $path, |
| 13 |
this_feff => $current, |
| 14 |
label => $config{histogram}{template}, |
| 15 |
position_column => $config{histogram}{position_column}, |
| 16 |
height_column => $config{histogram}{height_column}, |
| 17 |
); |
| 18 |
|
| 19 |
map {$_ -> configure(-state=>'disabled')} |
| 20 |
($gsd_menu, $feff_menu, $paths_menu, $data_menu, $sum_menu, $fit_menu); #, $settings_menu); |
| 21 |
SWITCH: { |
| 22 |
$opparams->packForget(), last SWITCH if ($current_canvas eq 'op'); |
| 23 |
$gsd ->packForget(), last SWITCH if ($current_canvas eq 'gsd'); |
| 24 |
$feff ->packForget(), last SWITCH if ($current_canvas eq 'feff'); |
| 25 |
$path ->packForget(), last SWITCH if ($current_canvas eq 'path'); |
| 26 |
}; |
| 27 |
$current_canvas = 'histogram'; |
| 28 |
my $histo = $fat -> Canvas(-relief=>'flat', |
| 29 |
-borderwidth=>0, |
| 30 |
@window_size, |
| 31 |
-highlightcolor=>$config{colors}{background}) |
| 32 |
-> pack(); |
| 33 |
|
| 34 |
$histo -> packPropagate(0); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
$histo -> Label(-text=>"Histogram tool", @title2) |
| 39 |
-> pack(-side=>'top', -anchor=>'w', -padx=>6); |
| 40 |
|
| 41 |
$histo -> Button(-text=>'Return to the main window', @button_list, |
| 42 |
#-background=>$config{colors}{background}, |
| 43 |
#-activebackground=>$config{colors}{activebackground}, |
| 44 |
-command=>sub{ |
| 45 |
$histo->packForget; |
| 46 |
$current_canvas = ""; |
| 47 |
&display_properties; |
| 48 |
set_fit_button('fit'); |
| 49 |
Echo("Restored normal view"); |
| 50 |
}) |
| 51 |
-> pack(-side=>'bottom', -fill=>'x', -pady=>2); |
| 52 |
|
| 53 |
|
| 54 |
my $labframe = $histo -> LabFrame(-label=>$paths{$current}->get('lab') . ": $path", |
| 55 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 56 |
-labelside=>'acrosstop') |
| 57 |
-> pack(-side=>'top'); |
| 58 |
|
| 59 |
$widgets{histo_header} = $labframe -> ROText(-width=>49, -height=>10, relief=>'flat', |
| 60 |
-wrap=>'none', -font=>$config{fonts}{fixed}) |
| 61 |
-> pack(-side=>'top', -anchor=>'c'); |
| 62 |
&disable_mouse3($widgets{histo_header}); |
| 63 |
$widgets{histo_header} -> tagConfigure('absorber', -foreground=>$config{colors}{button}); |
| 64 |
|
| 65 |
$widgets{histo_header} -> delete(qw(1.0 end)); |
| 66 |
my $i = 0; |
| 67 |
open P, File::Spec->catfile($project_folder, $paths{$current}->get('id'), $path); |
| 68 |
my $switch = 0; |
| 69 |
while (<P>) { |
| 70 |
$switch = 1, next if ($_ =~ /^\s+-------/); |
| 71 |
next unless $switch; |
| 72 |
last if ($_ =~ /\@\#$/); |
| 73 |
$_ =~ s/\s+absorbing/ absorbing/; |
| 74 |
($_ =~ / 0 /) ? |
| 75 |
$widgets{histo_header} -> insert('end', $_ , 'absorber') : |
| 76 |
$widgets{histo_header} -> insert('end', $_); |
| 77 |
++$i; |
| 78 |
}; |
| 79 |
close P; |
| 80 |
$widgets{histo_header} -> configure(-height=>$i); |
| 81 |
|
| 82 |
my $frame = $histo -> Frame() |
| 83 |
-> pack(-side=>'top', -fill=>'x'); |
| 84 |
$frame -> Button(-text=>"Path list entry:", |
| 85 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 86 |
-activeforeground=>$config{colors}{activehighlightcolor}, |
| 87 |
-font=>$config{fonts}{med}, |
| 88 |
-relief=>'flat', -borderwidth=>0, |
| 89 |
-command=>[\&Echo, $click_help{'Path list entry'}] |
| 90 |
) |
| 91 |
-> pack(-side=>'left', -padx=>6); |
| 92 |
$frame -> Entry(-width=>25, -textvariable=>\$histo_params{label}, |
| 93 |
-font=>$config{fonts}{fixed}) |
| 94 |
-> pack(-side=>'left', -fill=>'x', -expand=>1); |
| 95 |
$histo -> Label(-text=>'(%p=path file name, %r=bin distance, %n=bin height, %i=index)', |
| 96 |
-foreground=>$config{colors}{foreground}, |
| 97 |
-font=>$config{fonts}{small} |
| 98 |
) |
| 99 |
-> pack(-side=>'top'); |
| 100 |
|
| 101 |
$frame = $histo -> Frame() |
| 102 |
-> pack(-side=>'top'); |
| 103 |
$frame -> Button(-text=>'Position column:', |
| 104 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 105 |
-activeforeground=>$config{colors}{activehighlightcolor}, |
| 106 |
-font=>$config{fonts}{med}, |
| 107 |
-relief=>'flat', -borderwidth=>0, |
| 108 |
-command=>[\&Echo, $click_help{'Position column'}] |
| 109 |
) |
| 110 |
-> pack(-side=>'left', -padx=>0); |
| 111 |
$frame -> NumEntry(-width=>4, |
| 112 |
-orient=>'horizontal', |
| 113 |
-foreground=>$config{colors}{foreground}, |
| 114 |
-textvariable=>\$histo_params{position_column}, |
| 115 |
-minvalue=>1, |
| 116 |
) |
| 117 |
-> pack(-side=>'left', -padx=>4); |
| 118 |
$frame -> Label(-width=>4) |
| 119 |
-> pack(-side=>'left', -padx=>0); |
| 120 |
$frame -> Button(-text=>'Height column:', |
| 121 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 122 |
-activeforeground=>$config{colors}{activehighlightcolor}, |
| 123 |
-font=>$config{fonts}{med}, |
| 124 |
-relief=>'flat', -borderwidth=>0, |
| 125 |
-command=>[\&Echo, $click_help{'Height column'}] |
| 126 |
) |
| 127 |
-> pack(-side=>'left', -padx=>0); |
| 128 |
$frame -> NumEntry(-width=>4, |
| 129 |
-orient=>'horizontal', |
| 130 |
-foreground=>$config{colors}{foreground}, |
| 131 |
-textvariable=>\$histo_params{height_column}, |
| 132 |
-minvalue=>1, |
| 133 |
) |
| 134 |
-> pack(-side=>'left', -padx=>4); |
| 135 |
|
| 136 |
$widgets{histo_fileframe} = $histo |
| 137 |
-> LabFrame(-label=>'Histogram file', |
| 138 |
-foreground=>$config{colors}{activehighlightcolor}, |
| 139 |
-labelside=>'acrosstop') |
| 140 |
-> pack(-side=>'top', -expand=>1, -fill=>'both'); |
| 141 |
|
| 142 |
|
| 143 |
$widgets{histo_text} = $widgets{histo_fileframe} |
| 144 |
-> Scrolled('Text', -scrollbars=>'osoe', -width=>10, -height=>10, |
| 145 |
-font=>$config{fonts}{fixed}) |
| 146 |
-> pack(-side=>'top', -expand=>1, -fill=>'both'); |
| 147 |
$widgets{histo_text} -> Subwidget("xscrollbar") |
| 148 |
->configure(-background=>$config{colors}{background}, |
| 149 |
($is_windows) ? () : (-width=>8)); |
| 150 |
$widgets{histo_text} -> Subwidget("yscrollbar") |
| 151 |
->configure(-background=>$config{colors}{background}, |
| 152 |
($is_windows) ? () : (-width=>8)); |
| 153 |
BindMouseWheel($widgets{histo_text}); |
| 154 |
|
| 155 |
$frame = $histo -> Frame() |
| 156 |
-> pack(-side=>'top', -fill=>'x'); |
| 157 |
$frame -> Button(-text => 'Make histogram', @button2_list, |
| 158 |
-command => |
| 159 |
sub { histogram_build(\%histo_params) }, |
| 160 |
) |
| 161 |
-> pack(-side=>'left', -padx=>4, -fill=>'x', -expand=>1); |
| 162 |
$frame -> Button(-text => 'Browse', @button2_list, |
| 163 |
-command => |
| 164 |
sub { |
| 165 |
my $path = $current_data_dir || cwd; |
| 166 |
my $types = [['All files', '*'],]; |
| 167 |
my $file = $top -> getOpenFile(-filetypes=>$types, |
| 168 |
##(not $is_windows) ? |
| 169 |
## (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 170 |
-initialdir=>$path, |
| 171 |
-title => "Artemis: Open a histogram file"); |
| 172 |
return unless ($file); |
| 173 |
$current_data_dir = dirname($file); |
| 174 |
$widgets{histo_fileframe} -> configure(-label=>$file); |
| 175 |
$widgets{histo_text} -> delete('1.0', 'end'); |
| 176 |
local $/ = undef; |
| 177 |
open F, $file; |
| 178 |
$widgets{histo_text} -> insert('end', <F>); |
| 179 |
close F; |
| 180 |
}) |
| 181 |
-> pack(-side=>'left', -padx=>4); |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
set_fit_button('disabled'); |
| 186 |
Echo("Showing histogram tool"); |
| 187 |
$top -> update; |
| 188 |
}; |
| 189 |
|
| 190 |
|
| 191 |
sub histogram_build { |
| 192 |
my $rhash = $_[0]; |
| 193 |
my $feff = $$rhash{this_feff}; |
| 194 |
my $path = $$rhash{this_path}; |
| 195 |
my $label = $$rhash{label}; |
| 196 |
|
| 197 |
## intrpline is the same for each of these histogram bins |
| 198 |
## my $start = $widgets{feff_intrp} -> search(-exact=>substr($path,4,4), "1.0") || 0; |
| 199 |
## my $end = (split(/\./, $start))[0] . ".end"; |
| 200 |
## my $intrpline = ($start) ? $widgets{feff_intrp}->get($start, $end) : ""; |
| 201 |
my $intrpline = ""; |
| 202 |
|
| 203 |
my $text = $widgets{histo_text} -> get('1.0', 'end'); |
| 204 |
my $index = 0; |
| 205 |
foreach my $line (split(/\n/, $text)) { |
| 206 |
++$index; |
| 207 |
my @line = split(" ", $line); |
| 208 |
my $r = $line[$$rhash{position_column}-1] || 0; |
| 209 |
my $n = $line[$$rhash{height_column}-1] || 0; |
| 210 |
my %sub = (r=>$r, n=>$n, p=>$path, i=>sprintf("%3.3d", $index)); |
| 211 |
(my $this_label = $label) =~ s/\%([inpr])/$sub{$1}/g; |
| 212 |
|
| 213 |
my $this = $list -> addchild($feff); |
| 214 |
$paths{$this} = Ifeffit::Path -> new(id => $this, |
| 215 |
type => 'path', |
| 216 |
file => $path, |
| 217 |
include => 1, |
| 218 |
plotpath => 0, |
| 219 |
parent => $feff, |
| 220 |
do_k => 1, |
| 221 |
data => $paths{$current}->data, |
| 222 |
intrpline => $intrpline, |
| 223 |
family => \%paths); |
| 224 |
my @autoparams = @{$paths{$feff}{autoparams}}; |
| 225 |
foreach my $p (qw(s02 e0 delr sigma^2 ei 3rd 4th)) { |
| 226 |
my $ap = shift @autoparams; |
| 227 |
$paths{$this} -> make($p=>$ap); |
| 228 |
}; |
| 229 |
$paths{$this} -> make(header=> nnnn_header($this,File::Spec->catfile($project_folder, $paths{$current}->get('id'), $path))); |
| 230 |
$paths{$this} -> make(lab => $this_label, |
| 231 |
deg => $n, |
| 232 |
label => "bin of $n at $r using $path", |
| 233 |
delr => "($r-reff)*delta"); |
| 234 |
$list -> entryconfigure($this, -style=>$list_styles{enabled}, -text=>$this_label); |
| 235 |
$paths{$this} -> pathgroup(\%paths); |
| 236 |
## $list->anchorSet($this); |
| 237 |
## $list->selectionClear; |
| 238 |
## $list->selectionSet($this); |
| 239 |
}; |
| 240 |
|
| 241 |
|
| 242 |
}; |