#! /usr/local/bin/perl require 5.002; use strict; use FileHandle; use Getopt::Std; use File::Basename; use vars qw ( $VERSION $cmdname $opt_h ); $VERSION = "1.00 (2005.248)"; ######################################################################## # print_syntax - print syntax and exit. ######################################################################## sub print_syntax { my ($cmdname) = @_; printf "$cmdname version $VERSION $cmdname - convert Telemetry SEED files to MiniSEED files. Syntax: $cmdname [-h] file_1 ... file_n where: -h Help - prints this help message. file_1 ... file_n is a list of one or more telemetry SEED file to convert to MiniSEED. Notes: 1. If a file is not in Telemetry SEED format, it will be skipped. 2. A Telemetry SEED file will be REPLACED with the MiniSEED file. Examples: 1. $cmdname CMB.BK.BHZ..D.2005.250 2. $cmdname *.D.* "; exit(0); } { #################################################################### # Initialization. #################################################################### STDERR->autoflush(1); STDOUT->autoflush(1); ######################################################################## # Parse command line. ######################################################################## $cmdname = basename($0); &getopts ('h'); &print_syntax($cmdname) if ($opt_h); my($minhdr) = 21; for my $tsfile (@ARGV) { my($msfile) = "$tsfile.$$"; my($ifh) = new IO::File "<$tsfile"; die ("Error: unable to open input file $tsfile\n") if (! defined $ifh); # Read the (presumed) volume header, and skip it if found. my($volhdr,$rectype,$lreclen); $ifh->read($volhdr, $minhdr); ($rectype,$lreclen) = $volhdr =~ /^\d{6}(\w) 008\d\d\d\d....(\d\d)/; undef($ifh), print (STDERR "$tsfile not telemetry seed format - skipping\n"), next if ($rectype ne "V"); die ("Invalid SEED record length\n") unless ($lreclen >=8 && $lreclen <= 13); $lreclen = 2**$lreclen; my($rec); $ifh->read($volhdr, $lreclen-$minhdr); # Copy the rest of the file to the mseed output file. my($ofh) = new IO::File ">$msfile"; die ("Error: unable to open output file $msfile\n") if (! defined $ofh); while ($rec=<$ifh>) { print($ofh $rec) || die ("Error: writing file $msfile\n"); } close($ifh) || die ("Error: closing file $tsfile\n"); close($ofh) || die ("Error: closing file $msfile\n"); # Rename the mseed file to replace the tseed file. rename ($msfile,$tsfile) || die ("Error: unable to rename tmp file $msfile to $tsfile\n"); } exit(0); }