package Step2; use strict; use File::Copy; ################################################################################################################ ## This subroutine computes the cross correlation between each 1-day file ## ## 1. all the sac files contained in the current folder are listed ## ## 2. a FTN90 program determines the output names, following this model: YYYYDDD.NW1.ST1.NW2.ST2.CHN.sac ## ## 3. SAC is run and feeded with the file created by the FTN program ## ################################################################################################################ sub cross { my($workpath) = @_; my @files; my $files; my ($nbcross, $nbcrosscor); my ($i, $j); print("\n_______________________________________________________________________________________________________\n"); print("Cross-correlation process\n\n"); print("Changing to folder: $workpath\n"); chdir($workpath); opendir(FOLD,"$workpath"); unlink("liste"); unlink("crosslist"); @files = readdir(FOLD); closedir(FOLD); open(LISTE,">liste") or die("\n\nCouldn't create the new 'liste' file, cross correlation module: $1\n"); foreach $files (@files) { chomp($files); if($files =~ /sac$/) { print(LISTE "$files"); print(LISTE "\n"); } } print(LISTE "liste"); close(LISTE); open(NAMES,"|dontgivemenames") or die("\n\nCouldn't open the naming program, cross correlation module: $1\n"); close(NAMES); print("\n\n"); open(CROSSLISTE,"crosslist"); @files = ; close(CROSSLISTE); # We are here determining the number of iteration for the cross-correlating loop. # The filenames inside of the crosslist file go by 3: the two files to cross-correlate, and the name of the output # file. # As the perl language is begining any count by 0, I have to add 1 to the number of items in the list. The # operations are very simple, but it's much safer and easier to understand if the steps are separated. $nbcross = $#files; $nbcross = $nbcross + 1; $nbcross = $nbcross / 3; $nbcrosscor = $nbcross - 1; mkdir("norm_files"); # Here is the part where SAC is used open(SAC, "|sac"); # SAC is opened at the beginning of the loops print(SAC "echo on commands\n"); for($i = 0; $i < $nbcross; $i++) { $j = 3*$i; chomp($files[$j]); chomp($files[$j+1]); chomp($files[$j+2]); print(SAC "*** $i / $nbcrosscor ***\n"); print(SAC "read ".$files[$j]." ".$files[$j+1]."\n"); # The pair of files which have to be cross-correlated are loaded into memory #print("read ".$files[$j]." ".$files[$j+1]."\n"); print(SAC "correlate master 1\n"); #print("correlate master 1\n"); print(SAC "write trash ".$files[$j+2]."\n"); # The auto-correlation is useless, the cross-correlation is saved print(SAC "deletechannel all\n"); # Memory is emptied. } print(SAC "quit\n"); close(SAC); # The loops are over, therefore SAC is closed as well open(LISTE,"liste"); @files = ; close(LISTE); foreach $files (@files) { if($files =~ /sac$/) { chomp($files); File::Copy::move("$files","norm_files/$files") or die("\nCouldn't move the files, module cross: $!\n"); } } } 1;