From octave-sources-request at bevo dot che dot wisc dot edu Mon Jan 27 14:10:47 2003 Subject: area2metric.m From: Stefan Burger To: octave-sources at bevo dot che dot wisc dot edu Date: Mon, 27 Jan 2003 07:44:36 -0600 --------------Boundary-00=_MVKDRRGN69BYT7G94Y70 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable --------------Boundary-00=_MVKDRRGN69BYT7G94Y70 Content-Type: text/plain; charset="us-ascii"; name="area2metric.m" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="area2metric.m" ## Copyright (C) 2003 Stefan Burger ## ## This file is part of Octave. ## ## Octave 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 2, or (at your option) any ## later version. ## ## Octave 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 Octave; see the file COPYING. If not, write to the Free ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. ## -*- texinfo -*- ## at deftypefn {Function File} {} area2metric (@var{unitstr}, @var{val}, @var{metstr}, ) ## Converts metric measures to non-SI or US area measures . ## Input: ## at var{val} ; Value to be converted, ## at var{unitstr} : unit to be converted to, ## at var{metstr} : unit to be converted from, optional, defaults to 'm', meters. ## ## Currently, the following units are supported: ## in2, squareinch, ft2, squarefoot, USsurvey-squarefoot, yd2, squareyard, mi2, squaremile, ## USsurvey-squaremile, acre ## ## Metric units: ## km2, m2, dm2, cm2, mm2, um2, nm2. ## ## References: ## See NIST Guide to SI units, Appendix B8, ## at www.nist.gov/Pubs/SP811/appenB8.html ## ## at end deftypefn ## at seealso{metric2area, len2metric and vol2metric} ## Author: Stefan Burger ## Description: converts area values to SI (metric) area units. function v = area2metric (unitstr, val, metstr) if (nargin ==1) val = 1.0; metstr = "m2"; %% if no value given, default to one. %% if no metric string given, default to meters. %% reason: usage val * len2metric("inch") endif if (nargin == 2) metstr = "m2"; %% if not specified, default to meters elseif (nargin < 1 || nargin > 3 ) usage("area2metric(unitstr [, val, metstr])"); endif if (! (isstr(unitstr) && isstr(metstr))) usage("area2metric(unitstr [, val, metstr])"); endif switch (unitstr) %% determine conversion value from input unit %% to standard meters squared case {"in2", "square-inch"} fv = ( len2metric("inch") )^2; case {"ft2", "square-foot"} fv = ( len2metric("foot") )^2; case {"USsurvey-squarefoot"} fv = ( len2metric("USsurvey-foot") )^2; case {"mi2", "square-mile"} fv = ( len2metric("mile") )^2; case {"USsurvey-squaremile"} fv = ( len2metric("USsurvey-mile") )^2; case {"acre"} fv = 160 * ( len2metric("rod") )^2; %% or, alternatively, %% fv = 43560* (len2metric("USsurvey-foot", 1, m) )^2; %% 1 acre = 160 rod squared = 160 * 272.25 USsurveyfoot ^2 case {"circular-mil"} fv = ( len2metric("inch") / 2000 ) ^ 2 *pi; %% area of circle with diameter 1 mil %% thus, 1 mil = inch/1000, %% radius = diameter / 2, %% area = radius ^ 2 * PI. case {"squareyard"; "yd2"} fv = len2metric("yard",1,"m")^2; case {"section"} fv = (len2metric("USsurvey-mile")) ^2; %% basically another name for US-survey-square-mile. case {"township"} fv = 36 * (len2metric("USsurvey-mile")) ^2; %% 1 township equals 36 sections. case {"homestead"} fv = 160 * (160 * ( len2metric("rod") )^2); %% 1 homestead equals 160 acre. %% Area of land granted by the 1862 Homestead Act of the United States Congress %% %% The following units are not-so-common units based on the metric system. case {"are"} fv = 1E2; %% 1 are equals 100 square meters case {"hectare"} fv = 1E4; %% 1 hectare equals 100 are, equals 1/100 kilometer squared. %% %% also allow for metric units to be converted from. case {"m2"} %% meter squared fv = 1; case {"km2"} %% kilometer squared fv = 1E6; case {"dm2"} %% decimeter squared fv = 01E-2; case {"cm2"} %% centimeter squared fv = 1E-4; case {"mm2"} %% millimeter squared fv = 1E-6; case {"um2"} %% micrometer squared fv = 1E-12; case {"nm2"} %% nanometer squared fv = 1E-18; otherwise disp (unitstr) error ("area2metric: unrecognized option"); endswitch switch (metstr) %% determine conversion value from standard meters squared %% to unit desired. case {"m2"} %% meter squared fm = 1; case {"km2"} %% kilometer squared fm = 1E-6; case {"dm2"} %% decimeter squared fm = 1E2; case {"cm2"} %% centimeter squared fm = 1E4; case {"mm2"} %% millimeter squared fm = 1E6; case {"um2"} %% micrometer squared fm = 1E12; case {"nm2"} %% nanometer squared fm = 1E18; otherwise disp (metstr) error("area2metric: unrecognized option"); endswitch v = val * fv * fm; endfunction --------------Boundary-00=_MVKDRRGN69BYT7G94Y70--