[GRASS-SVN] r41084 - in grass-addons/raster: r.out.gmt r.out.gmt2

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 18 07:48:35 EST 2010


Author: hamish
Date: 2010-02-18 07:48:35 -0500 (Thu, 18 Feb 2010)
New Revision: 41084

Modified:
   grass-addons/raster/r.out.gmt/r.out.gmt
   grass-addons/raster/r.out.gmt2/r.out.gmt2
Log:
deal with rasters without color tables

Modified: grass-addons/raster/r.out.gmt/r.out.gmt
===================================================================
--- grass-addons/raster/r.out.gmt/r.out.gmt	2010-02-18 12:47:50 UTC (rev 41083)
+++ grass-addons/raster/r.out.gmt/r.out.gmt	2010-02-18 12:48:35 UTC (rev 41084)
@@ -186,47 +186,53 @@
 
 # create cpt color table from raster's colr file
 eval `g.findfile elem=colr file="$GIS_OPT_INPUT" | grep "^file="`
-COLR_FILE="$file"
+if [ -z "$file" ] ; then
+   g.message "Input map does not have explicit color rules defined. CPT file not created."
+   OUTPUT_CPT=jet.cpt
+else
+   COLR_FILE="$file"
+   
+   echo "#" > "$OUTPUT_CPT"
+   echo "# GMT colormap created by the `g.version` r.out.gmt script" >> "$OUTPUT_CPT"
+   echo "# from base map [$GIS_OPT_INPUT]" >> "$OUTPUT_CPT"
+   echo "# created by ${USER}@${HOSTNAME} at `date`" >> "$OUTPUT_CPT"
+   echo "#" >> "$OUTPUT_CPT"
+   echo "# COLOR_MODEL = RGB" >> "$OUTPUT_CPT"
+   
+   for line in `cat "$COLR_FILE" | tail -n+2 | grep -v "^nv" | tr ' ' '|'` ; do
+       C_BEGIN="`echo "$line" | cut -f1 -d'|'`"
+       C_END="`echo "$line" | cut -f2 -d'|'`"
+   
+       C_BEGIN="`echo "$line" | cut -f1 -d'|'`"
+       C_END="`echo "$line" | cut -f2 -d'|'`"
+   
+       # translate 1 color value into 3
+       if [ "`echo "$C_BEGIN" | tr ':' '\n' | wc -l`" -eq 2 ] ; then
+   	RULE_CAT="`echo "$C_BEGIN" | cut -f1 -d:`"
+   	RULE_COLOR="`echo "$C_BEGIN" | cut -f2 -d:`"
+   	C_BEGIN="${RULE_CAT}:${RULE_COLOR}:${RULE_COLOR}:${RULE_COLOR}"
+       fi
+       if [ "`echo "$C_END" | tr ':' '\n' | wc -l`" -eq 2 ] ; then
+   	RULE_CAT="`echo "$C_END" | cut -f1 -d:`"
+   	RULE_COLOR="`echo "$C_END" | cut -f2 -d:`"
+   	C_END="${RULE_CAT}:${RULE_COLOR}:${RULE_COLOR}:${RULE_COLOR}"
+       fi     
+   
+       C_STRING="${C_BEGIN}:${C_END}"
+       echo "$C_STRING" | tr ':' '\t' >> "$OUTPUT_CPT"
+   done
+   # copy color of null value, if any
+   C_NULL="`grep "^nv" "$COLR_FILE" | cut -f2 -d':'`"
+   if [ -n "$C_NULL" ] ; then
+       if [ "`echo "$C_NULL" | tr ':' '\n' | wc -l`" -eq 1 ] ; then
+   	C_STRING="N:${C_NULL}:${C_NULL}:${C_NULL}"
+       else
+   	C_STRING="N:${C_NULL}"
+       fi
+       
+       echo "$C_STRING" | tr ':' '\t' >> "$OUTPUT_CPT"
+   fi
 
-echo "#" > "$OUTPUT_CPT"
-echo "# GMT colormap created by the `g.version` r.out.gmt script" >> "$OUTPUT_CPT"
-echo "# from base map [$GIS_OPT_INPUT]" >> "$OUTPUT_CPT"
-echo "# created by ${USER}@${HOSTNAME} at `date`" >> "$OUTPUT_CPT"
-echo "#" >> "$OUTPUT_CPT"
-echo "# COLOR_MODEL = RGB" >> "$OUTPUT_CPT"
-
-for line in `cat "$COLR_FILE" | tail -n+2 | grep -v "^nv" | tr ' ' '|'` ; do
-    C_BEGIN="`echo "$line" | cut -f1 -d'|'`"
-    C_END="`echo "$line" | cut -f2 -d'|'`"
-
-    C_BEGIN="`echo "$line" | cut -f1 -d'|'`"
-    C_END="`echo "$line" | cut -f2 -d'|'`"
-
-    # translate 1 color value into 3
-    if [ "`echo "$C_BEGIN" | tr ':' '\n' | wc -l`" -eq 2 ] ; then
-	RULE_CAT="`echo "$C_BEGIN" | cut -f1 -d:`"
-	RULE_COLOR="`echo "$C_BEGIN" | cut -f2 -d:`"
-	C_BEGIN="${RULE_CAT}:${RULE_COLOR}:${RULE_COLOR}:${RULE_COLOR}"
-    fi
-    if [ "`echo "$C_END" | tr ':' '\n' | wc -l`" -eq 2 ] ; then
-	RULE_CAT="`echo "$C_END" | cut -f1 -d:`"
-	RULE_COLOR="`echo "$C_END" | cut -f2 -d:`"
-	C_END="${RULE_CAT}:${RULE_COLOR}:${RULE_COLOR}:${RULE_COLOR}"
-    fi     
-
-    C_STRING="${C_BEGIN}:${C_END}"
-    echo "$C_STRING" | tr ':' '\t' >> "$OUTPUT_CPT"
-done
-# copy color of null value, if any
-C_NULL="`grep "^nv" "$COLR_FILE" | cut -f2 -d':'`"
-if [ -n "$C_NULL" ] ; then
-    if [ "`echo "$C_NULL" | tr ':' '\n' | wc -l`" -eq 1 ] ; then
-	C_STRING="N:${C_NULL}:${C_NULL}:${C_NULL}"
-    else
-	C_STRING="N:${C_NULL}"
-    fi
-    
-    echo "$C_STRING" | tr ':' '\t' >> "$OUTPUT_CPT"
 fi
 
 

Modified: grass-addons/raster/r.out.gmt2/r.out.gmt2
===================================================================
--- grass-addons/raster/r.out.gmt2/r.out.gmt2	2010-02-18 12:47:50 UTC (rev 41083)
+++ grass-addons/raster/r.out.gmt2/r.out.gmt2	2010-02-18 12:48:35 UTC (rev 41084)
@@ -221,9 +221,13 @@
 
 # create cpt color table from raster's colr file
 eval `g.findfile elem=colr file="$input_map" | grep "^file="`
-colr_file="$file"
-
-cat<<EOT > "$output_cpt"
+if [ -z "$file" ] ; then
+   g.message "Input map does not have explicit color rules defined. CPT file not created."
+   output_cpt=jet.cpt
+else
+   colr_file="$file"
+   
+   cat<<EOT > "$output_cpt"
 #
 # GMT colormap created by the `g.version` r.out.gmt2 script
 # from base map [$input_map]
@@ -231,42 +235,44 @@
 #
 # COLOR_MODEL = RGB
 EOT
+   
+   for line in `cat "$colr_file" | tail -n+2 | grep -v "^nv" | tr ' ' '|'`; do
+       c_begin="`echo "$line" | cut -f1 -d'|'`"
+       c_end="`echo "$line" | cut -f2 -d'|'`"
+   
+       c_begin="`echo "$line" | cut -f1 -d'|'`"
+       c_end="`echo "$line" | cut -f2 -d'|'`"
+   
+       # translate 1 color value into 3
+       if [ "`echo "$c_begin" | tr ':' '\n' | wc -l`" -eq 2 ]; then
+   	rule_cat="`echo "$c_begin" | cut -f1 -d:`"
+   	rule_color="`echo "$c_begin" | cut -f2 -d:`"
+   	c_begin="$rule_cat:$rule_color:$rule_color:$rule_color"
+       fi
+       if [ "`echo "$c_end" | tr ':' '\n' | wc -l`" -eq 2 ]; then
+   	rule_cat="`echo "$c_end" | cut -f1 -d:`"
+   	rule_color="`echo "$c_end" | cut -f2 -d:`"
+   	c_end="$rule_cat:$rule_color:$rule_color:$rule_color"
+       fi
+   
+       c_string="$c_begin:$c_end"
+       echo "$c_string" | tr ':' '\t' >> "$output_cpt"
+   done
+   
+   # copy color of null value, if any
+   c_null="`grep "^nv" "$colr_file" | cut -f2 -d':'`"
+   if [ -n "$c_null" ]; then
+       if [ "`echo "$c_null" | tr ':' '\n' | wc -l`" -eq 1 ]; then
+   	c_string="N:$c_null:$c_null:$c_null"
+       else
+   	c_string="N:$c_null"
+       fi
+   
+       echo "$c_string" | tr ':' '\t' >> "$output_cpt"
+   fi
+fi
 
-for line in `cat "$colr_file" | tail -n+2 | grep -v "^nv" | tr ' ' '|'`; do
-    c_begin="`echo "$line" | cut -f1 -d'|'`"
-    c_end="`echo "$line" | cut -f2 -d'|'`"
 
-    c_begin="`echo "$line" | cut -f1 -d'|'`"
-    c_end="`echo "$line" | cut -f2 -d'|'`"
-
-    # translate 1 color value into 3
-    if [ "`echo "$c_begin" | tr ':' '\n' | wc -l`" -eq 2 ]; then
-	rule_cat="`echo "$c_begin" | cut -f1 -d:`"
-	rule_color="`echo "$c_begin" | cut -f2 -d:`"
-	c_begin="$rule_cat:$rule_color:$rule_color:$rule_color"
-    fi
-    if [ "`echo "$c_end" | tr ':' '\n' | wc -l`" -eq 2 ]; then
-	rule_cat="`echo "$c_end" | cut -f1 -d:`"
-	rule_color="`echo "$c_end" | cut -f2 -d:`"
-	c_end="$rule_cat:$rule_color:$rule_color:$rule_color"
-    fi
-
-    c_string="$c_begin:$c_end"
-    echo "$c_string" | tr ':' '\t' >> "$output_cpt"
-done
-
-# copy color of null value, if any
-c_null="`grep "^nv" "$colr_file" | cut -f2 -d':'`"
-if [ -n "$c_null" ]; then
-    if [ "`echo "$c_null" | tr ':' '\n' | wc -l`" -eq 1 ]; then
-	c_string="N:$c_null:$c_null:$c_null"
-    else
-	c_string="N:$c_null"
-    fi
-
-    echo "$c_string" | tr ':' '\t' >> "$output_cpt"
-fi
-
 # show suggested PostScript creation commands
 if [ $GIS_FLAG_P -eq 1 ]; then
     echo 1>&2



More information about the grass-commit mailing list