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
99 changes: 63 additions & 36 deletions docs/create_api_rst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,76 @@ C API

EOF

for item in $(ls $SDIR); do
echo $item
if [ -d $SDIR/$item ]; then
mkdir -p $PDIR/$item
content=(
"$item"
"========================================="
""
".. toctree::"
" :maxdepth: 2"
""
)
printf "%s\n" "${content[@]}" > $PDIR/$item.rst

for hnm in $(ls $SDIR/$item); do
# 递归处理目录和文件
process_directory() {
local source_dir=$1
local target_dir=$2
local relative_path=$3

echo $source_dir $target_dir $relative_path

for item in $(ls $source_dir); do
local source_item="$source_dir/$item"
local target_item="$target_dir/$item"
local relative_item="$relative_path/$item"

if [ -d $source_item ]; then
# 创建对应的目标目录
mkdir -p "$target_item"

# 为目录创建.rst文件
local rst_file="${target_dir}/${item}.rst"
content=(
"$item"
"========================================="
""
".. toctree::"
" :maxdepth: 2"
""
)
printf "%s\n" "${content[@]}" > "$rst_file"

# 将目录添加到父目录的toctree中
if [ "$relative_path" != "." ]; then
local parent_rst="${target_dir}.rst"
echo " $(basename $source_dir)/${item}" >> "$parent_rst"
else
# 如果是顶级目录下的目录,添加到主toctree
echo " C_extension/${item}" >> "$c_api_rst"
fi

# 递归处理子目录
process_directory "$source_item" "$target_item" "$relative_item"

elif [ -f $source_item ] && [[ $item == *.h ]]; then
# 处理.h文件
# local base_name="${item%%.*}"
local base_name="${item}"
content=(
"$hnm"
"$item"
"--------------------------------------"
""
".. doxygenfile:: $hnm"
".. doxygenfile:: ${relative_item#./}"
" :project: h_PyGRT"
""
)
printf "%s\n" "${content[@]}" > $PDIR/$item/${hnm%%.*}.rst
echo " $item/${hnm%%.*}" >> $PDIR/$item.rst
done

elif [ -f $SDIR/$item ]; then
content=(
"$item"
"--------------------------------------"
""
".. doxygenfile:: $item"
" :project: h_PyGRT"
""
)
printf "%s\n" "${content[@]}" > $PDIR/${item%%.*}.rst
fi

echo " C_extension/${item%%.*}" >> $c_api_rst
printf "%s\n" "${content[@]}" > "${target_dir}/${base_name}.rst"

# 如果是顶级目录下的文件,添加到主toctree
if [ "$relative_path" == "." ]; then
echo " C_extension/${base_name}" >> "$c_api_rst"
else
# 将文件添加到父目录的toctree中
local parent_rst="${target_dir}.rst"
echo " $(basename ${target_dir})/${base_name}" >> "$parent_rst"
fi
fi
done
}

# 从SDIR开始处理
process_directory "$SDIR" "$PDIR" "."


done



Expand Down
6 changes: 3 additions & 3 deletions pygrt/C_extension/include/grt.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include <ctype.h>
#include <stdbool.h>

#include "common/const.h"
#include "common/logo.h"
#include "grt/common/const.h"
#include "grt/common/logo.h"
#include "grt/common/checkerror.h"

#include "grt_error.h"

#define GRT_MAIN_COMMAND "grt" ///< 主程序名

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "common/const.h"
#include "grt/common/const.h"

/**
* 品质因子Q 对 波速的影响, Futterman causal Q, 参考Aki&Richards, 2009, Chapter 5.5.1
Expand All @@ -23,9 +23,9 @@
*
* @return atncoef 系数因子,作用在 \f$ k=\omega / c(\omega)\f$的计算
*/
MYCOMPLEX attenuation_law(MYREAL Qinv, MYCOMPLEX omega);
MYCOMPLEX grt_attenuation_law(MYREAL Qinv, MYCOMPLEX omega);

/**
* attenuation_law函数在python中被调用的版本,长度2的数组分别表示复数的实部和虚部
*/
void py_attenuation_law(MYREAL Qinv, MYREAL omg[2], MYREAL atte[2]);
void grt_py_attenuation_law(MYREAL Qinv, MYREAL omg[2], MYREAL atte[2]);
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "common/const.h"
#include "grt/common/const.h"

/**
* 计算Bessel函数 \f$ J_m(x), m=0,1,2 \f$
Expand All @@ -19,7 +19,7 @@
* @param[out] bj2 \f$ J_2(x) \f$
*
*/
void bessel012(MYREAL x, MYREAL *bj0, MYREAL *bj1, MYREAL *bj2);
void grt_bessel012(MYREAL x, MYREAL *bj0, MYREAL *bj1, MYREAL *bj2);


/**
Expand All @@ -31,4 +31,4 @@ void bessel012(MYREAL x, MYREAL *bj0, MYREAL *bj1, MYREAL *bj2);
* @param[in,out] bj2 传入 \f$ J_2(x) \f$, 返回\f$ J_2^{'}(x) \f$
*
*/
void besselp012(MYREAL x, MYREAL *bj0, MYREAL *bj1, MYREAL *bj2);
void grt_besselp012(MYREAL x, MYREAL *bj0, MYREAL *bj1, MYREAL *bj2);
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file grt_error.h
* @file checkerror.h
* @author Zhu Dengda (zhudengda@mail.iggcas.ac.cn)
* @date 2025-08
*
* 一些用于报错的宏
* 一些检查和报错的宏
*
*/

Expand All @@ -14,7 +14,7 @@
#include <dirent.h>
#include <errno.h>

#include "common/colorstr.h"
#include "grt/common/colorstr.h"

// GRT自定义报错信息
#define GRTRaiseError(ErrorMessage, ...) ({\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <complex.h>
#include <tgmath.h>

#include "grt_error.h"
#include "grt/common/checkerror.h"

// CMPLX macro not exist on MacOS
#ifndef CMPLX
Expand Down Expand Up @@ -109,8 +109,6 @@ typedef int MYINT; ///< 整数
};\
})

#define GRT_SAFE_

// -----------------------------------------------------------------------------
#define CHANNEL_NUM 3 ///< 3, 代码中分量个数(ZRT,ZNE)

Expand Down Expand Up @@ -163,4 +161,4 @@ extern const char ZNEchs[];
*
* @param[in] num_threads 线程数
*/
void set_num_threads(int num_threads);
void grt_set_num_threads(int num_threads);
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @param[in] theta r轴相对x轴的旋转弧度(负数表示逆变换,即zrt->zxy)
* @param[out] A 待旋转的矢量(s1, s2, s3)
*/
void rot_zxy2zrt_vec(double theta, double A[3]);
void grt_rot_zxy2zrt_vec(double theta, double A[3]);



Expand All @@ -27,7 +27,7 @@ void rot_zxy2zrt_vec(double theta, double A[3]);
* @param[in] theta r轴相对x轴的旋转弧度(负数表示逆变换,即zrt->zxy)
* @param[out] A 待旋转的二阶对称张量(s11, s12, s13, s22, s23, s33)
*/
void rot_zxy2zrt_symtensor2odr(double theta, double A[6]);
void grt_rot_zxy2zrt_symtensor2odr(double theta, double A[6]);


/**
Expand All @@ -53,4 +53,4 @@ void rot_zxy2zrt_symtensor2odr(double theta, double A[6]);
* @param[in,out] upar 柱坐标下的位移空间偏导
* @param[in] r r轴坐标
*/
void rot_zrt2zxy_upar(const double theta, double u[3], double upar[3][3], const double r);
void grt_rot_zrt2zxy_upar(const double theta, double u[3], double upar[3][3], const double r);
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include <stdio.h>

#include "common/model.h"
#include "common/kernel.h"
#include "grt/common/model.h"
#include "grt/common/kernel.h"


/**
Expand All @@ -43,11 +43,11 @@
*
* @return k 积分截至时的波数
*/
MYREAL discrete_integ(
const MODEL1D *mod1d, MYREAL dk, MYREAL kmax, MYREAL keps, MYCOMPLEX omega,
MYREAL grt_discrete_integ(
const GRT_MODEL1D *mod1d, MYREAL dk, MYREAL kmax, MYREAL keps, MYCOMPLEX omega,
MYINT nr, MYREAL *rs,
MYCOMPLEX sum_J[nr][SRC_M_NUM][INTEG_NUM],
bool calc_upar,
MYCOMPLEX sum_uiz_J[nr][SRC_M_NUM][INTEG_NUM],
MYCOMPLEX sum_uir_J[nr][SRC_M_NUM][INTEG_NUM],
FILE *fstats, KernelFunc kerfunc, MYINT *stats);
FILE *fstats, GRT_KernelFunc kerfunc, MYINT *stats);
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#include <stdio.h>

#include "common/const.h"
#include "common/model.h"
#include "common/kernel.h"
#include "grt/common/const.h"
#include "grt/common/model.h"
#include "grt/common/kernel.h"



Expand Down Expand Up @@ -50,13 +50,13 @@
*
* @return k 积分截至时的波数
*/
MYREAL linear_filon_integ(
const MODEL1D *mod1d, MYREAL k0, MYREAL dk0, MYREAL filondk, MYREAL kmax, MYREAL keps, MYCOMPLEX omega,
MYREAL grt_linear_filon_integ(
const GRT_MODEL1D *mod1d, MYREAL k0, MYREAL dk0, MYREAL filondk, MYREAL kmax, MYREAL keps, MYCOMPLEX omega,
MYINT nr, MYREAL *rs,
MYCOMPLEX sum_J[nr][SRC_M_NUM][INTEG_NUM],
bool calc_upar,
MYCOMPLEX sum_uiz_J[nr][SRC_M_NUM][INTEG_NUM],
MYCOMPLEX sum_uir_J[nr][SRC_M_NUM][INTEG_NUM],
FILE *fstats, KernelFunc kerfunc, MYINT *stats);
FILE *fstats, GRT_KernelFunc kerfunc, MYINT *stats);


Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

#include "common/const.h"
#include "grt/common/const.h"

/**
* 计算核函数和Bessel函数的乘积,相当于计算了一个小积分区间内的值。参数中涉及两种数组形状:
Expand All @@ -24,7 +24,7 @@
* @param[out] SUM 该dk区间内的积分值
*
*/
void int_Pk(
void grt_int_Pk(
MYREAL k, MYREAL r,
const MYCOMPLEX QWV[SRC_M_NUM][QWV_NUM],
bool calc_uir,
Expand All @@ -39,7 +39,7 @@ void int_Pk(
* @param[in] sum_J 积分结果
* @param[out] tol Z、R、T分量结果
*/
void merge_Pk(
void grt_merge_Pk(
const MYCOMPLEX sum_J[SRC_M_NUM][INTEG_NUM], MYCOMPLEX tol[SRC_M_NUM][CHANNEL_NUM]);


Expand All @@ -58,7 +58,7 @@ void merge_Pk(
* @param[out] SUM 该dk区间内的积分值
*
*/
void int_Pk_filon(
void grt_int_Pk_filon(
MYREAL k, MYREAL r, bool iscos,
const MYCOMPLEX QWV[SRC_M_NUM][QWV_NUM],
bool calc_uir,
Expand All @@ -77,7 +77,7 @@ void int_Pk_filon(
* @param[out] SUM 该三点区间内的积分值
*
*/
void int_Pk_sa_filon(
void grt_int_Pk_sa_filon(
const MYREAL k3[3], MYREAL r,
const MYCOMPLEX QWV3[3][SRC_M_NUM][QWV_NUM],
bool calc_uir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <stdbool.h>
#include <stdio.h>

#include "common/const.h"
#include "grt/common/const.h"



Expand All @@ -26,7 +26,7 @@
* @note 文件记录的值均为波数积分的中间结果,与最终的结果还差一系列的系数,
* 记录其值主要用于参考其变化趋势。
*/
void write_stats(
void grt_write_stats(
FILE *f0, MYREAL k, const MYCOMPLEX QWV[SRC_M_NUM][QWV_NUM]);


Expand All @@ -38,7 +38,7 @@ void write_stats(
*
* @return 0表示读取成功,-1表示读取结果/失败
*/
MYINT extract_stats(FILE *bf0, FILE *af0);
MYINT grt_extract_stats(FILE *bf0, FILE *af0);



Expand All @@ -53,7 +53,7 @@ MYINT extract_stats(FILE *bf0, FILE *af0);
* 记录其值主要用于参考其变化趋势。
*
*/
void write_stats_ptam(
void grt_write_stats_ptam(
FILE *f0,
MYREAL Kpt[SRC_M_NUM][INTEG_NUM][PTAM_MAX_PT],
MYCOMPLEX Fpt[SRC_M_NUM][INTEG_NUM][PTAM_MAX_PT]);
Expand All @@ -67,5 +67,5 @@ void write_stats_ptam(
*
* @return 0表示读取成功,-1表示读取结果/失败
*/
MYINT extract_stats_ptam(FILE *bf0, FILE *af0);
MYINT grt_extract_stats_ptam(FILE *bf0, FILE *af0);

Loading