#!/bin/bash

#dipoles of the first intermediate state
cp dipoles_AA_complex_sph_harmonic fort.142
cp dipoles_AB_complex_sph_harmonic fort.143

#dipoles of the second intermediate state
cp dipoles_AA_complex_sph_harmonic fort.242
cp dipoles_AB_complex_sph_harmonic fort.243

cat > inp_template << EOF
&TWOPHOTONINP
use_dummy_dipoles = .true.
bound_transition_chiral = >>BCH<<
continuum_transition_chiral = >>CCH<<

lab_frame_p1 = >>P1<<           !lab frame polarization of the first photon
lab_frame_p2 = 0                !lab frame polarization of the second photon (applies if lab_frame_E_p2(1:3) = 0.0_idp)
lab_frame_E_p2 = >>XPOL<<,0.0d0,0.0d0 !direction of the E-field vector of the 2nd photon: if this vector is non-zero it overrides the value lab_frame_p2. If it is zero then lab_frame_p2 applies.
ionization_potential = 0.1d0
no_intermediate_states = >>NST<<
index_initial_state = 1,1       !indices of the intermediate bound states from the input dipole files.
index_final_state = 1           !index of the final cationic state
                                !excitation amplitudes for the first intermediate state:
amplitudes( 1,1) = 0.0d0 !-1
amplitudes( 2,1) = 1.0d0 !0
amplitudes( 3,1) = 0.0d0 !1

amplitudes( 1,2) = 0.0d0 !-1
amplitudes( 2,2) = 0.5d0 !0
amplitudes( 3,2) = 0.0d0 !1
&END

                                 !dipoles for the first intermediate state:
&dipelminp
  lu_pw_dipoles= 142,143,143,
  nset_pw_dipoles= 1,1,1,
  point_group='C2',
  format_pw_dipoles = 'FORMATTED'
&end
                                 !dipoles for the second intermediate state,etc.:
&dipelminp
  lu_pw_dipoles= 242,243,243,
  nset_pw_dipoles= 1,1,1,
  point_group='C2',
  format_pw_dipoles = 'FORMATTED'
&end
EOF

rm ./results_all
for xpol in "1.0d0" "0.0d0"
do
for p1 in "1" "-1" "0"
do
for no_states in "1" "2"
do
for bound_chiral in ".false." ".true."
do
for continuum_chiral in ".false." ".true."
do
   sed "s/>>P1<</${p1}/g" inp_template > tmp1
   sed "s/>>XPOL<</${xpol}/g" tmp1 > tmp2
   sed "s/>>BCH<</${bound_chiral}/g" tmp2 > tmp3
   sed "s/>>CCH<</${continuum_chiral}/g" tmp3 > tmp4
   sed "s/>>NST<</${no_states}/g" tmp4 > inp
   echo "INPUT PARAMETERS: p1= ${p1}, XPOL = ${xpol}, bound transition chiral = ${bound_chiral}, continuum transition chiral = ${continuum_chiral}, number of states = ${no_states}." >> results_all
   ./two_photon < inp > tmp
   grep -i 'beta_LM' ./tmp >> results_all
   rm ./tmp[1-4] inp
# test_two_photon_${no_states}_${bound_chiral}_${continuum_chiral}
done
done
done
done
done
