From 15d525a3a59168c1932c67e8907e28647e44b235 Mon Sep 17 00:00:00 2001 From: Dengda98 Date: Thu, 27 Mar 2025 15:46:08 +0800 Subject: [PATCH 1/2] FEAT: add simple tool `grt.b2a` to convert waveforms data in SAC file into ASCII file. --- pygrt/C_extension/src/dynamic/Makefile | 7 +- pygrt/C_extension/src/dynamic/grt_b2a.c | 89 +++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 pygrt/C_extension/src/dynamic/grt_b2a.c diff --git a/pygrt/C_extension/src/dynamic/Makefile b/pygrt/C_extension/src/dynamic/Makefile index e65790a5..81022052 100644 --- a/pygrt/C_extension/src/dynamic/Makefile +++ b/pygrt/C_extension/src/dynamic/Makefile @@ -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 @@ -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) diff --git a/pygrt/C_extension/src/dynamic/grt_b2a.c b/pygrt/C_extension/src/dynamic/grt_b2a.c new file mode 100644 index 00000000..24d5d003 --- /dev/null +++ b/pygrt/C_extension/src/dynamic/grt_b2a.c @@ -0,0 +1,89 @@ +/** + * @file grt_b2a.c + * @author Zhu Dengda (zhudengda@mail.iggcas.ac.cn) + * @date 2025-03-27 + * + * 一个简单的小程序,将二进制SAC文件中的波形文件转为方便可读的文本文件, + * 可供没有安装SAC程序和不使用Python的用户临时使用。 + * + */ + + +#include +#include +#include +#include + +#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 \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 Date: Thu, 27 Mar 2025 15:48:05 +0800 Subject: [PATCH 2/2] CI: comment some tests to save time --- .github/workflows/testbuild.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/testbuild.yml b/.github/workflows/testbuild.yml index 4e0cb743..6cfb2b8f 100644 --- a/.github/workflows/testbuild.yml +++ b/.github/workflows/testbuild.yml @@ -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 @@ -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: |