Skip to content

Commit 07ec329

Browse files
authored
Merge pull request #57 from Dirack/develop/2.2.3
Develop/2.2.3
2 parents 43f5ed7 + f89e21e commit 07ec329

File tree

10 files changed

+228
-15
lines changed

10 files changed

+228
-15
lines changed

Mvfsacrsnh.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ int main(int argc, char* argv[])
6464
float **mtgraph=NULL;
6565
char strerr[50];
6666
bool useprecseed;
67+
int mMAX, hMAX; // Option to define aperture in CMP and Offset
6768

6869
/* RSF files I/O */
6970
sf_file in; /* Seismic data cube A(m,h,t) */
@@ -158,6 +159,12 @@ int main(int argc, char* argv[])
158159
if(!sf_getbool("useprecseed",&useprecseed)) useprecseed=false;
159160
/* y: Use a more precise seed for vfsa; n: Use time(NULL)*/
160161

162+
if(!sf_getint("mmax",&mMAX)) mMAX=50;
163+
/* CMP aperture */
164+
165+
if(!sf_getint("hmax",&hMAX)) hMAX=50;
166+
/* Offset aperture */
167+
161168
if(! sf_getbool("verb",&verb)) verb=false;
162169
/* y: active mode; n: quiet mode */
163170

@@ -183,6 +190,15 @@ int main(int argc, char* argv[])
183190
sf_floatread(t[0][0],nm*nh*nt,in);
184191
sf_fileclose(in);
185192

193+
if(!validBoundariesAndApertureForCMP(nm0, om0, dm0, mMAX, nm, om, dm, strerr))
194+
sf_error("%s",strerr);
195+
196+
if(!validBoundariesAndApertureForOffset(nh,oh,dh,hMAX,strerr))
197+
sf_error("%s",strerr);
198+
199+
if(!validBoundariesAndApertureForT0(nt0, ot0, dt0, nt, ot, dt, strerr))
200+
sf_error("%s",strerr);
201+
186202
if (verb) {
187203
sf_warning("Active mode on!!!");
188204
sf_warning("Input file parameters: ");
@@ -270,7 +286,7 @@ int main(int argc, char* argv[])
270286
otrn=c[0];
271287
otrnip=c[1];
272288
otbeta=c[2];
273-
semb0=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,c[0],c[1],c[2],t,half);
289+
semb0=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,c[0],c[1],c[2],t,mMAX,hMAX,half);
274290
otsemb = semb0;
275291
}
276292

@@ -289,7 +305,7 @@ int main(int argc, char* argv[])
289305

290306
semb=0;
291307

292-
semb=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,RN,RNIP,BETA,t,half);
308+
semb=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,RN,RNIP,BETA,t,mMAX,hMAX,half);
293309

294310
/* VFSA parameters convergence condition */
295311
if(fabs(semb) > fabs(semb0) ){

docs/VERSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.2
1+
2.2.3

infra/scripts/version_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Check current version based on active develop branch name
44

5-
CURRENTVERSION="2.2.2"
5+
CURRENTVERSION="2.2.3"
66

77
VERSIONDOC=$(cat docs/VERSION.md)
88

test/bug/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# License: GPL-3.0 <https://www.gnu.org/licenses/gpl-3.0.txt>.
1212

13-
TESTS=test_issue_32 test_issue_46
13+
TESTS=test_issue_32 test_issue_46 test_issue_52
1414

1515
all: $(TESTS)
1616

test/bug/issue_52/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Makefile
2+
#
3+
# Purpose: Tests for bug related in issue 52.
4+
#
5+
# Site: https://www.geofisicando.com
6+
#
7+
# Programmer: Rodolfo A C Neves (Dirack) 27/02/2024
8+
#
9+
10+
#
11+
# License: GPL-3.0 <https://www.gnu.org/licenses/gpl-3.0.txt>.
12+
13+
# Uncomment the line below to run on a CENTOS system. Or call make as 'make CENTOS=1'
14+
#CENTOS=1
15+
16+
DEP = ../../../vfsacrsnh_lib.c
17+
GDBDEP = ../../../Mvfsacrsnh.c $(DEP)
18+
UNITY = ../../Unity/unity.c
19+
20+
# Default is to run the test
21+
all: Test_bug_issue_52.x
22+
@./Test_bug_issue_52.x \
23+
; rm Test_bug_issue_52.x
24+
25+
%.x: %.c
26+
ifdef CENTOS
27+
@gcc -I$$RSFSRC/include -I../.. -I/usr/include/openblas -L$$RSFSRC/lib $< $(DEP) $(UNITY) -o $@ -lm -lrsf -lopenblas -g
28+
else
29+
@gcc -I$$RSFSRC/include -I../.. -L$$RSFSRC/lib $< $(DEP) $(UNITY) -o $@ -lm -lrsf
30+
endif
31+
32+
clean:
33+
rm *.x
34+
35+
help:
36+
@echo "Compilation of the tests\nRun 'make' to unit test"
37+
38+
.PHONY: clean help all

test/bug/issue_52/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Tests for libraries and functions
2+
3+
Those tests run using the program make

test/bug/issue_52/Test_bug_issue_52.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Test_bug_issue_52.c (C)
3+
*
4+
* Purpose: Test of bug related in issue 52.
5+
*
6+
* Site: https://www.geofisicando.com
7+
*
8+
* Programmer: Rodolfo A C Neves (Dirack) 27/02/2024
9+
*
10+
11+
*
12+
* License: GPL-3.0 <https://www.gnu.org/licenses/gpl-3.0.txt>.
13+
*/
14+
15+
#include "Unity/unity.h"
16+
#include "../vfsacrsnh_lib.h"
17+
#include <rsf.h>
18+
#define ITMAX 100
19+
#define hMAX 50
20+
#define mMAX 50
21+
22+
void setUp(){};
23+
24+
void tearDown(){};
25+
26+
void testFunctionValueInsideBoundaries(){
27+
/*< Function to assure that value is inside boundaries >*/
28+
TEST_ASSERT_TRUE(checkValueInsideBoundaries(1.0,0.,2.0));
29+
TEST_ASSERT_FALSE(checkValueInsideBoundaries(1.0,1.1,2.0));
30+
TEST_ASSERT_FALSE(checkValueInsideBoundaries(1.0,0.,0.5));
31+
}
32+
33+
void checkValidBoundariesAndApertureForCMP(){
34+
/*< Function to assure that m0 values are inside boundaries to avoid segmentation fault errors >*/
35+
36+
char strerr[100];
37+
int nm=401;
38+
float dm=0.025, om=0.;
39+
int nm0=1;
40+
float dm0=1., om0=3;
41+
int aperture=50;
42+
43+
TEST_ASSERT_TRUE(validBoundariesAndApertureForCMP(nm0, om0, dm0, aperture, nm, om, dm, strerr));
44+
45+
om0=1.;
46+
TEST_ASSERT_FALSE(validBoundariesAndApertureForCMP(nm0, om0, dm0, aperture, nm, om, dm, strerr));
47+
TEST_ASSERT_EQUAL_STRING("Invalid boundaries for CMP m0min=-0.250000 m0max=2.250000. Please check aperture!",strerr);
48+
49+
om0=9.;
50+
TEST_ASSERT_FALSE(validBoundariesAndApertureForCMP(nm0, om0, dm0, aperture, nm, om, dm, strerr));
51+
TEST_ASSERT_EQUAL_STRING("Invalid boundaries for CMP m0min=7.750000 m0max=10.250000. Please check aperture!",strerr);
52+
}
53+
54+
void checkValidBoundariesAndApertureForOffset(){
55+
/*< Function to assure that Offset values are inside boundaries to avoid segmentation fault errors >*/
56+
57+
char strerr[100];
58+
int nh=161;
59+
float dh=0.0125, oh=0.;
60+
int aperture=50;
61+
62+
TEST_ASSERT_TRUE(validBoundariesAndApertureForOffset(nh, oh, dh, aperture, strerr));
63+
64+
oh=0.;
65+
aperture=162;
66+
TEST_ASSERT_FALSE(validBoundariesAndApertureForOffset(nh, oh, dh, aperture, strerr));
67+
TEST_ASSERT_EQUAL_STRING("Invalid boundaries for Offset hmin=0.000000 hmax=2.025000. Please check aperture!",strerr);
68+
69+
}
70+
71+
void checkValidBoundariesAndApertureForT0(){
72+
/*< Function to assure that t0 values are inside boundaries to avoid segmentation fault errors >*/
73+
74+
char strerr[100];
75+
int nt=1001;
76+
float dt=0.004, ot=0.;
77+
int nt0=1;
78+
float dt0=1., ot0=3;
79+
80+
TEST_ASSERT_TRUE(validBoundariesAndApertureForT0(nt0, ot0, dt0, nt, ot, dt, strerr));
81+
82+
ot0=4.004;
83+
TEST_ASSERT_FALSE(validBoundariesAndApertureForT0(nt0, ot0, dt0, nt, ot, dt, strerr));
84+
TEST_ASSERT_EQUAL_STRING("Invalid boundaries for time t0 t0min=4.004000 t0max=4.004000. Please check aperture!",strerr);
85+
86+
ot0=-0.004;
87+
TEST_ASSERT_FALSE(validBoundariesAndApertureForT0(nt0, ot0, dt0, nt, ot, dt, strerr));
88+
TEST_ASSERT_EQUAL_STRING("Invalid boundaries for time t0 t0min=-0.004000 t0max=-0.004000. Please check aperture!",strerr);
89+
}
90+
91+
92+
int main(int argc, char* argv[]){
93+
94+
UNITY_BEGIN();
95+
RUN_TEST(testFunctionValueInsideBoundaries);
96+
RUN_TEST(checkValidBoundariesAndApertureForCMP);
97+
RUN_TEST(checkValidBoundariesAndApertureForOffset);
98+
RUN_TEST(checkValidBoundariesAndApertureForT0);
99+
100+
return UNITY_END();
101+
}

test/libraries/Test_vfsacrsnh_lib.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include "../vfsacrsnh_lib.h"
1717
#include <rsf.h>
1818
#define ITMAX 100
19+
#define hMAX 50
20+
#define mMAX 50
1921

2022
/* Seimic datacube parameters to be used in tests */
2123
float*** t; // it stores seismic datacube
22-
float returnedValues[2*mMAX+1][hMAX]; // nonHyperbolicCRSapp returned values
24+
float **returnedValues; // nonHyperbolicCRSapp returned values
2325
int nt=1001, nh=401, nm=161; // datacube dimensions
2426
sf_file in; // datacube RSF file
2527

@@ -124,7 +126,7 @@ void nonHyperbolicCRSapp_function_for_pre_calculated_values(){
124126
int h;
125127
int half=1;
126128

127-
nonHyperbolicCRSapp(returnedValues,m0,dm,om,dh,oh,t0,v0,RN,RNIP,BETA,half);
129+
nonHyperbolicCRSapp(returnedValues,mMAX,hMAX,m0,dm,om,dh,oh,t0,v0,RN,RNIP,BETA,half);
128130

129131
/* In the CMP m0 and h0, time is equal to t0 */
130132
/* CMP 51 is m0, that is the midle of CMP window */
@@ -148,7 +150,7 @@ void semblance_return_value_between_0_1(){
148150
int half=1;
149151

150152
for(i=0;i<100;i++){
151-
semb=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,RN,RNIP,BETA,t,half);
153+
semb=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,RN,RNIP,BETA,t,mMAX,hMAX,half);
152154
TEST_ASSERT(semb>=0.0 && semb <= 1.0);
153155
}
154156
}
@@ -340,7 +342,6 @@ void mt_convergence_graph_file_preparation(){
340342
TEST_ASSERT_EQUAL_STRING("Semblance",label);
341343
}
342344

343-
344345
int main(int argc, char* argv[]){
345346

346347
/* Redirect the stdin to datacube file */
@@ -353,6 +354,8 @@ int main(int argc, char* argv[]){
353354
t=sf_floatalloc3(nt,nh,nm);
354355
sf_floatread(t[0][0],nm*nh*nt,in);
355356

357+
returnedValues = sf_floatalloc2(hMAX,2*mMAX+1);
358+
356359
UNITY_BEGIN();
357360
RUN_TEST(signal_function_return_1_for_positive_values_and_zero);
358361
RUN_TEST(signal_function_return_minus_1_for_negative_values);

test/test_parameters/rnip_beta_plane_interface/Test_parameter_values.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ check_value(){
4545
}
4646

4747
check_value test_rnip_interface1.txt "1.0" "0.1"
48-
check_value test_rnip_interface2.txt "1.95" "0.1"
48+
check_value test_rnip_interface2.txt "1.95" "0.12"
4949
check_value test_beta_interface1.txt "0.00" "0.1"
5050
check_value test_beta_interface2.txt "0.00" "0.1"
5151

vfsacrsnh_lib.c

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
1414
*/
1515

16-
#define hMAX 50 // Max of samples to stack in half-offset
17-
#define mMAX 50 // Max of samples to stack in CMP
1816
#include <math.h>
1917
#include <stdio.h>
2018
#include <stdlib.h>
@@ -109,7 +107,9 @@ VFSA algorithm disturb parameters step.
109107

110108
}
111109

112-
void nonHyperbolicCRSapp( float t[2*mMAX+1][hMAX] /* non-hyperbolic CRS traveltime surface */,
110+
void nonHyperbolicCRSapp( float **t /* non-hyperbolic CRS traveltime surface */,
111+
int mMAX /* CMP aperture */,
112+
int hMAX /* Offset aperture */,
113113
float m0 /* Central CMP of the approximation */,
114114
float dm, /* CMP sampling */
115115
float om /* CMP axis origin */,
@@ -169,6 +169,8 @@ float semblance(float m0 /* Central CMP of the approximation */,
169169
float RNIP /* RNIP, CRS parameter */,
170170
float BETA /* BETA, CRS parameter */,
171171
float*** t /* reflection data cube A(m,h,t) */,
172+
int mMAX, /* CMP aperture */
173+
int hMAX, /* Offset aperture */
172174
bool half /* Half-offset coordinates */)
173175
/*< Calculate semblance between the Non Hyperbolic CRS approximation surface and reflection data >*/
174176
{
@@ -179,13 +181,15 @@ float semblance(float m0 /* Central CMP of the approximation */,
179181
float amplitudeSquaredSampleSum=0.;
180182
float semblance=0;
181183
int tetai;
182-
float teta[2*mMAX+1][hMAX];
184+
float **teta;
183185
int m0_index_init, m0_index_end;
184186

187+
teta = sf_floatalloc2(hMAX,2*mMAX+1);
188+
185189
m0_index_init = (int)(m0/dm)-mMAX;
186190
m0_index_end = (int)(m0/dm)+mMAX;
187191

188-
nonHyperbolicCRSapp(teta,m0,dm,om,dh,oh,t0,v0,RN,RNIP,BETA,half);
192+
nonHyperbolicCRSapp(teta,mMAX,hMAX,m0,dm,om,dh,oh,t0,v0,RN,RNIP,BETA,half);
189193

190194
for (im=m0_index_init; im < m0_index_end; im++){
191195

@@ -213,6 +217,54 @@ float semblance(float m0 /* Central CMP of the approximation */,
213217

214218
}
215219

220+
bool checkValueInsideBoundaries(float value, float min, float max)
221+
/*< check if the value is inside the boundaries min < value < max >*/
222+
{
223+
return (min < value && value < max);
224+
}
225+
226+
bool validBoundariesAndApertureForCMP(int nm0, float om0, float dm0, int mMAX, int nm, float om, float dm, char *strerr)
227+
/*< Check if CMP coordinates for m0s are inside data cube space to avoid segmentation fault errors >*/
228+
{
229+
float m0min, m0max;
230+
231+
m0min = om0-(dm*mMAX);
232+
m0max = om0+dm0*(nm0-1)+(dm*mMAX);
233+
234+
if(m0min < om || m0max > (om+dm*(nm-1))){
235+
sprintf(strerr,"Invalid boundaries for CMP m0min=%f m0max=%f. Please check aperture!",m0min,m0max);
236+
return false;
237+
}
238+
239+
return true;
240+
}
241+
242+
bool validBoundariesAndApertureForOffset(int nh, float oh, float dh, int hMAX, char *strerr)
243+
/*< Check if Offset coordinates are inside data cube space to avoid segmentation fault errors >*/
244+
{
245+
if((oh+dh*hMAX) > (oh+dh*(nh-1))){
246+
sprintf(strerr,"Invalid boundaries for Offset hmin=%f hmax=%f. Please check aperture!",oh,oh+dh*hMAX);
247+
return false;
248+
}
249+
250+
return true;
251+
}
252+
253+
bool validBoundariesAndApertureForT0(int nt0, float ot0, float dt0, int nt, float ot, float dt, char *strerr)
254+
/*< Check if t0 coordinates are inside data cube space to avoid segmentation fault errors >*/
255+
{
256+
float t0min = ot0;
257+
float t0max = ot0+dt0*(nt0-1);
258+
259+
if(t0min < ot || t0max > ot+dt*(nt-1)){
260+
sprintf(strerr,"Invalid boundaries for time t0 t0min=%f t0max=%f. Please check aperture!",t0min,t0max);
261+
return false;
262+
}
263+
264+
return true;
265+
}
266+
267+
216268
bool repeatOptionEqual1ForGetConvergenceGraphTrue(bool get_convergence_graph, int repeat)
217269
/*< Repeat option should be equal one when get_convergence_graph flag is on to avoid multiple thread >*/
218270
{

0 commit comments

Comments
 (0)