#!/bin/ksh
#	group2rdb version 1.1 6/6/03
#	original author Joel Johnson, California District
#	This is OSW Scripts page version.
#       Refer questions to "gs-w osw scripts"

#	Modified 6/4/03, jdj - to preserve orignal Agency code rather than
#	just defaulting to USGS and to ask for group by name rather than
#       by number

# 	creates a contol file for downloading data using nwts2rdb by using
# 	an existing ADAPS group and additional information from interactive
#	prompting.

print
print 'CREATE AN NWTS2RDB CONTROL FILE FROM AN ADAPS GROUP FILE'
print
print

  read ctrlfile?"Enter RDB control file name to be created: "

print
print
print 'CHOOSE AN ADAPS GROUP FROM THE FOLLOWING LIST'
print
print 

for x in /usr/opt/nwis/data/auxdata/groups/database1/*.$LOGNAME
do
xs=`basename $x`
echo '    ' `basename $xs .$LOGNAME`
done

print
print

read infile?'Enter ADAPS group name to use: '

print
print

grpfile=/usr/opt/nwis/data/auxdata/groups/database1/$infile.$LOGNAME

if [ ! -f $grpfile ]
  then
   print
   print 'Invalid group name'
   print
   print 'Please try again....'
   print
   exit
fi

print
print 'Required information for time-series retrieval includs the data type,'
print 'If data type is DV, then provide the DV stat code as sub-type'
print 'If data type is UV, then provide UV type, E=edited, C=computed'
print

  read dt?"Enter Data Type (UV,DV,PK,MS,DC,SV): "
  read st?"Enter Data Sub-Type (DV=stat_code, UV=N,M,E,C,R,S): "
  read bd?"Enter Begin Date/time  (YYYYMMDDhhmmss): "
  read ed?"Enter Ending Date/time (YYYYMMDDhhmmss): "


sed -e '1i\
DATATYPE	AGENCY	STATION	DDID	SUBTYPE	BEGDATE	ENDDATE\
2s	5s	15s	4s	5s	14s	14s' \
-e 's/  */	/g' -e '/\DESC/d' -e "s/\/SITE/$dt/" -e 's/ *$//' \
-e "s/$/	$st	$bd	$ed/" \
$grpfile > $ctrlfile

print
print 'nwts2rdb control file created: '$ctrlfile
print
