year=2011
ncks=/cluster/gcc-4.8.5/tools/bin/ncks
path=/data3/data/HYCOM/hindcasts/GLBv0.08/2011/ssuv

for i in {01..12..01}
do
mkdir -p ${path}/${i}

if [ ${i} -ge 7 ] ;then
  vv=537
else
  vv=536
fi

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

cd ${path}/${i}
  for j in {01..31..01}
  do
    for k in {00..18..06}
    do
    file=hycom_ssu_2011${i}${j}12_t0${k}.nc
    panosize=`ls -l ${file} |cut -d ' ' -f 5`
    if [[ ! -f ${file} ]] || [[ ${panosize} -le 29000000 ]];then
      ${ncks} -v water_u -d depth,0 ${path}/../${i}/hycom_GLBv0.08_${vv}_2011${i}${j}12_t0${k}.nc hycom_ssu_2011${i}${j}12_t0${k}.nc
      ${ncks} -v water_v -d depth,0 ${path}/../${i}/hycom_GLBv0.08_${vv}_2011${i}${j}12_t0${k}.nc hycom_ssv_2011${i}${j}12_t0${k}.nc
    fi

    if [ -f ${file} ]; then
      echo "${i}${j}_t0${k} ok" >> record.txt
    else
      echo "${i}${j}_t0${k} false" >> record.txt
    fi
    done
  done
done

