#!/bin/bash
# Bill Barrett Jun 2020

# Seasons to be processed
declare -a seasons=("north" "south")
# Years to be processed
declare -a years=("07" "08" "09" "10")
#declare -a years=("07")
# Levels to be processed
declare -a levels=("2a" "2b")

for season in "${seasons[@]}"; do
  for year in "${years[@]}"; do
    seasonYear="${season}_20${year}"
    # north_2014 is the only possible combination of season and year
    #  that should be excluded
    for level in "${levels[@]}"; do
      sourceDir="/aim/data/cips/${seasonYear}/raa/level_${level}/ver_01.10/rev_05/"
      echo $sourceDir
      # It is meaningful to continue only if the source directory exists
      if [ -d "$sourceDir" ]; then
        echo "${sourceDir} exists"
        # Then rename the destination files from r04 => r05
       for file in "$sourceDir"/*; do
          if [ -f "${file}" ] ; then
            mv -v $file "${file//gza/gz}"
          else for sfile in "${sourceDir}/${file}/*"; do
            mv -v $sfile "${sfile//gza/gz}"
          done
          fi
       done
      fi
    done
  done
done

