#!/bin/sh
#
############################################################################
#
# MODULE:	v.in.asciipoints for GRASS 5.7
# AUTHOR(S):	Michael Barton 
# PURPOSE:	Imports ASCII point file using v.in.ascii
# COPYRIGHT:	(C) 2004 by the GRASS Development Team
#
#		This program is free software under the GNU General Public
#		License (>=v2). Read the file COPYING that comes with GRASS
#		for details.
#
#############################################################################


#%Module
#%  description: v.in.asciipoints - Imports ASCII points file using v.in.ascii
#%End
#%option
#% key: input
#% type: string
#% gisprompt: old_file,file,file
#% description: ASCII points file to import (default format xcol|ycol|val|...)
#% required : yes
#%end
#%option
#% key: output
#% type: string
#% description: Name of GRASS vector points file to create
#% required : yes
#%end
#%option
#% key: fs
#% type: string
#% answer: |
#% description: field separator (default=|)
#% required : no
#%end
#%option
#% key: xcol
#% type: integer
#% description: Number of column to use for x-coordinate
#% answer: 1
#% required : no
#%end
#%option
#% key: ycol
#% type: integer
#% description: Number of column to use for y-coordinate
#% answer: 2
##% required : no
#%end
#%option
#% key: zcol
#% type: integer
#% description: Number of column to use for z-coordinate
#% answer: 0
##% required : no
#%end
#%option
#% key: catcol
#% type: integer
#% description: Number of column to use as category (if catcol=0, unique number assigned to each case in new 'cat' column).
#% answer: 3
##% required : no
#%end
#%option
#% key: columns
#% type: string
#% description: Column definitions (SQL format: e.g., x double precision, y double precision, cat int, name varchar(10))
#% required: no
#% multiple: yes
#%end

if  [ -z "$GISBASE" ] ; then
 echo "You must be in GRASS GIS to run this program."
 exit 1
fi   

if [ "$1" != "@ARGS_PARSED@" ] ; then
  exec g.parser "$0" "$@"
fi

GIS_OPT_FS='"'$GIS_OPT_FS'"'
GIS_OPT_COLUMNS="'"$GIS_OPT_COLUMNS"'"

cmd="cat "$GIS_OPT_INPUT" | v.in.ascii output="$GIS_OPT_OUTPUT" xcol="$GIS_OPT_XCOL" ycol="$GIS_OPT_YCOL" zcol="$GIS_OPT_ZCOL" catcol="$GIS_OPT_CATCOL" fs="$GIS_OPT_FS
#" columns="$GIS_OPT_COLUMNS 

if [ "$GIS_OPT_COLUMNS" != "" ] ; then
    cmd=$cmd" columns="$GIS_OPT_COLUMNS
fi

echo $GIS_OPT_COLUMNS
echo $cmd

eval $cmd

echo ""
echo "Done. GRASS vector points file $GIS_OPT_OUTPUT created from ASCII points file $GIS_OPT_INPUT"
