-
Notifications
You must be signed in to change notification settings - Fork 10
/
mcms2sac
executable file
·93 lines (82 loc) · 3.49 KB
/
mcms2sac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/tcsh -f
#
# Converts miniSEED files (obtained from MCGETMS) inside a directory
# to properly named SAC files via the intermediary of MSEED2SAC.
# Hand-edit for file selection. No instrument conversion is done here,
# we do that in MCMS2MAT.m which therefore supersedes this code here.
#
# [Historical note 1:
# Currently, the KNETWK and KHOLE have been set, but we used to have to move
# .S0001..HHX.D.2017.073.170000.SAC or XX.S0001..HHX.D.2017.073.170000.SAC
# to PP.S0001.00.HHX.D.2017.073.170000.SAC
# Only exception where this needed to be done by hand is 2017/06/19
# when the conversion between old and new file name convention
# happened right at the 18th hour.]
#
# [Historical note 2:
# As of 06/20/2017, we get a mostly stable GPS timing feed, but we
# used to get MSEED2SAC returning more than one file, dated at
# past the ??000 hour, due to timing errors. We got rid of those
# mistimed short files, while keeping a log of what not successfully
# converted. In the archived data, these will persist but all has been
# looked at.
#
# Last modified by jirving-at-princeton.edu on 03/30/2018
# Last modified by fjsimons-at-alum.mit.edu on 04/23/2020
# See also IFEMPTYREMOVE, MCSAC2SAC, MCMS2MAT.M
# Fix permissions, if you'd done any before, will refuse to redo it
# OLD FILES, which didn't have this set yet, new files do
set KNETWK = PP
set KHOLE = 00
# Into the directory structure
set years = `ls -d 20??`
# SPECIFIC YEAR ########################################
set years = 2020
# Go in, come out!
foreach year ($years[*])
cd $year
set monts = `ls -d ??`
# SPECIFIC MONTH ########################################
set monts = 02
foreach mont ($monts[*])
cd $mont
set days = `ls -d ??`
# SPECIFIC DAY ########################################
set days = 18
foreach day ($days[*])
cd $day
# OLD FILES ########################################
set files = `ls S0001.*.miniseed`
# NEW FILES ########################################
set files = `ls PP.S0001.*.miniseed`
foreach file ($files[*])
# CONVERSION
mseed2sac $file
# We think there should only be one file created, with the same time as in the filename
# which, in practice, should be a very round number, e.g. 120000
set exptim = `echo $file | sed 's/\_/ /g' | sed 's/\.miniseed//g' | awk '{print $NF}'`
# And so we rename this file, assuming it exists
# OLD BEHAVIOR ########################################
# set oldfile = `ls .S0001..*{$exptim}.SAC`
# set newfile = `echo $oldfile | sed 's/\.\./\.'$KHOLE'\./g'`
# mv $oldfile {$KNETWK}$newfile
# Keep a record of the files that showed up unexpectedly, and were not converted
# Ignore the "no match" statements, that means there wasn't anything unexpected
# ls .S0001..*.SAC >>! notconverted
# And remove them, ignoring the "no match" statements
# /bin/rm .S0001..*.SAC
# NEW BEHAVIOR ########################################
# We get most of it right, except it may not have a bunch of zeros where we want it
set exphrs = `echo $exptim | sed 's/0000//g'`
set badfile = `ls PP.S0001.*{$exphrs}[1-9]???.SAC`
/bin/rm -f $badfile
echo $badfile >>! notconverted
end
cd ..
end
cd ..
end
cd ..
end
# For the OLD FILES, we followed up with a bunch of SETVAR.PL for
# KINSTM and KNETWK, see MCSAC2SAC.