#!/bin/bash
#$ -cwd
#$ -V
#$ -j y
#$ -o lcs.log 
#$ -S /bin/bash
#$ -l mem_free=200G

# Run multiple LCS computations (flow maps and FTLE) with the start date stating from startDate_start until startDate_end.
# Each LCS computation uses a time window of timeWindow (in days)
# The start date is shifted by an amount startDay_shift (in days) for each computation until the start date equals startDate_end
# Results are stored in the corresponding directories in WorkDir

# IMPORTANT: If you want to use data from PE velocities interpolated on flat levels, then provide the correct input *.nc file,
# and also provide the depth value at which the computation is to be done, as a parameter to the function.

solver='1'                                      # 1 for PDE, 2 for trajectories
PEFile='/projects/dri_calypso/Product/Pe4LCS/2019Apr06R002/pe_out_2_140m_R200deg_w_long.nc'	# Location of the PE output file
startDate_start='[2019 04 07 12 00 00]'				# Start of the starting date of the LCS computation
startDate_end='[2019 04 07 12 00 00]'				# End of the starting date of the LCS computation
startDay_shift='Inf'						# Shift in the start date (in days) for each of the LCS computation (start date goes from startDate_start to startDate_end)
timeWindow='96.0/24'							# Time window (in days) of the LCS computation
plot_depth_idx='[]'                               # Depth indices at which plots are to be made (0 for surface, [] for all depths)
clim='[]'                               # Colormap limits (leave empty for automatic choice)

echo Simulation started on $(date)

matlab -nosplash -nodesktop<<EOF
LCS($solver, '$PEFile', $startDate_start, $startDate_end, $startDay_shift, $timeWindow, 'forward', $plot_depth_idx, $clim);
LCS($solver, '$PEFile', $startDate_start, $startDate_end, $startDay_shift, $timeWindow, 'backward', $plot_depth_idx, $clim);
close all
clear
exit;
EOF

echo Simulation end on $(date)