From 56ebf2fe54e96d59e9d52cc4274b50f83411f247 Mon Sep 17 00:00:00 2001
From: Jan Thorbecke <janth@xs4all.nl>
Date: Wed, 15 Nov 2017 09:21:15 +0100
Subject: [PATCH] time bookkeeping for reverse time modeling

---
 fdelmodc/demo/pars        | 5 -----
 fdelmodc/fdelmodc.c       | 2 +-
 fdelmodc/writeRec.c       | 7 ++++++-
 fdelmodc/writeSnapTimes.c | 7 +++++--
 4 files changed, 12 insertions(+), 9 deletions(-)
 delete mode 100644 fdelmodc/demo/pars

diff --git a/fdelmodc/demo/pars b/fdelmodc/demo/pars
deleted file mode 100644
index e94ff54..0000000
--- a/fdelmodc/demo/pars
+++ /dev/null
@@ -1,5 +0,0 @@
-file_cp=syncl_cp.su ischeme=1 file_den=syncl_ro.su file_src=wave.su \
-file_rcv=shot_xsrc-200.su src_type=7 src_orient=1 \
-src_injectionrate=1 rec_type_vz=0 rec_type_p=1 rec_int_vz=2 \
-dtrcv=0.004 rec_delay=0.1 verbose=2 tmod=4.10 dxrcv=10.0 xrcv1=-2250 \
-xrcv2=2250 zrcv1=0 zrcv2=0 xsrc=0 zsrc=1150 ntaper=200 left=2 right=2 top=1 bottom=2
diff --git a/fdelmodc/fdelmodc.c b/fdelmodc/fdelmodc.c
index 691f8d1..899f78c 100644
--- a/fdelmodc/fdelmodc.c
+++ b/fdelmodc/fdelmodc.c
@@ -90,7 +90,7 @@ char *sdoc[] = {
 "   file_beam=beam.su . base name for beam fields ",
 "   dx= ............... read from model file: if dx==0 then dx= can be used to set it",
 "   dz= ............... read from model file: if dz==0 then dz= can be used to set it",
-"   dt= ............... read from file_src: if dt==0 then dt= can be used to set it",
+"   dt= ............... read from file_src: if dt is set it will interpolate file_src to dt sampling",
 "" ,
 " OPTIONAL PARAMETERS:",
 "   ischeme=3 ......... 1=acoustic, 2=visco-acoustic 3=elastic, 4=visco-elastic",
diff --git a/fdelmodc/writeRec.c b/fdelmodc/writeRec.c
index 877bbe9..167e5f7 100644
--- a/fdelmodc/writeRec.c
+++ b/fdelmodc/writeRec.c
@@ -85,7 +85,12 @@ int writeRec(recPar rec, modPar mod, bndPar bnd, wavPar wav, int ixsrc, int izsr
     hdr.ns     = nsam;
     hdr.trwf   = rec.n;
     hdr.ntr    = (ishot+1)*rec.n;
-    hdr.f1     = 0.0;
+    if (mod.grid_dir) { /* reverse time modeling */
+        hdr.f1 = (-mod.nt+1)*mod.dt;
+    }
+    else {
+        hdr.f1 = 0.0;
+    }
     hdr.d1     = mod.dt*rec.skipdt;
     hdr.d2     = (rec.x[1]-rec.x[0])*mod.dx;
     hdr.f2     = mod.x0+rec.x[0]*mod.dx;
diff --git a/fdelmodc/writeSnapTimes.c b/fdelmodc/writeSnapTimes.c
index 3790496..2b68a69 100644
--- a/fdelmodc/writeSnapTimes.c
+++ b/fdelmodc/writeSnapTimes.c
@@ -37,7 +37,7 @@ int writeSnapTimes(modPar mod, snaPar sna, bndPar bnd, int ixsrc, int izsrc, int
 	static int first=1;
 	int n1, ibndx, ibndz, ixs, izs, ize, i, j;
 	int ix, iz, ix2;
-	float *snap, sdx;
+	float *snap, sdx, stime;
 	segy hdr;
 
 	if (sna.nsnap==0) return 0;
@@ -65,7 +65,10 @@ int writeSnapTimes(modPar mod, snaPar sna, bndPar bnd, int ixsrc, int izsrc, int
 		  (itime <= sna.delay+(sna.nsnap-1)*sna.skipdt) ) {
 
 		isnap = NINT((itime-sna.delay)/sna.skipdt);
-		if (verbose) vmess("Writing snapshot(%d) at time=%.4f", isnap+1, itime*mod.dt);
+
+        if (mod.grid_dir)  stime = (-mod.nt+1+itime)*mod.dt;  /* reverse time modeling */
+        else  stime = itime*mod.dt;
+		if (verbose) vmess("Writing snapshot(%d) at time=%.4f", isnap+1, stime);
 	
 		if (first) {
 			append=0;
-- 
GitLab