# FILE: avf2ppm.tcl # # This file must be evaluated by mmDispSh package require Oc 1.1.1.2 package require Mmdispcmds 1.1.1.0 Oc_ForceStderrDefaultMessage catch {wm withdraw .} Oc_Main SetAppName avf2ppm Oc_Main SetVersion 1.1.1.2 Oc_CommandLine Option console {} {} Oc_CommandLine Option v { {level {regexp {^[0-9]+$} $level} {is a decimal integer}} } { global verbosity; scan $level %d verbosity } {Verbosity level (default = 1)} set verbosity 1 Oc_CommandLine Option f {} { global forceOutput; set forceOutput 1 } {Force overwrite of output files} set forceOutput 0 Oc_CommandLine Option format { {format {regexp -nocase {P3|P6|B24} $format} {is one of {P3,P6,B24}}} } { global bitmapFormat; set bitmapFormat [string toupper $format] } {Format of output bitmap file(s) (default=P6)} set bitmapFormat P6 set configFiles [list [file join [file dirname \ [Oc_DirectPathname [info script]]] avf2ppm.def]] Oc_CommandLine Option config {file} { global configFiles; lappend configFiles $file } "Append file to list of configuration files" Oc_CommandLine Option ipat { {pattern {} {is in glob-style}} } { global inputPattern; set inputPattern $pattern } {Pattern specifying input files} Oc_CommandLine Option opatexp { {regexp {} {is a regular expression}} } { global opatexp; set opatexp $regexp } {Pattern: part of input filename to replace} set opatexp {(\.[^.]?[^.]?[^.]?$|$)} Oc_CommandLine Option opatsub {sub} { global opatsub; set opatsub $sub } {Replacement in input filename to get output filename} Oc_CommandLine Option filter { {pipeline {} {is an output pipeline}} } { global filter; set filter $pipeline } {Post-processing programs to apply to output} Oc_CommandLine Option [Oc_CommandLine Switch] { {{file list} {} {Input vector field file(s)}} } { global infile; set infile $file } {End of options; next argument is file} Oc_CommandLine Parse $argv # Get the configuration settings from config file list foreach c $configFiles { source $c } # Turn -ipat pattern into list of input files set inGlob [list] if {[info exists inputPattern]} { set inGlob [lsort -dictionary [glob -nocomplain -- $inputPattern]] } else { set inputPattern "" } # Set default output filename substitution if {![info exists opatsub]} { switch $bitmapFormat { B24 {set opatsub .bmp} default {set opatsub .ppm} } } if {$verbosity >= 3} { puts stderr "##############" puts stderr "Input files: $infile $inGlob" puts stderr "##############" } if {$verbosity >= 2} { puts stderr "ipat: $inputPattern" puts stderr "opatexp: $opatexp" puts stderr "opatsub: $opatsub" puts stderr "Output bitmap format: $bitmapFormat" if {[info exists filter]} { puts stderr "Filter command: $filter" } puts stderr "Arrow Configuration--- Display: $plot_config(arrow,status) Colormap name: $plot_config(arrow,colormap) Colormap size: $plot_config(arrow,colorcount) Quantity: $plot_config(arrow,quantity) Autosample: $plot_config(arrow,autosample) Subsample: $plot_config(arrow,subsample) Size: $plot_config(arrow,size) Antialias: $plot_config(arrow,antialias)" puts stderr "Pixel Configuration--- Display: $plot_config(pixel,status) Colormap name: $plot_config(pixel,colormap) Colormap size: $plot_config(pixel,colorcount) Quantity: $plot_config(pixel,quantity) Autosample: $plot_config(pixel,autosample) Subsample: $plot_config(pixel,subsample) Size: $plot_config(pixel,size)" puts stderr "Misc Configuration---- Background color: $plot_config(misc,background) Draw boundary: $plot_config(misc,drawboundary) Margin: $plot_config(misc,margin) Dimensions: $plot_config(misc,width) x $plot_config(misc,height) Zoom: $plot_config(misc,zoom) Crop: $plot_config(misc,crop) Rotation: $plot_config(misc,rotation) Datascale: $plot_config(misc,datascale)" } # Loop through input files set input_file_list [concat $infile $inGlob] if {[llength $input_file_list]<1} { Oc_Log Log [Oc_CommandLine Usage] info puts stderr "\nERROR: No input files" exit } foreach in $input_file_list { # Contents of plot_config() influence [ChangeMesh] ChangeMesh $in $plot_config(misc,width) $plot_config(misc,height) \ $plot_config(misc,rotation) $plot_config(misc,zoom) if {[string match Vf_EmptyMesh [GetMeshType]]} { puts stderr "Skipping $in" continue } # Adjust data scaling SetDataValueScaling $plot_config(misc,datascale) # create myBitmap from the frame Bitmap Create myBitmap if {[regsub -- $opatexp $in $opatsub out] != 1} { set out $in$opatsub } if {!$forceOutput} { set next 0 foreach {outChan out next} \ [Oc_OpenUniqueFile -start $next -pfx $out -sep1 -] break } else { set outChan [open $out w] } if {[info exists filter]} { if {$verbosity >= 1} { puts stderr "$in --> $filter --> $out" } set out "| 2>@stderr $filter > [list $out]" } elseif {$verbosity >= 1} { puts stderr "$in --> $out" } set outChan [open $out w] fconfigure $outChan -translation binary -buffersize 10000 # send myBitmap to output in requested format Bitmap Write myBitmap $bitmapFormat $outChan Bitmap Delete myBitmap if {[catch {close $outChan} msg]} { return -code error $msg } } exit 0