Diff of /inst/op_fwd.m [000000] .. [d89be7]  Maximize  Restore

Switch to side-by-side view

--- a
+++ b/inst/op_fwd.m
@@ -0,0 +1,148 @@
+## Copyright (C) 2009, José Luis García Pallero, <jgpallero@gmail.com>
+##
+## This file is part of OctPROJ.
+##
+## OctPROJ 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 Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File}{[@var{X},@var{Y}] =}op_fwd(@var{lon},@var{lat},@var{params})
+##
+## This function projects geodetic coordinates into cartesian projected
+## coordinates in the defined cartographic projection using the PROJ.4 function
+## pj_fwd().
+##
+## @var{lon} is a scalar or a vector containing the geodetic longitude, in
+## radians.
+## @var{lat} is a scalar or a vector containing the geodetic latitude, in
+## radians.
+## @var{params} is a text string containing the projection parameters in PROJ.4
+## format.
+##
+## @var{X} is a scalar or a column vector containing the X projected
+## coordinates.
+## @var{Y} is a scalar or a column vector containing the Y projected
+## coordinates.
+##
+## If a projection error occurs, the resultant coordinates for the affected
+## points have both Inf value and a warning message is emitted (one for each
+## erroneous point).
+## @seealso{op_inv}
+## @end deftypefn
+
+
+
+
+function [X,Y] = op_fwd(lon,lat,params)
+
+try
+    functionName = 'op_fwd';
+    argumentNumber = 3;
+
+%*******************************************************************************
+%NUMBER OF INPUT ARGUMENTS CHECKING
+%*******************************************************************************
+
+    %number of input arguments checking
+    if nargin~=argumentNumber
+        error(['Incorrect number of input arguments (%d)\n\t         ',...
+               'Correct number of input arguments = %d'],...
+              nargin,argumentNumber);
+    end
+
+%*******************************************************************************
+%INPUT ARGUMENTS CHECKING
+%*******************************************************************************
+
+    %lon must be a column vector
+    if ismatrix(lon)
+        %lon dimensions
+        [row,col] = size(lon);
+        %checking dimensions
+        if (row>1)&(col>1)
+            %error message
+            error('The first input argument must be scalar or column vector');
+        elseif col>1
+            %convert into column vector, if it was a row vector
+            lon = lon(:);
+        end
+    else
+        error('The first input argument is not numeric');
+    end
+    %lat must be a column vector
+    if ismatrix(lat)
+        %lat dimensions
+        [row,col] = size(lat);
+        %checking dimensions
+        if (row>1)&(col>1)
+            %error message
+            error('The second input argument must be scalar or column vector');
+        elseif col>1
+            %convert into column vector, if it was a row vector
+            lat = lat(:);
+        end
+    else
+        error('The second input argument is not numeric');
+    end
+    %params must be a text string
+    if ~ischar(params)
+        error('The third input argument is not a text string');
+    end
+catch
+    %error message
+    error('\n\tIn function %s:\n\t -%s ',functionName,lasterr);
+end
+
+%*******************************************************************************
+%COMPUTATION
+%*******************************************************************************
+
+try
+    %calling oct function
+    [X,Y] = _op_fwd(lon,lat,params);
+catch
+    %error message
+    error('\n\tIn function %s:\n\tIn function %s ',functionName,lasterr);
+end
+
+
+
+
+%*****END OF FUNCION*****
+
+
+
+
+%*****FUNCTION TESTS*****
+
+
+
+
+% %!test
+% %!  [x,y,z]=op_params(pi/5,pi/3,1000,6378388,1/297);
+% %!  assert(x,2587045.81927379,1e-5)
+% %!  assert(y,1879598.80960088,1e-5)
+% %!  assert(z,5501461.60635409,1e-5)
+%!error(op_fwd)
+%!error(op_fwd(1,2,3,4))
+%!error(op_fwd('string',2))
+%!error(op_fwd(1,'string',3))
+%!error(op_fwd(1,2,3))
+%!error(op_fwd([1 1;2 2],2,'+proj=poly +ellps=clrk66 +lon_0=90W'))
+%!error(op_fwd(1,[2 2;3 3],'+proj=poly +ellps=clrk66 +lon_0=90W'))
+
+
+
+
+%*****END OF TESTS*****