|
1 #!/usr/bin/perl |
|
2 #====================================================================== |
|
3 # S P L I T R D I |
|
4 # doc: Sat Aug 21 22:20:27 2010 |
|
5 # dlm: Sun Sep 14 17:47:48 2014 |
|
6 # (c) 2010 A.M. Thurnherr |
|
7 # uE-Info: 54 0 NIL 0 0 72 2 2 4 NIL ofnI |
|
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 |
|
14 # Jun 24, 2011: - replaced -b, -n by -o |
|
15 # Feb 13, 2014: - updated doc |
|
16 # Mar 19, 2014: - added -s)kip small files |
|
17 # Sep 14, 2014: - added -f)irst |
|
18 |
|
19 # NOTES: |
|
20 # - it is assumed that the input file begins with ensemble #1 |
|
21 # - turning-point ensembles are written to preceding profile, |
|
22 # for compatibility with [yoyo] |
|
23 |
|
24 # FILE NAME CONVENTION: |
|
25 # - in order to assign individual yoyo casts numerical station numbers, |
|
26 # by default, the yoyo cast number is inserted after the station number |
|
27 |
|
28 # EXAMPLES: |
|
29 # splitRDI 017DL000.000 `mkProfile 017DL000.000 | yoyo -QFens -ut` |
|
30 |
|
31 $0 =~ m{(.*/)[^/]+}; |
|
32 require "$1RDI_BB_Read.pl"; |
|
33 use Getopt::Std; |
|
34 |
|
35 die("Usage: $0 " . |
|
36 "[-o)ut-file <fmt[e.g. 017%02dDL000.000]>] " . |
|
37 "[-f)irst <cast #>] " . |
|
38 "[require -m)in <ens> to produce output] " . |
|
39 "<RDI file> <ens> <ens[...]>\n") |
|
40 unless (&getopts('f:o:m:') && @ARGV>=3); |
|
41 |
|
42 $opt_o = substr($ARGV[0],0,3) # default output filename format |
|
43 . '%02d' |
|
44 . substr($ARGV[0],-9) |
|
45 unless defined($opt_o); |
|
46 |
|
47 $opt_m = 0 unless defined($opt_m); # default: produce tiny files as well |
|
48 |
|
49 readHeader($ARGV[0],\%hdr); shift; # get length of ensembles |
|
50 $ens_len = $hdr{ENSEMBLE_BYTES} + 2; |
|
51 |
|
52 $first_ens = $ARGV[0]+1; shift; # initialize loop |
|
53 $last_ens = $ARGV[0]; shift; |
|
54 $cnr = 0; |
|
55 |
|
56 do { # split data |
|
57 sysseek(WBRF,($first_ens-2)*$ens_len,0) || # read next block of data |
|
58 die("$WBRcfn: $!"); |
|
59 $last_ens++ unless defined($ARGV[0]); |
|
60 $nBytes = ($last_ens-$first_ens+1) * $ens_len; |
|
61 sysread(WBRF,$buf,$nBytes) == $nBytes || |
|
62 die("$WBRcfn: file truncated"); |
|
63 |
|
64 if ($last_ens-$first_ens+1 > $opt_m) { # produce file only if sufficient # of ensembles |
|
65 $fn = sprintf($opt_o,$opt_f+$cnr++); |
|
66 open(F,">$fn") || die("$fn: $!\n"); |
|
67 syswrite(F,$buf,$nBytes) == $nBytes || |
|
68 die("$fn: $!\n"); |
|
69 close(F); |
|
70 printf(STDERR "$fn: %d ensembles ($nBytes bytes)\n",$last_ens-$first_ens+1); |
|
71 } |
|
72 |
|
73 $first_ens = $last_ens+1; |
|
74 $last_ens = $ARGV[0]; shift; |
|
75 } while defined($last_ens); |
|
76 |
|
77 exit(0); |
|
78 |
|
79 |