Oct_11_2011/time_series.pl
author A.M. Thurnherr <ant@ldeo.columbia.edu>
Thu, 21 Nov 2013 09:07:17 -0500
changeset 13 2788bf1bf1de
parent 3 9c021fdea1ff
permissions -rw-r--r--
after DIMES US5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     1
#======================================================================
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     2
#                    T I M E _ S E R I E S . P L 
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     3
#                    doc: Sun May 23 16:40:53 2010
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     4
#                    dlm: Tue Oct 11 14:08:55 2011
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     5
#                    (c) 2010 A.M. Thurnherr
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     6
#                    uE-Info: 17 69 NIL 0 0 72 2 2 4 NIL ofnI
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     7
#======================================================================
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     8
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
     9
# HISTORY:
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    10
#	May 23, 2010: - created from [perl-tools/RDI_Utils.pl]
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    11
#	Oct 20, 2010: - disabled max_gap profile-restarting code
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    12
#	Dec 17, 2010: - re-added {DEPTH} field to ensembles
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    13
#	Dec 18, 2010: - max gap re-enabled
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    14
#	Dec 20, 2010: - cosmetics
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    15
#	Jul  2, 2011: - tightened gap-detection code
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    16
#	Jul  4, 2011: - added support for $skip_ens
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    17
#	Oct 11, 2011: - BUG: {DEPTH} had not been set at start of profile
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    18
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    19
# NOTES:
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    20
#	- resulting DEPTH field based on integrated w without any sound speed correction
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    21
#	- single-ping ensembles assumed, i.e. no percent-good tests applied
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    22
#	- specified bin numbers are 1-relative
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    23
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    24
sub ref_lr_w($$$$)										# calc ref-layer vert vels
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    25
{
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    26
	my($dta,$ens,$rl_b0,$rl_b1) = @_;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    27
	my($i,@n,@bn,@v,@vel,@bv,@w);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    28
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    29
	for ($i=$rl_b0-1; $i<=$rl_b1-1; $i++) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    30
		if (defined($dta->{ENSEMBLE}[$ens]->{W}[$i])) {							# valid w
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    31
			$vel[2] += $dta->{ENSEMBLE}[$ens]->{W}[$i]; $n[2]++;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    32
			$vel[3] += $dta->{ENSEMBLE}[$ens]->{ERRVEL}[$i], $n[3]++ if defined($dta->{ENSEMBLE}[$ens]->{ERRVEL}[$i]);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    33
			push(@w,$dta->{ENSEMBLE}[$ens]->{W}[$i]); 							# for stderr test
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    34
		}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    35
	}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    36
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    37
	my($w) = $n[2] ? $vel[2]/$n[2] : undef;				# w uncertainty
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    38
	my($sumsq) = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    39
	for ($i=0; $i<=$#w; $i++) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    40
		$sumsq += ($w-$w[$i])**2;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    41
	}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    42
	my($stderr) = $n[2]>=2 ? sqrt($sumsq)/($n[2]-1) : undef;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    43
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    44
	if (defined($w)) {									# valid w
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    45
		$dta->{ENSEMBLE}[$ens]->{REFLR_W} = $w;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    46
		$dta->{ENSEMBLE}[$ens]->{REFLR_W_ERR} = $stderr;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    47
	}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    48
}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    49
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    50
#======================================================================
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    51
# ($firstgood,$lastgood,$atbottom,$w_gap_time) =
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    52
#	calcLADCPts($dta,$skip_ens,$lr_b0,$lr_b1,$min_corr,$max_e,$max_gap);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    53
#======================================================================
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    54
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    55
sub calcLADCPts($$$$)
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    56
{
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    57
	my($dta,$skip_ens,$rl_b0,$rl_b1,$max_gap) = @_;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    58
	my($firstgood,$lastgood,$atbottom,$w_gap_time,$max_depth);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    59
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    60
	for (my($depth)=0,my($e)=$skip_ens; $e<=$#{$dta->{ENSEMBLE}}; $e++) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    61
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    62
		ref_lr_w($dta,$e,$rl_b0,$rl_b1);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    63
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    64
		if (defined($firstgood)) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    65
			$dta->{ENSEMBLE}[$e]->{ELAPSED} =				# time since start
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    66
				$dta->{ENSEMBLE}[$e]->{UNIX_TIME} -
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    67
				$dta->{ENSEMBLE}[$firstgood]->{UNIX_TIME};
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    68
		} else {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    69
			if (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) {		# start of prof.
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    70
				$firstgood = $lastgood = $e;		    
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    71
				$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    72
				$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    73
			}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    74
			next;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    75
		}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    76
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    77
		unless (defined($dta->{ENSEMBLE}[$e]->{REFLR_W})) {				# gap
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    78
			$w_gap_time += $dta->{ENSEMBLE}[$e]->{UNIX_TIME} -
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    79
						   $dta->{ENSEMBLE}[$e-1]->{UNIX_TIME};
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    80
			next;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    81
		}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    82
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    83
		my($dt) = $dta->{ENSEMBLE}[$e]->{UNIX_TIME} -		# time step since
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    84
				  $dta->{ENSEMBLE}[$lastgood]->{UNIX_TIME}; # ... last good ens
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    85
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    86
		if ($dt > $max_gap) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    87
			if ($max_depth>50 && $depth<0.1*$max_depth) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    88
				warning(1,"long gap (%ds) near end of profile --- terminated at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    89
				last;				
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    90
            }
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    91
            if ($depth < 10) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    92
				warning(1,"long gap (%ds) near beginning of profile --- restarted at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}\n",$dt);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    93
				$firstgood = $lastgood = $e;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    94
				undef($atbottom); undef($max_depth);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    95
				$depth = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    96
				$dta->{ENSEMBLE}[$e]->{ELAPSED} = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    97
				$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    98
				$w_gap_time = 0;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
    99
				next;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   100
			}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   101
			if ($dta->{ENSEMBLE}[$e]->{ELAPSED} < 200) {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   102
				warning(1,"long gap (%ds) at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}, %ds into the profile\n",
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   103
					$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED});
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   104
			} else {
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   105
				warning(1,"long gap (%ds) at ensemble #$dta->{ENSEMBLE}[$e]->{NUMBER}, %.1fmin into the profile\n",
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   106
					$dt,$dta->{ENSEMBLE}[$e]->{ELAPSED}/60);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   107
			}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   108
		}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   109
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   110
		$depth += $dta->{ENSEMBLE}[$lastgood]->{REFLR_W} * $dt;			# integrate
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   111
		$dta->{ENSEMBLE}[$e]->{DEPTH} = $depth;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   112
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   113
		$atbottom = $e, $max_depth = $depth if ($depth > $max_depth); 
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   114
		$lastgood = $e;
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   115
	}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   116
	
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   117
	return ($firstgood,$lastgood,$atbottom,$w_gap_time);
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   118
}
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   119
9c021fdea1ff Before replacing command-line options by default variables.
A.M. Thurnherr <athurnherr@yahoo.com>
parents:
diff changeset
   120
1;