#!/bin/csh

#setup to compute roratio based on either daily or monthly naturalized flows
# must change set commands...

set scenario = historical
set basedir = /home/disk/larix/marketa/CSC/vic_ca_0.0625
set fluxdir = {$basedir}/output/fluxes/   ##need trailing /
set srcdir = {$basedir}/runoff_precip_ratios/check_hist_monthly
set stnlist =  {$basedir}/runoff_precip_ratios/station.list
set outdir = {$basedir}/runoff_precip_ratios/stats

rm -rf logmo*
foreach f (`cat {$stnlist}`)
 set obs = /home/disk/larix/marketa/CSC/vic_ca_0.0625/nat_flow/{$f}_obs_mon_af.txt.cfs  #units are cfs
 set llist = /home/disk/larix/marketa/CSC/vic_ca_0.0625/nat_flow/llists/{$f}_ll.txt
 set ncells = `wc $llist | awk '{print $1;}'`
 set outfile = {$outdir}/roratio_{$f}
 set DA = `awk '{if($1~/'$f'/) print $2;}' {$basedir}/runoff_precip_ratios/site_DA.txt`  #units sq mi

 awk '{if($1>=1950) print $1,$2,$3;}' $obs >! tmp_obs

 echo {$srcdir}/check_obs_RPratio {$fluxdir} 1950 2009 1915 {$llist} {$ncells} {$outfile} tmp_obs {$DA}
 {$srcdir}/check_obs_RPratio {$fluxdir} 1950 2009 1915 {$llist} {$ncells} {$outfile} tmp_obs {$DA}
 #Wrong command line arguments: enter <pat8> <startyear> <endyear> <begindatayear> <soilfile> <NF> <outTS> <obs discharge at outlet> <drainage area>

 awk '{sum1+=$6;sum2+=$7;}END{print sum1/59, sum2/59;}' {$outfile} >! {$outdir}/avgroratio_{$f}
 
 wait

end

wait
exit
