关于seed文件的读取方法

本文介绍了如何使用Golang读取地震Seed文件的头信息,包括关键数据块如010、011、012、050、052、070和074等,这些信息对于正确解析和后续的数据内容读取至关重要。通过顺序读取和关键字定位,可以确定数据块的起始位置和长度。种子文件的头信息包含台站标识码、时间信息和数据记录范围等,为地震测震和强震数据的处理提供基础。

本文是我捣鼓了一个多月的总结,目的是自己的备忘录,也可供系统内有需求的同仁以参考。

这里的seed文件的读取方法只限于地震测震和强震数据,其他应用领域的数据没有测试过所以也不知道是否适用。

参考资料《地震波形数据交换格式》和 jopens软件程序

程序实例语言 :golang

这里的seed文件是指以seed为后缀名的文件,该格式广泛应用与数字地震波形数据存储和数据交换。其编码结构在《地震波形数据交换格式》中有详细说明,在这里不做赘述,有兴趣者可以下载《地震波形数据交换格式》自行研究。本文只介绍在seed文件读取解码过程中的关键点和方法步骤(只少我是认为这些是比较关键的)

seed文件一般是由两部分组成,一部分是头文件内容(使用ASCII格式存储),一部分是数据内容(使用二进制格式存储);头文件信息的正确读取直接决定着后面的数据内容是否可以正常读取。

头文件内容是由多个数据块组成,数据块长度不固定,其数据格式大体是“数据块类型”-》“数据块长度”-》“数据块存储的各类信息”     如下所示:

卷台站头段索引子块 [11]
0110021001JXH  000005
解析:
011   子块类型
0021  子块长度
001   台站数
JXH   台站标识码(这里是5位有两个空格)
000005  台站头端顺序号   (S标志)      
卷时间片索引子块 [12]
012006300012023,101,16:00:00.0000~2023,102,16:00:00.0000~000012
解析:
012   子块类型
0063  子块长度
0001  卷中时间片数量
2023,101,16:00:00.0000   时间片的开始时间
~     分隔符
2023,102,16:00:00.0000   时间片的结束时间
~     分隔符
000012                   时间片头段顺序号(T标志)

数据块和数据块之间一般没有间隔,数据块的识别我是通过文件顺序读取检索关键字的方式处理的。代码如下:

// 按照关键字查找返回信息字段起始位置和信息长度
// file 文件指针;p_start 游标开始位置; keyword 关键字(关键字后三位必须是子块类型码)
func (s *HeadInfo) GetInfoSL(file *os.File, p_start int, keyword string) (int, int, error) {
	scanner := bufio.NewScanner(file)

	file.Seek(int64(p_start), 0)
	str_length := 0
	p := 0
	buf := make([]byte, 0, 64*1024)
	scanner.Buffer(buf, 1024*1024)
	for scanner.Scan() {

		str := scanner.Text()
		ide_s := strings.Index(str, keyword)
		if ide_s != -1 {

			p += ide_s
			buffer := make([]byte, 4)
			n, err := file.ReadAt(buffer, int64(p_start+p+len(keyword)))
			if err != nil {

				//panic(err)
				return 0, 0, err

			}
			str_length, err = strconv.Atoi(string(buffer[:n]))
			if err != nil {
               log.Println("keyword:",keyword)
				//panic(err)
				return 0, 0, err

			}


	
% Known encoding formats are the following FDSN codes: % 0: ASCII % 1: 16-bit integer % 2: 24-bit integer (untested) % 3: 32-bit integer % 4: IEEE float32 % 5: IEEE float64 % 10: Steim-1 % 11: Steim-2 % 12: GEOSCOPE 24-bit (untested) % 13: GEOSCOPE 16/3-bit gain ranged % 14: GEOSCOPE 16/4-bit gain ranged (untested) % 19: Steim-3 (alpha and untested) % % See also MKMSEED to export data in miniSEED format. % % % Author: Franois Beauducel % Institut de Physique du Globe de Paris % Created: 2010-09-17 % Updated: 2012-04-21 % % Acknowledgments: % Ljupco Jordanovski, Jean-Marie Saurel, Mohamed Boubacar, Jonathan Berger, % Shahid Ullah. % % References: % IRIS (2010), SEED Reference Manual: SEED Format Version 2.4, May 2010, % IFDSN/IRIS/USGS, http://www.iris.edu % Trabant C. (2010), libmseed: the Mini-SEED library, IRIS DMC. % Steim J.M. (1994), 'Steim' Compression, Quanterra Inc. % History: % [2012-04-21] % - Correct bug with Steim + little-endian coding % (thanks to Shahid Ullah) % [2012-03-21] % - Adds IDs for warning messages % [2011-11-10] % - Correct bug with multiple channel name length (thanks to % Jonathan Berger) % [2011-10-27] % - Add LocationIdentifier to X.ChannelFullName % [2011-10-24] % - Validation of IEEE double encoding (with PQL) % - Import/plot data even with file integrity problem (like PQL) % [2011-07-21] % - Validation of ASCII encoding format (logs) % - Blockettes are now stored in substructures below a single % field X.BLOCKETTES % - Add import of blockettes 500 and 2000 % - Accept multi-channel files with various data coding % [2010-10-16] % - Alpha-version of Steim-3 decoding... % - Extend output parameters with channel detection % - Add gaps and overlaps on plots % - Add possibility to force the plot % [2010-10-02] % - Add the input formats for GEOSCOPE multiplexed old data files % - Additional output argument with gap and overlap analysis % - Create a plot when no output argument are specified % - Optimize script coding (30 times faster STEIM decoding!) % % [2010-09-28] % - Correction of a problem with STEIM-1 nibble 3 decoding (one % 32-bit difference) % - Add reading of files without blockette 1000 with additional % input arguments (like Seismic Handler output files). % - Uses warning() function instead of fprintf().
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值