diff --git a/templates/event-generator/prepare_experiment.sh b/templates/event-generator/prepare_experiment.sh index 61e98b40190161a6a79b3619a9ccfb56af4d73b2..39f68d9dd18778ef16d4862606f189da31906baa 100644 --- a/templates/event-generator/prepare_experiment.sh +++ b/templates/event-generator/prepare_experiment.sh @@ -29,12 +29,45 @@ function download_file() { fi } +function check_url() { + # Check if the url exists + local url="$1" + status=$( + (curl -s --head $url | head -n 1 | grep "HTTP/2 200 " >/dev/null) + echo $? + ) + if [ $status -eq 0 ]; then + echo "true" + else + echo "false" + fi +} + +function get_grfinfo_file(){ + local filename="$1" + new_suffix="-grfinfo.nc" + new_filename="$(basename "$filename" .nc)$new_suffix" + echo "$new_filename" +} + # Download grid files and external parameters BASEURL=http://icon-downloads.mpimet.mpg.de/grids/public/edzw download_file $BASEURL/${DYNAMICS_GRID_FILENAME} download_file $BASEURL/${RADIATION_GRID_FILE} download_file $BASEURL/${EXTERNAL_PARAMETERS_FILE} +# In case the grfinfo files exist, we download them as well +RADIATION_GRID_INFO_FILE=$( get_grfinfo_file ${RADIATION_GRID_FILE} ) +DYNAMICS_GRID_INFO_FILE=$( get_grfinfo_file ${DYNAMICS_GRID_FILENAME} ) + +if [ $( check_url "$BASEURL/${RADIATION_GRID_INFO_FILE}" ) == "true" ]; then + download_file "$BASEURL/${RADIATION_GRID_INFO_FILE}" +fi + +if [ $( check_url "$BASEURL/${DYNAMICS_GRID_INFO_FILE}" ) == "true" ]; then + download_file "$BASEURL/${DYNAMICS_GRID_INFO_FILE}" +fi + # Define the function function grid_filename_from_extpar() {