# FILE: avf2ovf.tcl # # This file must be evaluated by mmDispSh package require Oc 1.1.1.0 package require Mmdispcmds 1.1.1.0 Oc_ForceStderrDefaultMessage catch {wm withdraw .} Oc_Main SetAppName avf2ovf Oc_Main SetVersion 1.2.0.3 Oc_CommandLine Option console {} {} proc FlipStringCheck { str } { set okaystr 0 catch { if {[regexp {^[-+]?([xyz]):[-+]?([xyz]):[-+]?([xyz])$} \ $str dummy c1 c2 c3] \ && ![string match $c1 $c2] \ && ![string match $c1 $c3] \ && ![string match $c2 $c3]} { set okaystr 1 ;# Good flip string } } return $okaystr } Oc_CommandLine Option flip { {flipstr { FlipStringCheck $flipstr } {is like z:-y:x (axes permutation)}} } { upvar #0 flipstr globalflipstr regsub -all -- {[+]} $flipstr {} globalflipstr } {Coordinate tranform} set flipstr x:y:z proc IsFloat { x } { if {[regexp -- {^-?[0-9]+\.?[0-9]*((e|E)(-|\+)?[0-9]+)?$} $x] || \ [regexp -- {^-?[0-9]*\.?[0-9]+((e|E)(-|\+)?[0-9]+)?$} $x]} { if {![catch {expr $x}]} { return 1 } } return 0 } proc ClipStringCheck { args } { set okaystr 0 catch { if {[llength $args]==6} { set okaystr 1 # Format check foreach x $args { if {![string match "-" $x] && ![IsFloat $x]} { set okaystr 0 break } } # Relative order check if {[lindex $args 0]>[lindex $args 3] \ || [lindex $args 1]>[lindex $args 4] \ || [lindex $args 2]>[lindex $args 5]} { set okaystr 0 } } } return $okaystr } Oc_CommandLine Option clip { {xmin {} {is minimum x}} {ymin {} {is minimum y}} {zmin {} {is minimum z}} {xmax {} {is maximum x}} {ymax {} {is maximum y}} {zmax { ClipStringCheck $xmin $ymin $zmin $xmax $ymax $zmax} {is maximum z}} } { global clipstr set clipstr [list $xmin $ymin $zmin $xmax $ymax $zmax] } "\n\tClipping box (optional)" set clipstr {} Oc_CommandLine Option format { {format {regexp {text|b4|b8} $format} {is one of {text,b4,b8}}} } { upvar #0 format globalformat; set globalformat $format } {Format of output file: text, 4-, or 8-byte binary} set format text Oc_CommandLine Option grid { {type {regexp {reg|irreg} $type} {is one of {reg,irreg}}} } { global grid; set grid $type } {Grid type of output file: regular or irregular} set grid reg Oc_CommandLine Option info {} {global info; set info 1} {Print mesh info} set info 0 Oc_CommandLine Option [Oc_CommandLine Switch] { {file {} {Input vector field file}} } { global infile; set infile $file } {End of options; next argument is file} Oc_CommandLine Parse $argv array set formatmap { text text b4 binary4 b8 binary8 } array set gridmap { reg regular irreg irregular } # Check that file is accessible. set infilefullname [Oc_DirectPathname $infile] if {![file readable $infilefullname]} { puts stderr "ERROR: Unable to open \"$infilefullname\" for reading." exit 1 } ChangeMesh $infilefullname 0 0 0 -1 if {[string match "Vf_EmptyMesh" [GetMeshType]]} { puts stderr "ERROR loading input file \"$infilefullname\"" exit 2 } set title [GetMeshTitle] set desc [GetMeshDescription] if {$info} { puts stderr "File: $infilefullname" if {![catch {file size $infilefullname} filesize]} { puts stderr "File size: $filesize bytes" } puts stderr "Mesh title: $title" if {[string first "\n" $desc]<0} { # Single line description puts stderr "Mesh desc: $desc" } else { # Mult-line description regsub -all "\n" $desc "\n: " desc puts stderr "Mesh desc---\n: $desc" } puts stderr [GetMeshStructureInfo] exit 0 } if {[string match Vf_GeneralMesh3f [GetMeshType]] && ![string match irregular $gridmap($grid)]} { puts stderr "Input file has irregular grid; so must output." } puts stderr "Copying Title field: $title\nYou may want to edit this\ field in the output by hand." if {![string match "x:y:z" $flipstr] || ![string match {} $clipstr]} { # Perform coordinate transform and/or clipping CopyMesh 0 0 0 $flipstr $clipstr } # $filename == "" --> write to stdout WriteMesh "" $formatmap($format) $gridmap($grid) $title $desc exit 0