Hi, so I have been doing ok making a relatively simple script just processing some data. However I am now at the point where im struggling to find the specific help I need.
I have files in the form of yyyy.ddd.hh.mm.ss.stationnumber.component (they are earthquake events). eg.
2006.162.20.11.27.N60027.e
2006.162.20.11.27.N60027.n
2006.162.20.11.27.N60027.z
2006.165.04.28.18.N60027.e
2006.165.04.28.18.N60027.n
2006.165.04.28.18.N60027.z ....
So each event is split into 3 files, and i have ~ 30 events.
I need to read these all into a program 3 at a time, ie the e, n & z. And this is where i am having the problem.
I can do
read day1time1. and this reads all the n,e,z components at the same time, so do i need to create a loop? to then run the section of the script again but to read in day2time2. ?
The Bash version Im using is 3.2.25(1).
Any help/tips will be greatly appreciated, thanks!
EDIT for exact filenames
You can try:
for i in {1..30}; do
your_program "day${i}time${i}"*
done
Thanks bartus11
However i think i may have over simplified my file names! and it may be a little more complicated. The files are name in the format yyyy.ddd.hh.mm.ss.stationnumber.component (they are earthquake events). For eg.
2006.162.20.11.27.N60027.e
2006.162.20.11.27.N60027.n
2006.162.20.11.27.N60027.z
2006.165.04.28.18.N60027.e
2006.165.04.28.18.N60027.n
2006.165.04.28.18.N60027.z
Sorry!
Is the order in which those files are processed by your program important? i.e. does it matter if 2006.165.04.28.18* files are processed before 2006.162.20.11.27*?
No. The program just rotates the .e and .n components into radial and tangential components. The date is only for grouping them into an event
Try:
for i in *.e; do
your_program "${i%.e}"*
done
Thanks again, however im not sure why that doesnt work, it still asks me to specify the files.
Here, I have an example script for the program im trying to use but it uses csh and im trying to use bash.
#/bin/csh
#
# The files should be named:
# basename[n,e,z]
# and the event and station coordinates should
# be in the header of the files.
#
if ($#argv == 0) then
echo "Usage: equalize basename waterlevel gauss_width tshift"
exit 1
endif
#
# Set up the input
#
set filename = $1
set outfile = $1
set waterlevel = $2
set gaussian = $3
set time_shift = $4
#
# Run the Program
#
pwaveqn << echo
$filename
y
n
$outfile
$waterlevel
$gaussian
$time_shift
n
echo
# All Done
Really sorry this is turning out to be more of a problem then i originally expected!
Can you post example of executing this script?
Ive only been teaching myself since a few weeks ago and im not sure about arguments, i dont really know much. But from what i got from the example i do something like this?
set 2006.229.11.20.26.N6027.* = $1
set 2006.229.11.20.26.N6027 = $2
set 0.001 = $3
set 2 = $4
set 30 = $5
#
# Run the Program
#
pwaveqn <<echo
$1
y
n
$2
$3
$4
$5
n
However this done not work. I know im doing something wrong.
Here is the script executed...
Specify quake file: Real data (y or n)? nerr = ** in sacio read
nerr = ** in sacio read
nerr = ** in sacio read
p r o b l e m i n r o t a t e
+ horz direction: 1= ******** 2= ********
for proper rotation 2= ******** difference = 90.0000
Window data (y or n)? npts= 15 nft= 16 fny= 0.0000 delf= 0.0000 dt=******
Specify outfil: Trough filler, c = invalid number: incomprehensible list input
apparent state: unit 5 (unnamed)
last format: list io
lately reading sequential formatted external IO
./new: line 32: 5559 Aborted pwaveqn <<echo
$1
y
n
$2
$3
$4
$5
n
echo
It is not reading the file/parameters.
What is your shell? Don't often see variables set like that.
in the example it is csh, but i would like it to be in bash if possible, as my script before is bash, eventually i want to combine them.
The problem is not the script, is the pwaveqn program. I have the same problem here running only pwaveqn. I've tried changing the SAC file header values but didn't work. I'm trying to figure out what is happening, if you have some news tell me.
Regards.
hi,
I have found a working way to do this, i got help from another student at my uni. He too said it was a pain to figure out.
for file in 2006.*.N6027.e; do
filename=${file%?}
outfile=${file%??}
#
pwaveqn << echo
$filename
y
n
$outfile
0.001
2
30
y
echo
done
That reads in all my data 3 at a time (without extensions) and exports them as the same filename but with pwaveqn extensions.
Hopefully u can use this as a guide to help, although im fairly new to all this.