#!/bin/bash

function get_hycom_ftp_file() {
#usage hycom_file=$(get_hycom_ftp_file [year] [month] [date] [fhours])
#example ::
#  to get hycom file of 2005/02/03 t012
#  hycom_file=$(./get_hycom_ftp_file 5 2 3 12)
#  or
#  hycom_file=$(./get_hycom_ftp_file 2005 02 3 012)

local dtg=${yr}${mn}${dd}12_t${fh}
local hycom_ftp=ftp://ftp.hycom.org/datasets

case ${yr} in
  200[1-9] | 201[0-3])
    echo ${hycom_ftp}/GLBv0.08/expt_53.X/data/$yr/hycom_GLBv0.08_5*_${dtg}.nc
  ;;

  2014)
    if [ $mn -le 6 ] ; then
      echo $hycom_ftp/GLBv0.08/expt_53.X/data/$yr/hycom_GLBv0.08_5*_${dtg}.nc
    else
      echo $hycom_ftp/GLBv0.08/expt_56.3/data/hindcasts/$yr/hycom_GLBv0.08_563_${dtg}.nc
    fi
  ;;
  
  2015)
    echo $hycom_ftp/GLBv0.08/expt_56.3/data/hindcasts/$yr/hycom_GLBv0.08_563_${dtg}.nc
  ;;

  2016)
    if [ $mn -le 4 ] ; then
       echo $hycom_ftp/GLBv0.08/expt_56.3/data/hindcasts/$yr/hycom_GLBv0.08_563_${dtg}.nc
    else
       echo $hycom_ftp/GLBv0.08/expt_57.2/data/hindcasts/$yr/hycom_GLBv0.08_572_${dtg}.nc
    fi
  ;;

  2017)
    case $mn in
    01)
      echo $hycom_ftp/GLBv0.08/expt_57.2/data/hindcasts/$yr/hycom_GLBv0.08_572_${dtg}.nc
    ;;

    02 | 03 | 04 | 05)
      echo $hycom_ftp/GLBv0.08/expt_92.8/data/hindcasts/$yr/hycom_glbv_928_${dtg}_*.nc
    ;;

    06 | 07 | 08 | 09)     
      echo $hycom_ftp/GLBv0.08/expt_57.7/data/$yr/hycom_GLBv0.08_577_${dtg}.nc
    ;;

    10 | 11 | 12)
      echo $hycom_ftp/GLBv0.08/expt_92.9/data/hindcasts/$yr/hycom_glbv_929_${dtg}_*.nc
    esac
  ;;

  2018)
    echo $hycom_ftp/GLBv0.08/expt_93.0/data/hindcasts/$yr/hycom_glbv_930_${dtg}_*.nc
  ;;

  2019 | 2020 | 2021 | 2022 | 2023 | 2024)
    echo $hycom_ftp/GLBy0.08/expt_93.0/data/hindcasts/$yr/hycom_glby_930_${dtg}_*.nc
  ;;
  
  *)
    echo nofile
esac
}

