#! /bin/csh -f

set exedir = $RUNDIR; cd $exedir

set mod_dompath = $DIN_LOC_ROOT/ocn/docn7
set mod_domfile = domain.ocn.gx1v6.090206.nc
set dat_dompath = /scratch2/portfolios/BMC/enso/slee/cesm1_0_4/inputdata_user/ocn/docn7/SOM
set dat_domfile = pop_frc.1x1d.twin.nc
set dat_datpath = /scratch2/portfolios/BMC/enso/slee/cesm1_0_4/inputdata_user/ocn/docn7/SOM
set dat_datfile = pop_frc.1x1d.twin.nc

# year_align  is the model year that will be aligned with data for year_first
# year_first  is the first year of data that will be used
# year_last   is the last  year of data that will be used

set DOMAINFILE = ${mod_dompath}/${mod_domfile}
set DATAMODE   = SOM
set year_align = 1
set year_start = 1
set year_end   = 5
set STREAM     = SOM
set STREAM1TXT = docn.stream.txt

#--- create namelist files ---
cat >! docn_in << EOF1
  &docn_nml
     ocn_in = 'docn_ocn_in'
     decomp = '1d'
  /
EOF1

cat >! docn_ocn_in << EOF1
 &shr_strdata_nml
   dataMode       = '$DATAMODE'
   domainFile     = '$DOMAINFILE'
   streams        = '$STREAM1TXT $year_align $year_start $year_end ',
                    'null' ,
                    'null'
   vectors        = 'null'
  /
EOF1


cat >! $STREAM1TXT << EOF
<streamstemplate>
      <general_comment>
         streams template for docn in CCSM4
      </general_comment>
<stream>
      <comment>
         Dx7 stream description file
      </comment>
      <dataSource>
         Generic datasource for SOM
      </dataSource>
      <domainInfo>
         <variableNames>
            time time
            xc   lon
            yc   lat
            area area
            mask mask
         </variableNames>
         <filePath>
            $dat_dompath
         </filePath>
         <fileNames>
            $dat_domfile
         </fileNames>
      </domainInfo>
      <fieldInfo>
         <variableNames>
            T     t
            S     s
            U     u
            V     v
            dhdx  dhdx
            dhdy  dhdy
            hblt  h
            qdp   qbot
             masksom masksom
         </variableNames>
         <filePath>
            $dat_datpath
         </filePath>
         <fileNames>
            $dat_datfile
         </fileNames>
      </fieldInfo>
      <!-- Information on the program that created this file -->
      <build_streams_documentation>
         This CCSM stream text file was created by build_streams using the command line:
               /scratch2/portfolios/BMC/enso/slee/cesm1_0_4/scripts/ccsm_utils/Tools/build_streams -t /scratch2/portfolios/BMC/enso/slee/cesm1_0_4/cases/e11.f19_g16.001/Tools/Templates/docn.template.streams.xml -s SOM -dp $dat_dompath -do $dat_domfile -p $dat_datpath -filename $dat_datfile
         For more information on build_streams:
             /scratch2/portfolios/BMC/enso/slee/cesm1_0_4/scripts/ccsm_utils/Tools/build_streams -help
      </build_streams_documentation>
</stream>
</streamstemplate>

EOF

echo DOMAINFILE = ${DOMAINFILE} >! $CASEBUILD/docn.input_data_list
$UTILROOT/Tools/listfilesin_streams -input_data_list -t $STREAM1TXT >> $CASEBUILD/docn.input_data_list

