-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add velocity model object and allocate_velocity_model utility function * .cc file to .cpp * new velocity testing file * set up separate files for velocity and libseis * simple velocity model function for generating quick velocity model with just a starting velocity and gradient
- Loading branch information
1 parent
aff5fb5
commit c8bb196
Showing
9 changed files
with
236 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,6 @@ include/* | |
lib/* | ||
bin/* | ||
test/test_runner | ||
Testing | ||
test/Temporary | ||
*.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,77 @@ | ||
#include "libseis.h" | ||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <math.h> | ||
|
||
double *read_double(char path[], int nt, int nx) { | ||
FILE *fptr; | ||
double *data; | ||
data = (double *) malloc(nt * nx * sizeof(double)); | ||
fptr = fopen(path, "rb"); | ||
if (fptr == NULL) { | ||
printf("unable to open file at %s\n", path); | ||
exit(EXIT_FAILURE); | ||
} | ||
for (int i = 0; i < nt * nx; i++) { | ||
fread(&data[i], sizeof(double), 1, fptr); | ||
} | ||
fclose(fptr); | ||
return data; | ||
FILE *fptr; | ||
double *data; | ||
data = (double *)malloc(nt * nx * sizeof(double)); | ||
fptr = fopen(path, "rb"); | ||
if (fptr == NULL) { | ||
printf("unable to open file at %s\n", path); | ||
exit(EXIT_FAILURE); | ||
} | ||
for (int i = 0; i < nt * nx; i++) { | ||
fread(&data[i], sizeof(double), 1, fptr); | ||
} | ||
fclose(fptr); | ||
return data; | ||
} | ||
|
||
void write_double(char path[], double *data, int nt, int nx) { | ||
FILE *fptr; | ||
fptr = fopen(path, "wb"); | ||
if (fptr == NULL) { | ||
printf("unable to open file at %s\n", path); | ||
exit(EXIT_FAILURE); | ||
} | ||
for (int i = 0; i < nx * nt; i++) { | ||
fwrite(&data[i], sizeof(double), 1, fptr); | ||
} | ||
fclose(fptr); | ||
FILE *fptr; | ||
fptr = fopen(path, "wb"); | ||
if (fptr == NULL) { | ||
printf("unable to open file at %s\n", path); | ||
exit(EXIT_FAILURE); | ||
} | ||
for (int i = 0; i < nx * nt; i++) { | ||
fwrite(&data[i], sizeof(double), 1, fptr); | ||
} | ||
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. | ||
* 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. | ||
* @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(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; | ||
double t_pow = pow(time, power); | ||
int data_index = (trace_index * new_gather->nt) + sample_index; | ||
new_gather->data[data_index] = gather->data[data_index] * t_pow; | ||
} | ||
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; | ||
double t_pow = pow(time, power); | ||
int data_index = (trace_index * new_gather->nt) + sample_index; | ||
new_gather->data[data_index] = gather->data[data_index] * t_pow; | ||
} | ||
return new_gather; | ||
} | ||
return new_gather; | ||
} | ||
|
||
void display_gather(Gather *gather) { | ||
printf("--------------------\n"); | ||
printf("Gather: id %d\n", gather->id); | ||
printf("Sample Rate: %f seconds\n", gather->dt); | ||
printf("Sampling Frequency: %f Hz\n", 1 / gather->dt); | ||
printf("Nyquist Frequency: %f Hz\n", 1 / (gather->dt * 2)); | ||
printf("Samples per trace: %d\n", gather->nt); | ||
printf("Number of traces: %d\n", gather->nx); | ||
printf("--------------------\n"); | ||
printf("--------------------\n"); | ||
printf("Gather: id %d\n", gather->id); | ||
printf("Sample Rate: %f seconds\n", gather->dt); | ||
printf("Sampling Frequency: %f Hz\n", 1 / gather->dt); | ||
printf("Nyquist Frequency: %f Hz\n", 1 / (gather->dt * 2)); | ||
printf("Samples per trace: %d\n", gather->nt); | ||
printf("Number of traces: %d\n", gather->nx); | ||
printf("--------------------\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "velocity.h" | ||
|
||
#include <stdlib.h> | ||
|
||
VelocityModel *allocate_velocity_model(const int rows, const int cols) { | ||
VelocityModel *model = malloc(sizeof(VelocityModel)); | ||
model->rows = rows; | ||
model->cols = cols; | ||
|
||
model->data = (double **)malloc(rows * sizeof(double *)); | ||
for (int i = 0; i < rows; i++) { | ||
model->data[i] = (double *)malloc(cols * sizeof(double)); | ||
} | ||
|
||
return model; | ||
} | ||
|
||
VelocityModel *simple_velocity_model(VelocityModel *model, | ||
const double gradient, | ||
const double startingVelocity) { | ||
|
||
for (int i = 0; i < model->rows; i++) { | ||
for (int j = 0; j < model->cols; j++) { | ||
model->data[i][j] = startingVelocity + gradient * i; | ||
} | ||
}; | ||
return model; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// Created by dg on 5/4/24. | ||
// | ||
|
||
#ifndef VELOCITY_H | ||
#define VELOCITY_H | ||
|
||
typedef struct { | ||
int rows; | ||
int cols; | ||
double **data; | ||
} VelocityModel; | ||
|
||
VelocityModel *allocate_velocity_model(int rows, int cols); | ||
|
||
VelocityModel *simple_velocity_model(VelocityModel *model, double gradient, | ||
double startingVelocity); | ||
|
||
#endif // VELOCITY_H |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.