splitRDI
changeset 21 0b5bbe60131c
parent 18 bb7bb9f83db9
equal deleted inserted replaced
19:e23a5fd2923a 21:0b5bbe60131c
     1 #!/usr/bin/perl
     1 #!/usr/bin/perl
     2 #======================================================================
     2 #======================================================================
     3 #                    S P L I T R D I 
     3 #                    S P L I T R D I 
     4 #                    doc: Sat Aug 21 22:20:27 2010
     4 #                    doc: Sat Aug 21 22:20:27 2010
     5 #                    dlm: Wed Mar 19 16:35:45 2014
     5 #                    dlm: Sun Sep 14 17:47:48 2014
     6 #                    (c) 2010 A.M. Thurnherr
     6 #                    (c) 2010 A.M. Thurnherr
     7 #                    uE-Info: 36 43 NIL 0 0 72 2 2 4 NIL ofnI
     7 #                    uE-Info: 54 0 NIL 0 0 72 2 2 4 NIL ofnI
     8 #======================================================================
     8 #======================================================================
     9 
     9 
    10 # split RDI files based on list of ensemble numbers (e.g. from yoyo -t)
    10 # split RDI files based on list of ensemble numbers (e.g. from yoyo -t)
    11 
    11 
    12 # HISTORY:
    12 # HISTORY:
    13 #	Aug 21, 2010: - created
    13 #	Aug 21, 2010: - created
    14 #	Jun 24, 2011: - replaced -b, -n by -o
    14 #	Jun 24, 2011: - replaced -b, -n by -o
    15 #   Feb 13, 2014: - updated doc
    15 #   Feb 13, 2014: - updated doc
    16 #	Mar 19, 2014: - added -s)kip small files
    16 #	Mar 19, 2014: - added -s)kip small files
       
    17 #	Sep 14, 2014: - added -f)irst 
    17 
    18 
    18 # NOTES:
    19 # NOTES:
    19 #   - it is assumed that the input file begins with ensemble #1
    20 #   - it is assumed that the input file begins with ensemble #1
    20 #   - turning-point ensembles are written to preceding profile,
    21 #   - turning-point ensembles are written to preceding profile,
    21 #     for compatibility with [yoyo]
    22 #     for compatibility with [yoyo]
    31 require "$1RDI_BB_Read.pl";
    32 require "$1RDI_BB_Read.pl";
    32 use Getopt::Std;
    33 use Getopt::Std;
    33 
    34 
    34 die("Usage: $0 " .
    35 die("Usage: $0 " .
    35 	"[-o)ut-file <fmt[e.g. 017%02dDL000.000]>] " .
    36 	"[-o)ut-file <fmt[e.g. 017%02dDL000.000]>] " .
       
    37 	"[-f)irst <cast #>] " .
    36 	"[require -m)in <ens> to produce output] " .
    38 	"[require -m)in <ens> to produce output] " .
    37 	"<RDI file> <ens> <ens[...]>\n")
    39 	"<RDI file> <ens> <ens[...]>\n")
    38 		unless (&getopts('o:m:') && @ARGV>=3);
    40 		unless (&getopts('f:o:m:') && @ARGV>=3);
    39 
    41 
    40 $opt_o = substr($ARGV[0],0,3)					# default output filename format
    42 $opt_o = substr($ARGV[0],0,3)					# default output filename format
    41 		 . '%02d'
    43 		 . '%02d'
    42 		 . substr($ARGV[0],-9)
    44 		 . substr($ARGV[0],-9)
    43 			unless defined($opt_o);
    45 			unless defined($opt_o);
    58 	$nBytes = ($last_ens-$first_ens+1) * $ens_len;
    60 	$nBytes = ($last_ens-$first_ens+1) * $ens_len;
    59 	sysread(WBRF,$buf,$nBytes) == $nBytes ||
    61 	sysread(WBRF,$buf,$nBytes) == $nBytes ||
    60 		die("$WBRcfn: file truncated");
    62 		die("$WBRcfn: file truncated");
    61 
    63 
    62 	if ($last_ens-$first_ens+1 > $opt_m) {		# produce file only if sufficient # of ensembles
    64 	if ($last_ens-$first_ens+1 > $opt_m) {		# produce file only if sufficient # of ensembles
    63 		$fn = sprintf($opt_o,$cnr++);
    65 		$fn = sprintf($opt_o,$opt_f+$cnr++);
    64 		open(F,">$fn") || die("$fn: $!\n");
    66 		open(F,">$fn") || die("$fn: $!\n");
    65 		syswrite(F,$buf,$nBytes) == $nBytes ||
    67 		syswrite(F,$buf,$nBytes) == $nBytes ||
    66 			die("$fn: $!\n");
    68 			die("$fn: $!\n");
    67 		close(F);
    69 		close(F);
    68 	    printf(STDERR "$fn: %d ensembles ($nBytes bytes)\n",$last_ens-$first_ens+1);
    70 	    printf(STDERR "$fn: %d ensembles ($nBytes bytes)\n",$last_ens-$first_ens+1);