From 617ab760a551aae0ba0d7505f5361e1de00c32c7 Mon Sep 17 00:00:00 2001
From: JanThorbecke <janth@xs4all.nl>
Date: Thu, 25 Feb 2021 07:24:19 +0100
Subject: [PATCH] added changevalue

---
 utils/Makefile      |  21 +++++++--
 utils/changevalue.c | 105 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 4 deletions(-)
 create mode 100644 utils/changevalue.c

diff --git a/utils/Makefile b/utils/Makefile
index d345730..e874c0c 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -7,7 +7,7 @@ LIBS    += -L$L -lgenfft -lzfp
 #OPTC += -openmp 
 #OPTC += -g -O0
 
-ALL: makemod makewave extendModel fconv correigen green green3D basop syn2d mat2su ftr1d mutesnap padmodel truncate combine combine_induced reshape_su HomG snap2shot makeR1D pwshift convhomg
+ALL: makemod makewave extendModel fconv correigen green green3D basop syn2d mat2su ftr1d mutesnap padmodel truncate combine combine_induced reshape_su HomG snap2shot makeR1D pwshift convhomg changevalue
 
 SRCM	= \
 		makemod.c  \
@@ -245,6 +245,13 @@ SRCCH	= convhomg.c \
         docpkge.c \
 		readSnapData3D.c 
 
+SRCVL	= changevalue.c \
+		wallclock_time.c \
+		getpars.c \
+		verbosepkg.c \
+		atopkge.c \
+        docpkge.c 
+
 OBJM	= $(SRCM:%.c=%.o)
 
 makemod:	$(OBJM) 
@@ -355,7 +362,12 @@ OBJCH	= $(SRCCH:%.c=%.o)
 convhomg:  $(OBJCH)
 	$(CC) $(LDFLAGS) $(OPTC) $(CFLAGS) -o convhomg $(OBJCH) $(LIBS)
 
-install: makemod makewave extendModel fconv correigen green green3D basop syn2d mat2su ftr1d mutesnap padmodel truncate combine combine_induced reshape_su HomG snap2shot makeR1D pwshift convhomg
+OBJVL	= $(SRCVL:%.c=%.o)
+
+changevalue: $(OBJVL)
+	$(CC) $(LDFLAGS) $(OPTC) $(CFLAGS) -o changevalue $(OBJVL) $(LIBS)
+
+install: makemod makewave extendModel fconv correigen green green3D basop syn2d mat2su ftr1d mutesnap padmodel truncate combine combine_induced reshape_su HomG snap2shot makeR1D pwshift convhomg changevalue
 	cp makemod $B
 	cp makewave $B
 	cp extendModel $B
@@ -378,9 +390,10 @@ install: makemod makewave extendModel fconv correigen green green3D basop syn2d
 	cp makeR1D $B
 	cp pwshift $B
 	cp convhomg $B
+	cp changevalue $B
 
 clean:
-		rm -f core $(OBJM) makemod $(OBJW) makewave $(OBJE) extendModel $(OBJF) fconv $(OBJG) $(OBJC) correigen green $(OBJG3) green3D $(OBJB) basop $(OBJJ) syn2d $(OBJS) mat2su $(OBJA) ftr1d $(OBJT) mutesnap $(OBJMS) truncate $(OBJTR) padmodel $(OBJPM) combine $(OBJCO) makeR1D $(OBJMR) reshape_su $(OBJRS) combine_induced $(OBJCI) HomG $(OBJHG) snap2shot $(OBJSS) pwshift $(OBJPW) convhomg $(OBJCH)
+		rm -f core $(OBJM) makemod $(OBJW) makewave $(OBJE) extendModel $(OBJF) fconv $(OBJG) $(OBJC) correigen green $(OBJG3) green3D $(OBJB) basop $(OBJJ) syn2d $(OBJS) mat2su $(OBJA) ftr1d $(OBJT) mutesnap $(OBJMS) truncate $(OBJTR) padmodel $(OBJPM) combine $(OBJCO) makeR1D $(OBJMR) reshape_su $(OBJRS) combine_induced $(OBJCI) HomG $(OBJHG) snap2shot $(OBJSS) pwshift $(OBJPW) convhomg $(OBJCH) changevalue $(OBJVL)
 
 realclean: clean
-		rm -f $B/makemod $B/makewave $B/extendModel $B/fconv $B/correigen $B/green $B/green3D $B/basop $B/syn2d $B/mat2su $B/ftr1d $B/mutesnap $B/padmodel $B/truncate $B/combine $B/combine_induced $B/reshape_su $B/HomG $B/snap2shot $B/makeR1D $B/pwshift $B/convhomg
+		rm -f $B/makemod $B/makewave $B/extendModel $B/fconv $B/correigen $B/green $B/green3D $B/basop $B/syn2d $B/mat2su $B/ftr1d $B/mutesnap $B/padmodel $B/truncate $B/combine $B/combine_induced $B/reshape_su $B/HomG $B/snap2shot $B/makeR1D $B/pwshift $B/convhomg $B/changevalue
diff --git a/utils/changevalue.c b/utils/changevalue.c
new file mode 100644
index 0000000..5c57b63
--- /dev/null
+++ b/utils/changevalue.c
@@ -0,0 +1,105 @@
+#include "par.h"
+#include "segy.h"
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <math.h>
+#include <assert.h>
+
+/*********************** self documentation **********************/
+char *sdoc[] = {
+" ",
+" changevalue - change data-range to a different value",
+" ",
+" fconv file_in= file_out= [optional parameters]",
+" ",
+" Required parameters: ",
+" ",
+"   file_in= ................. input file",
+"   file_out= ................ output file",
+" ",
+" Optional parameters: ",
+" ",
+"   file_out= ................ output file",
+"   rmin=0 ................... minimum value in range to change",
+"   rmax=rmin ................ maximum value in range to change",
+"   value=0 .................. value to replace [rmin:rmax]",
+"   verbose=0 ................ silent option; >0 display info",
+" ",
+NULL};
+/**************** end self doc ***********************************/
+
+int main (int argc, char **argv)
+{
+	FILE	*fp_in, *fp_out;
+	size_t  nwrite,nread;
+	int		oneshot, verbose, n1, i;
+	float   rmin, rmax, value, *trace;
+    double  t0, t1, t2;
+	char 	*file_in, *file_out;
+	segy	hdr;
+
+
+	t0 = wallclock_time();
+	initargs(argc, argv);
+	requestdoc(1);
+
+	if(!getparstring("file_in", &file_in)) file_in=NULL;
+	if(!getparstring("file_out", &file_out)) file_out=NULL;
+	if(!getparfloat("rmin", &rmin)) rmin = 0.0;
+	if(!getparfloat("rmax", &rmax)) rmax = rmin;
+	if(!getparfloat("value", &value)) value=0.0;
+	if(!getparint("verbose", &verbose)) verbose=0;
+
+/* Reading input data for file_in1 */
+
+	if (file_in==NULL) fp_in = stdout;
+	else {
+	    fp_in = fopen(file_in, "r");
+	    if (fp_in == NULL) verr("error on opening input file_in=%s", file_in);
+	}
+	
+	if (file_out==NULL) fp_out = stdout;
+	else {
+		fp_out = fopen(file_out, "w+");
+		if (fp_out==NULL) verr("error on creating output file");
+	}
+
+/*================ loop over all shot records ================*/
+
+    oneshot = 1;
+    nread = fread(&hdr, 1, TRCBYTES, fp_in);
+    n1 = hdr.ns;
+	trace = (float *)malloc(n1*sizeof(float));
+    while (oneshot) {
+        nread = fread(trace, sizeof(float), n1, fp_in);
+        assert (nread == n1);
+
+		for (i=0; i<n1; i++) {
+			if (trace[i]>=rmin && trace[i]<=rmax) {
+				trace[i]=value;
+			}
+		}
+        nwrite = fwrite(&hdr, 1, TRCBYTES, fp_out);
+        assert(nwrite == TRCBYTES);
+        nwrite = fwrite(trace, sizeof(float), n1, fp_out);
+        assert (nwrite == n1);
+
+        nread = fread(&hdr, 1, TRCBYTES, fp_in);
+        if (nread == 0) break;
+        assert(nread == TRCBYTES);
+    }
+	fclose(fp_in);
+
+	t1 = wallclock_time();
+	if ((fp_out!=stdout) && (fp_out!=NULL)) {
+		fflush(fp_out);
+		fclose(fp_out);
+	}
+	if (verbose) vmess("Total CPU-time = %f",t1-t0);
+	
+	free(trace);
+
+	return 0;
+}
+
-- 
GitLab