author | A.M. Thurnherr <athurnherr@yahoo.com> |
Sun, 12 Mar 2017 12:11:40 -0400 | |
changeset 37 | 40d85448debf |
parent 36 | 515b06dae59c |
child 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 |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
5 |
# dlm: Sat Jul 30 18:50:43 2016 |
1 | 6 |
# (c) 2010 A.M. Thurnherr |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
7 |
# uE-Info: 69 60 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 |
1 | 22 |
|
23 |
# NOTES: |
|
14 | 24 |
# - it is assumed that the input file begins with ensemble #1 |
25 |
# - turning-point ensembles are written to preceding profile, |
|
26 |
# for compatibility with [yoyo] |
|
1 | 27 |
|
7 | 28 |
# FILE NAME CONVENTION: |
14 | 29 |
# - 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
|
30 |
# by default, an underscore and the yoyo cast number is added to the basename |
7 | 31 |
|
14 | 32 |
# EXAMPLES: |
33 |
# splitRDI 017DL000.000 `mkProfile 017DL000.000 | yoyo -QFens -ut` |
|
7 | 34 |
|
1 | 35 |
$0 =~ m{(.*/)[^/]+}; |
36 |
require "$1RDI_BB_Read.pl"; |
|
37 |
use Getopt::Std; |
|
38 |
||
39 |
die("Usage: $0 " . |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
40 |
"[-o)ut-file <fmt[e.g. 017DL_%02d.000]>] " . |
21 | 41 |
"[-f)irst <cast #>] " . |
18 | 42 |
"[require -m)in <ens> to produce output] " . |
1 | 43 |
"<RDI file> <ens> <ens[...]>\n") |
21 | 44 |
unless (&getopts('f:o:m:') && @ARGV>=3); |
1 | 45 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
46 |
unless (defined($opt_o)) { |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
47 |
my($bn,$extn) = ($ARGV[0] =~ m{([^/]+)\.([^\.]+)$}); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
48 |
$opt_o = "${bn}_%02d.$extn"; |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
49 |
} |
18 | 50 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
51 |
$opt_m = 0 unless defined($opt_m); # default: produce tiny files as well |
7 | 52 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
53 |
readHeader($ARGV[0],\%hdr); shift; # get length of ensembles |
1 | 54 |
$ens_len = $hdr{ENSEMBLE_BYTES} + 2; |
55 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
56 |
$first_ens = $ARGV[0]+1; shift; # initialize loop |
1 | 57 |
$last_ens = $ARGV[0]; shift; |
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
58 |
$cnr = 1; |
1 | 59 |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
60 |
do { # split data |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
61 |
sysseek(WBRF,($first_ens-2)*$ens_len,0) || # begin next block of ensembles |
1 | 62 |
die("$WBRcfn: $!"); |
63 |
$last_ens++ unless defined($ARGV[0]); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
64 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
65 |
sysread(WBRF,$ids,2) || die("$WBRcfn: file truncated"); # read 1st ensemble & ensure DSID is 0x7f |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
66 |
$ids = pack('H4','7f7f'); # reset DSID |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
67 |
sysread(WBRF,$febuf,$ens_len-4) == $ens_len-4 || |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
68 |
die("$WBRcfn: file truncated"); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
69 |
sysread(WBRF,$csum,2) || die("$WBRcfn: file truncated"); |
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
70 |
$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
|
71 |
|
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
72 |
$nBytes = ($last_ens-$first_ens) * $ens_len; # read remaining ensembles in block |
1 | 73 |
sysread(WBRF,$buf,$nBytes) == $nBytes || |
74 |
die("$WBRcfn: file truncated"); |
|
75 |
||
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
76 |
if ($last_ens-$first_ens+1 >= $opt_m) { # write output only if sufficient # of ensembles |
21 | 77 |
$fn = sprintf($opt_o,$opt_f+$cnr++); |
18 | 78 |
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
|
79 |
syswrite(F,$ids.$febuf.$csum.$buf,$nBytes+$ens_len) == $nBytes+$ens_len || |
18 | 80 |
die("$fn: $!\n"); |
81 |
close(F); |
|
36
515b06dae59c
version at end of ECOGIG EN586 cruise
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
23
diff
changeset
|
82 |
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
|
83 |
$last_ens-$first_ens+1,$nBytes+$ens_len); |
18 | 84 |
} |
1 | 85 |
|
86 |
$first_ens = $last_ens+1; |
|
87 |
$last_ens = $ARGV[0]; shift; |
|
88 |
} while defined($last_ens); |
|
89 |
||
90 |
exit(0); |
|
91 |
||
92 |