% Write the input script "fort.90" with desired parameters
INPUT = 'setup_and_run.sh';
fid = fopen(INPUT,'wt');

fprintf(fid,[...
'#!/bin/bash\n',...
'mkdir -p $CINECA_SCRATCH/HeLaZ/wk\n',...
'mkdir -p $CINECA_SCRATCH/HeLaZ/bin\n\n',...
...
'cd $CINECA_SCRATCH/HeLaZ/wk/\n',...
'cp $HOME/HeLaZ/wk/fort.90 .\n',...
'cp $HOME/HeLaZ/wk/batch_script.sh .\n',...
...%'cp $HOME/HeLaZ/bin/helaz ../bin\n\n',...
'cp -r $HOME/HeLaZ/iCa ..\n\n',...
...
'mkdir -p ', BASIC.RESDIR,'\n',...
...
'sbatch batch_script.sh\n',...
'echo $CINECA_SCRATCH/HeLaZ/results/',BASIC.SIMID,'/',BASIC.PARAMS,'/out.txt']);

fclose(fid);
system(['cp setup_and_run.sh ',BASIC.RESDIR,'/.']);

% Write the sbatch script
INPUT = 'batch_script.sh';
fid = fopen(INPUT,'wt');

fprintf(fid,[...
'#!/bin/bash\n',...
'#SBATCH --time=', CLUSTER.TIME,'\n',...
'#SBATCH --nodes=', CLUSTER.NODES,'\n',...
'#SBATCH --cpus-per-task=', CLUSTER.CPUPT,'\n',...
'#SBATCH --ntasks-per-node=', CLUSTER.NTPN,'\n',...
'#SBATCH --mem=', CLUSTER.MEM,'\n',...
'#SBATCH --error=', BASIC.RESDIR,'err.txt\n',...
'#SBATCH --output=', BASIC.RESDIR,'out.txt\n',...
'#SBATCH --account=FUA34_GBSedge\n',...
'#SBATCH --partition=skl_fua_',CLUSTER.PART,'\n\n',...
...% '#SBATCH --job-name=',PARAMS,'\n\n',...
'module load intel\n',...
'module load intelmpi\n',...
'module load autoload hdf5/1.10.4--intelmpi--2018--binary\n',...
'module load fftw\n',...
'srun --cpu-bind=cores ./../bin/helaz']);

fclose(fid);
system(['cp batch_script.sh ',BASIC.RESDIR,'/.']);

system('scp {fort.90,setup_and_run.sh,batch_script.sh} ahoffman@login.marconi.cineca.it:/marconi/home/userexternal/ahoffman/HeLaZ/wk');
