Wednesday, January 20, 2010

[Bash] ps2png

New version is here ps2png
#!/bin/bash
# To convert a ps file into png format
# Usage:
#            ps2png [psfile.ps]
# @ http://scriptdemo.blogspot.com

if [ $# == 0 ]; then
   for psname in *.ps
   do
         if [ -e $psname ]; then
            pngname=`echo ${psname%%.*}`
            convert $psname ${pngname}.png
         else
            echo "${psname} does not exist!"
         fi
   done
else
   for psname in $*
   do
        if [ -e $psname ]; then
           pngname=`echo ${psname%%.*}`
           convert $psname ${pngname}.png
        else
           echo "${psname} does not exist!"
        fi
   done
fi

NCO example

#!/bin/bash
# usage:
# OBCjob.sh obcfile.nc OBCType VarType
# @ http://scriptdemo.blogspot.com
 if [ $# != 3 ]; then
    sed -n '1,3p' OBCjob.sh
    exit
 fi
 obcfile=$1
 obctype=$2
 vartype=$3
# increase
 ncap2 -v -S mygrow${vartype}.nco $obcfile aa.nc
 ncdump aa.nc > aa1 && rm -f aa.nc
 sed '/x\ =\ 129\ /d' aa1 > aa0 && rm -f aa1
 ncgen -o aa.nc aa0 && rm -f aa0
#
 ncrename -O -d new_x,x aa.nc
 case "$vartype" in
   'TS')
       ncrename -O -v new_vosaline,vosaline aa.nc
       ncrename -O -v new_votemper,votemper aa.nc
       ;;
    'U')
       ncrename -O -v new_vozocrtx,vozocrtx aa.nc
       ;;
    'V')
       ncrename -O -v new_vomecrty,vomecrty aa.nc
      ;;
      *)
       echo "vartype=$vartype is not defined"
       exit
      ;;
 esac
#
 case "$obctype" in
    'N'|'n')
        if [ ! -e north.nc ]; then
           ncks -F -d y,111,111 -v nav_lon,nav_lat coordinates_arc5.nc north.nc
           ncwa -a y north.nc north2.nc mv north2.nc north.nc
       fi
          ncks -A -v nav_lon,nav_lat north.nc aa.nc && mv aa.nc new_$obcfile
      ;;
   'S'|'s')
      if [ ! -e south.nc ]; then
         ncks -F -d y,2,2 -v nav_lon,nav_lat coordinates_arc5.nc south.nc
         ncwa -a y south.nc south2.nc
         mv south2.nc south.nc
      fi
      ncks -A -v nav_lon,nav_lat south.nc aa.nc && mv aa.nc new_$obcfile
      ;;
    *)
      echo "obctype=$obctype is not defined"
      exit
      ;;
 esac


$cat mygrowTS.nco
  defdim("new_x",$x.size+2);
  new_vosaline[$time_counter,$z,$new_x]=0.0f;
  new_votemper[$time_counter,$z,$new_x]=0.0f;
  new_vosaline(0:$time_counter.size-1,0:$z.size-1,1:$x.size)=vosaline;
  new_votemper(0:$time_counter.size-1,0:$z.size-1,1:$x.size)=votemper;

ShowCalendar