#!/bin/bash

for expid in HIPPO_r0??i1850p1f12?? HIPPO_r00[1356789]i1850p1f1203? HIPPO_r010i1850p1f1203?; do
# for expid in HIPPO_r001i1850p1f1200; do

   for year in $(seq 1850 2009); do

#      for file in \
#      ${expid}_${year}_6h.specia.grb \
#      ${expid}_${year}_day.toasurf.grb \
#      ${expid}_${year}_mon.alllevs.nc \
#      ${expid}_${year}_mon.meridional.nc \
#      ${expid}_${year}_mon.special.nc \
#      ${expid}_${year}_mon.stdlevs.nc \
#      ${expid}_${year}_mon.toasurf.nc \
#      ${expid}_${year}_year.special.nc ; do

      for file in \
      ${expid}/means/${expid}_${year}_6h.special.grb \
      ${expid}/means/${expid}_${year}_day.toasurf.grb \
      ${expid}/means/${expid}_${year}_mon.alllevs.nc \
      ${expid}/means/${expid}_${year}_mon.meridional.nc \
      ${expid}/means/${expid}_${year}_mon.special.nc \
      ${expid}/means/${expid}_${year}_mon.stdlevs.nc \
      ${expid}/means/${expid}_${year}_mon.toasurf.nc ; do

#         timemode=$(echo ${file} | sed -e "s/${expid}_${year}_\([a-z|0-9]*\).*/\1/g")
#
#         case ${timemode} in
#            6h)   tmin=1420 ;;
#            day)  tmin=365 ;;
#            mon)  tmin=12 ;;
#	    year) tmin=1 ;;
#         esac

#          ntime=$(cdo -s ntime ${expid}/means/${file} || echo "0")

         if [ ! -e ${file} ]; then
		 echo "${expid}, ${year}: $(basename ${file}) does not exist!"
         else
#            if [ ${ntime} -lt ${tmin} ]; then echo "${expid}, ${year}: ${file} has only ${ntime} timesteps (should be at least ${tmin})"; fi
             continue
	 fi

      done

   done # year

done # expid

exit 0
