Debian Codegraph @

hephaestus_parts/line.pl

raw
1
2 ## ===========================================================================
3 ## This is the find lines portion of hephaestus
4
5 sub line {
6 $periodic_table -> packForget() if $current =~ /$uses_periodic_regex/;
7 switch({page=>"line", text=>'Ordered List of Fluorescence Line Energies'});
8 };
9
10
11 sub setup_line {
12 my $frame = $_[0] -> Frame(-borderwidth=>2, -relief=>'flat');
13
14 $data{line_min} = 100;
15 $data{line_energy} ||= 8047;
16 $data{line_harmonic} = 1;
17
18 ## snarf (quietly!) the list of energies from the list used for the
19 ## next_energy function in Xray::Absoprtion::Elam
20 my $hash;
21 do {
22 no warnings;
23 $hash = $$Xray::Absorption::Elam::r_elam{line_list};
24 };
25 my @line_list = ();
26 foreach my $key (keys %$hash) {
27 next unless exists $$hash{$key}->[2];
28 push @line_list, $$hash{$key};
29 };
30 ## and sort by increasing energy
31 @line_list = sort {$a->[2] <=> $b->[2]} @line_list;
32 $data{line_list} = \@line_list;
33
34 ## a list of all edges and energies
35 my $lf = $frame -> LabFrame(-label=>"All fluorescence lines ($data{line_min} eV - 135 keV)",
36 -labelside=>'acrosstop',@label_args)
37 -> pack(-fill=>'y', -side=>'left', -padx=>10, -pady=>1);
38 my $lb = $lf -> Scrolled("Listbox",
39 -scrollbars => 'e',
40 -width => 46,
41 -selectmode => 'single',
42 -font => $config{fonts}{fixed},)
43 -> pack(-fill=>'both', -expand=>1, -side=>'left');
44 BindMouseWheel($lb);
45 $data{line_lb} = $lb;
46 foreach (@line_list) {
47 next if ($_->[2] < $data{line_min});
48 $lb -> insert('end', sprintf("%-2s %-8s %-9s (%6.4f) .... %8.1f ",
49 ucfirst($_->[0]),
50 Xray::Absorption->get_Siegbahn_full($_->[1]),
51 Xray::Absorption->get_IUPAC($_->[1]),
52 Xray::Absorption->get_intensity($_->[0],$_->[1]),
53 $_->[2]));
54 };
55
56 ## the interactive part
57 $lf = $frame -> LabFrame(-label=>'Target energy',
58 -labelside=>'acrosstop', @label_args)
59 -> pack(-fill=>'x', -expand=>1, -side=>'right', -pady=>1, -padx=>10);
60 my $fr = $lf -> Frame() -> pack(-side=>'top', -pady=>3, -anchor=>'c');
61 my $entry = $fr -> Entry(-width => 8,
62 -textvariable => \$data{line_energy},
63 -font => $config{fonts}{smfixed},
64 -validate => 'key',
65 -validatecommand => \&set_variable)
66 -> pack(-side=>'left', -pady=>4);
67 $fr -> Label(-text=>'eV', @label_args)
68 -> pack(-side=>'right');
69 ## $fr = $lf -> Frame() -> pack(-side=>'top', -pady=>3, -anchor=>'c');
70 ## $fr -> Label(-text=>'Harmonic: ', @label_args)
71 ## -> pack(-side=>'left');
72 ## $fr -> Radiobutton(-text=>"Fundamental", -variable=>\$data{line_harmonic},
73 ## -value=>1, -command => \&line_energy)
74 ## -> pack(-side=>'left');
75 ## $fr -> Radiobutton(-text=>"2nd", -variable=>\$data{line_harmonic},
76 ## -value=>2, -command => \&line_energy)
77 ## -> pack(-side=>'left');
78 ## $fr -> Radiobutton(-text=>"3rd", -variable=>\$data{line_harmonic},
79 ## -value=>3, -command => \&line_energy)
80 ## -> pack(-side=>'left');
81 my $button = $lf -> Button(-width=>8, -text=>"Find it!", @button_args,
82 -command => \&line_energy)
83 -> pack(-side=>'bottom', -pady=>3, -fill=>'x', -expand=>1);
84 $entry -> bind("<KeyPress-Return>"=>sub{$button->invoke});
85
86 ## initialize
87 &line_energy;
88 return $frame;
89 };
90
91 sub line_energy {
92 ## deal with the harmonic setting
93 my $energy = $data{line_energy} * $data{line_harmonic};
94 ## deal with energies below the low energy cutoff
95 if ($energy <= $data{line_min}) {
96 $data{line_lb} -> see(0);
97 $data{line_lb} -> selectionClear(0, 'end');
98 $data{line_lb} -> selectionSet(0);
99 return;
100 };
101 ## find the line energy just above the specified energy
102 my $count = -2;
103 foreach (@{$data{line_list}}) {
104 next if ($_->[2] < $data{line_min});
105 my $en = $_->[2];
106 ++$count;
107 last if ($en >= $energy);
108 };
109 ## display the line energy just below the specified energy
110 $data{line_lb} -> see($count);
111 $data{line_lb} -> selectionClear(0, 'end');
112 $data{line_lb} -> selectionSet($count);
113 };