
# SLICS: 
#model='SLICS' # for noise free V1 sims
#for LOS in {74..99}; do

# cosmo-SLICS:
model='fid_f'
#dz='dz10'
#A_IA='_AIA1.0'   #1.0
#A_IA='_AIA1.5'    #1.5
#A_IA='_AIA2.0'   #2.0
A_IA='_AIA-2.0'   #2.0

for LOS in {1..5}; do

for tomobin in {1..5}; do
let tomobin2_min=$tomobin
#tomobin2=$tomobin2_min # auto
#tomobin2=2
for tomobin2 in $(seq $tomobin2_min 5); do # cross
#----------
# IA mocks: 
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth5Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth1Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth05Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth025Mpcoverh/'
dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_smooth01Mpcoverh/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks_nosmooth/'
#dir_in='/home/jharno/Projects/cosmoSLICS/'$model'/IA_mocks/'
dir_in2=$dir_in

dir_out=$dir_in'/xipm_revised/'
mkdir -p $dir_out

#filename_sources_in='GalCatalog_IA_bin'$tomobin'.dat_LOS'$LOS
#filename_sources_in2='GalCatalog_IA_bin'$tomobin2'.dat_LOS'$LOS
#filename_sources_in='GalCatalog_IA_bin'$tomobin$A_IA'.dat_LOS'$LOS
#filename_sources_in2='GalCatalog_IA_bin'$tomobin2$A_IA'.dat_LOS'$LOS
filename_sources_in='GalCatalog_KiDS1000_IA_NLAdelta_bin'$tomobin$A_IA'.dat_LOS'$LOS
filename_sources_in2='GalCatalog_KiDS1000_IA_NLAdelta_bin'$tomobin2$A_IA'.dat_LOS'$LOS
#---------


# specify name for cross
#treecorr_out_name='IA_bin'$tomobin'_bin'$tomobin2'_'$LOS'_'$model$A_IA'.dat'
treecorr_out_name='IA_NLAdelta_bin'$tomobin'_bin'$tomobin2'_'$LOS'_'$model$A_IA'.dat'


echo 'Launching TreeCorr on redshift bin' $tomobin ' and ' $tomobin2' , LOS' $LOS ' model' $model', for file' $filename_sources_in 'and ' $filename_sources_in2

#---
# interactive:
# create link to input file

rm GalCat_sources.dat ;  ln -s $dir_in$filename_sources_in GalCat_sources.dat ;
rm GalCat_sources2.dat ;  ln -s $dir_in2$filename_sources_in2 GalCat_sources2.dat ;

corr2 IA_JHD_config_noisefree.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_noisefree'_cone$LOS
corr2 IA_JHD_config_noisy_noIA.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_noisy_noIA'_cone$LOS
corr2 IA_JHD_config_noisefree_IA_model1.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_model1'_cone$LOS
corr2 IA_JHD_config_noisefree_II_model1.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_II'_cone$LOS
corr2 IA_JHD_config_noisefree_GI_model1.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_gI'_cone$LOS
#corr2 IA_JHD_config.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_gI_15'
#corr2 IA_JHD_config.yaml ; wait ; mv gg.out $dir_out'/xipm_'$treecorr_out_name'_gI_30'

#  -- OR --

#---
# to workers:
# Create unique config file:

#-------
# for SLICS/cosmo-SLICS
#cp config_SLICS_xipm_V1_DES_noisefree_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_2.yaml' 
#-------

#--------
# for peaks catalogue
# noise free
#cp config_SLICS_xipm_peaks_DES_noisefree_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'_e2flip_noisefree/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' 
#----

#---
# noise free + mbias
#cp config_SLICS_xipm_peaks_DES_noisefree_mbias_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'_e2flip_noisefree_mbias/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' 
#---

#-----
# shape noise
#cp config_SLICS_xipm_peaks_DES_sbatch.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm\/xipm_'"$filename_sources_in"'_mbias_fixed/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' 
#---
#-----
# shape noise + cross-correlation
#cp config_SLICS_xipm_peaks_DES_sbatch_cross.yaml config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml'
#sed 's/XXXX/'"$filename_sources_in"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'
#sed 's/YYYY/xipm_'"$treecorr_out_name"'_mbias_fixed/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_1.yaml'  > config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml'
#sed 's/ZZZZ/'"$filename_sources_in2"'/' config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_2.yaml' > config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_3.yaml'
#my_config=config_SLICS_xipm_peaks_DES_sbatch_$tomobin$tomobin2'_R'$Field'_LOS'$LOS'.dat_it'$it'_3.yaml' 
#---


#sbatch batch_treecorr.sh  ${dir_in} ${filename_sources_in} ${my_config} ;
#sbatch batch_treecorr_cross.sh  ${dir_in} ${dir_in2} ${filename_sources_in} ${filename_sources_in2} ${my_config} ;

#done
done
done
done
