#!/bin/bash

grid_type=$1
grid_inc=$2
input_folder=$3

echo "Checking $input_folder"
for file in $( echo ${input_folder[@]}) ; do
  grid_type_in_file=$(cdo griddes $file | grep gridtype | awk -F"=" '{print $2}' | sed "s/ //g")
  if [[ $grid_type_in_file != $grid_type ]];then
    echo "$file 's grid type ($grid_type_in_file) doesn't match the announced one ($grid_type)"
    exit 1
  fi
  grid_inc_in_file=$(cdo griddes $file | grep xinc | awk -F"=" '{print $2}'  | sed "s/ //g")
  if [[ $grid_inc_in_file != $grid_inc ]];then
    echo "$file 's grid_increment ($grid_inc_in_file) doesn't match the announced one ($grid_inc)"
    exit 1
  fi
done
echo "All files match the announced grid type"
exit 1
