ppth=/data/public/HYCOM/shian/hindcast/GLBv0.08
ncks=/cluster/gcc-4.8.5/tools/bin/ncks
rm -rf record.txt
for yy in {2010..2010..01}
do
  for mm in {06..12..01}
  do
    mkdir -p ${ppth}/${yy}/sst/${mm}
    mkdir -p ${ppth}/${yy}/sss/${mm}
    mkdir -p ${ppth}/${yy}/ssuv/${mm}
    mkdir -p ${ppth}/${yy}/ssh/${mm}
    mkdir -p ${ppth}/${yy}/others/${mm}



    #get file
    year=${yy}
    path_ssh=${ppth}/${yy}/ssh/${mm}
    path_sst=${ppth}/${yy}/sst/${mm}
    path_sss=${ppth}/${yy}/sss/${mm}
    path_ssuv=${ppth}/${yy}/ssuv/${mm}
    path_others=${ppth}/${yy}/others/${mm}

      vv=536
      case ${yy}${mm} in
           201107|201108|201109|201110|201111|201112)
              vv=537
              ;;
          *)
      esac
      case ${yy} in
           2012)
              vv=537
              ;;
          *)
      esac
      case ${yy} in
           2015)
              vv=563
              ;;
          *)
      esac
      case ${yy}${mm} in
           201301|201302|201303|201304|201305|201306)
              vv=537
              ;;
          *)
      esac
      case ${yy}${mm} in
           201307|201308|201309|201310|201311|201312|201401|201402|201403|201404|201405|201406)
              vv=538
              ;;
          *)
      esac
      case ${yy}${mm} in
           201407|201408|201409|201410|201411|201412)
              vv=563
              ;;
          *)
      esac


      rm -rf ${path}/${mm}/record.txt

    for j in {01..31..01}
    do
      for k in {00..18..06}
      do
      echo "do ${yy}${mm}${j}12_t0${k}"
########
#get ssh
      file=hycom_ssh_${yy}${mm}${j}12_t0${k}.nc
      panosize=`ls -l ${path_ssh}/${file} |cut -d ' ' -f 5`
      if [[ ! -f ${path_ssh}/${file} ]] || [[ ${panosize} -le 29000000 ]];then
        ${ncks} -v surf_el ${ppth}/${yy}/${mm}/hycom_GLBv0.08_${vv}_${yy}${mm}${j}12_t0${k}.nc ${path_ssh}/hycom_ssh_${yy}${mm}${j}12_t0${k}.nc
      fi

      if [ -f ${path_ssh}/${file} ]; then
        echo "ssh_${yy}${mm}${j}_t0${k} ok" >> record.txt
      else
        echo "ssh_${yy}${mm}${j}_t0${k} false" >> record.txt
      fi
########
#get sst
      file=hycom_sst_${yy}${mm}${j}12_t0${k}.nc
      panosize=`ls -l ${path_sst}/${file} |cut -d ' ' -f 5`
      if [[ ! -f ${path_sst}/${file} ]] || [[ ${panosize} -le 29000000 ]];then
        ${ncks} -v water_temp -d depth,0 ${ppth}/${yy}/${mm}/hycom_GLBv0.08_${vv}_${yy}${mm}${j}12_t0${k}.nc ${path_sst}/hycom_sst_${yy}${mm}${j}12_t0${k}.nc
      fi
  
      if [ -f ${path_sst}/${file} ]; then
        echo "sst_${yy}${mm}${j}_t0${k} ok" >> record.txt
      else
        echo "sst_${yy}${mm}${j}_t0${k} false" >> record.txt
      fi
########
#get sss
      file=hycom_sss_${yy}${mm}${j}12_t0${k}.nc
      panosize=`ls -l ${path_sss}/${file} |cut -d ' ' -f 5`
      if [[ ! -f ${path_sss}/${file} ]] || [[ ${panosize} -le 29000000 ]];then
        ${ncks} -v salinity -d depth,0 ${ppth}/${yy}/${mm}/hycom_GLBv0.08_${vv}_${yy}${mm}${j}12_t0${k}.nc ${path_sss}/hycom_sss_${yy}${mm}${j}12_t0${k}.nc
      fi
  
      if [ -f ${path_sss}/${file} ]; then
        echo "sss_${yy}${mm}${j}_t0${k} ok" >> record.txt
      else
        echo "sss_${yy}${mm}${j}_t0${k} false" >> record.txt
      fi
########
#get ssu & ssv
      file=hycom_ssv_${yy}${mm}${j}12_t0${k}.nc
      panosize=`ls -l ${path_ssuv}/${file} |cut -d ' ' -f 5`
      if [[ ! -f ${path_ssuv}/${file} ]] || [[ ${panosize} -le 29000000 ]];then
        ${ncks} -v water_u -d depth,0 ${ppth}/${yy}/${mm}/hycom_GLBv0.08_${vv}_${yy}${mm}${j}12_t0${k}.nc ${path_ssuv}/hycom_ssu_${yy}${mm}${j}12_t0${k}.nc
        ${ncks} -v water_v -d depth,0 ${ppth}/${yy}/${mm}/hycom_GLBv0.08_${vv}_${yy}${mm}${j}12_t0${k}.nc ${path_ssuv}/hycom_ssv_${yy}${mm}${j}12_t0${k}.nc
      fi
  
      if [ -f ${path_ssuv}/${file} ]; then
        echo "ssuv_${yy}${mm}${j}_t0${k} ok" >> record.txt
      else
        echo "ssuv_${yy}${mm}${j}_t0${k} false" >> record.txt
      fi

#######
#get M20 M15 MLD
      file=hycom_MLD_${yy}${mm}${j}12_t0${k}.nc
      panosize=`ls -l ${path_others}/${file} |cut -d ' ' -f 5`
      if [[ ! -f ${path_others}/${file} ]] || [[ ${panosize} -le 29000000 ]];then
        export hfile=${ppth}/${yy}/${mm}/hycom_GLBv0.08_${vv}_${yy}${mm}${j}12_t0${k}.nc
        export ohfile1=${path_others}/hycom_M15_${yy}${mm}${j}12_t0${k}.nc
        export ohfile2=${path_others}/hycom_M20_${yy}${mm}${j}12_t0${k}.nc
        export ohfile3=${path_others}/hycom_MLD_${yy}${mm}${j}12_t0${k}.nc
        echo "${hfile}"
        python get2.py
      fi

      if [ -f ${path_others}/${file} ]; then
        echo "M15M20MLD_${yy}${mm}${j}_t0${k} ok" >> record.txt
      else
        echo "M15M20MLD_${yy}${mm}${j}_t0${k} false" >> record.txt
      fi
      
      echo "done ${yy}${mm}${j}12_t0${k}"
      done
    done
  done
done
