su嘻嘻

转]CWP/SU地震软件使用说明-2  

2009-10-12 10:40:26|  分类: 十字路口 |  标签:seismic  unix  su  地震数据处理   |字号 订阅

 
 
第10章 利用SU编程

10.1对Makefile的设置

CWP/SU软件包的Makefile结构非常成熟,因此当你开发新代码时也可以使用。在开始写新代码之前你应该在你的工作区建一个新目录,然后copy目录 $CWPROOT/src/su/main下的Makefile,并且加入以下的修改:

1. Change:
D = $L/libcwp.a $L/libpar.a $L/libsu.a
LFLAGS= $(PRELFLAGS) -L$L -lsu -lpar -lcwp -lm $(POSTLFLAGS)
to:
D = $L/libcwp.a $L/libpar.a $L/libsu.a
B = .
OPTC = -g

LFLAGS= $(PRELFLAGS) -L$L -lsu -lpar -lcwp -lm $(POSTLFLAGS)

2. Change:

PROGS = \

$B/bhedtopar \

...

...

PROGS = \

$B/yourprogram

where the source code of your program is called “yourporgram.c” and resides in this directory.

然后你只要输入“make”你的程序就会被编译。

作为测试你可以从$CWPROOT/src/su复制一个现成的SU程序,像上面那样修改Makefile然后输入make。Indeed, because all new SU programs may be viewed as beginning as clones of existing SU programs of a similar structure, this is perhaps the best way to begin any new coding veture.

这里利用的编译器是cc,已经加入了-g选项,可以利用gdb来调试。

10.2 A template SU program

以下的代码是从程序sumute中摘录的,可以作为一个典型的SU样板。进行有效的SU编程的关键是找到一个与你想写的所类似的程序。

/* SUMUTE: $Revision: 1.20 $ ; $Date: 2002/08/22 20:19:54 $ */ [1]

#include "su.h" [2]

#include "segy.h"

/*********************** self documentation **********************/ [3]

char *sdoc[] = {};

/**************** end self doc ***********************************/

/* Credits:

* CWP: Jack Cohen, John Stockwell

*/

segy tr; [4]

main(int argc, char **argv)

{

int ns; /* number of samples */ [5]

...

/* Initialize */

initargs(argc, argv); [6]

requestdoc(1); [7]

/* Get parameters */

if (!getparint("ntaper", &ntaper)) ntaper = 0; [8]

/* Get info from first trace */

if (!gettr(&tr)) err("can't read first trace"); [9]

if (!tr.dt) err("dt header field must be set"); [10]

/* Loop over traces */

do { [11]

int nt = (int) tr.ns; [12]

if (below == 0) { [13]

nmute = NINT((t - tmin)/dt);

memset((void *) tr.data, (int) '\0', nmute*FSIZE);

for (i = 0; i < ntaper; ++i)

tr.data[i+nmute] *= taper[i];

} else {

nmute = NINT((nt*dt - t)/dt);

memset((void *) (tr.data+nt-nmute),(int) '\0', nmute*FSIZE);

for (i = 0; i < ntaper; ++i)

tr.data[nt-nmute-1-i] *= taper[i];

}

puttr(&tr); [14]

} while (gettr(&tr)); [15]

return EXIT_SUCCESS; [16]

}

Discussion of numbered lines:

1. 这是UNIX源代码管理工具RCS产生的版本号。

2. su.h文件包含了(直接或间接)所有我们定义的macros和prototypes。segy.h包含了对文件道头的定义。

3. 星号括着的是“self-doc"。

4. 这是一个外部声明的SU (SEG-Y) trace buffer(缓冲器).用来避免浪费stack space.

5. 在申明变量的时候要进行描述. Examine codes related to yours to increase consistency of nomenclature (there is no official SU naming standard).

6. The initargs subroutine sets SU's command line passing facility (see page 75).

7. 子程序requestdoc调用指定的环境,在此环境下self-doc会显示给用户。The argument `1' applies to the typical program that uses only standard input (i.e.<) to read an SU trace file. Use `0' for codes that create synthetic data (like suplane) and `2' for codes that require two input files (we could say “et cetera,” but there are no existing SU mains that require three or more input files).

8. 这是从命令行读取参数的标准代码。这样解释:如果用户没有给定值就使用缺省值。子程序必须指定类型,这里在读一个integer参数。

9. 读第一道,空则退出。子程序fgettr知道SU的道格式。通常道文件是从标准输入中读取得,然后我们使用gettr(一个基于fgettr的宏,在 su.h中定义)。注意第一道读入到了the trace buffer (here called tr)中,因此我们需要在调用fgettr读入下一道前对它进行处理。

10. 读取了第一道,因为需要从第一道的到头中得到一些参数,例如采样点数(tr.ns)和/或采样间隔(tr.dt)。在SEGY-Y标准里,这两个对所有的道都一样。

11. 由于在主循环开始之前已经读取了第一道,因此使用一个do-while会在循环的末尾读入地震道

12. 我们喜欢在允许的地方使用局部变量。

13. 这里是地震算法(这里不完整),我们留了一些sumute的代码因为它正好包含了些对新代码有用的行,可以在这里调用子函数来做实际的工作。

14. fputtr和puttr类似于fgettr和gettr的作用。

15. 当所有的道都读完,循环末尾的gettr返回0,然后处理结束。

16. 这是一个ANSI-C macro通常用来指示程序顺利结束。

10.3 写一个新程序:suvlength

一位用户询问关于利用SU来处理可变长度的地震道。At his institute,数据的采集是从激发时间开始,但是结束时间是变化的。对SU来说困难在于所有的SU处理都是基于标准的所有道都相等的SEG-Y格式。因此最好的解决方式就是写一个数据转换程序,把可变长度的数据变通过补0换成固定长度的数据——假设命名为suvlength。可以把输出道的长度设成由用户给定的参数。If there is a reasonable choice, it makes sense to provide a default value for parameters. Here, using the length of the first trace seems the best choice since that value can be ascertained before the main processing loop starts.
 
 
 
 
  评论这张
转发至微博
转发至微博
0  分享到:        
阅读(443)| 评论(0)| 转载 (1) |举报
 

历史上的今天

 

评论

点击登录|昵称:
  取消
 
 
 
 
 
原文地址:https://www.cnblogs.com/guosj/p/2553322.html