before Hamburg
authorA.M. Thurnherr <athurnherr@yahoo.com>
Sat, 18 Nov 2017 18:55:17 -0500
changeset 32 4c6434bb5124
parent 31 a93075e0b008
child 33 f891ea33a728
before Hamburg
antsio.pl
antsusage.pl
libALEC.pl
librand.pl
libvec.pl
--- a/antsio.pl
+++ b/antsio.pl
@@ -2,9 +2,9 @@
 #======================================================================
 #                    A N T S I O . P L 
 #                    doc: Fri Jun 19 19:22:51 1998
-#                    dlm: Fri Mar 10 09:53:21 2017
+#                    dlm: Wed Apr  5 13:45:32 2017
 #                    (c) 1998 A.M. Thurnherr
-#                    uE-Info: 214 71 NIL 0 0 70 2 2 4 NIL ofnI
+#                    uE-Info: 215 83 NIL 0 0 70 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -211,7 +211,8 @@
 #						 otherwise, dependencies are not inherited => presumably, Sep 27 bug fix has been
 #						 reversed
 #	Sep 13, 2016: - modified &antsAddParams to make more flexible
-#	Mar 10, 2017: - BUT: antsCheckDeps() used ctime instead of mtime!!!
+#	Mar 10, 2017: - BUG: antsCheckDeps() used ctime instead of mtime!!!
+#	Apr  5, 2017: - BUG: stale file mtime dependency info was not printed correctly
 
 # GENERAL NOTES:
 #	- %P was named without an ants-prefix because associative arrays
@@ -309,7 +310,7 @@
 	  for (my($d)=0; $d<=$#antsDeps; $d++) {
 		  @stat = stat($antsDeps[$d]);
 		  if (@stat) {
-			  croak("$0: <$infile> ($mtime) is stale with respect to <$antsDeps[$d]> ($stat[$mtime])\n")
+			  croak("$0: <$infile> ($mtime) is stale with respect to <$antsDeps[$d]> ($stat[$mtimef])\n")
 				  unless ($stat[$mtimef] <= $mtime);
 		  } elsif (!$warned) {
 			  &antsInfo("WARNING: dependency $antsDeps[$d] (&, possibly, others) not found");
--- a/antsusage.pl
+++ b/antsusage.pl
@@ -2,9 +2,9 @@
 #======================================================================
 #                    A N T S U S A G E . P L 
 #                    doc: Fri Jun 19 13:43:05 1998
-#                    dlm: Wed Aug 24 15:06:44 2016
+#                    dlm: Wed Aug 30 16:21:35 2017
 #                    (c) 1998 A.M. Thurnherr
-#                    uE-Info: 163 46 NIL 0 0 70 2 2 4 NIL ofnI
+#                    uE-Info: 164 80 NIL 0 0 70 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -161,6 +161,7 @@
 #	May 15, 2015: - changed (()) semantics to expand only to existing files
 #	Aug 24, 2016: - removed -ve number heuristics (unshifting a -- under certain conditions),
 #				  	which I believe is ancient
+#	Aug 30, 2017: - BUG: new (()) semantics did not work for single-value ranges
 
 # NOTES:
 #	- ksh expands {}-arguments with commas in them!!! Use + instead
@@ -387,7 +388,7 @@
 	                    }
 	                }
 				} else {
-					push(@exp,"$pref$_$suff");
+					push(@exp,"$pref$_$suff") if (-f "$pref$_$suff");
 	            }
 	        }
 			close(F);
new file mode 100644
--- /dev/null
+++ b/libALEC.pl
@@ -0,0 +1,78 @@
+#======================================================================
+#                    . . / L I B / L I B A L E C . P L 
+#                    doc: Wed Jun  1 20:38:19 2011
+#                    dlm: Thu Nov 16 09:20:00 2017
+#                    (c) 2011 A.M. Thurnherr
+#                    uE-Info: 36 30 NIL 0 0 70 2 2 4 NIL ofnI
+#======================================================================
+
+# HISTORY:
+#	Nov 15, 2017: - created
+
+require "$ANTS/libvec.pl";
+require "$ANTS/libfuns.pl";
+
+#----------------------------------------------------------------------
+# User Routines
+#----------------------------------------------------------------------
+
+sub ALEC_u($$$$$$$)
+{
+    my($vx,$vy,$alpha,$compA,$compB,$beta,$magdec) =
+		&antsFunUsage(7,'fffffff','<vx[cm/s]> <vy[cm/s]> <alpha> <compA> <compB> <beta>',@_);
+
+	my($c) = ALEC_vel_speed($vx,$vy,$alpha);
+	my($d) = ALEC_vel_dir($compA,$compB,$beta,$vx,$vy);
+	return vel_u($c,$d-$magdec);
+}
+
+sub ALEC_v($$$$$$$)
+{
+    my($vx,$vy,$alpha,$compA,$compB,$beta,$magdec) =
+		&antsFunUsage(7,'fffffff','<vx[cm/s]> <vy[cm/s]> <alpha> <compA> <compB> <beta>',@_);
+
+	my($c) = ALEC_vel_speed($vx,$vy,$alpha);
+	my($d) = ALEC_vel_dir($compA,$compB,$beta,$vx,$vy);
+	return vel_v($c,$d-$magdec);
+}
+
+#------------------------------------------------------------------------------
+# Routines mostly as per ALEC manual
+#		- weird atan corrections cause data discontinuities
+#			=> removed
+#		- routines verified with first PITTA time series
+# 	ALEC_vel_speed(vx,vy,alpha)
+#	ALEC_heading(compA,compB,beta)
+# 	ALEC_vel_instrument_dir(vx,vy)
+# 	ALEC_vel_dir(compA,compB,beta,vx,vy)
+#------------------------------------------------------------------------------
+
+sub ALEC_vel_speed(@)
+{
+    my($vx,$vy,$alpha) = &antsFunUsage(3,'fff','<vx[cm/s]> <vy[cm/s]> <alpha>',@_);
+	my($ssq) = ($vx**2 + $vy**2);
+	return inf unless ($ssq > 1e-6);
+	return (1 + $alpha*(4*$vx**2*$vy**2)/($ssq**2)) * sqrt($ssq);
+}
+
+sub ALEC_heading(@)
+{
+    my($compA,$compB,$beta) =
+        &antsFunUsage(3,'fff','<compass output A> <compass output B> <beta>',@_);
+    return angle_pos(deg(atan2($compA,$compB)) + $beta);
+}
+
+sub ALEC_vel_instrument_dir($$)
+{
+    my($vx,$vy) = &antsFunUsage(2,'ff','<vx[cm/s]> <vy[cm/s]>',@_);
+	return deg(atan2($vx,$vy));
+}
+
+sub ALEC_vel_dir($$$$$)
+{
+    my($compA,$compB,$beta,$vx,$vy) =
+        &antsFunUsage(5,'fffff','<compass output A> <compass output B> <beta> <vx[cm/s]> <vy[cm/s]>',@_);
+    return ALEC_heading($compA,$compB,$beta) + ALEC_vel_instrument_dir($vx,$vy);
+}
+
+1;
--- a/librand.pl
+++ b/librand.pl
@@ -1,17 +1,48 @@
 #======================================================================
 #                    L I B R A N D . P L 
 #                    doc: Thu Nov 19 14:27:19 2015
-#                    dlm: Tue Mar  8 15:50:35 2016
+#                    dlm: Wed Sep  6 10:18:42 2017
 #                    (c) 2015 A.M. Thurnherr
-#                    uE-Info: 10 27 NIL 0 0 72 2 2 4 NIL ofnI
+#                    uE-Info: 17 61 NIL 0 0 70 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
 #	Nov 19, 2015: - created
+#	Sep  6, 2017: - finally implemented gauss_rand()
 
-sub gauss_rand($$)
+#----------------------------------------------------------------------------------------------------
+# From info found at [http://www.design.caltech.edu/erik/Misc/Gaussian.html]
+#
+# verified with:
+#	plot '<Cat -Lrand -f =1,1,1e5 -F r=gauss_rand() | Hist  r
+#----------------------------------------------------------------------------------------------------
+
+{ my($cached);	# NB: cached values is normalized
+
+sub gauss_rand(@)
 {
-	my($mu,$sigma) = &antsFunUsage(2,'ff','mu, sigma',@_);
+	my($mu,$sigma) = &antsFunUsage(-1,'ff','[mu[,sigma]]',@_)
+		if (@_);
+	$sigma = 1 unless defined($sigma);
+	$mu	   = 0 unless defined($mu);
+
+	if (defined($cached)) {
+		my($Y) = $cached * $sigma + $mu;
+		undef($cached);
+		return $Y;
+	}
+
+	my($X1,$X2,,$w);
+	do {
+		$X1 = 2*rand() - 1;
+		$X2 = 2*rand() - 1;
+		$w  = $X1**2 + $X2**2;
+	} while ($w >= 1);
+	$w = sqrt((-2 * log($w)) / $w);
+	my($cached) = $X2 * $w;	
+	return $X1 * $w * $sigma + $mu;
+}
+
 }
 
 #----------------------------------------------------------------------------------------------------
--- a/libvec.pl
+++ b/libvec.pl
@@ -1,9 +1,9 @@
 #======================================================================
-#                    L I B V E C . P L 
+#                    . . / L I B / L I B V E C . P L 
 #                    doc: Sat Mar 20 12:50:32 1999
-#                    dlm: Sun Aug  7 22:06:57 2016
+#                    dlm: Wed Nov 15 18:30:55 2017
 #                    (c) 1999 A.M. Thurnherr
-#                    uE-Info: 137 37 NIL 0 0 70 2 2 4 NIL ofnI
+#                    uE-Info: 44 70 NIL 0 0 70 2 2 4 NIL ofnI
 #======================================================================
 
 # HISTORY:
@@ -41,6 +41,7 @@
 #						 processing with IMP data with confused coord
 #						 system)
 #	Aug  7, 2016: - made vel_u and vel_v deal with nans
+#	Nov 15, 2017: - re-enabled usage-message (of sorts) for vel_u only
 
 require "$ANTS/libPOSIX.pl";	# acos()
 
@@ -139,7 +140,10 @@
 	return $r * cos($PI*$phi/180);
 }
 
-sub vel_u(@) { return &cartesian_x($_[0],90-$_[1]); }
+sub vel_u(@) {
+	if (@_) { return &cartesian_x($_[0],90-$_[1]); }
+	else 	{ return &cartesian_x(); }
+}
 
 sub cartesian_y(@)
 {