Artifact 2342178bd4062904d2f3a62e56b3e3ea4b923740125fa8aa213339b6c9709d79:


#! /bin/sh

sys=$1

out=${sys}_gnuplot.wish
tmp=${sys}_gnuplot.tmp

struc=${sys}_struc.txt
dat2=${sys}_odes.dat2

Nx=`mtt_getsize ${sys} x`
Ny=`mtt_getsize ${sys} y`


## write header
cat <<EOF > ${out}
#!/bin/sh
# Next line replaces shell with wish\\
exec wish "\$0" "\$@"

## main window
wm title . "MTT Viewer: ${sys}"

button .print -text "Print" -command print
button .quit  -text "Quit"  -command exit

## states canvas
canvas		.cx
listbox		.cx.l
scrollbar	.cx.sy	-orient v
label		.cx.t	-text		"States"

## outputs canvas
canvas		.cy
listbox		.cy.l
scrollbar	.cy.sy	-orient v
label		.cy.t	-text		"Outputs"

## configure scrollbars
.cx.sy configure -command ".cx.l yview"
.cy.sy configure -command ".cy.l yview"
.cx.l configure -yscrollcommand ".cx.sy set"
.cy.l configure -yscrollcommand ".cy.sy set"

## bind lists
bind .cx.l <<ListboxSelect>> { plot [ .cx.l get anchor ] }
bind .cy.l <<ListboxSelect>> { plot [ .cy.l get anchor ] }

EOF

## create states and outputs lists
awk '
($1 == "state") {
    printf ".cx.l insert end state:%s\n", $4
}
($1 == "output") {
    printf ".cy.l insert end output:%s\n", $4
}' ${struc} >> ${out}

cat <<EOF >> ${out}

pack .cx.t -expand false -fill x -side top
pack .cy.t -expand false -fill x -side top

pack .cx.sy -expand false -fill y -side right
pack .cy.sy -expand false -fill y -side right

pack .cx.l -expand true -fill both -side left
pack .cy.l -expand true -fill both -side left

pack .cx -expand true -fill both
place .cy -in .cx -relx 0 -rely 0 -relwidth 1 -relheight 1 -anchor nw -bordermode outside

radiobutton .states  -text "States"  -value states  -variable view -command { raise .cx } -relief solid
radiobutton .outputs -text "Outputs" -value outputs -variable view -command { raise .cy } -relief solid

pack .states .outputs -side left

pack .quit  -expand false -fill x -side right
pack .print -expand false -fill x -side right


## map names to column numbers
EOF

awk '
BEGIN {
    print "proc \"plot\" \"title\" {";
}
($1 == "state") {
    printf "if (\"%s\"==\"state:%s\") { plot_var \"%s\" %d }\n", Title, $4, $4, $2+2+Ny;
}
($1 == "output") {
    printf "if (\"%s\"==\"output:%s\") { plot_var \"%s\" %d }\n", Title, $4, $4, $2+1;
}    
END {
    print  "}"
}
' Title=\$title Ny=${Ny} ${struc} >> ${out}


cat <<EOF >> ${out}

## call gnuplot
proc "plot_var" "title column" {
    exec echo plot \\\"${dat2}\\\" using 1:\$column title \\\"\$title\\\" with lines > ${tmp}
    exec echo pause -1 >> ${tmp}
    exec gnuplot -title "\$title" ${tmp} &
}

## print output
proc "print" "" {
    exec echo set term postscript > ${tmp}.print
    exec echo set output \\\"../${sys}_gnuplot.ps\\\" >> ${tmp}.print
    exec grep -v pause ${tmp} >> ${tmp}.print
    exec gnuplot ${tmp}.print
    puts "Graph printed to ${sys}_gnuplot.ps"
}

EOF
chmod +x ${out}


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]