libvec.pl
changeset 29 f41d125405a6
parent 11 56799f01321a
child 30 1a1a12d5edc1
equal deleted inserted replaced
28:db6c3d13f8be 29:f41d125405a6
     1 #======================================================================
     1 #======================================================================
     2 #                    L I B V E C . P L 
     2 #                    L I B V E C . P L 
     3 #                    doc: Sat Mar 20 12:50:32 1999
     3 #                    doc: Sat Mar 20 12:50:32 1999
     4 #                    dlm: Sun Jul  6 15:33:50 2014
     4 #                    dlm: Fri Jul 29 15:26:45 2016
     5 #                    (c) 1999 A.M. Thurnherr
     5 #                    (c) 1999 A.M. Thurnherr
     6 #                    uE-Info: 150 24 NIL 0 0 70 2 2 4 NIL ofnI
     6 #                    uE-Info: 42 32 NIL 0 0 70 2 2 4 NIL ofnI
     7 #======================================================================
     7 #======================================================================
     8 
     8 
     9 # HISTORY:
     9 # HISTORY:
    10 #	Mar 20, 1999: - created for ANTS_2.1 (no more c-code)
    10 #	Mar 20, 1999: - created for ANTS_2.1 (no more c-code)
    11 #	May 27, 1999: - added polar/cartesian conversions
    11 #	May 27, 1999: - added polar/cartesian conversions
    34 #	Jun  5, 2012: - added &closestPointOnStraightLine()
    34 #	Jun  5, 2012: - added &closestPointOnStraightLine()
    35 #	Jun 11, 2012: - addeed $t output to &closestPointOnStraightLine()
    35 #	Jun 11, 2012: - addeed $t output to &closestPointOnStraightLine()
    36 #	Nov 27, 2013: - added &angle_pos(), mag_heading()
    36 #	Nov 27, 2013: - added &angle_pos(), mag_heading()
    37 #	Mar  3, 2014: - made deg(), rad() handle nans
    37 #	Mar  3, 2014: - made deg(), rad() handle nans
    38 #	Mar  4, 2014: - made some angle funs handle nans
    38 #	Mar  4, 2014: - made some angle funs handle nans
       
    39 #	Jul 29, 2016: - BUG: mag_heading was inconsistent with ADCP headings
       
    40 #						 (previous version only used for 2014 CLIVAR P06
       
    41 #						 processing with IMP data with confused coord
       
    42 #						 system)
    39 
    43 
    40 require "$ANTS/libPOSIX.pl";	# acos()
    44 require "$ANTS/libPOSIX.pl";	# acos()
    41 
    45 
    42 #----------------------------------------------------------------------
    46 #----------------------------------------------------------------------
    43 # &rad()							calc radians
    47 # &rad()							calc radians
   144 sub vel_v(@) { return &cartesian_y($_[0],90-$_[1]); }
   148 sub vel_v(@) { return &cartesian_y($_[0],90-$_[1]); }
   145 
   149 
   146 #----------------------------------------------------------------------
   150 #----------------------------------------------------------------------
   147 # magnetic heading from magnetometers
   151 # magnetic heading from magnetometers
   148 #	- atan2 handles all the singularities
   152 #	- atan2 handles all the singularities
   149 #	- without the minus, the heading turns the wrong way when comparing
   153 #	- the current version (7/29/2016) was verified with ECOGIG EN586
   150 #	  IMP and WH300 data
   154 #	  data, where the IMP Mk.3 rev 2 (i.e. with coordinate mapping
       
   155 #	  in the sensor board) on profiles 1-15 was accidentally installed
       
   156 #	  in a consistent orientation with the DL (very similar pitch/roll
       
   157 #	  measured by both instruments) => heading is directly comparable
   151 #----------------------------------------------------------------------
   158 #----------------------------------------------------------------------
   152 
   159 
   153 sub mag_heading($$)
   160 sub mag_heading($$)
   154 {
   161 {
   155     return angle_pos(deg(-atan2($_[0],$_[1])));
   162 #    return angle_pos(deg(-atan2($_[0],$_[1])));	# used for 2014 CLIVAR P06 IMP processing with confused coord systems
       
   163 	return angle_pos(deg(atan2($_[1],$_[0])));
   156 }
   164 }
   157 
   165 
   158 #----------------------------------------------------------------------
   166 #----------------------------------------------------------------------
   159 # &angle(val)
   167 # &angle(val)
   160 #	return angle in range [-180,180]
   168 #	return angle in range [-180,180]