1 #!/bin/sh 2 3 GFS2D="^# Gerris Flow Solver 2D " 4 GFS3D="^# Gerris Flow Solver 3D " 5 GFV2D="^# GfsView 2D" 6 GFV3D="^# GfsView 3D" 7 8 usage() 9 { 10 cat <<EOF 11 Usage: gfsview [OPTIONS] FILE1 FILE2 ... 12 13 Opens Gerris and/or GfsView files using the appropriate (2D or 3D) 14 version of GfsView. All the files must have the same dimension (2D or 15 3D). 16 17 Options: 18 [......] any valid option of GfsView 19 [--help] display this message and exits 20 EOF 21 exit $1 22 } 23 24 format="Unknown" 25 26 twod() 27 { 28 if [ $format = "3D" ] ; then 29 zenity --error --title="gfsview" --text="Error: All files must have the same dimension\n\n'$1' is 2D, all the other files are 3D" 30 exit 1 31 fi 32 format="2D" 33 } 34 35 threed() 36 { 37 if [ $format = "2D" ] ; then 38 zenity --error --title="gfsview" --text="Error: All files must have the same dimension\n\n'$1' is 3D, all the other files are 2D" 39 exit 1 40 fi 41 format="3D" 42 } 43 44 if test $# -lt 1; then 45 usage 1 1>&2 46 fi 47 48 for f in "$@"; do 49 case $f in 50 --help) 51 usage 0 1>&2 52 ;; 53 *.gfs) 54 if head "$f" | grep -q "$GFS2D"; then twod "$f"; 55 elif head "$f" | grep -q "$GFS3D"; then threed "$f"; fi 56 ;; 57 *.gfs.gz) 58 if zcat "$f" | head | grep -q "$GFS2D"; then twod "$f"; 59 elif zcat "$f" | head | grep -q "$GFS3D"; then threed "$f"; fi 60 ;; 61 *.gfv) 62 if head "$f" | grep -q "$GFV2D"; then twod "$f"; 63 elif head "$f" | grep -q "$GFV3D"; then threed "$f"; fi 64 ;; 65 esac 66 done 67 68 case $format in 69 3D) 70 gfsview3D "$@" 71 ;; 72 *) 73 gfsview2D "$@" 74 ;; 75 esac