1 |
#!/afs/isis/pkg/perl-582/bin/perl |
---|
2 |
#raw2proc.perl |
---|
3 |
#Time-stamp: <2006-03-28 15:23:52 lstearns> |
---|
4 |
# |
---|
5 |
#Abstract: Take raw tower/roof/buoy data and convert to monthly netcdf files |
---|
6 |
# of converted data! |
---|
7 |
# |
---|
8 |
#Usage: |
---|
9 |
#####!/afs/isis/pkg/isis/bin/perl |
---|
10 |
|
---|
11 |
|
---|
12 |
########################## |
---|
13 |
# Luke Stearns # |
---|
14 |
# lstearns@email.unc.edu # |
---|
15 |
# work: (919)-962-0301 # |
---|
16 |
# mobile: (919)-619-5057 # |
---|
17 |
########################## |
---|
18 |
use Date::Manip; |
---|
19 |
|
---|
20 |
$starttime = time; |
---|
21 |
|
---|
22 |
if (1){ |
---|
23 |
$data_dir = '/seacoos/data/nc-coos/tower/'; |
---|
24 |
$raw_dir2 = $data_dir.'raw_data/'; |
---|
25 |
$proc_dir = $data_dir.'proc_data/'; |
---|
26 |
$perl_dir = '/opt/local/seacoos/bin/'; |
---|
27 |
} |
---|
28 |
|
---|
29 |
$now_LOCAL = &ParseDate("today"); |
---|
30 |
$now_LOCAL_str = &UnixDate($now_LOCAL, "%Y:%m:%d %H:%M:%S (%Z)"); |
---|
31 |
print "\n========= Starting: $now_LOCAL_str ========= Perl Version: $]\n"; |
---|
32 |
|
---|
33 |
|
---|
34 |
#$data_dir = '/afs/isis.unc.edu/depts/marine/workspace/hseim/sablam4/'. |
---|
35 |
# 'lstearns/perl/test_nemo/'; |
---|
36 |
#$raw_dir = $data_dir.'raw_data/'; |
---|
37 |
|
---|
38 |
#$perl_dir = '/afs/isis.unc.edu/depts/marine/workspace/hseim/sablam4/'. |
---|
39 |
# 'lstearns/perl/test_nemo/'; |
---|
40 |
#$perl_dir = "$data_dir"; |
---|
41 |
|
---|
42 |
|
---|
43 |
#Directory where files are pushed from iridium! (soon will move to nemo) |
---|
44 |
#$raw_dir = '/afs/isis/depts/marine/workspace/haines/nc-coos/'. |
---|
45 |
# 'test_tower_push_data/'; |
---|
46 |
$raw_dir = '/seacoos/ftp/'; |
---|
47 |
|
---|
48 |
@towers = ('R4','LSRB','T1'); |
---|
49 |
|
---|
50 |
foreach $tower_id (@towers){ |
---|
51 |
|
---|
52 |
#See if there are any new files. |
---|
53 |
@new_files = glob("${raw_dir}$tower_id/$tower_id*.txt"); |
---|
54 |
if ($#new_files>=0) { |
---|
55 |
|
---|
56 |
#Move files from nemo ftp to nemo raw dir directory |
---|
57 |
system("mv ${raw_dir}$tower_id/$tower_id*.txt ${raw_dir2}$tower_id/"); |
---|
58 |
#system("cp ${raw_dir}$tower_id/$tower_id*.txt ${raw_dir2}$tower_id/"); |
---|
59 |
|
---|
60 |
@new_file_list = glob("${raw_dir2}$tower_id/$tower_id*.txt"); |
---|
61 |
|
---|
62 |
foreach $new_file (@new_file_list) { |
---|
63 |
#Loop through files and pick out month list. |
---|
64 |
$new_file =~m/${raw_dir2}$tower_id\/$tower_id\_(.*)\_.*/; |
---|
65 |
$date_stamp = $1; |
---|
66 |
@date_stamp = split('',$date_stamp); |
---|
67 |
$month_st1 = join('',@date_stamp[0..5]); |
---|
68 |
$month_st2 = join('',@date_stamp[0..3]).'_'. |
---|
69 |
join('',@date_stamp[4..5]); |
---|
70 |
|
---|
71 |
$months{$month_st1} = $month_st2;#.".nc"; |
---|
72 |
#print "input: $month_st1 output: $month_st2\n"; |
---|
73 |
} |
---|
74 |
|
---|
75 |
foreach $month (keys %months) { |
---|
76 |
#print "$month and $months{$month}\n"; |
---|
77 |
mkdir("${raw_dir2}$tower_id/$months{$month}/"); |
---|
78 |
system("mv -f ${raw_dir2}$tower_id/${tower_id}_${month}*.txt ". |
---|
79 |
"${raw_dir2}$tower_id/$months{$month}/"); |
---|
80 |
# system("mv ${raw_dir2}$tower_id/nccoos_${tower_id}_*_${month}.txt ". |
---|
81 |
# "${raw_dir2}$tower_id/$months{$month}/"); |
---|
82 |
|
---|
83 |
print "${perl_dir}tower_parse_dev.perl $month -d 1 -t $tower_id\n"; |
---|
84 |
#system("${perl_dir}tower_parse.perl $month -out ". |
---|
85 |
# "${tower_id}_$months{$month}.nc -d 1 -t $tower_id"); |
---|
86 |
system("${perl_dir}tower_parse_dev.perl $month ". |
---|
87 |
"-d 1 -t $tower_id"); |
---|
88 |
} |
---|
89 |
} |
---|
90 |
else { |
---|
91 |
print "No new files for $tower_id\n"; |
---|
92 |
} |
---|
93 |
} |
---|
94 |
|
---|
95 |
|
---|
96 |
print "elapsed time ". time - $start_time. " seconds\n"; |
---|