diff --git a/.github/workflows/testbuild.yml b/.github/workflows/testbuild.yml new file mode 100644 index 00000000..4e0cb743 --- /dev/null +++ b/.github/workflows/testbuild.yml @@ -0,0 +1,292 @@ +name: Just test + +# 触发机制为“非主分支的提交” +on: + push: + branches-ignore: + - main # 排除主分支 + - master # 如果有 master 分支,也可以排除 + +jobs: + build: # 编译C程序和C库 + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: windows-2022 + arch: x86_64 # windows x86_6 + - os: ubuntu-22.04 + arch: x86_64 # Ubuntu x86_64 + - os: macos-13 + arch: x86_64 # macOS Intel + - os: macos-14 + arch: arm64 # macOS Apple Silicon + + fail-fast: true + + defaults: + run: + shell: bash + + steps: + - name: Set MSYS2 (Windows) # windows平台使用MSYS2工具编译程序 + if: contains(matrix.os, 'windows') + uses: msys2/setup-msys2@v2 + with: + msystem: UCRT64 + install: >- + git + mingw-w64-ucrt-x86_64-gcc + make + mingw-w64-ucrt-x86_64-fftw + + - name: Configured git attributes for line endings (Windows) # 防止接下来在windows平台checkout代码时,文本文件的换行符发生变化,导致MSYS2工作出错 + if: contains(matrix.os, 'windows') + run: git config --global core.autocrlf input + + - name: Checkout code # 下载库代码 + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + # --------------------------- 安装依赖 ------------------------------------------ + - name: Install dependencies (Ubuntu) + if: contains(matrix.os, 'ubuntu') + run: | + sudo apt update + sudo apt install -y libfftw3-dev + + - name: Install dependencies (macOS) + # 匹配包含 "macos" 的操作系统 + if: contains(matrix.os, 'macos') + run: | + brew install libomp + brew install fftw + + FFTW_PREFIX=$(brew --prefix fftw) + echo "FFT_INC_PATH=$FFTW_PREFIX/include" >> $GITHUB_ENV + echo "FFT_LIB_PATH=$FFTW_PREFIX/lib" >> $GITHUB_ENV + + # ----------------- 编译C库和C程序 ---------------------------------- + - name: Build the project (macOS) + if: contains(matrix.os, 'macos') + working-directory: ./pygrt/C_extension + run: | + + # Mac系统需要显式设置头文件路径和库路径 + export C_INCLUDE_PATH=$FFT_INC_PATH:$C_INCLUDE_PATH + export LIBRARY_PATH=$FFT_LIB_PATH:${LIBRARY_PATH} + export LD_LIBRARY_PATH=$FFT_LIB_PATH:${LD_LIBRARY_PATH} + export DYLD_LIBRARY_PATH=$FFT_LIB_PATH:${DYLD_LIBRARY_PATH} + + make ARCH="-arch ${{ matrix.arch }}" \ + CC=gcc-14 \ + LFFT_FLAGS="$FFT_LIB_PATH/libfftw3.a $FFT_LIB_PATH/libfftw3f.a" + make cleanbuild + otool -L lib/libgrt.so + otool -L bin/* + + - name: Build the project (Ubuntu) + if: contains(matrix.os, 'ubuntu') + working-directory: ./pygrt/C_extension + run: | + make + make cleanbuild + ldd lib/libgrt.so + ldd bin/* + + - name: Build the project (Windows) + if: contains(matrix.os, 'windows') + shell: msys2 {0} + working-directory: ./pygrt/C_extension + run: | + make + make cleanbuild + ldd lib/libgrt.so + ldd bin/* + + + # ------------------------ 定义接下来打包程序命名时的系统名后缀 --------------- + - name: Define the package OS suffix + run: | + # 符合pypi命名规范,否则上传失败 + if [[ "${{ matrix.os }}" == *"ubuntu"* ]]; then + SUFFIX_PLAT_NAME="manylinux2014_x86_64" + elif [[ "${{ matrix.os }}" == *"macos"* && "${{ matrix.arch }}" == *"x86_64"* ]]; then + SUFFIX_PLAT_NAME="macosx_10_9_x86_64" + elif [[ "${{ matrix.os }}" == *"macos"* && "${{ matrix.arch }}" == *"arm64"* ]]; then + SUFFIX_PLAT_NAME="macosx_11_0_arm64" + elif [[ "${{ matrix.os }}" == *"windows"* ]]; then + SUFFIX_PLAT_NAME="win_amd64" + else + echo " Unsupported OS: ${{ matrix.os }} (${{ matrix.arch }})" + exit 1 + fi + + echo "SUFFIX_PLAT_NAME=$SUFFIX_PLAT_NAME" >> $GITHUB_ENV + + # --------------------------- 打包整个程序 --------------------- + - name: Package the binary + run: | + PACK_NAME=pygrt_kit-${{ github.ref_name }}-${{ env.SUFFIX_PLAT_NAME }} + echo "PACK_NAME=$PACK_NAME" >> $GITHUB_ENV + FILE_CONTENT=$(ls) + mkdir -p $PACK_NAME + cp -r ${FILE_CONTENT} $PACK_NAME/ + tar -czvf $PACK_NAME.tar.gz $PACK_NAME + rm -rf $PACK_NAME + + # -------------------- upload artifacts ----------------------- + - name: Upload artifact (*.tar.gz) + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}-${{ matrix.arch }}_tar + path: ${{ env.PACK_NAME }}.tar.gz + + + # ======================================================================================= + test_project: # 在全新系统上测试程序,不安装其它依赖,看能否运行 + runs-on: ${{ matrix.os }} + needs: build + strategy: + matrix: + include: + - os: windows-2022 + arch: x86_64 # windows x86_6 + - os: ubuntu-22.04 + arch: x86_64 # Ubuntu x86_64 + - os: macos-13 + arch: x86_64 # macOS Intel + - os: macos-14 + arch: arm64 # macOS Apple Silicon + + fail-fast: true + + defaults: + run: + shell: bash + + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: ${{ matrix.os }}-${{ matrix.arch }}_tar + path: artifacts + + - name: Display structure of downloaded files, and Uncompress + run: | + ls -R artifacts + echo "------------------- tar output -----------------------------" + tar -xzvf artifacts/*.tar.gz + echo "------------------------------------------------------------" + + # 获得压缩包解压出来的文件夹名 + PACK_NAME=$(ls | grep pygrt_kit) + echo "PACK_NAME=$PACK_NAME" >> $GITHUB_ENV + + # 从解压出的文件夹命名来推断${{ env.SUFFIX_PLAT_NAME }} + SUFFIX_PLAT_NAME=$(echo $PACK_NAME | sed 's/.*-\(.*\)/\1/') + echo "SUFFIX_PLAT_NAME=$SUFFIX_PLAT_NAME" >> $GITHUB_ENV + + echo $PACK_NAME + echo $SUFFIX_PLAT_NAME + + # --------------------------- 安装依赖 ------------------------------------------ + # 实际使用时可能需要安装libomp + # - name: Install libomp (Ubuntu) + # if: contains(matrix.os, 'ubuntu') + # run: | + # sudo apt install -y libomp-dev + + - name: Set alias (MacOS) + if: contains(matrix.os, 'macos') + run: | + brew install coreutils + echo "alias timeout=gtimeout" >> ~/.bashrc + + # --------------------搭建python环境,开始测试,并制作wheel文件 ------------------------------ + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install dependencies + working-directory: ${{ env.PACK_NAME }} + run: | + python -m pip install --upgrade pip + pip install --upgrade setuptools wheel build + pip install -v . + + - name: Clean up build and egg-info directories + working-directory: ${{ env.PACK_NAME }} + run: | + # 清理临时文件 + rm -rf build/ + rm -rf pygrt_kit.egg-info/ + + - name: Add the C library path to the environment + working-directory: ${{ env.PACK_NAME }} + run: | + echo "$(pwd)/pygrt/C_extension/bin" >> "$GITHUB_PATH" + + - name: Copy the test files + working-directory: ${{ env.PACK_NAME }} + run: | + cp -r example test_tmp + # don't use $(pwd) to get abspath, not valid on Windows + echo "EXAMPLE_COPY_PATH=${{ env.PACK_NAME }}/test_tmp" >> $GITHUB_ENV + + - name: Test 1 compare_results + working-directory: ${{ env.EXAMPLE_COPY_PATH }}/compare_results + run: | + chmod +x *.sh + ./run_milrow_grt.sh + python plot_cps_pygrt.py + + - name: Test 2 site_effect + working-directory: ${{ env.EXAMPLE_COPY_PATH }}/site_effect + run: | + chmod +x *.sh + ./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 4 lamb_problem + working-directory: ${{ env.EXAMPLE_COPY_PATH }}/lamb_problem + run: | + chmod +x *.sh + ./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: Remove the test files + run: | + rm -rf ${{ env.EXAMPLE_COPY_PATH }} + + # --------------------------- 制作wheels --------------------- + # - name: Build the Python Wheel + # working-directory: ${{ env.PACK_NAME }} + # run: | + # python setup.py bdist_wheel --plat-name=${{ env.SUFFIX_PLAT_NAME }} # 只制作wheel,这里不打包源码 + + # - name: Upload artifact (*.whl) + # uses: actions/upload-artifact@v4 + # with: + # name: ${{ env.PACK_NAME }}_whl + # path: ${{ env.PACK_NAME }}/dist/*.whl + \ No newline at end of file diff --git a/pygrt/C_extension/Makefile b/pygrt/C_extension/Makefile old mode 100755 new mode 100644 index 99c6b35e..b5fc9f13 --- a/pygrt/C_extension/Makefile +++ b/pygrt/C_extension/Makefile @@ -1,7 +1,5 @@ - -SRC_DIR := src -INC_DIR := include BUILD_DIR := build +INC_DIR := include BIN_DIR := bin LIB_DIR := lib LNAME := grt @@ -9,11 +7,7 @@ LIBS_NAME := lib$(LNAME).a LIBD_NAME := lib$(LNAME).so VERSION := v$(shell cat version ) -CURRENT_DIR := $(shell pwd) -# use static library, make life easier... -# RPATH_FLAGS := -L$(LIB_DIR) -l:$(LIBS_NAME) # ':libXYZ.a' not worked on MacOS -RPATH_FLAGS := $(LIB_DIR)/$(LIBS_NAME) # link options for FFTW # NEED EXPLICITY SET LIBRARY PATH on MacOS @@ -44,94 +38,52 @@ ARCH = # However, Maybe -static is not working for standard-lib on MacOS, # at least for now, it's not a big problem. -CFLAGS := $(LINK_STATIC) $(LFFT_FLAGS) -lm -O3 -g \ - -fPIC -Wall -Wextra $(STACK_MEM) -I$(INC_DIR) \ - -DGRT_VERSION="\"$(VERSION)\"" $(ARCH) $(FOMPFLAGS) +CFLAGS := $(LINK_STATIC) $(LFFT_FLAGS) -lm -O3 \ + -fPIC -Wall -Wextra $(STACK_MEM) -I$(shell realpath $(INC_DIR)) \ + -D'GRT_VERSION=\"$(VERSION)\"' $(ARCH) $(FOMPFLAGS) # -fdump-tree-all -g -ffast-math -O3 -fno-associative-math -march=native -mtune=native -INCS := $(wildcard $(INC_DIR)/*.h) -SRCS := $(wildcard $(SRC_DIR)/*.c) -SRCS_NOMAIN := $(SRCS) - -# remove main functions -SRCS_NOMAIN := $(filter-out $(SRC_DIR)/grt_main.c, $(SRCS_NOMAIN)) -SRCS_NOMAIN := $(filter-out $(SRC_DIR)/grt_syn.c, $(SRCS_NOMAIN)) -SRCS_NOMAIN := $(filter-out $(SRC_DIR)/grt_travt.c, $(SRCS_NOMAIN)) -OBJS_NOMAIN := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS_NOMAIN)) -OBJS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS)) - - -.PHONY: all clean cleanbuild - -# library and several programs -TARGET = libgrt \ - grt \ - grt.syn \ - grt.travt +# 定义子目录 +SUBDIRS = \ + src/common \ + src/dynamic \ + src/travt -all: $(TARGET) +all: objs progs libs -libgrt: $(LIB_DIR)/$(LIBS_NAME) $(LIB_DIR)/$(LIBD_NAME) -grt: $(BIN_DIR)/grt -grt.syn: $(BIN_DIR)/grt.syn -grt.travt: $(BIN_DIR)/grt.travt +objs: + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir CC="$(CC)" CFLAGS="$(CFLAGS)" objs; \ + done -# generate executable files -$(BIN_DIR)/grt: $(BUILD_DIR)/grt_main.o libgrt - @echo $(shell ls $(LIB_DIR)/*) - @mkdir -p $(BIN_DIR) - $(CC) -o $@ $< $(RPATH_FLAGS) $(CFLAGS) +progs: objs + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir CC="$(CC)" CFLAGS="$(CFLAGS)" progs; \ + done -$(BIN_DIR)/grt.syn: $(BUILD_DIR)/grt_syn.o libgrt - @echo $(shell ls $(LIB_DIR)/*) - @mkdir -p $(BIN_DIR) - $(CC) -o $@ $< $(RPATH_FLAGS) $(CFLAGS) -$(BIN_DIR)/grt.travt: $(BUILD_DIR)/grt_travt.o libgrt - @echo $(shell ls $(LIB_DIR)/*) - @mkdir -p $(BIN_DIR) - $(CC) -o $@ $< $(RPATH_FLAGS) $(CFLAGS) +libs: objs $(LIB_DIR) $(LIB_DIR)/$(LIBS_NAME) $(LIB_DIR)/$(LIBD_NAME) +$(LIB_DIR): + @mkdir -p $@ # build dynamic library # The order in the compiled statement is critical, otherwise the library will not be linked -$(LIB_DIR)/$(LIBD_NAME): $(OBJS_NOMAIN) - @mkdir -p $(BUILD_DIR) - @mkdir -p $(LIB_DIR) - $(CC) -shared -o $@ $^ $(LDFLAGS) +OBJS = $(wildcard $(BUILD_DIR)/**/*.o) +$(LIB_DIR)/$(LIBD_NAME): + $(CC) -shared -o $@ $(OBJS) $(LDFLAGS) # build static library -$(LIB_DIR)/$(LIBS_NAME): $(OBJS_NOMAIN) - @mkdir -p $(BUILD_DIR) - @mkdir -p $(LIB_DIR) - ar rcs $@ $^ +$(LIB_DIR)/$(LIBS_NAME): + ar rcs $@ $(OBJS) -# Compile object file -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c - @mkdir -p $(BUILD_DIR) - $(CC) -o $@ -c $< $(CFLAGS) - - -# Automatically generate dependencies -DEPENDS := $(OBJS:.o=.d) --include $(DEPENDS) - -$(BUILD_DIR)/%.d: $(SRC_DIR)/%.c - @mkdir -p $(BUILD_DIR) - @$(CC) $(CFLAGS) -MM $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,$(BUILD_DIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ - -# remove all generated files -clean: - rm -rf $(BIN_DIR) +cleanbuild: rm -rf $(BUILD_DIR) - rm -rf $(LIB_DIR) -# remove object files -cleanbuild: - rm -rf $(BUILD_DIR) \ No newline at end of file +clean: cleanbuild + rm -rf $(LIB_DIR) + rm -rf $(BIN_DIR) \ No newline at end of file diff --git a/pygrt/C_extension/include/attenuation.h b/pygrt/C_extension/include/common/attenuation.h similarity index 95% rename from pygrt/C_extension/include/attenuation.h rename to pygrt/C_extension/include/common/attenuation.h index cb6e4b8f..9a066947 100755 --- a/pygrt/C_extension/include/attenuation.h +++ b/pygrt/C_extension/include/common/attenuation.h @@ -9,7 +9,7 @@ #pragma once -#include "const.h" +#include "common/const.h" /** * 品质因子Q 对 波速的影响, Futterman causal Q, 参考Aki&Richards, 2009, Chapter 5.5.1 diff --git a/pygrt/C_extension/include/bessel.h b/pygrt/C_extension/include/common/bessel.h similarity index 94% rename from pygrt/C_extension/include/bessel.h rename to pygrt/C_extension/include/common/bessel.h index ca08a96c..aca4e03c 100755 --- a/pygrt/C_extension/include/bessel.h +++ b/pygrt/C_extension/include/common/bessel.h @@ -8,7 +8,7 @@ #pragma once -#include "const.h" +#include "common/const.h" /** * 计算Bessel函数 \f$ J_m(x), m=0,1,2 \f$ diff --git a/pygrt/C_extension/include/colorstr.h b/pygrt/C_extension/include/common/colorstr.h similarity index 100% rename from pygrt/C_extension/include/colorstr.h rename to pygrt/C_extension/include/common/colorstr.h diff --git a/pygrt/C_extension/include/const.h b/pygrt/C_extension/include/common/const.h similarity index 100% rename from pygrt/C_extension/include/const.h rename to pygrt/C_extension/include/common/const.h diff --git a/pygrt/C_extension/include/logo.h b/pygrt/C_extension/include/common/logo.h similarity index 96% rename from pygrt/C_extension/include/logo.h rename to pygrt/C_extension/include/common/logo.h index e5ab423a..ba223fdd 100644 --- a/pygrt/C_extension/include/logo.h +++ b/pygrt/C_extension/include/common/logo.h @@ -12,9 +12,9 @@ #include -#include "const.h" -#include "version.h" -#include "colorstr.h" +#include "common/const.h" +#include "common/version.h" +#include "common/colorstr.h" #if _TEST_WHETHER_WIN32_ #include diff --git a/pygrt/C_extension/include/matrix.h b/pygrt/C_extension/include/common/matrix.h similarity index 99% rename from pygrt/C_extension/include/matrix.h rename to pygrt/C_extension/include/common/matrix.h index bec0ef67..b2d7776e 100755 --- a/pygrt/C_extension/include/matrix.h +++ b/pygrt/C_extension/include/common/matrix.h @@ -8,7 +8,7 @@ #pragma once -#include "const.h" +#include "common/const.h" /** * 计算2x2复矩阵的逆 diff --git a/pygrt/C_extension/include/model.h b/pygrt/C_extension/include/common/model.h similarity index 99% rename from pygrt/C_extension/include/model.h rename to pygrt/C_extension/include/common/model.h index 716308a7..c8da5f1f 100755 --- a/pygrt/C_extension/include/model.h +++ b/pygrt/C_extension/include/common/model.h @@ -10,7 +10,7 @@ #include #include -#include "const.h" +#include "common/const.h" /** * 单个水平层的结构体 diff --git a/pygrt/C_extension/include/progressbar.h b/pygrt/C_extension/include/common/progressbar.h similarity index 94% rename from pygrt/C_extension/include/progressbar.h rename to pygrt/C_extension/include/common/progressbar.h index d2b4d97e..6bf6174e 100755 --- a/pygrt/C_extension/include/progressbar.h +++ b/pygrt/C_extension/include/common/progressbar.h @@ -7,7 +7,7 @@ * */ -#include "const.h" +#include "common/const.h" #define _PROGRESSBAR_WIDTH_ 45 ///< 定义进度条的长度 diff --git a/pygrt/C_extension/include/prtdbg.h b/pygrt/C_extension/include/common/prtdbg.h similarity index 100% rename from pygrt/C_extension/include/prtdbg.h rename to pygrt/C_extension/include/common/prtdbg.h diff --git a/pygrt/C_extension/include/sacio.h b/pygrt/C_extension/include/common/sacio.h similarity index 100% rename from pygrt/C_extension/include/sacio.h rename to pygrt/C_extension/include/common/sacio.h diff --git a/pygrt/C_extension/include/search.h b/pygrt/C_extension/include/common/search.h similarity index 97% rename from pygrt/C_extension/include/search.h rename to pygrt/C_extension/include/common/search.h index 40d4207b..7ef63a4a 100644 --- a/pygrt/C_extension/include/search.h +++ b/pygrt/C_extension/include/common/search.h @@ -8,7 +8,8 @@ #pragma once -#include "const.h" +#include +#include "common/const.h" /** * 该函数对输入的整数数组进行线性搜索,找到目标值时返回其索引。 diff --git a/pygrt/C_extension/include/version.h b/pygrt/C_extension/include/common/version.h similarity index 100% rename from pygrt/C_extension/include/version.h rename to pygrt/C_extension/include/common/version.h diff --git a/pygrt/C_extension/include/dwm.h b/pygrt/C_extension/include/dynamic/dwm.h similarity index 98% rename from pygrt/C_extension/include/dwm.h rename to pygrt/C_extension/include/dynamic/dwm.h index 01921cc4..33701c90 100644 --- a/pygrt/C_extension/include/dwm.h +++ b/pygrt/C_extension/include/dynamic/dwm.h @@ -13,7 +13,7 @@ #pragma once -#include "model.h" +#include "common/model.h" /** diff --git a/pygrt/C_extension/include/fim.h b/pygrt/C_extension/include/dynamic/fim.h similarity index 98% rename from pygrt/C_extension/include/fim.h rename to pygrt/C_extension/include/dynamic/fim.h index b99b2f72..d2a2f92d 100755 --- a/pygrt/C_extension/include/fim.h +++ b/pygrt/C_extension/include/dynamic/fim.h @@ -12,8 +12,8 @@ #pragma once -#include "const.h" -#include "model.h" +#include "common/const.h" +#include "common/model.h" diff --git a/pygrt/C_extension/include/grt.h b/pygrt/C_extension/include/dynamic/grt.h similarity index 99% rename from pygrt/C_extension/include/grt.h rename to pygrt/C_extension/include/dynamic/grt.h index aa868cc5..2ed060cc 100755 --- a/pygrt/C_extension/include/grt.h +++ b/pygrt/C_extension/include/dynamic/grt.h @@ -14,7 +14,7 @@ #pragma once -#include "model.h" +#include "common/model.h" /** * 设置OpenMP多线程数 diff --git a/pygrt/C_extension/include/iostats.h b/pygrt/C_extension/include/dynamic/iostats.h similarity index 99% rename from pygrt/C_extension/include/iostats.h rename to pygrt/C_extension/include/dynamic/iostats.h index 2aa32f3e..0550ff57 100755 --- a/pygrt/C_extension/include/iostats.h +++ b/pygrt/C_extension/include/dynamic/iostats.h @@ -11,7 +11,7 @@ #include #include -#include "const.h" +#include "common/const.h" diff --git a/pygrt/C_extension/include/layer.h b/pygrt/C_extension/include/dynamic/layer.h similarity index 99% rename from pygrt/C_extension/include/layer.h rename to pygrt/C_extension/include/dynamic/layer.h index e062af80..0b1a0482 100755 --- a/pygrt/C_extension/include/layer.h +++ b/pygrt/C_extension/include/dynamic/layer.h @@ -13,8 +13,8 @@ #pragma once -#include "model.h" -#include "const.h" +#include "common/model.h" +#include "common/const.h" /** * 计算自由表面的反射系数,公式(5.3.10-14) diff --git a/pygrt/C_extension/include/propagate.h b/pygrt/C_extension/include/dynamic/propagate.h similarity index 99% rename from pygrt/C_extension/include/propagate.h rename to pygrt/C_extension/include/dynamic/propagate.h index b1a868b8..6d9ec9e1 100755 --- a/pygrt/C_extension/include/propagate.h +++ b/pygrt/C_extension/include/dynamic/propagate.h @@ -14,8 +14,8 @@ #pragma once -#include "const.h" -#include "model.h" +#include "common/const.h" +#include "common/model.h" diff --git a/pygrt/C_extension/include/ptam.h b/pygrt/C_extension/include/dynamic/ptam.h similarity index 99% rename from pygrt/C_extension/include/ptam.h rename to pygrt/C_extension/include/dynamic/ptam.h index 00fd81b4..44ba22c6 100755 --- a/pygrt/C_extension/include/ptam.h +++ b/pygrt/C_extension/include/dynamic/ptam.h @@ -16,7 +16,7 @@ #pragma once -#include "model.h" +#include "common/model.h" #define PTAM_MAX_PEAK_TROUGH 36 ///< 最后统计波峰波谷的目标数量 diff --git a/pygrt/C_extension/include/quadratic.h b/pygrt/C_extension/include/dynamic/quadratic.h similarity index 98% rename from pygrt/C_extension/include/quadratic.h rename to pygrt/C_extension/include/dynamic/quadratic.h index d9fbdc92..77d106d7 100755 --- a/pygrt/C_extension/include/quadratic.h +++ b/pygrt/C_extension/include/dynamic/quadratic.h @@ -12,7 +12,7 @@ #pragma once -#include "const.h" +#include "common/const.h" /** diff --git a/pygrt/C_extension/include/signals.h b/pygrt/C_extension/include/dynamic/signals.h similarity index 100% rename from pygrt/C_extension/include/signals.h rename to pygrt/C_extension/include/dynamic/signals.h diff --git a/pygrt/C_extension/include/source.h b/pygrt/C_extension/include/dynamic/source.h similarity index 96% rename from pygrt/C_extension/include/source.h rename to pygrt/C_extension/include/dynamic/source.h index dcaf34fc..cb495b08 100755 --- a/pygrt/C_extension/include/source.h +++ b/pygrt/C_extension/include/dynamic/source.h @@ -11,8 +11,8 @@ #pragma once -#include "const.h" -#include "model.h" +#include "common/const.h" +#include "common/model.h" /** diff --git a/pygrt/C_extension/include/travt.h b/pygrt/C_extension/include/travt/travt.h similarity index 96% rename from pygrt/C_extension/include/travt.h rename to pygrt/C_extension/include/travt/travt.h index fc829e31..0c854720 100644 --- a/pygrt/C_extension/include/travt.h +++ b/pygrt/C_extension/include/travt/travt.h @@ -9,7 +9,7 @@ #pragma once -#include "const.h" +#include "common/const.h" /** * 已知每层的厚度和速度,且震源和场点位于(虚拟)界面上, diff --git a/pygrt/C_extension/src/common/Makefile b/pygrt/C_extension/src/common/Makefile new file mode 100644 index 00000000..76c3ec9e --- /dev/null +++ b/pygrt/C_extension/src/common/Makefile @@ -0,0 +1,36 @@ + +CC := gcc +CFLAGS := -Wall -g -fPIC -I../../include -lm + +BUILD_DIR = ../../build/common +SRCS := $(wildcard *.c) +OBJS := $(patsubst %.c, $(BUILD_DIR)/%.o, $(SRCS)) +DEPS := $(OBJS:.o=.d) + +all: objs + +objs: $(BUILD_DIR) $(OBJS) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + + +$(BUILD_DIR)/%.o: %.c + $(CC) -o $@ -c $< $(CFLAGS) + + +# ----------------------- Dependency generation ----------------------- +-include $(DEPS) + +$(BUILD_DIR)/%.d: %.c + @mkdir -p $(shell dirname $@) + @$(CC) $(CFLAGS) -MM $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,$(BUILD_DIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +# --------------------------------------------------------------------- + +cleanbuild: clean + +clean: + rm -rf $(BUILD_DIR) \ No newline at end of file diff --git a/pygrt/C_extension/src/attenuation.c b/pygrt/C_extension/src/common/attenuation.c similarity index 81% rename from pygrt/C_extension/src/attenuation.c rename to pygrt/C_extension/src/common/attenuation.c index dc7cd5df..2b8ad23d 100755 --- a/pygrt/C_extension/src/attenuation.c +++ b/pygrt/C_extension/src/common/attenuation.c @@ -7,8 +7,8 @@ */ -#include "attenuation.h" -#include "const.h" +#include "common/attenuation.h" +#include "common/const.h" diff --git a/pygrt/C_extension/src/bessel.c b/pygrt/C_extension/src/common/bessel.c similarity index 81% rename from pygrt/C_extension/src/bessel.c rename to pygrt/C_extension/src/common/bessel.c index a5ead0fa..125e82d2 100755 --- a/pygrt/C_extension/src/bessel.c +++ b/pygrt/C_extension/src/common/bessel.c @@ -7,8 +7,8 @@ */ -#include "bessel.h" -#include "const.h" +#include "common/bessel.h" +#include "common/const.h" void bessel012(MYREAL x, MYREAL *bj0, MYREAL *bj1, MYREAL *bj2){ *bj0 = J0(x); diff --git a/pygrt/C_extension/src/model.c b/pygrt/C_extension/src/common/model.c similarity index 98% rename from pygrt/C_extension/src/model.c rename to pygrt/C_extension/src/common/model.c index 015fa2d3..3836d2b7 100755 --- a/pygrt/C_extension/src/model.c +++ b/pygrt/C_extension/src/common/model.c @@ -11,10 +11,10 @@ #include #include -#include "model.h" -#include "prtdbg.h" -#include "attenuation.h" -#include "colorstr.h" +#include "common/model.h" +#include "common/prtdbg.h" +#include "common/attenuation.h" +#include "common/colorstr.h" void print_mod1d(const MODEL1D *mod1d){ diff --git a/pygrt/C_extension/src/progressbar.c b/pygrt/C_extension/src/common/progressbar.c similarity index 95% rename from pygrt/C_extension/src/progressbar.c rename to pygrt/C_extension/src/common/progressbar.c index a9d82c7c..2614f92d 100755 --- a/pygrt/C_extension/src/progressbar.c +++ b/pygrt/C_extension/src/common/progressbar.c @@ -9,7 +9,7 @@ #include -#include "progressbar.h" +#include "common/progressbar.h" void printprogressBar(const char *prefix, MYINT percentage) { diff --git a/pygrt/C_extension/src/sacio.c b/pygrt/C_extension/src/common/sacio.c similarity index 99% rename from pygrt/C_extension/src/sacio.c rename to pygrt/C_extension/src/common/sacio.c index 99cccd78..1210c5ee 100644 --- a/pygrt/C_extension/src/sacio.c +++ b/pygrt/C_extension/src/common/sacio.c @@ -29,7 +29,7 @@ #include #include #include -#include "sacio.h" +#include "common/sacio.h" /* function prototype for local use */ static void byte_swap (char *pt, size_t n); diff --git a/pygrt/C_extension/src/search.c b/pygrt/C_extension/src/common/search.c similarity index 96% rename from pygrt/C_extension/src/search.c rename to pygrt/C_extension/src/common/search.c index 3a2ca67d..eda3b11e 100644 --- a/pygrt/C_extension/src/search.c +++ b/pygrt/C_extension/src/common/search.c @@ -9,8 +9,8 @@ #include #include -#include "search.h" -#include "const.h" +#include "common/search.h" +#include "common/const.h" static bool _gt_(MYREAL a1, MYREAL a2) { return a1 > a2; } static bool _lt_(MYREAL a1, MYREAL a2) { return a1 < a2; } diff --git a/pygrt/C_extension/src/dynamic/Makefile b/pygrt/C_extension/src/dynamic/Makefile new file mode 100644 index 00000000..e65790a5 --- /dev/null +++ b/pygrt/C_extension/src/dynamic/Makefile @@ -0,0 +1,62 @@ + +CC := gcc +CFLAGS := -Wall -g -fPIC -I../../include -lm + +COMMON_OBJS := $(wildcard ../../build/common/*.o) +TRAVT_OBJS := $(wildcard ../../build/travt/*.o) + +BUILD_DIR = ../../build/dynamic +BIN_DIR = ../../bin +SRCS := $(wildcard *.c) +OBJS := $(patsubst %.c, $(BUILD_DIR)/%.o, $(SRCS)) + +DEPS := $(OBJS:.o=.d) # include main functions here + +OBJS := $(filter-out \ + $(BUILD_DIR)/grt_main.o \ + $(BUILD_DIR)/grt_syn.o \ + , $(OBJS)) + +PROGS := $(BIN_DIR)/grt \ + $(BIN_DIR)/grt.syn + +all: objs progs + +objs: $(BUILD_DIR) $(OBJS) + +progs: $(OBJS) $(BIN_DIR) $(PROGS) + + +$(BUILD_DIR): + @mkdir -p $(BUILD_DIR) + +$(BUILD_DIR)/%.o: %.c + $(CC) -o $@ -c $< $(CFLAGS) + + +# ------------------------Executable files------------------------ +$(BIN_DIR): + @mkdir -p $(BIN_DIR) + +$(BIN_DIR)/grt: grt_main.c $(OBJS) + $(CC) -o $@ $^ $(COMMON_OBJS) $(TRAVT_OBJS) $(CFLAGS) + +$(BIN_DIR)/grt.syn: grt_syn.c $(OBJS) + $(CC) -o $@ $^ $(COMMON_OBJS) $(TRAVT_OBJS) $(CFLAGS) + +# ----------------------- Dependency generation ----------------------- +-include $(DEPS) + +$(BUILD_DIR)/%.d: %.c + @mkdir -p $(shell dirname $@) + @$(CC) $(CFLAGS) -MM $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,$(BUILD_DIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +# --------------------------------------------------------------------- + +cleanbuild: + rm -rf $(BUILD_DIR) + +clean: cleanbuild + rm -f $(PROGS) \ No newline at end of file diff --git a/pygrt/C_extension/src/dwm.c b/pygrt/C_extension/src/dynamic/dwm.c similarity index 97% rename from pygrt/C_extension/src/dwm.c rename to pygrt/C_extension/src/dynamic/dwm.c index b8e17380..c7a7b083 100644 --- a/pygrt/C_extension/src/dwm.c +++ b/pygrt/C_extension/src/dynamic/dwm.c @@ -15,11 +15,11 @@ #include #include -#include "dwm.h" -#include "const.h" -#include "model.h" -#include "propagate.h" -#include "iostats.h" +#include "dynamic/dwm.h" +#include "dynamic/propagate.h" +#include "dynamic/iostats.h" +#include "common/model.h" +#include "common/const.h" MYREAL discrete_integ( diff --git a/pygrt/C_extension/src/fim.c b/pygrt/C_extension/src/dynamic/fim.c similarity index 98% rename from pygrt/C_extension/src/fim.c rename to pygrt/C_extension/src/dynamic/fim.c index 6feb6aad..f591fb21 100755 --- a/pygrt/C_extension/src/fim.c +++ b/pygrt/C_extension/src/dynamic/fim.c @@ -14,11 +14,11 @@ #include #include -#include "fim.h" -#include "iostats.h" -#include "const.h" -#include "model.h" -#include "propagate.h" +#include "dynamic/fim.h" +#include "dynamic/iostats.h" +#include "dynamic/propagate.h" +#include "common/const.h" +#include "common/model.h" diff --git a/pygrt/C_extension/src/grt.c b/pygrt/C_extension/src/dynamic/grt.c similarity index 98% rename from pygrt/C_extension/src/grt.c rename to pygrt/C_extension/src/dynamic/grt.c index e79ff30c..e4013e04 100755 --- a/pygrt/C_extension/src/grt.c +++ b/pygrt/C_extension/src/dynamic/grt.c @@ -20,17 +20,17 @@ #include #include -#include "grt.h" -#include "dwm.h" -#include "const.h" -#include "model.h" -#include "propagate.h" -#include "prtdbg.h" -#include "search.h" -#include "ptam.h" -#include "fim.h" -#include "iostats.h" -#include "progressbar.h" +#include "dynamic/grt.h" +#include "dynamic/dwm.h" +#include "dynamic/propagate.h" +#include "dynamic/fim.h" +#include "dynamic/ptam.h" +#include "dynamic/iostats.h" +#include "common/const.h" +#include "common/model.h" +#include "common/prtdbg.h" +#include "common/search.h" +#include "common/progressbar.h" diff --git a/pygrt/C_extension/src/grt_main.c b/pygrt/C_extension/src/dynamic/grt_main.c similarity index 99% rename from pygrt/C_extension/src/grt_main.c rename to pygrt/C_extension/src/dynamic/grt_main.c index fd9e20fb..008ee0da 100644 --- a/pygrt/C_extension/src/grt_main.c +++ b/pygrt/C_extension/src/dynamic/grt_main.c @@ -18,15 +18,16 @@ #include #include -#include "const.h" -#include "model.h" -#include "grt.h" -#include "search.h" -#include "sacio.h" -#include "travt.h" -#include "logo.h" -#include "signals.h" -#include "colorstr.h" +#include "dynamic/grt.h" +#include "dynamic/signals.h" +#include "travt/travt.h" +#include "common/const.h" +#include "common/model.h" +#include "common/search.h" +#include "common/sacio.h" +#include "common/logo.h" +#include "common/colorstr.h" + #ifdef GRT_USE_FLOAT #define _FFTW_COMPLEX fftwf_complex diff --git a/pygrt/C_extension/src/grt_syn.c b/pygrt/C_extension/src/dynamic/grt_syn.c similarity index 99% rename from pygrt/C_extension/src/grt_syn.c rename to pygrt/C_extension/src/dynamic/grt_syn.c index fcf0f7ea..38a5ec2d 100644 --- a/pygrt/C_extension/src/grt_syn.c +++ b/pygrt/C_extension/src/dynamic/grt_syn.c @@ -20,11 +20,11 @@ #include #include -#include "sacio.h" -#include "const.h" -#include "logo.h" -#include "colorstr.h" -#include "signals.h" +#include "dynamic/signals.h" +#include "common/sacio.h" +#include "common/const.h" +#include "common/logo.h" +#include "common/colorstr.h" #define DEG1 0.017453292519943295 #define COMPUTE_EXP 0 diff --git a/pygrt/C_extension/src/iostats.c b/pygrt/C_extension/src/dynamic/iostats.c similarity index 97% rename from pygrt/C_extension/src/iostats.c rename to pygrt/C_extension/src/dynamic/iostats.c index 5390f5ac..409f4544 100755 --- a/pygrt/C_extension/src/iostats.c +++ b/pygrt/C_extension/src/dynamic/iostats.c @@ -11,8 +11,8 @@ #include #include -#include "iostats.h" -#include "const.h" +#include "dynamic/iostats.h" +#include "common/const.h" diff --git a/pygrt/C_extension/src/layer.c b/pygrt/C_extension/src/dynamic/layer.c similarity index 98% rename from pygrt/C_extension/src/layer.c rename to pygrt/C_extension/src/dynamic/layer.c index 2ac0848a..8f38169e 100755 --- a/pygrt/C_extension/src/layer.c +++ b/pygrt/C_extension/src/dynamic/layer.c @@ -14,10 +14,10 @@ #include #include -#include "layer.h" -#include "model.h" -#include "prtdbg.h" -#include "matrix.h" +#include "dynamic/layer.h" +#include "common/model.h" +#include "common/prtdbg.h" +#include "common/matrix.h" diff --git a/pygrt/C_extension/src/propagate.c b/pygrt/C_extension/src/dynamic/propagate.c similarity index 99% rename from pygrt/C_extension/src/propagate.c rename to pygrt/C_extension/src/dynamic/propagate.c index 09010a65..25e86c28 100755 --- a/pygrt/C_extension/src/propagate.c +++ b/pygrt/C_extension/src/dynamic/propagate.c @@ -15,13 +15,13 @@ #include #include -#include "propagate.h" -#include "bessel.h" -#include "model.h" -#include "matrix.h" -#include "layer.h" -#include "source.h" -#include "prtdbg.h" +#include "dynamic/propagate.h" +#include "dynamic/layer.h" +#include "dynamic/source.h" +#include "common/bessel.h" +#include "common/model.h" +#include "common/matrix.h" +#include "common/prtdbg.h" #define CMAT_ASSIGN_SPLIT 0 // 2x2的小矩阵赋值合并为1个循环,程序速度提升微小 diff --git a/pygrt/C_extension/src/ptam.c b/pygrt/C_extension/src/dynamic/ptam.c similarity index 98% rename from pygrt/C_extension/src/ptam.c rename to pygrt/C_extension/src/dynamic/ptam.c index 7eeee6d8..c732fce9 100755 --- a/pygrt/C_extension/src/ptam.c +++ b/pygrt/C_extension/src/dynamic/ptam.c @@ -18,12 +18,12 @@ #include #include -#include "ptam.h" -#include "iostats.h" -#include "const.h" -#include "model.h" -#include "propagate.h" -#include "quadratic.h" +#include "dynamic/ptam.h" +#include "dynamic/iostats.h" +#include "dynamic/propagate.h" +#include "dynamic/quadratic.h" +#include "common/const.h" +#include "common/model.h" /** diff --git a/pygrt/C_extension/src/quadratic.c b/pygrt/C_extension/src/dynamic/quadratic.c similarity index 95% rename from pygrt/C_extension/src/quadratic.c rename to pygrt/C_extension/src/dynamic/quadratic.c index c7861a6e..ec99b6a9 100755 --- a/pygrt/C_extension/src/quadratic.c +++ b/pygrt/C_extension/src/dynamic/quadratic.c @@ -12,8 +12,8 @@ #include -#include "quadratic.h" -#include "const.h" +#include "dynamic/quadratic.h" +#include "common/const.h" diff --git a/pygrt/C_extension/src/signals.c b/pygrt/C_extension/src/dynamic/signals.c similarity index 99% rename from pygrt/C_extension/src/signals.c rename to pygrt/C_extension/src/dynamic/signals.c index 51881a2b..f86a1868 100644 --- a/pygrt/C_extension/src/signals.c +++ b/pygrt/C_extension/src/dynamic/signals.c @@ -21,9 +21,9 @@ #include #include -#include "const.h" -#include "signals.h" -#include "colorstr.h" +#include "dynamic/signals.h" +#include "common/const.h" +#include "common/colorstr.h" bool check_tftype_tfparams(const char tftype, const char *tfparams){ diff --git a/pygrt/C_extension/src/source.c b/pygrt/C_extension/src/dynamic/source.c similarity index 96% rename from pygrt/C_extension/src/source.c rename to pygrt/C_extension/src/dynamic/source.c index 6ccba12d..d986a948 100755 --- a/pygrt/C_extension/src/source.c +++ b/pygrt/C_extension/src/dynamic/source.c @@ -12,10 +12,10 @@ #include #include -#include "source.h" -#include "model.h" -#include "matrix.h" -#include "prtdbg.h" +#include "dynamic/source.h" +#include "common/model.h" +#include "common/matrix.h" +#include "common/prtdbg.h" diff --git a/pygrt/C_extension/src/travt/Makefile b/pygrt/C_extension/src/travt/Makefile new file mode 100644 index 00000000..2bedc7f0 --- /dev/null +++ b/pygrt/C_extension/src/travt/Makefile @@ -0,0 +1,56 @@ + +CC := gcc +CFLAGS := -Wall -g -fPIC -I../../include -lm + +COMMON_OBJS := $(wildcard ../../build/common/*.o) + +BUILD_DIR = ../../build/travt +BIN_DIR = ../../bin +SRCS := $(wildcard *.c) +OBJS := $(patsubst %.c, $(BUILD_DIR)/%.o, $(SRCS)) + +DEPS := $(OBJS:.o=.d) # include main functions here + +OBJS := $(filter-out \ + $(BUILD_DIR)/grt_travt.o \ + , $(OBJS)) + +PROGS := $(BIN_DIR)/grt.travt + +all: objs progs + +objs: $(BUILD_DIR) $(OBJS) + +progs: $(OBJS) $(BIN_DIR) $(PROGS) + + +$(BUILD_DIR): + @mkdir -p $(BUILD_DIR) + +$(BUILD_DIR)/%.o: %.c + $(CC) -o $@ -c $< $(CFLAGS) + + +# ------------------------Executable files------------------------ +$(BIN_DIR): + @mkdir -p $(BIN_DIR) + +$(BIN_DIR)/grt.travt: grt_travt.c $(OBJS) + $(CC) -o $@ $^ $(COMMON_OBJS) $(CFLAGS) + +# ----------------------- Dependency generation ----------------------- +-include $(DEPS) + +$(BUILD_DIR)/%.d: %.c + @mkdir -p $(shell dirname $@) + @$(CC) $(CFLAGS) -MM $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,$(BUILD_DIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +# --------------------------------------------------------------------- + +cleanbuild: + rm -rf $(BUILD_DIR) + +clean: cleanbuild + rm -f $(PROGS) \ No newline at end of file diff --git a/pygrt/C_extension/src/grt_travt.c b/pygrt/C_extension/src/travt/grt_travt.c similarity index 98% rename from pygrt/C_extension/src/grt_travt.c rename to pygrt/C_extension/src/travt/grt_travt.c index 5914775e..6d29e1d7 100644 --- a/pygrt/C_extension/src/grt_travt.c +++ b/pygrt/C_extension/src/travt/grt_travt.c @@ -13,11 +13,11 @@ #include -#include "const.h" -#include "model.h" -#include "travt.h" -#include "logo.h" -#include "colorstr.h" +#include "travt/travt.h" +#include "common/const.h" +#include "common/model.h" +#include "common/logo.h" +#include "common/colorstr.h" extern char *optarg; extern int optind; diff --git a/pygrt/C_extension/src/travt.c b/pygrt/C_extension/src/travt/travt.c similarity index 99% rename from pygrt/C_extension/src/travt.c rename to pygrt/C_extension/src/travt/travt.c index eaf478e2..c43eb105 100644 --- a/pygrt/C_extension/src/travt.c +++ b/pygrt/C_extension/src/travt/travt.c @@ -13,7 +13,7 @@ #include -#include "const.h" +#include "common/const.h" MYREAL compute_travt1d(