author | A.M. Thurnherr <athurnherr@yahoo.com> |
Thu, 13 Jun 2019 20:31:30 -0400 | |
changeset 47 | 494a76548e94 |
parent 43 | b63fa355644c |
permissions | -rwxr-xr-x |
1 | 1 |
#!/usr/bin/perl |
2 |
#====================================================================== |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
3 |
# S P L I T P D 0 |
1 | 4 |
# doc: Sat Aug 21 22:20:27 2010 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
5 |
# dlm: Mon Apr 2 15:49:09 2018 |
1 | 6 |
# (c) 2010 A.M. Thurnherr |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
7 |
# uE-Info: 28 36 NIL 0 0 72 2 2 4 NIL ofnI |
1 | 8 |
#====================================================================== |
9 |
||
10 |
# split RDI files based on list of ensemble numbers (e.g. from yoyo -t) |
|
11 |
||
12 |
# HISTORY: |
|
13 |
# Aug 21, 2010: - created |
|
7 | 14 |
# Jun 24, 2011: - replaced -b, -n by -o |
14 | 15 |
# Feb 13, 2014: - updated doc |
18 | 16 |
# Mar 19, 2014: - added -s)kip small files |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
17 |
# Sep 14, 2014: - added -f)irst |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
18 |
# Jul 26, 2016: - changed file numbering to 1-relative |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
19 |
# Jul 30, 2016: - modified -o default |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
20 |
# - added code to set DSID of first ensemble of each |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
21 |
# output file to 0x7f7f |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
22 |
# Apr 2, 1018: - BUG in error messages |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
23 |
# - added header id check |
1 | 24 |
|
25 |
# NOTES: |
|
14 | 26 |
# - it is assumed that the input file begins with ensemble #1 |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
27 |
# - turning-point ensembles are written to next profile, |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
28 |
# for compatibility with [yoyo]? |
1 | 29 |
|
7 | 30 |
# FILE NAME CONVENTION: |
14 | 31 |
# - in order to assign individual yoyo casts numerical station numbers, |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
32 |
# by default, an underscore and the yoyo cast number is added to the basename |
7 | 33 |
|
14 | 34 |
# EXAMPLES: |
35 |
# splitRDI 017DL000.000 `mkProfile 017DL000.000 | yoyo -QFens -ut` |
|
7 | 36 |
|
1 | 37 |
$0 =~ m{(.*/)[^/]+}; |
38 |
require "$1RDI_BB_Read.pl"; |
|
39 |
use Getopt::Std; |
|
40 |
||
41 |
die("Usage: $0 " . |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
42 |
"[-o)ut-file <fmt[e.g. 017DL_%02d.000]>] " . |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
43 |
"[-f)irst output <cast #>] " . |
18 | 44 |
"[require -m)in <ens> to produce output] " . |
1 | 45 |
"<RDI file> <ens> <ens[...]>\n") |
21 | 46 |
unless (&getopts('f:o:m:') && @ARGV>=3); |
1 | 47 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
48 |
unless (defined($opt_o)) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
49 |
my($bn,$extn) = ($ARGV[0] =~ m{([^/]+)\.([^\.]+)$}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
50 |
$opt_o = "${bn}_%02d.$extn"; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
51 |
} |
18 | 52 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
53 |
$opt_m = 0 unless defined($opt_m); # default: produce tiny files as well |
7 | 54 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
55 |
$fn = $ARGV[0]; shift; |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
56 |
readHeader($fn,\%hdr); # get length of ensembles |
1 | 57 |
$ens_len = $hdr{ENSEMBLE_BYTES} + 2; |
58 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
59 |
$first_ens = $ARGV[0]+1; shift; # initialize loop |
1 | 60 |
$last_ens = $ARGV[0]; shift; |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
61 |
$cnr = 1; |
1 | 62 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
63 |
do { # split data |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
64 |
sysseek(WBRF,($first_ens-2)*$ens_len,0) || # begin next block of ensembles |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
65 |
die("$fn: $!"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
66 |
$last_ens++ unless defined($fn); |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
67 |
|
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
68 |
sysread(WBRF,$ids,2) || die("$fn: file truncated"); # read 1st ensemble & ensure DSID is 0x7f |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
69 |
die("$fn: illegal header id [0x" . unpack('H4',$ids) . "]") # require 1st byte to be 0x7f |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
70 |
unless (substr(unpack('H4',$ids),0,2) eq '7f'); |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
71 |
$ids = pack('H4','7f7f'); # reset DSID |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
72 |
sysread(WBRF,$febuf,$ens_len-4) == $ens_len-4 || |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
73 |
die("$fn: file truncated"); |
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
74 |
sysread(WBRF,$csum,2) || die("$fn: file truncated"); |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
75 |
$csum = pack('v',unpack('%16C*',$ids.$febuf)); # re-calculate checksum |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
76 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
77 |
$nBytes = ($last_ens-$first_ens) * $ens_len; # read remaining ensembles in block |
1 | 78 |
sysread(WBRF,$buf,$nBytes) == $nBytes || |
43
b63fa355644c
commit to merge with changes from EN620
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
36
diff
changeset
|
79 |
die("$fn: file truncated (ends before ens#$last_ens)"); |
1 | 80 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
81 |
if ($last_ens-$first_ens+1 >= $opt_m) { # write output only if sufficient # of ensembles |
21 | 82 |
$fn = sprintf($opt_o,$opt_f+$cnr++); |
18 | 83 |
open(F,">$fn") || die("$fn: $!\n"); |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
84 |
syswrite(F,$ids.$febuf.$csum.$buf,$nBytes+$ens_len) == $nBytes+$ens_len || |
18 | 85 |
die("$fn: $!\n"); |
86 |
close(F); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
87 |
printf(STDERR "$fn: %d ensembles (%d bytes)\n", |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
88 |
$last_ens-$first_ens+1,$nBytes+$ens_len); |
18 | 89 |
} |
1 | 90 |
|
91 |
$first_ens = $last_ens+1; |
|
92 |
$last_ens = $ARGV[0]; shift; |
|
93 |
} while defined($last_ens); |
|
94 |
||
95 |
exit(0); |
|
96 |
||
97 |