#!/bin/bash

# Input NetCDF file
input_file="/gpfs/projects/bsc32/cerise/UMD/luh2_v2h/yearly/states.nc"

# Output directory
output_dir="/gpfs/projects/bsc32/cerise/UMD/luh2_v2h/yearly/"

# Start year (default to 850 if not provided)
start_year=${1:-850}

# Get the number of time steps
num_times=$(cdo ntime $input_file)

# Calculate the index of the starting year
start_index=$((start_year - 850 + 1))

# Loop over each time step from the start year to the end
for ((t=start_index; t<=num_times; t++)); do
    year=$((850 + t - 1))  # Adjust year calculation
    output_file="${output_dir}/luh2_states_${year}.nc"
    cdo seltimestep,$t $input_file $output_file
done
