from sepscons import *

tardir = './../bin/'
repdir = './../inc/'

fld1 = Folders( T=tardir , M='#Util/mod'    , O='#Util/obj'    , B='#Util/bin'    , S=['#Util'   , '#',repdir] )
fld2 = Folders( T=tardir , M='#FFT/mod'     , O='#FFT/obj'     , B='#FFT/bin'     , S=['#FFT'    , '#',repdir] )
fld3 = Folders( T=tardir , M='#Spectra/mod' , O='#Spectra/obj' , B='#Spectra/bin' , S=['#Spectra', '#',repdir] )
fld4 = Folders( T=tardir , M='#Filter/mod'  , O='#Filter/obj'  , B='#Filter/bin'  , S=['#Filter' , '#',repdir] )
fld5 = Folders( T=tardir , M='#SI/mod'      , O='#SI/obj'      , B='#SI/bin'      , S=['#SI'     , '#',repdir] )
fld6 = Folders( T=tardir , M='#TP/mod'      , O='#TP/obj'      , B='#TP/bin'      , S=['#TP'     , '#',repdir] )
fld7 = Folders( T=tardir , M='#SPAC/mod'    , O='#SPAC/obj'    , B='#SPAC/bin'    , S=['#SPAC'   , '#',repdir] )
fld8 = Folders( T=tardir , M='#ETomo/mod'   , O='#ETomo/obj'   , B='#ETomo/bin'   , S=['#ETomo'  , '#',repdir] )
tstf = Folders( T=tardir , M='#TEST/mod'    , O='#TEST/obj'    , B='#TEST/bin'    , S=['#TEST'   , '#',repdir] )
bpfl = Folders( T=tardir , M='#BP/mod'      , O='#BP/obj'      , B='#BP/bin'      , S=['#BP'     , '#',repdir] )

# TAPER programs
eto = SepSCons( folders  = fld8 )
eto.Append( F90FLAGS  = ' -fast -inline-level=2' )
eto.Append( F90FLAGS  = ' -openmp' )
eto.Append( LINKFLAGS = ' -openmp' )
eto.Compile('EikonalTomo_omp.f90')
eto.Compile('SNRcalc.f90')

# Utility programs
gen = SepSCons( folders  = fld1 )
gen.Append( FORTRANLIBS  = ['sepgeef90'] )
gen.Append( F90FLAGS  = ' -fast -inline-level=2' )
gen.Append( F90FLAGS  = ' -openmp' )
gen.Append( LINKFLAGS = ' -openmp' )
gen.Compile('sdrPatch.f90')
gen.Compile('sdrLeaky.f90')
gen.Compile('sdrCirclestack.f90')
gen.Compile('sdrSignbit.f90')
gen.Compile('sdrDemean.f90')
gen.Compile('sdrPadd.f90')
gen.Compile('sdrAbs.f90')
gen.Compile('SRrotateMH2d.f90')
gen.Compile('sdrMHmask.f90')
gen.Compile('ConvertWF.f90')
gen.Compile('sdrAverage.f90')
gen.Compile('sdrFlipPolarity.f90')
gen.Compile('sdrNormalize1d.f90')
gen.Compile('sdrMute.f90')
gen.Compile('sdrMute_db.f90')
gen.Compile('sdrSIcausalstack.f90')
gen.Compile('sdrRegurizeSplines1d.f90')
gen.Compile('sdrRegurizeSplines2d.f90')
gen.Compile('sdrCylinTrans.f90')
gen.Compile('sdrAcousticModel.f90')

# TAPER programs
gen.Compile('sdrTape.f90')
gen.Compile('sdrTapers.f90')
gen.Compile('sdrMDTape.f90')
gen.Compile('sdrMDTapers.f90')
gen.Compile('sdrMTape.f90')
gen.Compile('sdrMTapers.f90')

# FFTW routines etc
fft = SepSCons( folders  = fld2 )
fft.Append( LIBPATH      = ['/opt/FFTW/lib'])
fft.Append( F90PATH      = ['/opt/FFTW/include'])
fft.Append( FORTRANLIBS  = ['fftw3f'] )
fft.Append( F90FLAGS  = ' -fast -inline-level=2' )
fft.Append( F90FLAGS  = ' -openmp' )
fft.Append( LINKFLAGS = ' -openmp' )
fft.Compile('sdrFFT1d.f90')
fft.Compile('sdrFFTmd.f90')
fft.Compile('sdrFFTshift1d.f90')
fft.Compile('sdrFFTshiftmd.f90')
fft.Compile('sdrMTFFT1d.f90')

# FFTW routines etc
tpt = SepSCons( folders  = fld6 )
tpt.Append( FORTRANLIBS = ['sepauxf90'] )
tpt.Append( F90FLAGS  = ' -fast -inline-level=2' )
tpt.Append( F90FLAGS  = ' -openmp' )
tpt.Append( LINKFLAGS = ' -openmp' )
tpt.Compile('sdrTPtrans2d.f90')
tpt.Compile('sdrTPtrans3d.f90')
tpt.Compile('sdrTPtrans2d_omp.f90')
tpt.Compile('sdrTPtrans3d_omp.f90')
tpt.Compile('sdrSpectraTP3d.f90')
tpt.Compile('sdrSpectraTP3d_omp.f90')
tpt.Compile('sdrSpectraTP2d.f90')
tpt.Compile('sdrSpectraTP2d_omp.f90')

# Spectra routines etc
spc = SepSCons( folders  = fld3 )
spc.Append( LIBPATH      = ['/opt/FFTW/lib'])
spc.Append( F90PATH      = ['/opt/FFTW/include'])
spc.Append( FORTRANLIBS  = ['fftw3f'] )
spc.Append( F90FLAGS  = ' -fast -inline-level=2' )
spc.Append( F90FLAGS  = ' -openmp' )
spc.Append( LINKFLAGS = ' -openmp' )
spc.Compile('sdrSpectra_w.f90')
spc.Compile('sdrSpectra1d.f90')
spc.Compile('sdrSpectra2d.f90')
spc.Compile('sdrSpectra3d.f90')
spc.Compile('sdrMTSpectra_w.f90')
spc.Compile('sdrMTSpectra1d.f90')

# Filter routines etc
bdp = SepSCons( folders  = fld4 )
bdp.Append( LIBPATH      = ['/opt/FFTW/lib'])
bdp.Append( F90PATH      = ['/opt/FFTW/include'])
bdp.Append( FORTRANLIBS  = ['fftw3f'] )
bdp.Append( F90FLAGS  = ' -fast -inline-level=2' )
bdp.Append( F90FLAGS  = ' -openmp' )
bdp.Append( LINKFLAGS = ' -openmp' )
bdp.Compile('sdrBandpass1d.f90')
bdp.Compile('sdrBandpass2d.f90')
bdp.Compile('sdrBandpass3d.f90')
bdp.Compile('sdrBandpass2dAng.f90')
bdp.Compile('sdrBandpass3dAng.f90')

# Interferometry routines
int = SepSCons( folders  = fld5 )
int.Append( FORTRANLIBS  = ['sepauxf90'] )
int.Append( LIBPATH      = ['/opt/FFTW/lib'])
int.Append( F90PATH      = ['/opt/FFTW/include'])
int.Append( FORTRANLIBS  = ['fftw3f'] )
int.Append( F90FLAGS  = ' -fast -inline-level=2' )
int.Append( F90FLAGS  = ' -openmp' )
int.Append( LINKFLAGS = ' -openmp' )
int.Compile('sdrSI2d_1d_t.f90')
int.Compile('sdrSI2d_1d_t_omp.f90')
int.Compile('sdrSI2d_self1d_t.f90')
int.Compile('sdrSI2d_self1d_t_omp.f90')
int.Compile('sdrSI2d_self1d_w.f90')
int.Compile('sdrSI2d_self1d_w_omp.f90')
int.Compile('sdrSI3d_self1d_t.f90')
int.Compile('sdrSI3d_self1d_t_omp.f90')
int.Compile('sdrSI3d_self1d_w.f90')
int.Compile('sdrSI3d_self1d_w_omp.f90')
int.Compile('sdrSI2d_self2d_t.f90')
int.Compile('sdrSI2d_self2d_t_omp.f90')
int.Compile('sdrSI2d_self2d_w.f90')
int.Compile('sdrSI2d_self2d_w_omp.f90')
int.Compile('sdrSI2d_self2d_wt.f90')
int.Compile('sdrSI2d_self2d_wt_omp.f90')
int.Compile('sdrMTSI2d_self1d_t.f90')
int.Compile('sdrMTSI2d_self1d_t_omp.f90')
int.Compile('sdrMTSI2d_self1d_w.f90')
int.Compile('sdrMTSI2d_self1d_w_omp.f90')
int.Compile('sdrMTSI3d_self1d_t.f90')
int.Compile('sdrMTSI3d_self1d_t_omp.f90')


# Test programs
test = SepSCons( folders = tstf )
test.Append( FORTRANLIBS  = ['sepgeef90'] )
#test.Append( F90FLAGS  = ' -fast -inline-level=2' )
#test.Append( F90FLAGS  = ' -openmp' )
#test.Append( LINKFLAGS = ' -openmp' )
test.Compile('test_real_sum.f90')
test.Compile('test_cmplx_sum.f90')
test.Compile('MemUse.f90')


# programs written while at BP
bpsc = SepSCons( folders = bpfl )
bpsc.Append( FORTRANLIBS  = ['sepgeef90'] )
bpsc.Compile('sdrAnisoArrow.f90')
bpsc.Compile('sdrEtomoAnisoCStatGraph.f90')
bpsc.Compile('sdrMaskValhall.f90')
bpsc.Compile('sdrRotate.f90')
bpsc.Compile('sdrTweak.f90')
bpsc.Compile('sdrCreateAnisoC.f90')
bpsc.Compile('sdrEtomoAnisoFit.f90')
bpsc.Compile('sdrMaxloc.f90')
bpsc.Compile('sdrSetSparseFlag.f90')
bpsc.Compile('sdrEikonalTomoCStats.f90')
bpsc.Compile('sdrLog.f90')
bpsc.Compile('sdrMaxloc_old.f90')
bpsc.Compile('sdrSIaverage.f90')
bpsc.Compile('sdrEikonalTomo.f90')
bpsc.Compile('sdrLogLog.f90')
bpsc.Compile('sdrRMS.f90')
bpsc.Compile('sdrSIexpand_headers.f90')
bpsc.Compile('sdrEtomoAnisoCStat.f90')
bpsc.Compile('sdrMakeSparse.f90')
bpsc.Compile('sdrRMSxyz.f90')
bpsc.Compile('sdrSIquality.f90')



# SPAC programs
spac = SepSCons( folders = fld7 )
spac.Append( FORTRANLIBS  = ['sepgeef90'] )
spac.Append( F90FLAGS  = ' -fast -inline-level=2' )
spac.Append( F90FLAGS  = ' -openmp' )
spac.Append( LINKFLAGS = ' -openmp' )
spac.Compile('sdrSPACv1.f90')
spac.Compile('sdrSPACv1_omp.f90')
spac.Compile('sdrSPACv2.f90')
spac.Compile('sdrSPACv2_omp.f90')
spac.Compile('sdrSPACv3_omp.f90')
#spac.Compile('sdrDispersionCurve.f90')
spac.Compile('sdrDispersionCurve1d.f90')

