From 88219a4ce1a309d064ea12b8ef4f5200790e69ba Mon Sep 17 00:00:00 2001
From: Jan at TU-Delft <J.W.Thorbecke@tudelft.nl>
Date: Tue, 16 Jul 2019 09:26:57 +0200
Subject: [PATCH] porting fdacrtmc to Intel compiler

---
 Makefile                                |   8 +-
 README                                  |   8 ++
 fdacrtmc/Examples/Synform/PlaneWave.scr |  12 +-
 fdacrtmc/Make_include_Max               | 144 ------------------------
 fdacrtmc/Makefile                       |   8 +-
 fdacrtmc/fileOpen.c                     |  49 +-------
 fdacrtmc/wisdom.c                       |   2 +-
 marchenko/demo/README                   |   3 +
 8 files changed, 29 insertions(+), 205 deletions(-)
 delete mode 100644 fdacrtmc/Make_include_Max
 mode change 100644 => 120000 fdacrtmc/fileOpen.c

diff --git a/Makefile b/Makefile
index 477383c..1351be2 100644
--- a/Makefile
+++ b/Makefile
@@ -10,8 +10,9 @@ all: mkdirs
 	cd corrvir		; $(MAKE) install
 	cd raytime		; $(MAKE) install
 	cd MDD			; $(MAKE) install
+	cd zfp			; $(MAKE) 
+	cd fdacrtmc		; $(MAKE) install
 
-#	cd fdelrtmc		; $(MAKE) install
 
 mkdirs:
 	-mkdir -p lib
@@ -22,13 +23,14 @@ clean:
 	cd FFTlib 		; $(MAKE) $@
 	cd fdelmodc		; $(MAKE) $@
 	cd fdelmodc3D	; $(MAKE) $@
-	cd fdelrtmc		; $(MAKE) $@
 	cd utils		; $(MAKE) $@
 	cd marchenko	; $(MAKE) $@
 	cd marchenko3D	; $(MAKE) $@
 	cd corrvir		; $(MAKE) $@
 	cd raytime		; $(MAKE) $@
 	cd MDD			; $(MAKE) $@
+	cd zfp			; $(MAKE) $@
+	cd fdacrtmc		; $(MAKE) $@
 
 realclean:
 	cd FFTlib 		; $(MAKE) $@
@@ -41,6 +43,8 @@ realclean:
 	cd corrvir		; $(MAKE) $@
 	cd raytime		; $(MAKE) $@
 	cd MDD			; $(MAKE) $@
+	cd zfp			; $(MAKE) $@
+	cd fdacrtmc		; $(MAKE) $@
 	rm -f lib/*
 	rm -f include/*
 	rm -f bin/*
diff --git a/README b/README
index f7643f0..54dd9c3 100644
--- a/README
+++ b/README
@@ -116,6 +116,14 @@ git clone https://github.com/JohnWStockwellJr/SeisUnix
 
 ==> Please make sure that SU is compiled without XDR (in $CWPROOT/Makefile.config make sure that XDRFLAG is NOT set). The SU output files of fdelmodc are all based on local IEEE data.
 
+ZFP
+---
+The fdacrtmc code makes use of ZFP compression to store the snaphots in CPU memory. This package is included in this repository for
+your convenience. The latest package and detailed explanation can be found on:
+
+https://github.com/LLNL/zfp
+
+
 MISC
 ----
 Other make commands which can be useful:
diff --git a/fdacrtmc/Examples/Synform/PlaneWave.scr b/fdacrtmc/Examples/Synform/PlaneWave.scr
index f3b6095..df999d5 100755
--- a/fdacrtmc/Examples/Synform/PlaneWave.scr
+++ b/fdacrtmc/Examples/Synform/PlaneWave.scr
@@ -44,7 +44,7 @@ for i in {1..1601};do cat SrcWav_Ricker_40Hz_2s.su >> SrcArr.su; done
 sushw <SrcArr.su key=tracl,tracr,fldr,tracf,scalco,sx a=1,1,1,1,-10,-20000 b=1,1,0,1,0,25 >tmp.su; mv -f tmp.su SrcArr.su;
 
 # 1.3: Model Data
-../../fdacrtmc/fdacrtmc        '#The RTM engine'\
+../../fdacrtmc        '#The RTM engine'\
 	file_cp=Synform_cp.su  '#The input acoustic velocity model'\
 	file_src=SrcArr.su     '#The input source array'\
 	file_rcv=RcvArr.su     '#The output receiver data base filename'\
@@ -60,7 +60,7 @@ sushw <SrcArr.su key=tracl,tracr,fldr,tracf,scalco,sx a=1,1,1,1,-10,-20000 b=1,1
 suwind <Synform_cp.su itmax=50 | sugain dt=1 scale=0.0 | sugain dt=1 bias=1900 >Direct_cp.su;
 
 # 2.2: Model Direct-Wave Data
-../../fdacrtmc/fdacrtmc file_cp=Direct_cp.su file_src=SrcArr.su\
+../../fdacrtmc file_cp=Direct_cp.su file_src=SrcArr.su\
 	file_rcv=DirArr.su\
 	top=2 npml=50 rcv_top=1 rcv_p=1 rcv_write=1 mig_mode=0 verbose=2;
 
@@ -79,7 +79,7 @@ rm -f Direct_cp.su Direct_ro.su RcvArr_rp.su DirArr_rp.su;
 # With    compression this migration needs about 0.75 GiB of RAM at a tol.  of 1e-6
 #                                                0.47 GiB of RAM at a tol.  of 1e-3
 #                                                0.16 GiB of RAM at a prec. of 1e-3
-../../fdacrtmc/fdacrtmc file_cp=Synform_cp.su file_src=SrcArr.su\
+../../fdacrtmc file_cp=Synform_cp.su file_src=SrcArr.su\
 	file_rcv=RcvArr_ND.su    '#We now use the direct-wave free reflection data'\
 	file_mig=Conventional.su '#Base filename for migrated image'\
 	top=2 npml=50\
@@ -90,13 +90,13 @@ rm -f Direct_cp.su Direct_ro.su RcvArr_rp.su DirArr_rp.su;
 	verbose=2;
 
 # 3.2: Display Migrated Image
-suximage <Conventional_mig.su title=Migrated_Image perc=98 &
+suximage <Conventional_mig.su title=Migrated_Image clip=2e5 &
 
 # 3.3: Migrate Using The Hilbert Transform Imaging Condition
-../../fdacrtmc/fdacrtmc file_cp=Synform_cp.su file_src=SrcArr.su file_rcv=RcvArr_ND.su\
+../../fdacrtmc file_cp=Synform_cp.su file_src=SrcArr.su file_rcv=RcvArr_ND.su\
 	file_mig=Hilbert.su '#Base filename for migrated image'\
 	top=2 npml=50 mig_mode=5 migdt=0.0025 migdx=5 migdz=5 compress=1 verbose=2;
 
 # 3.4: Display Migrated Image
-suximage <Hilbert_mig.su title=Hilbert_Image &
+suximage <Hilbert_mig.su title=Hilbert_Image clip=2e5 &
 exit;
diff --git a/fdacrtmc/Make_include_Max b/fdacrtmc/Make_include_Max
deleted file mode 100644
index a14dddc..0000000
--- a/fdacrtmc/Make_include_Max
+++ /dev/null
@@ -1,144 +0,0 @@
-# Makefile for general rules
-
-# To Change the compile environment to your current system you should set:
-#   -1- ROOT variable to the directory where you found this file
-#   -2- if needed use a different compiler (CC) if gcc is not available
-#   -3- on Solaris system use RANLIB=ranlib which is defined below
-
-# the current directory (in vi ":r!pwd")
-ROOT=/ribarsko/data/holicki/src/fdelrtmc
-
-########################################################################
-# C compiler; change this only if you are using a different C-compiler
-
-#GNU 
-CC = gcc
-#CC=/opt/gcc-4.7.4/bin/gcc
-#FC = gfortran
-# Linux gcc version 4.x
-#OPTC = -g
-#OPTC = -O3 -ffast-math
-#OPTC += -fopenmp
-
-#OPTF = -O3 -fno-trapping-math -ffast-math -msse3
-# for better performing code try:
-#OPTC = -O3 -fno-trapping-math -ffast-math -funroll-all-loops -msse3 -fomit-frame-pointer -mfpmath=sse -ftree-vectorizer-verbose=1 -fopenmp
-# Linux gcc version 3.x
-#OPTC = -O3 -ffast-math -funroll-all-loops -mfpmath=sse
-# Apple OSX gcc version 4.x (Snow Leopard)
-#CC = gcc
-OPTC = -O3 -ffast-math -funroll-all-loops -mssse3 -fomit-frame-pointer -mtune=nocona -mfpmath=sse -fdump-tree-vect -fopenmp -D WISDOMDIR="\"/tmp/fftw/\""
-
-#for double precision use  FFTlib and emmod
-#OPTC += -DDOUBLE
-#OPTF += -fdefault-double-8 -fdefault-real-8
-
-#Cray
-#CC=cc
-#FC=ftn
-#OPTC = -O2
-#OPTF = -O2
-
-#Intel 
-#CC = icc
-#FC = ifort
-
-# Linux
-#OPTC = -D -O3 -no-prec-div -xCORE-AVX2 -qopenmp -Wall
-#OPTC = -D -O3 -no-prec-div -xCORE-AVX2 -Wall -profile-loops=all
-#OPTC = -D WISDOMDIR="\"/tmp/fftw/\"" -O3 -no-prec-div -xCORE-AVX2 -qopenmp -Wall
-#OPTC = -D WISDOMDIR="\"/tmp/fftw/\"" -O3 -openmp -Wall
-#OPTC = -O3 -no-prec-div -xHOST -qopenmp -Wall
-#OPTC = -g
-#OPTC = -g -D WISDOMDIR="\"/tmp/fftw/\""
-#OPTC = -g -D WISDOMDIR="\"/tmp/fftw/\"" -fopenmp
-#OPTC = -g -qopenmp -mcmodel=large -D WISDOMDIR="\"/tmp/fftw/\""
-#OPTF = -O3 -no-prec-div 
-# Apple OSX intel 11.1.076 snow leopard 10.6.2
-#OPTC = -O3 -mssse3 -no-prec-div -vec-report2 -fno-builtin-__sprintf_chk 
-
-#PGI 
-#CC = pgcc
-#FC = pgf90
-#OPTC = -fast  -Minfo=vect -Mvect=simd:256 -Msafeptr
-#OPTC = -fast  -Minfo=vect -Mvect=simd:256 -Msafeptr -Mprof=lines
-#OPTF = -fast
-#LDFLAGS = -fast -Minfo=vect -Mvect=simd:256 -Msafeptr 
-
-#Pathscale 
-#CC = cc
-#FC = ftn
-#OPTC = -Ofast -OPT:Ofast -fno-math-errno
-#OPTF = -Ofast -OPT:Ofast -fno-math-errno
-
-#Apple OSX clang/gcc (10.9) llvm
-#CC = clang
-#OPTC = -Ofast
-#LDFLAGS = -Ofast
-
-#AMD Open64
-#CC = opencc
-#FC = openf95
-#OPTC = -O3
-#OPTC += -openmp
-#OPTF = -O3
-#LDFLAGS = -static -O3
-#
-#############################################################################
-# FOR FFT LIBRARIES
-#AMD ACML 4.4.0
-#AMDROOT = /home/thorbcke/amdsdk/v1.0/acml/open64_64
-#OPTC += -DACML440 -I$(AMDROOT)/include
-#LIBSM = -L$(AMDROOT)/lib -lacml -lfortran -lffio -lrt -lm
-
-#############################################################################
-# Some convenient abbreviations
-
-B = $(ROOT)/bin
-I = $(ROOT)/include
-L = $(ROOT)/lib
-
-########################################################################
-# standard CFLAGS
-CFLAGS = -I$I -I. -I/vardim/home/holicki/src/zfp-0.5.5/include
-
-#############################################################################
-# the archiver
-AR = ar
-
-#############################################################################
-# ar FLAGS
-ARFLAGS = rv
-
-#############################################################################
-# ranlib definition
-RANLIB = ar -s
-# on Sun SOLARIS use:
-#RANLIB = ranlib
-
-
-.SUFFIXES : .o .c .cc .f .a .F90
-.c.o	:
-	$(CC) -c $(CFLAGS) $(OPTC) $< -o $@
-.c.a	:
-	$(CC) -c $(CFLAGS) $(OPTC) $<
-	$(AR) $(ARFLAGS) $@ $*.o
-	rm -f $*.o
-.o.a	:
-	$(AR) $(ARFLAGS) $@ $*.o
-	rm -f $*.o
-.f.o	:
-	$(FC) -c $(FFLAGS) $(OPTF) $<
-.F90.o	:
-	$(FC) -c $(FFLAGS) $(OPTF) $<
-.f.a	:
-	$(FC) -c $(FFLAGS) -I$I $<
-	$(AR) $(ARFLAGS) $@ $*.o
-	rm -f $*.o
-.cc.a	:
-	$(C++) -c $(C++FLAGS) -I$I $<
-	$(AR) $(ARFLAGS) $@ $*.o
-	rm -f $*.o
-.cc.o	:
-	$(C++) -c $(C++FLAGS) $<
-
diff --git a/fdacrtmc/Makefile b/fdacrtmc/Makefile
index d4b6e06..9f5b6f3 100644
--- a/fdacrtmc/Makefile
+++ b/fdacrtmc/Makefile
@@ -4,13 +4,13 @@ include ../Make_include
 
 ########################################################################
 # define general include and system library
-CFLAGS  += -I/vardim/home/holicki/src/zfp-0.5.5/include
-#LIBS    += -L$L $(LIBSM) -lm -lfftw3 -lfftw3_omp -I/ribarsko/data/holicki/fftw3/fftw-3.3.6-pl1/api -L/ribarsko/data/holicki/fftw3/fftw-3.3.6-pl1/api -I/vardim/home/holicki/src/zfp-0.5.5/include -L/vardim/home/holicki/src/zfp-0.5.5/lib -lzfp
-LIBS    += -L$L $(LIBSM) -L/vardim/home/holicki/src/zfp-0.5.5/lib -lzfp
+CFLAGS  += -I$(ROOT)/zfp/include
+LIBS    += -L$L $(LIBSM) -L$(ROOT)/zfp/lib -lzfp
+
 #LIBS    += -L$L -lgenfft $(LIBSM) -lm 
 #LIBS    += -L$L -lgenfft -lm -lc
 #OPTC = -g -Wall -fsignaling-nans -O0
-#OPTC = -g -O0
+#OPTC += -g 
 #OPTC += -fopenmp -Waddress
 #OPTC := $(subst -O3 -ffast-math, -O1 -g ,$(OPTC))
 #PGI options for compiler feedback
diff --git a/fdacrtmc/fileOpen.c b/fdacrtmc/fileOpen.c
deleted file mode 100644
index b0ff806..0000000
--- a/fdacrtmc/fileOpen.c
+++ /dev/null
@@ -1,48 +0,0 @@
-#define _FILE_OFFSET_BITS 64
-#define _LARGEFILE_SOURCE
-#define _LARGEFILE64_SOURCE
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <math.h>
-#include <string.h>
-#include "segy.h"
-
-/**
-*  File handling routines 
-*
-*   AUTHOR:
-*           Jan Thorbecke (janth@xs4all.nl)
-*           The Netherlands 
-**/
-
-void name_ext(char *filename, char *extension);
-
-FILE *fileOpen(char *file, char *ext, int append)
-{
-	FILE *fp;
-	char filename[1024];
-
-	strcpy(filename, file);
-	name_ext(filename, ext);
-	if (append) fp = fopen(filename, "a");
-   	else fp = fopen(filename, "w");
-   	assert(fp != NULL);
-	
-	return fp;
-}
-
-int traceWrite(segy *hdr, float *data, int n, FILE *fp) 
-{
-    size_t  nwrite;
-
-    nwrite = fwrite( hdr, 1, TRCBYTES, fp);
-    assert(nwrite == TRCBYTES);
-    nwrite = fwrite( data, sizeof(float), n, fp);
-    assert(nwrite == n);
-
-	return 0;
-}
-
diff --git a/fdacrtmc/fileOpen.c b/fdacrtmc/fileOpen.c
new file mode 120000
index 0000000..665a0bd
--- /dev/null
+++ b/fdacrtmc/fileOpen.c
@@ -0,0 +1 @@
+../fdelmodc/fileOpen.c
\ No newline at end of file
diff --git a/fdacrtmc/wisdom.c b/fdacrtmc/wisdom.c
index aac6d0e..c31d124 100644
--- a/fdacrtmc/wisdom.c
+++ b/fdacrtmc/wisdom.c
@@ -1066,7 +1066,7 @@ int Create1DWavenumberTransformPlans(fftPlansPar *fftPlans,size_t nx,size_t nz){
 		if(PlanFFT_1d_c2c(in,nz,&(fftPlans->fft_1d_c2c_z),&(fftPlans->ifft_1d_c2c_Kz)))verr("Could not load generated FFTw wisdom!");
 	}
 
-	free(in);
+	fftw_free(in);
 	return(0);
 }
 
diff --git a/marchenko/demo/README b/marchenko/demo/README
index f5a7c12..5e24f94 100644
--- a/marchenko/demo/README
+++ b/marchenko/demo/README
@@ -2,3 +2,6 @@ The scripts to reproduce the Figures in the manuscript can be found in the direc
 
 A more complicated model can be found in the directory twoD and will takes several hours to model the reflection data. 
 
+The directory invisible demonstrates the use of the program marchenko_primaries.
+
+The directory WS15 contains the files and README's used for the EAGE workshop in London 2019: "Reproducing Research with the Marchenko Method and Inversion with the SEISCOPE Toolbox"
-- 
GitLab