Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .github/workflows/testbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ jobs:
./run1.sh
python run2.py

- name: Test 3 multi_traces
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/multi_traces
timeout-minutes: 1
run: |
chmod +x *.sh
./run1.sh
continue-on-error: true # 即使失败,仍然标记为成功
# - name: Test 3 multi_traces
# working-directory: ${{ env.EXAMPLE_COPY_PATH }}/multi_traces
# timeout-minutes: 1
# run: |
# chmod +x *.sh
# ./run1.sh
# continue-on-error: true # 即使失败,仍然标记为成功

- name: Test 4 lamb_problem
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/lamb_problem
Expand All @@ -265,14 +265,14 @@ jobs:
./run1.sh
python run2.py

- name: Test 5 far_field
working-directory: ${{ env.EXAMPLE_COPY_PATH }}/far_field
timeout-minutes: 1
run: |
chmod +x *.sh
./run_milrow_grt.sh
python plot_compare_pygrt.py
continue-on-error: true # 即使失败,仍然标记为成功
# - name: Test 5 far_field
# working-directory: ${{ env.EXAMPLE_COPY_PATH }}/far_field
# timeout-minutes: 1
# run: |
# chmod +x *.sh
# ./run_milrow_grt.sh
# python plot_compare_pygrt.py
# continue-on-error: true # 即使失败,仍然标记为成功

- name: Remove the test files
run: |
Expand Down
7 changes: 6 additions & 1 deletion pygrt/C_extension/src/dynamic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ DEPS := $(OBJS:.o=.d) # include main functions here
OBJS := $(filter-out \
$(BUILD_DIR)/grt_main.o \
$(BUILD_DIR)/grt_syn.o \
$(BUILD_DIR)/grt_b2a.o \
, $(OBJS))

PROGS := $(BIN_DIR)/grt \
$(BIN_DIR)/grt.syn
$(BIN_DIR)/grt.syn \
$(BIN_DIR)/grt.b2a

all: objs progs

Expand All @@ -44,6 +46,9 @@ $(BIN_DIR)/grt: grt_main.c $(OBJS)
$(BIN_DIR)/grt.syn: grt_syn.c $(OBJS)
$(CC) -o $@ $^ $(COMMON_OBJS) $(TRAVT_OBJS) $(CFLAGS)

$(BIN_DIR)/grt.b2a: grt_b2a.c
$(CC) -o $@ $^ $(COMMON_OBJS) $(CFLAGS)

# ----------------------- Dependency generation -----------------------
-include $(DEPS)

Expand Down
89 changes: 89 additions & 0 deletions pygrt/C_extension/src/dynamic/grt_b2a.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @file grt_b2a.c
* @author Zhu Dengda (zhudengda@mail.iggcas.ac.cn)
* @date 2025-03-27
*
* 一个简单的小程序,将二进制SAC文件中的波形文件转为方便可读的文本文件,
* 可供没有安装SAC程序和不使用Python的用户临时使用。
*
*/


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include "common/sacio.h"
#include "common/logo.h"
#include "common/colorstr.h"

extern char *optarg;
extern int optind;
extern int optopt;

/**
* 打印使用说明
*/
static void print_help(){
print_logo();
printf("\n"
"[grt.b2a]\n\n"
" Convert a binary SAC file into an ASCII file, \n"
" write to standard output (ignore header vars).\n"
"\n\n"
"Usage:\n"
"----------------------------------------------------------------\n"
" grt.b2a <sacfile>\n"
"\n\n\n"
);
}


int main(int argc, char **argv){
const char *command = argv[0];

// 输入不够
if(argc < 2){
fprintf(stderr, "[%s] " BOLD_RED "Error! Need set a SAC file. Use '-h' for help.\n" DEFAULT_RESTORE, command);
exit(EXIT_FAILURE);
}

// 输入过多
if(argc > 2){
fprintf(stderr, "[%s] " BOLD_RED "Error! You should set only one SAC file. Use '-h' for help.\n" DEFAULT_RESTORE, command);
exit(EXIT_FAILURE);
}

// 使用-h查看帮助
if(strcmp(argv[1], "-h") == 0){
print_help();
exit(EXIT_SUCCESS);
}

const char *filepath = argv[1];
// 检查文件名是否存在
if(access(filepath, F_OK) == -1){
fprintf(stderr, "[%s] " BOLD_RED "Error! %s not exists.\n" DEFAULT_RESTORE, command, filepath);
exit(EXIT_FAILURE);
}


// 读入SAC文件
SACHEAD hd;
float *arr=NULL;
if((arr = read_sac(filepath, &hd)) == NULL){
fprintf(stderr, "[%s] " BOLD_RED "read %s failed.\n" DEFAULT_RESTORE, command, filepath);
exit(EXIT_FAILURE);
}

// 将波形写入标准输出,第一列时间,第二列振幅
float begt = hd.b;
float dt = hd.delta;
int npts = hd.npts;
for(int i=0; i<npts; ++i){
printf("%13.7e %13.7e\n", begt+dt*i, arr[i]);
}

free(arr);
}