Skip to content

Commit

Permalink
use memcpy for creating new Gather during gain
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed Mar 6, 2023
1 parent fe6dbd3 commit e25b6c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

### Seismic library for geophysical processing

This is, first and foremost, a learn-by-doing project
This is a learn-by-doing project
to reacquaint myself with the C Programming Language and my geophysical background.

## Getting Started

1. clone this repo
2. do something else
3. etc.
4. etc.
...
24 changes: 18 additions & 6 deletions src/libseis.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,25 @@ void write_double(char path[], double *data, int nt, int nx) {
fclose(fptr);
}

/**
* Creates a new gather with the same data as the input gather, but with each sample
* multiplied by a power of its corresponding time value.
*
* @param gather The input gather to be multiplied.
* @param power The power to raise the time values to.
* @return A new gather with the same dimensions as the input gather, but with modified data.
*/
Gather *gain_gather(Gather *gather, double power) {
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(double));
Gather *new_gather = malloc(sizeof(Gather));
if (new_gather == NULL) {
fprintf(stderr, "Error: input gather is NULL\n");
}
memcpy(new_gather, gather, sizeof(Gather));
new_gather->data = malloc(gather->nt * gather->nx * sizeof(double));
if (new_gather->data == NULL) {
fprintf(stderr, "Error: input gather data is NULL\n");
}
memcpy(new_gather->data, gather->data, gather->nt * gather->nx * sizeof(double));
for (int trace_index = 0; trace_index < gather->nx; trace_index++) {
for (int sample_index = 0; sample_index < gather->nt; sample_index++) {
double time = (double) sample_index * new_gather->dt;
Expand Down

0 comments on commit e25b6c9

Please sign in to comment.