-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add working C class to load 2D BSL file
- Loading branch information
1 parent
b598e39
commit 940baf0
Showing
9 changed files
with
225 additions
and
0 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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
multi_data/* | ||
single_data/* | ||
*.pyc | ||
*.dll | ||
*.lib | ||
*.obj | ||
*.exe | ||
*.exp |
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,55 @@ | ||
#include "bsl_loader.h" | ||
#include <memory.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void loader_dealloc(Loader_params *params) { | ||
int i; | ||
|
||
for (i = 0; i < params->rasters; i++) { | ||
free(params->data[i]); | ||
} | ||
free(params->data); | ||
} | ||
|
||
void loader_init(Loader_params *params) { | ||
int i; | ||
|
||
params->data = malloc(sizeof(float *) * params->rasters); | ||
for (i = 0; i < params->rasters; i++) { | ||
params->data[i] = malloc(sizeof(float) * params->pixels); | ||
} | ||
} | ||
|
||
void load_frame(Loader_params *params) { | ||
struct record { | ||
float x; | ||
}; | ||
|
||
int frame; | ||
int raster; | ||
int pixel; | ||
int frame_pos; | ||
FILE *input_file; | ||
struct record my_record; | ||
|
||
input_file = fopen(params->filename, "rb"); | ||
|
||
if (!input_file) { | ||
printf("Unable to open file: %s\n", params->filename); | ||
return; | ||
} | ||
|
||
frame_pos = params->rasters * params->pixels * params->frame; | ||
fseek(input_file, frame_pos*sizeof(struct record), SEEK_SET); | ||
for (raster = 0; raster < params->rasters; raster++) { | ||
for (pixel = 0; pixel < params->pixels; pixel++) { | ||
fread(&my_record, sizeof(struct record), 1, input_file); | ||
params->data[raster][pixel] = my_record.x; | ||
} | ||
} | ||
|
||
fclose(input_file); | ||
|
||
return; | ||
} |
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,5 @@ | ||
LIBRARY bsl_loader | ||
EXPORTS | ||
loader_dealloc | ||
loader_init | ||
load_frame |
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,21 @@ | ||
#if !defined(bsl_loader) | ||
#define bsl_loader | ||
|
||
typedef struct Loader_params { | ||
// File to load | ||
char filename[50]; | ||
// Frame to load | ||
int frame; | ||
// Number of pixels in the file | ||
int pixels; | ||
// Number of rasters in the file | ||
int rasters; | ||
// Data to be returned; | ||
float **data; | ||
} Loader_params; | ||
|
||
void loader_dealloc(Loader_params *params); | ||
void loader_init(Loader_params *params); | ||
void load_frame(Loader_params *params); | ||
|
||
#endif |
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,2 @@ | ||
cl /LD bsl_loader.c /link /DEF:bsl_loader.def | ||
cl try_loader.c /link bsl_loader.lib |
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,20 @@ | ||
#include "bsl_loader.h" | ||
#include <string.h> | ||
|
||
int main() { | ||
Loader_params params; | ||
params.pixels = 1475; | ||
params.rasters = 1679; | ||
params.frame = 5; | ||
strcpy(params.filename, "../multi_data/B12001.629"); | ||
|
||
loader_init(¶ms); | ||
|
||
load_frame(¶ms); | ||
|
||
printf("data[766][1358] = %f\n", params.data[766][1358]); | ||
|
||
loader_dealloc(¶ms); | ||
|
||
return 1; | ||
} |
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,57 @@ | ||
#include <stdio.h> | ||
|
||
struct rec { | ||
float x; | ||
}; | ||
|
||
const int n_frames = 41; | ||
const long n_pixels = 1475; | ||
const long n_rasters = 1679; | ||
|
||
float frames[1475*1679*41]; | ||
|
||
int offset(int x, int y, int z) { | ||
return (z * n_pixels * n_rasters) + (y * n_pixels) + x; | ||
} | ||
|
||
int main() { | ||
// float frames[1679][1475][41]; | ||
|
||
int frame; | ||
int raster; | ||
int pixel; | ||
FILE *my_file; | ||
struct rec my_record; | ||
char filename[50]; | ||
FILE *save_file; | ||
|
||
my_file = fopen("multi_data/B12001.629", "rb"); | ||
|
||
if (!my_file) { | ||
printf("Unable to open input file"); | ||
return 1; | ||
} | ||
|
||
for (frame = 0; frame < n_frames; frame++) { | ||
sprintf(filename, "multi_data/export/frame%d.txt", frame); | ||
save_file = fopen(filename, "w"); | ||
if (!save_file) { | ||
printf("Unable to open save file: %s", filename); | ||
return 1; | ||
} | ||
for (raster = 0; raster < n_rasters; raster++) { | ||
for (pixel = 0; pixel < n_pixels; pixel++) { | ||
fread(&my_record, sizeof(struct rec), 1, my_file); | ||
frames[offset(raster, pixel, frame)] = my_record.x; | ||
fprintf(save_file, "%.2e ", my_record.x); | ||
} | ||
fprintf(save_file, "\n"); | ||
} | ||
printf("%s\n", filename); | ||
fclose(save_file); | ||
} | ||
|
||
fclose(my_file); | ||
|
||
return 0; | ||
} |
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,12 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import matplotlib.image as mpimg | ||
import sys | ||
|
||
frame = int(sys.argv[1]) | ||
|
||
data = np.loadtxt("multi_data/export/frame{}.txt".format(frame), dtype=np.float32) | ||
plt.imshow(data) | ||
# plt.xlim([700,850]) | ||
# plt.ylim([1275,1440]) | ||
plt.show() |
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,48 @@ | ||
#include <stdio.h> | ||
|
||
struct rec { | ||
float x; | ||
}; | ||
|
||
const long n_pixels = 1475; | ||
const long n_rasters = 1679; | ||
|
||
float data[1679][1475]; | ||
|
||
int main() { | ||
int frame = 0; | ||
int raster; | ||
int pixel; | ||
FILE *my_file; | ||
struct rec my_record; | ||
char filename[50]; | ||
FILE *save_file; | ||
|
||
my_file = fopen("multi_data/B12001.629", "rb"); | ||
|
||
if (!my_file) { | ||
printf("Unable to open input file"); | ||
return 1; | ||
} | ||
|
||
sprintf(filename, "multi_data/export/frame%d.txt", frame); | ||
save_file = fopen(filename, "w"); | ||
if (!save_file) { | ||
printf("Unable to open save file: %s", filename); | ||
return 1; | ||
} | ||
for (raster = 0; raster < n_rasters; raster++) { | ||
for (pixel = 0; pixel < n_pixels; pixel++) { | ||
fread(&my_record, sizeof(struct rec), 1, my_file); | ||
data[raster][pixel] = my_record.x; | ||
fprintf(save_file, "%.2e ", my_record.x); | ||
} | ||
fprintf(save_file, "\n"); | ||
} | ||
printf("%s\n", filename); | ||
fclose(save_file); | ||
|
||
fclose(my_file); | ||
|
||
return 0; | ||
} |