Home > fvcom_prepro > example_my_project.m

example_my_project

PURPOSE

function [out_east,out_north] = my_project(in_east,in_north,direction)

SYNOPSIS

This is a script file.

DESCRIPTION

`function [out_east,out_north] = my_project(in_east,in_north,direction)`

CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

SOURCE CODE

```0001 %function [out_east,out_north] = my_project(in_east,in_north,direction)
0002
0003 % Sample user-defined projection and inverse projection of (lon,lat) to (x,y)
0004 % Copy to my_project (not a member of the toolbox) and modify to suite you
0005 %
0006 % function [out_east,out_north] = my_project(in_east,in_north,direction)
0007 %
0008 % DESCRIPTION:
0009 %    Define projections between geographical and Euclidean coordinates
0010 %
0011 % INPUT:
0012 %   in_east   = 1D vector containing longitude (forward) x (reverse)
0013 %   in_north  = 1D vector containing latitude  (forward) y (reverse)
0014 %   direction = ['forward' ;  'inverse']
0015 %
0016 % OUTPUT:
0017 %   (lon,lat) or (x,y) depending on choice of forward or reverse projection
0018 %
0019 % EXAMPLE USAGE
0020 %    [lon,lat] = my_project(x,y,'reverse')
0021 %
0022 % Author(s):
0023 %    Geoff Cowles (University of Massachusetts Dartmouth)
0024 %
0025 % Revision history
0026 %
0027 %==============================================================================
0028
0029 %subname = 'my_project';
0030 %fprintf('\n')
0031 %fprintf(['begin : ' subname '\n'])
0032
0033 %------------------------------------------------------------------------------
0034 % Parse input arguments
0035 %------------------------------------------------------------------------------
0036
0037 ProjectDirection = 'forward';
0038
0039 if(direction == 'forward')
0040     ProjectDirection = 'forward';
0041         lon = in_east;
0042         lat = in_north;
0043 else
0044     ProjectDirection = 'inverse';
0045         x = in_east;
0046         y = in_north;
0047 end;
0048
0049
0050
0051 %------------------------------------------------------------------------------
0052 % Perform the projection:  USER DEFINED
0053 % Example:  project/inverse project to state plane 1802
0054 %------------------------------------------------------------------------------
0055
0056 %if(ProjectDirection == 'forward')
0057 %    fprintf('Projecting from (lon,lat) to (x,y)\n');
0058 %    [x,y] = sp_proj('1802','forward',lon,lat,'m');
0059 %
0060 %else
0061 %    fprintf('Inverse Projecting from (x,y) to (lon,lat)\n')
0062 %    [lon,lat] = sp_proj('1802','inverse',x,y,'m');
0063 %end;
0064
0065 %------------------------------------------------------------------------------
0066 % Skagit, UTM, Zone 10 (see http://www.dmap.co.uk/utmworld.htm)
0067 %------------------------------------------------------------------------------
0068 m_proj('UTM','longitude',[-123,-120],'latitude',[47,49],'zone',10,'hemisphere','north','ellipsoid','wgs84')
0069 %m_proj get
0070 %[x,y] = m_ll2xy(-122.530820 , 48.363114);
0071 %fprintf('x %f y %f\n',x,y-1e7);
0072 %fprintf('should be 534752, 5356766.\n')
0073 deltay = 1e7;
0074
0075 if(ProjectDirection == 'forward')
0076 %    fprintf('Projecting from (lon,lat) to (x,y)\n');
0077     [x,y]=m_ll2xy(lon,lat);
0078     y = y - deltay; %why?
0079 else
0080 %    fprintf('Inverse Projecting from (x,y) to (lon,lat)\n')
0081     [lon,lat]=m_xy2ll(x,y+deltay);
0082 end;
0083
0084
0085 % set the output
0086 if(ProjectDirection == 'forward')
0087   out_east = x;
0088   out_north = y;
0089 else
0090   out_east = lon;
0091   out_north = lat;
0092 end;
0093```

Generated on Thu 19-Mar-2015 12:20:56 by m2html © 2005