#!/bin/bash
#
# Get GFS analysis files 
#
#

for f in {2022..2022}
do
for m in {08..08}
do
for d in {08..31}
do
#set hracb=20
#set URL = "https://www.ncei.noaa.gov/thredds/fileServer/gfs-g4-anl-files"

URL="https://www.ncei.noaa.gov/data/global-forecast-system/access/grid-004-0.5-degree/analysis" 

#URL="https://www.ncei.noaa.gov/data/global-forecast-system/access/grid-004-0.5-degree/analysis"


#set URL = "ftp://nomads.ncdc.noaa.gov/GFS/analysis_only"

WGET=/usr/bin/wget

#/bin/mkdir ${f}${m}${d}
#cd ${f}${m}${d}

for hracb in {00,06,12,18}
do
#  foreach hra ( 00 06 12 18 24 30 36 42 48 54 60 66 72 )
       #$WGET -c - ${URL}/${f}/${f}${d}/gfsanl_4_${f}${d}_${hracb}00_000.grb2 
	$WGET ${URL}/${f}${m}/${f}${m}${d}/gfs_4_${f}${m}${d}_${hracb}00_000.grb2 
done

cdo mergetime gfs_4_${f}${m}${d}* ${f}${m}${d}.grb
rm gfs_4_${f}${m}${d}*
#cdo -f nc copy ${f}${d}.grb ${f}${d}.nc
#cdo -sellonlatbox,-180,180,-70,15 ${f}${d}.nc gfs_${f}${d}.nc
#cdo mergetime
#cdo select,name=gh a aa
#runIDV
#cdo  -sellevel,50000
#cdo -sellonlatbox,0,359.5,-70,15

#cdo -showname
#cdo -selname,tas
#cdo -invertlat

done
done
done
