#!/usr/bin/ksh
#
# candat_ascii2all_regen.ksh - Force production of CDFs
# for particular station and time range.
#
# Creation Date:
#
#								05 May 2008 TimQuinn
#
#	$1 = site abbreviation: atha,fsim,fsmi,gill,pina,rank,snkq
# $2 = start date (yyyymmdd)
#			 Input zero (0) if start date should be 20040101.
# $3 = end date (yyyymmdd)
#			 If no date given, current date will be used.
#	

## Set environment variables
#
  if [[ -z $THMSOC ]]
  then
    THMSOC=/disks/socware/thmsoc_dp_current
    export THMSOC
  fi
	. $THMSOC/src/config/soc_it_to_me.config

## Set local variables
#
  os=$(uname -s)
  site=PINA
  startdate=20110914
  enddate=20110916

	if [[ $os = "SunOS" ]]
	then
		ucsite=$(echo $site | nawk '{print toupper($1)}')
	else
		ucsite=$(echo $site | awk '{print toupper($1)}')
	fi

	if [[ -z $enddate ]]
	then
		enddate=$(date -u '+%Y%m%d')
	fi

	for date in $(cat $CONFIGDIR/date_list.txt 2>/dev/null)
	do
		if [[ $date = $enddate ]]
		then
			exit 0
		fi

		if [[ $date < $startdate ]]
		then
			continue
		fi

		year=$(echo $date |awk '{print substr($1,1,4)}')
		month=$(echo $date |awk '{print substr($1,5,2)}')
		day=$(echo $date |awk '{print substr($1,7,2)}')
		filename="${year}${month}${day}${ucsite}.F02.gz"
		input="${year}/${month}/${day}/${filename}"

		candat_ascii2all.ksh $input
		print $input
	done

exit 0
