Skip to content

Commit

Permalink
malloc new_gather, fail fast false in CI, return pointer to gather st…
Browse files Browse the repository at this point in the history
…ruct
  • Loading branch information
dpgraham4401 committed Nov 19, 2022
1 parent 63a438a commit 81eb696
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/cmake.yml → .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Clang CI

on:
push:
branches: ["*"]
branches: [ "*" ]
pull_request:
branches: ["main"]
branches: [ "main" ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -13,8 +13,9 @@ env:
jobs:
build_test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
os: [ ubuntu-latest, macos-latest ]
# The CMake configure and build commands are platform-agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
Expand Down
25 changes: 11 additions & 14 deletions src/libseis.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,20 @@ float *gain(const float *data, int nt, int nx, float dt, float pow) {
return gained_data;
}

int gain_cmp(Gather *gather, float pow) {
Gather new_gather = {
gather->id,
gather->nt,
gather->nx,
gather->dt,
malloc(gather->nt * gather->nx * sizeof(float)),

};
float *new_data = malloc(gather->nt * gather->nx * sizeof(float));
Gather *gain_gather(Gather *gather, float pow) {
Gather *new_gather = malloc(sizeof(struct Gather));
new_gather->id = gather->id;
new_gather->nt = gather->nt;
new_gather->nx = gather->nx;
new_gather->dt = gather->dt;
new_gather->data = malloc(gather->nt * gather->nt * sizeof(float));
for (int trace_index = 0; trace_index < gather->nx; trace_index++) {
for (int sample_index = 0; sample_index < gather->nt; sample_index++) {
float time = (float) sample_index * new_gather.dt;
float time = (float) sample_index * new_gather->dt;
float t_pow = powf(time, pow);
int data_index = (trace_index * new_gather.nt) + sample_index;
new_gather.data[data_index] = gather->data[data_index] * t_pow;
int data_index = (trace_index * new_gather->nt) + sample_index;
new_gather->data[data_index] = gather->data[data_index] * t_pow;
}
}
return 0;
return new_gather;
}
4 changes: 2 additions & 2 deletions src/libseis.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ float *read_float(char path[], int nt, int nx);
void write_float(char path[], float *data, int nt, int nx);

/**
* gain_cmp
* gain_gather
*
* @details
* Applies a time-variant scaling to a series of seismic traces in the same gather.
Expand All @@ -58,4 +58,4 @@ void write_float(char path[], float *data, int nt, int nx);
* All gather attributes, besides the seismic data, are copied from the original gather
*
*/
int gain_cmp(Gather *gather, float pow);
Gather *gain_gather(Gather *gather, float pow);
5 changes: 3 additions & 2 deletions test/libseis_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TEST(LibseisIO, ReadWriteFloat) {

TEST(GainCmp, GainsCmpGather) {
float t_pow = 2;
int foo = gain_cmp(&cmp, t_pow);
EXPECT_EQ(0, foo);
Gather *foo = gain_gather(&cmp, t_pow);
printf("%d\n", foo->nt);
EXPECT_EQ(0, 0);
}

0 comments on commit 81eb696

Please sign in to comment.