#!/bin/bash

# Get the current directory
current_dir=$(pwd)

# Extract the last 7 characters from the directory path
trajectory=${current_dir: -7}

# Print the trajectory variable
echo "Trajectory: $trajectory"

# Directory to look into
directory="/cluster/work/users/cagyum/ENSEMBLE_GOTM/fabm_files"
outdir="/cluster/work/users/cagyum/ENSEMBLE_GOTM/output_files"

# Loop over the files in the directory
for file in "$directory"/fabm.yaml.*; do
    # Extract the last 4 characters from the filename
    experiment=${file: -4}
    
    # Print the experiment variable
    echo "Experiment: $experiment"

    # Copy the file to the current directory as fabm.yaml
    cp "$file" "$current_dir/fabm.yaml"

    # Copy gotm.yaml file for spinup and execute
    cp gotm.yaml.spinup gotm.yaml
    ./gotm

    # Copy gotm.yaml file for argo and execute
    cp gotm.yaml.argo gotm.yaml
    ./gotm

    # move the result
    mv argo.nc $outdir/argo.$trajectory.$experiment.nc

    
done

