# HG changeset patch
# User Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
# Date 1393025104 -3600
#      Sat Feb 22 00:25:04 2014 +0100
# Node ID 3706c629872165a9f835ad97f73c98455f8a3a1b
# Parent  92dd0071c58db3e8b15136b9b30730d16f8d017d
Conversion between units of length.

* km2sm.m, km2nm.m, nm2sm.m, nm2km.m, sm2km.m, sm2nm.m: New functions with appropriate tests.

diff -r 92dd0071c58d -r 3706c6298721 inst/km2nm.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/km2nm.m	Sat Feb 22 00:25:04 2014 +0100
@@ -0,0 +1,34 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} km2nm (@var{km})
+## Convert kilometers into nautical miles.
+##
+## @seealso{km2sm, nm2km, nm2sm, sm2km, sm2nm}
+## @end deftypefn
+
+## Author: Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+
+function nm = km2nm (km)
+  if (nargin != 1)
+    print_usage ();
+  endif
+  persistent ratio = unitsratio ("nautical mile", "kilometer");
+  nm = km * ratio;
+endfunction
+
+%!assert (km2nm(1.852),1)
diff -r 92dd0071c58d -r 3706c6298721 inst/km2sm.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/km2sm.m	Sat Feb 22 00:25:04 2014 +0100
@@ -0,0 +1,34 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} km2sm (@var{km})
+## Convert kilometers into U.S. survey miles (statute miles).
+##
+## @seealso{km2nm, nm2km, nm2sm, sm2km, sm2nm}
+## @end deftypefn
+
+## Author: Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+
+function sm = km2sm (km)
+  if (nargin != 1)
+    print_usage ();
+  endif
+  persistent ratio = unitsratio ("statute mile", "kilometer");
+  sm = km * ratio;
+endfunction
+
+%!assert (km2sm(6336000),3937000)
diff -r 92dd0071c58d -r 3706c6298721 inst/nm2km.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/nm2km.m	Sat Feb 22 00:25:04 2014 +0100
@@ -0,0 +1,34 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} nm2km (@var{nm})
+## Convert nautical miles into kilometers.
+##
+## @seealso{km2nm, km2sm, nm2sm, sm2km, sm2nm}
+## @end deftypefn
+
+## Author: Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+
+function km = nm2km (nm)
+  if (nargin != 1)
+    print_usage ();
+  endif
+  persistent ratio = unitsratio ("kilometer", "nautical mile");
+  km = nm * ratio;
+endfunction
+
+%!assert (nm2km(1),1.852)
diff -r 92dd0071c58d -r 3706c6298721 inst/nm2sm.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/nm2sm.m	Sat Feb 22 00:25:04 2014 +0100
@@ -0,0 +1,34 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} nm2sm (@var{nm})
+## Convert nautical miles into U.S. survey miles (statute miles).
+##
+## @seealso{km2nm, km2sm, nm2km, sm2km, sm2nm}
+## @end deftypefn
+
+## Author: Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+
+function sm = nm2sm (nm)
+  if (nargin != 1)
+    print_usage ();
+  endif
+  persistent ratio = unitsratio ("statute mile", "nautical mile");
+  sm = nm * ratio;
+endfunction
+
+%!assert (nm2sm(50292),57875)
diff -r 92dd0071c58d -r 3706c6298721 inst/sm2km.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/sm2km.m	Sat Feb 22 00:25:04 2014 +0100
@@ -0,0 +1,34 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} sm2km (@var{sm})
+## Convert U.S. survey miles (statute miles) into kilometers.
+##
+## @seealso{km2nm, km2sm, nm2km, nm2sm, sm2nm}
+## @end deftypefn
+
+## Author: Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+
+function km = sm2km (sm)
+  if (nargin != 1)
+    print_usage ();
+  endif
+  persistent ratio = unitsratio ("kilometer", "statute mile");
+  km = sm * ratio;
+endfunction
+
+%!assert (sm2km(3937000),6336000)
diff -r 92dd0071c58d -r 3706c6298721 inst/sm2nm.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/inst/sm2nm.m	Sat Feb 22 00:25:04 2014 +0100
@@ -0,0 +1,34 @@
+## Copyright (C) 2014 Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+##
+## This program is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} sm2nm (@var{sm})
+## Convert U.S. survey miles (statute miles) into nautical miles.
+##
+## @seealso{km2nm, km2sm, nm2km, nm2sm, sm2km}
+## @end deftypefn
+
+## Author: Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
+
+function nm = sm2nm (sm)
+  if (nargin != 1)
+    print_usage ();
+  endif
+  persistent ratio = unitsratio ("nautical mile", "statute mile");
+  nm = sm * ratio;
+endfunction
+
+%!assert (sm2nm(57875),50292)
