SlideShare una empresa de Scribd logo
1 de 27
A chemical engineering ideal stage calculator
- Can read and save data to an ascii file
- Can add points with pointer or input location
- Can input an equation to plot as data
- Can clear data and start again
- Location of mouse pointer is displayed on screen
require 5.004;
use Tk 800.023;
use Tk qw/:eventtypes/;
use Tk::FileSelect;
use Tk::toplevel;
use Tk::Dialog;
use Cwd;
# ////////////////////////////////// Fundamentals
my(@menu_button_list, $quit_flag, $quit_code, $add_code);
my($scale,$screen_bump, $sb, $screen_sizex, $ssx, $beed_size, $bs);
$scale = 1;
$screen_bump = 20;
$sb = $screen_bump;
$screen_sizey = 400;
$ssy = $screen_sizey;
$screen_sizex = 400;
$ssx = $screen_sizex;
$beed_size = 1;
$bs = $beed_size;
@glines = [0,0,0,0];
@dlines = [0];
@pointsv = [0,0];
@pointsl = [0,0];
$dataldd = 0;
# ////////////////////////////////// Main Frame
$m->destroy if Exists($m);
$m = Tk::MainWindow->new;
$m->title('Distillation Simulator');
$m->iconname('sim');
$quit_flag = 0;
$quit_code = sub {$quit_flag = 1};
$m->protocol('WM_DELETE_WINDOW' => $quit_code);
$fsel = $m->FileSelect
(-directory => Cwd::cwd(), # Alias: -initialdir
-initialfile => "data.dat",
-filter => "*.pl",
-regexp => '*.*', #' does not work (?)
-filelabel => "Datei",
-filelistlabel => "Dateien",
-dirlabel => "Verzeichnis",
-dirlistlabel => "Verzeichnisse",
-verify => ['-T'], # accept only text files
);
# ////////////////////////////////// Menu
my $menubar = $m->Frame(qw/-relief raised -background DarkGreen -bd 2/);
$menubar->pack(-side => 'top', -fill => 'x');
$statustext = $menubar->Text(
-relief => 'groove',
-height => 1,
-width => $screen_sizex/24,
-border => 2,
-background => 'DarkGreen',
);
$statustext->pack(-side => 'top', -fill => 'x');
$statustext->insert('1.0', 'Left Mouse Button Adds Vapor point.');
mkmb($menubar, 'Data', 0, 'Loading Data etc.',
[
['Load', &load_data, 0],
['clear', &clear_data, 0],
['save', &NotDone, 0],
['Print', &NotDone, 0],
['Exit', sub{$m->bell}, 0],
]);
mkmb($menubar, 'Distill', 0, 'Distillation control',
[
['Distill', &dis_code, 2],
['Delete', &del_dis, 2],
]);
mkmb($menubar, 'Display', 0, 'Display settings',
[
['Redraw', &NotDone, 2],
['Clear', &NotDone, 2],
]);
mkmb($menubar, 'Help', 0, 'There when you need it',
[
['About..', [&about_help, $m], 0],
['Intro', &NotDone, 0],
['Contents', &NotDone, 0],
]);
$menu_button_list[$#menu_button_list]->pack(-side => 'right');
# ////////////////////////////////// About Help popup
sub about_help{
my $m = shift;
my $aboutm = $m->Dialog(-entry => 'stuff', -default_button => 'Yes', -buttons => [qw/Yes No
Cancel/]);
$aboutm->configure(-text => '
Distillation modelling program.
Enter VLE data via a formatted 
file or the two points methods.');
my $result = $aboutm->Show(-global);
print "Dialog result : ".$result;
}#
# ////////////////////////////////// Add Point Entry Frame
$cf = $m->Frame(-bd => 2 );
$cex = $cf->Entry(
-relief => 'sunken',
-bd => 2,
-width => $screen_sizex/20,
);
$cey = $cf->Entry(
-relief => 'sunken',
-bd => 2,
-width => $screen_sizex/20,
);
$cba = $cf->Button(
-text => 'Add Point',
-command => &add_code,
);
$cbr = $cf->Button(
-text => 'Load',
-command => &load_data,
);
$cbdv = $cf->Button(
-text => 'Del Vapor',
-command => &del_vapor,
);
$cbdl = $cf->Button(
-text => 'Del Liquid',
-command => &del_liquid,
);
$cex->pack(-side => 'left');
$cex->insert('0.0','New X>');
$cey->pack(-side => 'left');
$cey->insert('0.0','New Y>');
$cba->pack(-side => 'left');
$cbr->pack(-side => 'left');
$cbdv->pack(-side => 'left');
$cbdl->pack(-side => 'left');
$cf->pack;
# ////////////////////////////////// Distill Frame
$df = $m->Frame(-bd => 2 );
$dexs = $df->Entry(
-relief => 'sunken',
-bd => 2,
-width => $screen_sizex/16,
);
$dexl = $df->Entry(
-relief => 'sunken',
-bd => 2,
-width => $screen_sizex/16,
);
$dexf = $df->Label(
-text => 'stuff',
-relief => 'groove',
-border => 2,
-width => $screen_sizex/24,
);
$dbr = $df->Button(
-text => 'Distill',
-command => &dis_code,
);
$dbd = $df->Button(
-text => 'Delete',
-command => &del_dis,
);
$dexs->pack(-side => 'left');
$dexs->insert('0.0','Start X>');
$dexl->pack(-side => 'left');
$dexl->insert('0.0','Last X>');
$dexf->pack(-side => 'left');
$dbr->pack(-side => 'left');
$dbd->pack(-side => 'left');
$df->pack;
# ////////////////////////////////// Equation Frame
$uf = $m->Frame(-bd => 2 );
$uexf = $uf->Label(
-text => 'Insert Equation',
-relief => 'groove',
-border => 2,
-width => $screen_sizex/24,
);
$uexs = $uf->Entry(
-relief => 'sunken',
-bd => 2,
-width => $screen_sizex/12,
);
$ubd = $uf->Button(
-text => 'Add Equation To Vapor',
-command => &plot_data,
);
$uexf->pack(-side => 'left');
$uexs->pack(-side => 'left');
$ubd->pack(-side => 'left');
$uf->pack;
# ////////////////////////////////// Canvas Frame
$f = $m->Frame(-bd => 2 );
$c = $f->Canvas(
-relief => 'sunken',
-bd => 2,
-height => $sb + $ssy + $sb,
-width => $sb + $ssx + $sb,
);
$c->pack(-side => 'top');
$f->pack;
$m->bind($c, '<Motion>' => &ShowCoord);
$m->bind($c, '<Button-1>' => &AddVCoord);
$m->bind($c, '<Button-3>' => &AddLCoord);
$m->bind($c, '<Leave>' => &DeleteCoord);
my $otm, $ott;
sub ShowCoord{
$c->delete($otm);
$c->delete($ott);
my $e = $c->XEvent;
# Note: Cap X returns global x coord, Low Case x returns Canvas local coord.
my $xm = $e->x;
my $ym = $e->y;
my $xmt = ($xm-$sb)*$scale/$ssx;
my $ymt = ($sb+$ssy-$ym)*$scale/$ssy;
$otm = $c->createOval($xm-$beed_size,$ym-$beed_size,$xm+$beed_size,$ym+$beed_size);
$ott = $c->createText($xm,$ym-9,-text => $xmt.",".$ymt);
# print "x ".$xm." y ".$ym."n";
};
sub DeleteCoord{
$c->delete($otm);
$c->delete($ott);
}
sub AddVCoord{
my $e = $c->XEvent;
my $xm = ($e->x-$sb)*$scale/$ssx;
my $ym = ($sb+$ssy-$e->y)*$scale/$ssy;
add_vapor($xm,$ym);
print "Adding point : X ".$xm." Y ".$ym."n";
};
sub AddLCoord{
my $e = $c->XEvent;
my $xm = ($e->x-$sb)*$scale/$ssx;
my $ym = ($sb+$ssy-$e->y)*$scale/$ssy;
add_liquid($xm,$ym);
print "Adding point : X ".$xm." Y ".$ym."n";
};
# ////////////////////////////////// Get Data and Plot
sub clear_data{
del_vapor(0,0);
del_liquid(0,0);
}
sub load_data{
if($dataldd>0){
print "Deleting previous datan";
del_vapor(0,0);
del_liquid(0,0);
}
$datafile = $fsel->Show;
open(DATA, "$datafile") || die "Can't open $datafile: $!n";
$vapor = 1;
while(<DATA>)
{
my($gx0,$gy0,$gx1,$gy1);
chomp;
if(/Vapor/) {print $_."n"; $vapor = 1; pop @pointsv;}
elsif(/Liquid/) {print $_."n"; $vapor = 0; pop @pointsl;}
else
{
$point = [split(/,/),0];
# print "X :".${$point}[0]." Y :".${$point}[1]."n";
($xc,$yc) = (${$point}[0],${$point}[1]);
$xc = $xc*$ssx/$scale+$sb;
$yc = $yc*$ssy/$scale+$sb;
${$point}[2] = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-
$yc);
#
if($vapor){ push @pointsv, $point; }
else { push @pointsl, $point; }
#
#
}
} # end while
$dataldd = 1;
}
sub plot_data{
my $function = ($uexs->get);
for(my $xi = 0;$xi <= 100; $xi = $xi + 1){
my $x = $xi/100;
my $y = (eval $function);
add_vapor($x,$y);
# $xc = $x*$ssx/$scale+$sb;
# $yc = $y*$ssy/$scale+$sb;
# $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc);
}
}
sub add_grid{
pop @glines;
$gx0 = 0;$gy0 = 0;$gx1 = 0;$gy1 = 0;
my $glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb,$sb+0,$sb,$sb+$ssy)];
push @glines, $glineadd;
for(my $gx = 0;$gx <= 100;$gx += 10) {
$gx0 = $gx; $gy0 = 0; $gx1 = $gx; $gy1 = 0;
$glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb+$ssx/100*$gx,$sb+$ssy,$sb+
$ssx/100*$gx,$sb+$ssy+$sb/2)];
push @glines, $glineadd;
}
#
$gx0 = 0;$gy0 = 0;$gx1 = 0;$gy1 = 0;
$glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb,$sb+$ssy,$sb+$sb+$ssx,$sb+$ssy)];
push @glines, $glineadd;
for(my $gy = 0;$gy <= 100;$gy += 10) {
$gx0 = 0; $gy0 = $gy; $gx1 = 0; $gy1 = $gy;
$glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb/2,$sb+$ssy/100*$gy0,$sb,$sb+
$ssy/100*$gy0)];
push @glines, $glineadd;
}
foreach (@glines){ print ${$_}[0]." ".${$_}[1]." ".${$_}[2]." ".${$_}[3]." ".${$_}[4]."n"; };
};
add_grid;
sub nuke_grid{
foreach (@glines){
$c->delete(${$_}[4]);
};
};
# ////////////////////////////////// Distillation Code
sub dis_code
{
my $lowx, $highx, $liquidx, $xl, $vaporx, $xv, $startx, $lastx;
my $lowy, $highy, $liquidy, $yl, $vapory, $yv, $starty, $lasty;
$startx = $dexs->get;
$lastx = $dexl->get;
$liquidx = $startx;
$dexs->delete(0,15);
$dexs->insert('0.0','Start X>');
$dexl->delete(0,15);
$dexl->insert('0.0','Last X>');
$startx =~ s/Start X>//;
$lastx =~ s/Last X>//;
if(($startx<$scale)){} else {$startx = $scale/99}
if(($lastx<$scale)){} else {$lastx = $scale/1.09}
$got_yet = 1;
foreach (@pointsl)
{
if($got_yet) {
if(($startx < ${$_}[0]))
{
$highx = ${$_}[0];
$highy = ${$_}[1];
$got_yet = 0;
}
else
{
$lowx = ${$_}[0];
$lowy = ${$_}[1];
};
};
}; # foreach loop
$starty = $lowy + ($startx - $lowx)/($highx - $lowx)*($highy - $lowy);
$xl = $startx*$ssx/$scale+$sb;
$yl = $starty*$ssy/$scale+$sb;
push @dlines, $c->createOval($xl-$bs,$sb+$ssy+$bs-$yl,$xl+$bs,$sb+$ssy-$bs-$yl);
$liquidx = $startx;
$liquidy = $starty;
$vaporx = $liquidx;
# Iterate up the latter of Distillation Steps
while(($liquidx < $lastx)) {
# Get the next vapor point
$got_yet = 1;
foreach (@pointsv)
{
if($got_yet) {
if(($vaporx < ${$_}[0]))
{
$highx = ${$_}[0];
$highy = ${$_}[1];
$got_yet = 0;
}
else
{
$lowx = ${$_}[0];
$lowy = ${$_}[1];
};
};
}; # foreach loop
$vapory = $lowy + ($vaporx - $lowx)/($highx - $lowx)*($highy - $lowy);
$xl = $liquidx*$ssx/$scale+$sb;
$yl = $liquidy*$ssy/$scale+$sb;
$xv = $vaporx*$ssx/$scale+$sb;
$yv = $vapory*$ssy/$scale+$sb;
push @dlines, $c->createLine($xl,$sb+$sb+$ssy+$bs-$yl, $xv,$sb+$sb+$ssy+$bs-$yv);
push @dlines, $c->createOval($xv-$bs,$sb+$sb+$ssy+$bs-$yv,$xv+$bs,$sb+$sb+$ssy-$bs-
$yv);
$liquidy = $vapory;
# Get the next Liquid point
$got_yet = 1;
foreach (@pointsl)
{
if($got_yet) {
if(($liquidy < ${$_}[1]))
{
$highx = ${$_}[0];
$highy = ${$_}[1];
$got_yet = 0;
}
else
{
$lowx = ${$_}[0];
$lowy = ${$_}[1];
};
};
}; # foreach loop
$liquidx = $lowx + ($liquidy - $lowy)/($highy - $lowy)*($highx - $lowx);
$xl = $liquidx*$ssx/$scale+$sb;
$yl = $liquidy*$ssy/$scale+$sb;
$xv = $vaporx*$ssx/$scale+$sb;
$yv = $vapory*$ssy/$scale+$sb;
push @dlines, $c->createLine($xv,$sb+$sb+$ssy+$bs-$yv, $xl,$sb+$sb+$ssy+$bs-$yl);
push @dlines, $c->createOval($xl-$bs,$sb+$sb+$ssy+$bs-$yl,$xl+$bs,$sb+$sb+$ssy-$bs-$yl);
$vaporx = $liquidx;
} # end while loop
$lastx = $liquidx;
$lasty = $liquidy;
$dexf->configure(
-text => $lastx,
);
};
sub del_dis{
foreach (@dlines){
$c->delete($_);
}
@dlines = [];
}
# ////////////////////////////////// Vapor Phase Adjustments
sub del_vapor{
my($newx) = $cex->get;
my($newy) = $cey->get;
$cex->delete(0,15);
$cex->insert('0.0','New X>');
$cey->delete(0,15);
$cey->insert('0.0','New Y>');
my($newp) = 0;
$newx =~ s/New X>//;
$newy =~ s/New Y>//;
foreach (@pointsv) { $c->delete(${$_}[2]); }
if(($newx>0) || ($newy>0)) {
($xc,$yc) = ($newx,$newy);
$xc = $xc*$ssx/$scale+$sb;
$yc = $yc*$ssy/$scale+$sb;
$newp = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc);
@pointsv = [$newx,$newy,$newp];
}
else { @pointsv = []; pop @pointsv};
};
sub add_code{
my($newx) = $cex->get;
my($newy) = $cey->get;
$cex->delete(0,15);
$cex->insert('0.0','New X>');
$cey->delete(0,15);
$cey->insert('0.0','New Y>');
$newx =~ s/New X>//;
$newy =~ s/New Y>//;
if(($newx>0)&&($newy>0)) {
# print "New vapor point X :".$newx." Y :".$newy."n";
add_vapor($newx,$newy);
};
};
sub add_vapor
{
my($tempp) = [@_[0],@_[1],0];
# print "add vapor point ".${$tempp}[0]." ".@_[1]." ".@_[0]."n";
my(@tempv) = [];
pop @tempv;
my($added) = 1;
foreach (@pointsv)
{
# print "Old vapor points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]." cv : ".@{$_}[2]."n";
$c->delete(${$_}[2]);
if((${$tempp}[0] < ${$_}[0]))
{
if($added)
{
# print "adding point";
$added = 0;
push @tempv, $tempp;
push @tempv, $_;
}
else
{
push @tempv, $_;
}
}
else
{
push @tempv, $_;
};
};
if($added)
{
print "adding pointn";
$added = 0;
push @tempv, $tempp;
}
@pointsv = [];
pop @pointsv;
foreach (@tempv) { print "Temp points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; };
foreach (@tempv) {
$point = [@{$_},0];
($xc,$yc) = (${$point}[0],${$point}[1]);
$xc = $xc*$ssx/$scale+$sb;
$yc = $yc*$ssy/$scale+$sb;
${$point}[2] = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc);
push @pointsv, $point;
};
# foreach (@pointsv) { print "New vapor points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; };
};
# ////////////////////////////////// Liquid Phase Adjustments
sub del_liquid{
my($newx) = $cex->get;
my($newy) = $cey->get;
$cex->delete(0,15);
$cex->insert('0.0','New X>');
$cey->delete(0,15);
$cey->insert('0.0','New Y>');
my($newp) = 0;
$newx =~ s/New X>//;
$newy =~ s/New Y>//;
foreach (@pointsl) { $c->delete(${$_}[2]); }
if(($newx>0) || ($newy>0)) {
($xc,$yc) = ($newx,$newy);
$xc = $xc*$ssx/$scale+$sb;
$yc = $yc*$ssy/$scale+$sb;
$newp = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc);
@pointsl = [$newx,$newy,$newp];
}
else { @pointsl = []; pop @pointsl};
};
sub add_lcode{
my($newx) = $cex->get;
my($newy) = $cey->get;
$cex->delete(0,15);
$cex->insert('0.0','New X>');
$cey->delete(0,15);
$cey->insert('0.0','New Y>');
$newx =~ s/New X>//;
$newy =~ s/New Y>//;
if(($newx>0)&&($newy>0)) {
# print "New liquid point X :".$newx." Y :".$newy."n";
add_liquid($newx,$newy);
};
};
sub add_liquid
{
my($tempp) = [@_[0],@_[1],0];
# print "add liquid point ".${$tempp}[0]." ".@_[1]." ".@_[0]."n";
my(@templ) = [];
pop @templ;
my($added) = 1;
foreach (@pointsl)
{
# print "Old liquid points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]." cv : ".@{$_}[2]."n";
$c->delete(${$_}[2]);
if((${$tempp}[0] < ${$_}[0]))
{
if($added)
{
# print "adding point";
$added = 0;
push @templ, $tempp;
push @templ, $_;
}
else
{
push @templ, $_;
}
}
else
{
push @templ, $_;
};
};
if($added)
{
# print "adding pointn";
$added = 0;
push @templ, $tempp;
}
@pointsl = [];
pop @pointsl;
# foreach (@templ) { print "Temp points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; };
foreach (@templ) {
$point = [@{$_},0];
($xc,$yc) = (${$point}[0],${$point}[1]);
$xc = $xc*$ssx/$scale+$sb;
$yc = $yc*$ssy/$scale+$sb;
${$point}[2] = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc);
push @pointsl, $point;
};
foreach (@pointsl) { print "New liquid points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; };
};
# //////////////////////////////////////////////////////////////////////////////
# // Menu Bar Code
# //////////////////////////////////////////////////////////////////////////////
sub mkmb {
# (Ripped from nTk examples)
# Make a Menubutton widget; note that the menu is automatically created.
# We maintain a list of the Menubutton references since some callers
# need to refer to the Menubutton, as well as to suppress stray name
# warnings with Perl -w.
my($mb0, $mb_label, $mb_label_underline, $mb_msg, $mb_list_ref) = @_;
my $mb = $mb0->Menubutton(
-text => $mb_label,
-underline => $mb_label_underline,
-background => 'DarkGreen',
-foreground => 'Black',
);
my($menu) = $mb->Menu(-tearoff => 0);
$mb->configure(-menu => $menu);
my $mb_list;
foreach $mb_list (@{$mb_list_ref}) {
$mb->command(
-label => $mb_list->[0],
-command => $mb_list->[1] ,
-underline => $mb_list->[2],
-background => 'DarkGreen',
-foreground => 'White',
);
print " ".@{$mb_list}[0]." ".${$mb_list}[0]." ".$mb_list->[0]."n";
}
$mb->pack(-side => 'left');
$m->bind($mb, '<Enter>' => sub {ClearMsg; ShowMsg("Entering Menu : ")});
$m->bind($mb, '<Leave>' => &ClearMsg);
push @menu_button_list, $mb;
return $mb;
} # end mkmb
sub SimStart {
if (not $sim_running) {
$sim_running = 1;
$menu_button_list[1]->cget(-menu)->entryconfigure(0,
-state => 'disabled',
);
$menu_button_list[1]->cget(-menu)->entryconfigure(1,
-state => 'normal',
);
}
} # end SimStart
sub SimStop {
if ($sim_running) {
$sim_running = 0;
$menu_button_list[1]->cget(-menu)->entryconfigure(0,
-state => 'normal',
);
$menu_button_list[1]->cget(-menu)->entryconfigure(1,
-state => 'disabled',
);
}
} # end SimStop
sub NotDone {
print "Not yet implemented.n";
} # end NotDone
sub ShowMsg {
my($msg) = shift;
$statustext->delete('1.0', 'end');
$statustext->insert('1.0', $msg."show message");
} # end ShowMsg
sub ClearMsg {
$statustext->delete('1.0', 'end');
$statustext->insert('1.0', "Left Mouse Button Adds Vapor point.");
} # end ClearMsg
# ///////////////////////////////////////////////////////////////////////
print "finsished with Start up Start Main.n";
# ///////////////////////////////////////////////////////////////////////
while (1) {
if ($quit_flag) {
$m->destroy;
}
$m->DoOneEvent(ALL_EVENTS);
}

Más contenido relacionado

La actualidad más candente

Mkscript sh
Mkscript shMkscript sh
Mkscript shBen Pope
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Fabien Potencier
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011John Ford
 
PythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたPythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたitoxdev
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with ExtbaseJochen Rau
 
Devs for Leokz e 7Masters - WTF Oriented Programming
Devs for Leokz e 7Masters - WTF Oriented ProgrammingDevs for Leokz e 7Masters - WTF Oriented Programming
Devs for Leokz e 7Masters - WTF Oriented ProgrammingFabio Akita
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにYuya Takeyama
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»e-Legion
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)Yoshihiro Sugi
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)Dennis Knochenwefel
 

La actualidad más candente (20)

Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Camping
CampingCamping
Camping
 
R57.Php
R57.PhpR57.Php
R57.Php
 
Nop2
Nop2Nop2
Nop2
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
WordPress Security: Be a Superhero - WordCamp Raleigh - May 2011
 
PythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたPythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみた
 
Get into the FLOW with Extbase
Get into the FLOW with ExtbaseGet into the FLOW with Extbase
Get into the FLOW with Extbase
 
Devs for Leokz e 7Masters - WTF Oriented Programming
Devs for Leokz e 7Masters - WTF Oriented ProgrammingDevs for Leokz e 7Masters - WTF Oriented Programming
Devs for Leokz e 7Masters - WTF Oriented Programming
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
DOS
DOSDOS
DOS
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»Юрий Буянов «Squeryl — ORM с человеческим лицом»
Юрий Буянов «Squeryl — ORM с человеческим лицом»
 
全裸でワンライナー(仮)
全裸でワンライナー(仮)全裸でワンライナー(仮)
全裸でワンライナー(仮)
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
 

Destacado

Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58
Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58
Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58CIMNE
 
Sortimo Company Brochure English March 2015
Sortimo Company Brochure English March 2015Sortimo Company Brochure English March 2015
Sortimo Company Brochure English March 2015HandHEuroTech
 
Tuberculosis Prevention Brochure - IMC 2010 - 2011
Tuberculosis Prevention Brochure - IMC 2010 - 2011Tuberculosis Prevention Brochure - IMC 2010 - 2011
Tuberculosis Prevention Brochure - IMC 2010 - 2011Simon Rasin MD, MPH, PhD
 
ГИС Инвестора
ГИС ИнвестораГИС Инвестора
ГИС ИнвестораCSR
 
The twelve hotel press book may to dec 2012
The twelve hotel press book may to dec 2012The twelve hotel press book may to dec 2012
The twelve hotel press book may to dec 2012Twelve Hotel Galway
 
Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...
Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...
Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...vitriolum
 
Fmap Sbp Organogram
Fmap Sbp OrganogramFmap Sbp Organogram
Fmap Sbp Organogramjawadorak
 
Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...
Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...
Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...Startup AddVenture by CCC Startups
 
Ex post evaluation of cohesion policy programmes 2000 - 2006
Ex post evaluation of cohesion policy programmes 2000 - 2006Ex post evaluation of cohesion policy programmes 2000 - 2006
Ex post evaluation of cohesion policy programmes 2000 - 2006ekonkafr
 
HCTE C&C08(TDM)
HCTE C&C08(TDM) HCTE C&C08(TDM)
HCTE C&C08(TDM) Teksify
 
EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio...
 EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio... EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio...
EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio...mcburwell
 
Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)jeresig
 
Creatively Applying CMMI for Services in a Very Small Consulting Firm
Creatively Applying CMMI for Services in a Very Small Consulting FirmCreatively Applying CMMI for Services in a Very Small Consulting Firm
Creatively Applying CMMI for Services in a Very Small Consulting FirmLeading Edge Process Consultants LLC
 

Destacado (20)

April 2011
April 2011April 2011
April 2011
 
Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58
Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58
Presentation of EMPOWERING project in the last Workshop of the IEA Annex 58
 
Sortimo Company Brochure English March 2015
Sortimo Company Brochure English March 2015Sortimo Company Brochure English March 2015
Sortimo Company Brochure English March 2015
 
Tuberculosis Prevention Brochure - IMC 2010 - 2011
Tuberculosis Prevention Brochure - IMC 2010 - 2011Tuberculosis Prevention Brochure - IMC 2010 - 2011
Tuberculosis Prevention Brochure - IMC 2010 - 2011
 
ГИС Инвестора
ГИС ИнвестораГИС Инвестора
ГИС Инвестора
 
The twelve hotel press book may to dec 2012
The twelve hotel press book may to dec 2012The twelve hotel press book may to dec 2012
The twelve hotel press book may to dec 2012
 
Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...
Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...
Recomendado revista bienestar psiquiatrico n.33 articulo sobre la depresión p...
 
Fmap Sbp Organogram
Fmap Sbp OrganogramFmap Sbp Organogram
Fmap Sbp Organogram
 
камчатка Mini 1
камчатка Mini 1камчатка Mini 1
камчатка Mini 1
 
Kineziko rito
Kineziko ritoKineziko rito
Kineziko rito
 
Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...
Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...
Orkhan Babayev - Azerbaijan's 1st Accelerator - Startup AddVenture Middle Eas...
 
3 vgoru photo1
3 vgoru photo13 vgoru photo1
3 vgoru photo1
 
Dynamic-Englisch
Dynamic-EnglischDynamic-Englisch
Dynamic-Englisch
 
Ex post evaluation of cohesion policy programmes 2000 - 2006
Ex post evaluation of cohesion policy programmes 2000 - 2006Ex post evaluation of cohesion policy programmes 2000 - 2006
Ex post evaluation of cohesion policy programmes 2000 - 2006
 
Chip March 2012
Chip March 2012Chip March 2012
Chip March 2012
 
HCTE C&C08(TDM)
HCTE C&C08(TDM) HCTE C&C08(TDM)
HCTE C&C08(TDM)
 
WTO - World Trade Report 2011
WTO - World Trade Report 2011WTO - World Trade Report 2011
WTO - World Trade Report 2011
 
EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio...
 EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio... EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio...
EV traction motor comparison - Techno Frontier 2013 - M Burwell - Internatio...
 
Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)Advanced jQuery (Ajax Exp 2007)
Advanced jQuery (Ajax Exp 2007)
 
Creatively Applying CMMI for Services in a Very Small Consulting Firm
Creatively Applying CMMI for Services in a Very Small Consulting FirmCreatively Applying CMMI for Services in a Very Small Consulting Firm
Creatively Applying CMMI for Services in a Very Small Consulting Firm
 

Similar a distill

Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2osfameron
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev AssistantDave Cross
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of TransductionDavid Stockton
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and BeyondJochen Rau
 
R57shell
R57shellR57shell
R57shellady36
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked aboutTatsuhiko Miyagawa
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
R57php 1231677414471772-2
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2ady36
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus Ramberg
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Michael Schwern
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Templateguest48224
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Templatemussawir20
 

Similar a distill (20)

Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
Daily notes
Daily notesDaily notes
Daily notes
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Improving Dev Assistant
Improving Dev AssistantImproving Dev Assistant
Improving Dev Assistant
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
Extbase and Beyond
Extbase and BeyondExtbase and Beyond
Extbase and Beyond
 
R57shell
R57shellR57shell
R57shell
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
20 modules i haven't yet talked about
20 modules i haven't yet talked about20 modules i haven't yet talked about
20 modules i haven't yet talked about
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
R57php 1231677414471772-2
R57php 1231677414471772-2R57php 1231677414471772-2
R57php 1231677414471772-2
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Php
PhpPhp
Php
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Template
 
Smarty Template
Smarty TemplateSmarty Template
Smarty Template
 

Más de Thomas Knudstrup (9)

NinjaSynch
NinjaSynchNinjaSynch
NinjaSynch
 
GreyCount
GreyCountGreyCount
GreyCount
 
CLinkedList
CLinkedListCLinkedList
CLinkedList
 
Generics
GenericsGenerics
Generics
 
assembly
assemblyassembly
assembly
 
Fibonnaci
FibonnaciFibonnaci
Fibonnaci
 
HappyFeat
HappyFeatHappyFeat
HappyFeat
 
Sorter
SorterSorter
Sorter
 
Sorter
SorterSorter
Sorter
 

distill

  • 1. A chemical engineering ideal stage calculator - Can read and save data to an ascii file - Can add points with pointer or input location - Can input an equation to plot as data - Can clear data and start again - Location of mouse pointer is displayed on screen require 5.004; use Tk 800.023; use Tk qw/:eventtypes/; use Tk::FileSelect; use Tk::toplevel; use Tk::Dialog; use Cwd; # ////////////////////////////////// Fundamentals my(@menu_button_list, $quit_flag, $quit_code, $add_code); my($scale,$screen_bump, $sb, $screen_sizex, $ssx, $beed_size, $bs); $scale = 1; $screen_bump = 20; $sb = $screen_bump; $screen_sizey = 400; $ssy = $screen_sizey; $screen_sizex = 400; $ssx = $screen_sizex; $beed_size = 1; $bs = $beed_size;
  • 2. @glines = [0,0,0,0]; @dlines = [0]; @pointsv = [0,0]; @pointsl = [0,0]; $dataldd = 0; # ////////////////////////////////// Main Frame $m->destroy if Exists($m); $m = Tk::MainWindow->new; $m->title('Distillation Simulator'); $m->iconname('sim'); $quit_flag = 0; $quit_code = sub {$quit_flag = 1}; $m->protocol('WM_DELETE_WINDOW' => $quit_code); $fsel = $m->FileSelect (-directory => Cwd::cwd(), # Alias: -initialdir -initialfile => "data.dat", -filter => "*.pl", -regexp => '*.*', #' does not work (?) -filelabel => "Datei", -filelistlabel => "Dateien", -dirlabel => "Verzeichnis", -dirlistlabel => "Verzeichnisse", -verify => ['-T'], # accept only text files ); # ////////////////////////////////// Menu
  • 3. my $menubar = $m->Frame(qw/-relief raised -background DarkGreen -bd 2/); $menubar->pack(-side => 'top', -fill => 'x'); $statustext = $menubar->Text( -relief => 'groove', -height => 1, -width => $screen_sizex/24, -border => 2, -background => 'DarkGreen', ); $statustext->pack(-side => 'top', -fill => 'x'); $statustext->insert('1.0', 'Left Mouse Button Adds Vapor point.'); mkmb($menubar, 'Data', 0, 'Loading Data etc.', [ ['Load', &load_data, 0], ['clear', &clear_data, 0], ['save', &NotDone, 0], ['Print', &NotDone, 0], ['Exit', sub{$m->bell}, 0], ]); mkmb($menubar, 'Distill', 0, 'Distillation control', [ ['Distill', &dis_code, 2], ['Delete', &del_dis, 2], ]); mkmb($menubar, 'Display', 0, 'Display settings',
  • 4. [ ['Redraw', &NotDone, 2], ['Clear', &NotDone, 2], ]); mkmb($menubar, 'Help', 0, 'There when you need it', [ ['About..', [&about_help, $m], 0], ['Intro', &NotDone, 0], ['Contents', &NotDone, 0], ]); $menu_button_list[$#menu_button_list]->pack(-side => 'right'); # ////////////////////////////////// About Help popup sub about_help{ my $m = shift; my $aboutm = $m->Dialog(-entry => 'stuff', -default_button => 'Yes', -buttons => [qw/Yes No Cancel/]); $aboutm->configure(-text => ' Distillation modelling program. Enter VLE data via a formatted file or the two points methods.'); my $result = $aboutm->Show(-global); print "Dialog result : ".$result; }# # ////////////////////////////////// Add Point Entry Frame $cf = $m->Frame(-bd => 2 ); $cex = $cf->Entry(
  • 5. -relief => 'sunken', -bd => 2, -width => $screen_sizex/20, ); $cey = $cf->Entry( -relief => 'sunken', -bd => 2, -width => $screen_sizex/20, ); $cba = $cf->Button( -text => 'Add Point', -command => &add_code, ); $cbr = $cf->Button( -text => 'Load', -command => &load_data, ); $cbdv = $cf->Button( -text => 'Del Vapor', -command => &del_vapor, ); $cbdl = $cf->Button( -text => 'Del Liquid', -command => &del_liquid, );
  • 6. $cex->pack(-side => 'left'); $cex->insert('0.0','New X>'); $cey->pack(-side => 'left'); $cey->insert('0.0','New Y>'); $cba->pack(-side => 'left'); $cbr->pack(-side => 'left'); $cbdv->pack(-side => 'left'); $cbdl->pack(-side => 'left'); $cf->pack; # ////////////////////////////////// Distill Frame $df = $m->Frame(-bd => 2 ); $dexs = $df->Entry( -relief => 'sunken', -bd => 2, -width => $screen_sizex/16, ); $dexl = $df->Entry( -relief => 'sunken', -bd => 2, -width => $screen_sizex/16, ); $dexf = $df->Label( -text => 'stuff', -relief => 'groove', -border => 2,
  • 7. -width => $screen_sizex/24, ); $dbr = $df->Button( -text => 'Distill', -command => &dis_code, ); $dbd = $df->Button( -text => 'Delete', -command => &del_dis, ); $dexs->pack(-side => 'left'); $dexs->insert('0.0','Start X>'); $dexl->pack(-side => 'left'); $dexl->insert('0.0','Last X>'); $dexf->pack(-side => 'left'); $dbr->pack(-side => 'left'); $dbd->pack(-side => 'left'); $df->pack; # ////////////////////////////////// Equation Frame $uf = $m->Frame(-bd => 2 ); $uexf = $uf->Label( -text => 'Insert Equation', -relief => 'groove', -border => 2, -width => $screen_sizex/24,
  • 8. ); $uexs = $uf->Entry( -relief => 'sunken', -bd => 2, -width => $screen_sizex/12, ); $ubd = $uf->Button( -text => 'Add Equation To Vapor', -command => &plot_data, ); $uexf->pack(-side => 'left'); $uexs->pack(-side => 'left'); $ubd->pack(-side => 'left'); $uf->pack; # ////////////////////////////////// Canvas Frame $f = $m->Frame(-bd => 2 ); $c = $f->Canvas( -relief => 'sunken', -bd => 2, -height => $sb + $ssy + $sb, -width => $sb + $ssx + $sb, ); $c->pack(-side => 'top'); $f->pack; $m->bind($c, '<Motion>' => &ShowCoord);
  • 9. $m->bind($c, '<Button-1>' => &AddVCoord); $m->bind($c, '<Button-3>' => &AddLCoord); $m->bind($c, '<Leave>' => &DeleteCoord); my $otm, $ott; sub ShowCoord{ $c->delete($otm); $c->delete($ott); my $e = $c->XEvent; # Note: Cap X returns global x coord, Low Case x returns Canvas local coord. my $xm = $e->x; my $ym = $e->y; my $xmt = ($xm-$sb)*$scale/$ssx; my $ymt = ($sb+$ssy-$ym)*$scale/$ssy; $otm = $c->createOval($xm-$beed_size,$ym-$beed_size,$xm+$beed_size,$ym+$beed_size); $ott = $c->createText($xm,$ym-9,-text => $xmt.",".$ymt); # print "x ".$xm." y ".$ym."n"; }; sub DeleteCoord{ $c->delete($otm); $c->delete($ott); } sub AddVCoord{ my $e = $c->XEvent; my $xm = ($e->x-$sb)*$scale/$ssx; my $ym = ($sb+$ssy-$e->y)*$scale/$ssy;
  • 10. add_vapor($xm,$ym); print "Adding point : X ".$xm." Y ".$ym."n"; }; sub AddLCoord{ my $e = $c->XEvent; my $xm = ($e->x-$sb)*$scale/$ssx; my $ym = ($sb+$ssy-$e->y)*$scale/$ssy; add_liquid($xm,$ym); print "Adding point : X ".$xm." Y ".$ym."n"; }; # ////////////////////////////////// Get Data and Plot sub clear_data{ del_vapor(0,0); del_liquid(0,0); } sub load_data{ if($dataldd>0){ print "Deleting previous datan"; del_vapor(0,0); del_liquid(0,0); } $datafile = $fsel->Show; open(DATA, "$datafile") || die "Can't open $datafile: $!n"; $vapor = 1; while(<DATA>)
  • 11. { my($gx0,$gy0,$gx1,$gy1); chomp; if(/Vapor/) {print $_."n"; $vapor = 1; pop @pointsv;} elsif(/Liquid/) {print $_."n"; $vapor = 0; pop @pointsl;} else { $point = [split(/,/),0]; # print "X :".${$point}[0]." Y :".${$point}[1]."n"; ($xc,$yc) = (${$point}[0],${$point}[1]); $xc = $xc*$ssx/$scale+$sb; $yc = $yc*$ssy/$scale+$sb; ${$point}[2] = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs- $yc); # if($vapor){ push @pointsv, $point; } else { push @pointsl, $point; } # # } } # end while $dataldd = 1; } sub plot_data{ my $function = ($uexs->get); for(my $xi = 0;$xi <= 100; $xi = $xi + 1){
  • 12. my $x = $xi/100; my $y = (eval $function); add_vapor($x,$y); # $xc = $x*$ssx/$scale+$sb; # $yc = $y*$ssy/$scale+$sb; # $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc); } } sub add_grid{ pop @glines; $gx0 = 0;$gy0 = 0;$gx1 = 0;$gy1 = 0; my $glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb,$sb+0,$sb,$sb+$ssy)]; push @glines, $glineadd; for(my $gx = 0;$gx <= 100;$gx += 10) { $gx0 = $gx; $gy0 = 0; $gx1 = $gx; $gy1 = 0; $glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb+$ssx/100*$gx,$sb+$ssy,$sb+ $ssx/100*$gx,$sb+$ssy+$sb/2)]; push @glines, $glineadd; } # $gx0 = 0;$gy0 = 0;$gx1 = 0;$gy1 = 0; $glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb,$sb+$ssy,$sb+$sb+$ssx,$sb+$ssy)]; push @glines, $glineadd; for(my $gy = 0;$gy <= 100;$gy += 10) { $gx0 = 0; $gy0 = $gy; $gx1 = 0; $gy1 = $gy; $glineadd = [$gx0,$gy0,$gx1,$gy1,$c->createLine($sb/2,$sb+$ssy/100*$gy0,$sb,$sb+
  • 13. $ssy/100*$gy0)]; push @glines, $glineadd; } foreach (@glines){ print ${$_}[0]." ".${$_}[1]." ".${$_}[2]." ".${$_}[3]." ".${$_}[4]."n"; }; }; add_grid; sub nuke_grid{ foreach (@glines){ $c->delete(${$_}[4]); }; }; # ////////////////////////////////// Distillation Code sub dis_code { my $lowx, $highx, $liquidx, $xl, $vaporx, $xv, $startx, $lastx; my $lowy, $highy, $liquidy, $yl, $vapory, $yv, $starty, $lasty; $startx = $dexs->get; $lastx = $dexl->get; $liquidx = $startx; $dexs->delete(0,15); $dexs->insert('0.0','Start X>'); $dexl->delete(0,15); $dexl->insert('0.0','Last X>'); $startx =~ s/Start X>//; $lastx =~ s/Last X>//;
  • 14. if(($startx<$scale)){} else {$startx = $scale/99} if(($lastx<$scale)){} else {$lastx = $scale/1.09} $got_yet = 1; foreach (@pointsl) { if($got_yet) { if(($startx < ${$_}[0])) { $highx = ${$_}[0]; $highy = ${$_}[1]; $got_yet = 0; } else { $lowx = ${$_}[0]; $lowy = ${$_}[1]; }; }; }; # foreach loop $starty = $lowy + ($startx - $lowx)/($highx - $lowx)*($highy - $lowy); $xl = $startx*$ssx/$scale+$sb; $yl = $starty*$ssy/$scale+$sb; push @dlines, $c->createOval($xl-$bs,$sb+$ssy+$bs-$yl,$xl+$bs,$sb+$ssy-$bs-$yl); $liquidx = $startx; $liquidy = $starty;
  • 15. $vaporx = $liquidx; # Iterate up the latter of Distillation Steps while(($liquidx < $lastx)) { # Get the next vapor point $got_yet = 1; foreach (@pointsv) { if($got_yet) { if(($vaporx < ${$_}[0])) { $highx = ${$_}[0]; $highy = ${$_}[1]; $got_yet = 0; } else { $lowx = ${$_}[0]; $lowy = ${$_}[1]; }; }; }; # foreach loop $vapory = $lowy + ($vaporx - $lowx)/($highx - $lowx)*($highy - $lowy); $xl = $liquidx*$ssx/$scale+$sb; $yl = $liquidy*$ssy/$scale+$sb; $xv = $vaporx*$ssx/$scale+$sb;
  • 16. $yv = $vapory*$ssy/$scale+$sb; push @dlines, $c->createLine($xl,$sb+$sb+$ssy+$bs-$yl, $xv,$sb+$sb+$ssy+$bs-$yv); push @dlines, $c->createOval($xv-$bs,$sb+$sb+$ssy+$bs-$yv,$xv+$bs,$sb+$sb+$ssy-$bs- $yv); $liquidy = $vapory; # Get the next Liquid point $got_yet = 1; foreach (@pointsl) { if($got_yet) { if(($liquidy < ${$_}[1])) { $highx = ${$_}[0]; $highy = ${$_}[1]; $got_yet = 0; } else { $lowx = ${$_}[0]; $lowy = ${$_}[1]; }; }; }; # foreach loop $liquidx = $lowx + ($liquidy - $lowy)/($highy - $lowy)*($highx - $lowx); $xl = $liquidx*$ssx/$scale+$sb; $yl = $liquidy*$ssy/$scale+$sb;
  • 17. $xv = $vaporx*$ssx/$scale+$sb; $yv = $vapory*$ssy/$scale+$sb; push @dlines, $c->createLine($xv,$sb+$sb+$ssy+$bs-$yv, $xl,$sb+$sb+$ssy+$bs-$yl); push @dlines, $c->createOval($xl-$bs,$sb+$sb+$ssy+$bs-$yl,$xl+$bs,$sb+$sb+$ssy-$bs-$yl); $vaporx = $liquidx; } # end while loop $lastx = $liquidx; $lasty = $liquidy; $dexf->configure( -text => $lastx, ); }; sub del_dis{ foreach (@dlines){ $c->delete($_); } @dlines = []; } # ////////////////////////////////// Vapor Phase Adjustments sub del_vapor{ my($newx) = $cex->get; my($newy) = $cey->get; $cex->delete(0,15); $cex->insert('0.0','New X>'); $cey->delete(0,15);
  • 18. $cey->insert('0.0','New Y>'); my($newp) = 0; $newx =~ s/New X>//; $newy =~ s/New Y>//; foreach (@pointsv) { $c->delete(${$_}[2]); } if(($newx>0) || ($newy>0)) { ($xc,$yc) = ($newx,$newy); $xc = $xc*$ssx/$scale+$sb; $yc = $yc*$ssy/$scale+$sb; $newp = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc); @pointsv = [$newx,$newy,$newp]; } else { @pointsv = []; pop @pointsv}; }; sub add_code{ my($newx) = $cex->get; my($newy) = $cey->get; $cex->delete(0,15); $cex->insert('0.0','New X>'); $cey->delete(0,15); $cey->insert('0.0','New Y>'); $newx =~ s/New X>//; $newy =~ s/New Y>//; if(($newx>0)&&($newy>0)) { # print "New vapor point X :".$newx." Y :".$newy."n";
  • 19. add_vapor($newx,$newy); }; }; sub add_vapor { my($tempp) = [@_[0],@_[1],0]; # print "add vapor point ".${$tempp}[0]." ".@_[1]." ".@_[0]."n"; my(@tempv) = []; pop @tempv; my($added) = 1; foreach (@pointsv) { # print "Old vapor points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]." cv : ".@{$_}[2]."n"; $c->delete(${$_}[2]); if((${$tempp}[0] < ${$_}[0])) { if($added) { # print "adding point"; $added = 0; push @tempv, $tempp; push @tempv, $_; } else {
  • 20. push @tempv, $_; } } else { push @tempv, $_; }; }; if($added) { print "adding pointn"; $added = 0; push @tempv, $tempp; } @pointsv = []; pop @pointsv; foreach (@tempv) { print "Temp points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; }; foreach (@tempv) { $point = [@{$_},0]; ($xc,$yc) = (${$point}[0],${$point}[1]); $xc = $xc*$ssx/$scale+$sb; $yc = $yc*$ssy/$scale+$sb; ${$point}[2] = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc); push @pointsv, $point; };
  • 21. # foreach (@pointsv) { print "New vapor points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; }; }; # ////////////////////////////////// Liquid Phase Adjustments sub del_liquid{ my($newx) = $cex->get; my($newy) = $cey->get; $cex->delete(0,15); $cex->insert('0.0','New X>'); $cey->delete(0,15); $cey->insert('0.0','New Y>'); my($newp) = 0; $newx =~ s/New X>//; $newy =~ s/New Y>//; foreach (@pointsl) { $c->delete(${$_}[2]); } if(($newx>0) || ($newy>0)) { ($xc,$yc) = ($newx,$newy); $xc = $xc*$ssx/$scale+$sb; $yc = $yc*$ssy/$scale+$sb; $newp = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc); @pointsl = [$newx,$newy,$newp]; } else { @pointsl = []; pop @pointsl}; }; sub add_lcode{ my($newx) = $cex->get;
  • 22. my($newy) = $cey->get; $cex->delete(0,15); $cex->insert('0.0','New X>'); $cey->delete(0,15); $cey->insert('0.0','New Y>'); $newx =~ s/New X>//; $newy =~ s/New Y>//; if(($newx>0)&&($newy>0)) { # print "New liquid point X :".$newx." Y :".$newy."n"; add_liquid($newx,$newy); }; }; sub add_liquid { my($tempp) = [@_[0],@_[1],0]; # print "add liquid point ".${$tempp}[0]." ".@_[1]." ".@_[0]."n"; my(@templ) = []; pop @templ; my($added) = 1; foreach (@pointsl) { # print "Old liquid points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]." cv : ".@{$_}[2]."n"; $c->delete(${$_}[2]); if((${$tempp}[0] < ${$_}[0])) {
  • 23. if($added) { # print "adding point"; $added = 0; push @templ, $tempp; push @templ, $_; } else { push @templ, $_; } } else { push @templ, $_; }; }; if($added) { # print "adding pointn"; $added = 0; push @templ, $tempp; } @pointsl = []; pop @pointsl;
  • 24. # foreach (@templ) { print "Temp points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; }; foreach (@templ) { $point = [@{$_},0]; ($xc,$yc) = (${$point}[0],${$point}[1]); $xc = $xc*$ssx/$scale+$sb; $yc = $yc*$ssy/$scale+$sb; ${$point}[2] = $c->createOval($xc-$bs,$sb+$sb+$ssy+$bs-$yc,$xc+$bs,$sb+$sb+$ssy-$bs-$yc); push @pointsl, $point; }; foreach (@pointsl) { print "New liquid points 0 : ".@{$_}[0]." 1 : ".@{$_}[1]."n"; }; }; # ////////////////////////////////////////////////////////////////////////////// # // Menu Bar Code # ////////////////////////////////////////////////////////////////////////////// sub mkmb { # (Ripped from nTk examples) # Make a Menubutton widget; note that the menu is automatically created. # We maintain a list of the Menubutton references since some callers # need to refer to the Menubutton, as well as to suppress stray name # warnings with Perl -w. my($mb0, $mb_label, $mb_label_underline, $mb_msg, $mb_list_ref) = @_; my $mb = $mb0->Menubutton( -text => $mb_label, -underline => $mb_label_underline, -background => 'DarkGreen',
  • 25. -foreground => 'Black', ); my($menu) = $mb->Menu(-tearoff => 0); $mb->configure(-menu => $menu); my $mb_list; foreach $mb_list (@{$mb_list_ref}) { $mb->command( -label => $mb_list->[0], -command => $mb_list->[1] , -underline => $mb_list->[2], -background => 'DarkGreen', -foreground => 'White', ); print " ".@{$mb_list}[0]." ".${$mb_list}[0]." ".$mb_list->[0]."n"; } $mb->pack(-side => 'left'); $m->bind($mb, '<Enter>' => sub {ClearMsg; ShowMsg("Entering Menu : ")}); $m->bind($mb, '<Leave>' => &ClearMsg); push @menu_button_list, $mb; return $mb; } # end mkmb sub SimStart { if (not $sim_running) {
  • 26. $sim_running = 1; $menu_button_list[1]->cget(-menu)->entryconfigure(0, -state => 'disabled', ); $menu_button_list[1]->cget(-menu)->entryconfigure(1, -state => 'normal', ); } } # end SimStart sub SimStop { if ($sim_running) { $sim_running = 0; $menu_button_list[1]->cget(-menu)->entryconfigure(0, -state => 'normal', ); $menu_button_list[1]->cget(-menu)->entryconfigure(1, -state => 'disabled', ); } } # end SimStop sub NotDone { print "Not yet implemented.n"; } # end NotDone sub ShowMsg {
  • 27. my($msg) = shift; $statustext->delete('1.0', 'end'); $statustext->insert('1.0', $msg."show message"); } # end ShowMsg sub ClearMsg { $statustext->delete('1.0', 'end'); $statustext->insert('1.0', "Left Mouse Button Adds Vapor point."); } # end ClearMsg # /////////////////////////////////////////////////////////////////////// print "finsished with Start up Start Main.n"; # /////////////////////////////////////////////////////////////////////// while (1) { if ($quit_flag) { $m->destroy; } $m->DoOneEvent(ALL_EVENTS); }