利用perl脚本实现SAC文件头段变量写入

将"ttime.dat"里面的t1(最后一列)写到"./001"的所有"*.sac"中, 并标记为t1, perl脚本如下:

 

#!/usr/bin/env perl
#by liuyi

open(PICK,"<","ttime.dat")||die"cannot open the file:$!\n";

$i=0;
while(){
	@lines=split(" ");
	$t1[$i]=@lines[3];
	$i=$i+1;
}
$size=$i;

$j=0;
my $DIR_PATH="/home/*/001";
opendir DIR, ${DIR_PATH}|| die "Can not open dir \n";
@filelist=readdir DIR;
foreach $file (@filelist){

	open(SAC, "| sac") or die "Error in opening SAC\n";
	print SAC "wild echo off \n";
 
	print SAC "r $DIR_PATH/$file \n";
	
	print SAC "ch t1 $t1[$j] \n";
	print SAC "wh \n";
	print SAC "q \n";
 
	close(SAC);
	$j=$j+1;
}

以上,在此做一记录。

你可能感兴趣的:(perl,perl脚本,SAC,写入SAC头段变量)