Home > atmlab > geographical > shift_longitudes.m

shift_longitudes

PURPOSE ^

SHIFT_LONGITUDES Ensures that longitudes are inside defined range

SYNOPSIS ^

function lon = shift_longitudes(lon,varargin)

DESCRIPTION ^

 SHIFT_LONGITUDES   Ensures that longitudes are inside defined range

    The function shifts longitudes to match the defined longitude range.
    Longitudes will end up in therange [lonlow,lonhigh], that must
    be 360 degrees wide. 

    There is no demand on input longitudes (except not beig NaN), the
    function shifts n*360, where n is the suitable integer.

 FORMAT   lon = shift_longitudes(lon,lonlow,lonhigh)
        
 OUT   lon       Longitudes, restricted to defined range.
 IN    lon       Original longitudes.
 OPT   lonlow    Lower limit for expected longitude range. Default is 0.
       lonhigh   Upper limit for expected longitude range. Default is 360.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

shift_longitudes.m

SOURCE CODE ^

0001 % SHIFT_LONGITUDES   Ensures that longitudes are inside defined range
0002 %
0003 %    The function shifts longitudes to match the defined longitude range.
0004 %    Longitudes will end up in therange [lonlow,lonhigh], that must
0005 %    be 360 degrees wide.
0006 %
0007 %    There is no demand on input longitudes (except not beig NaN), the
0008 %    function shifts n*360, where n is the suitable integer.
0009 %
0010 % FORMAT   lon = shift_longitudes(lon,lonlow,lonhigh)
0011 %
0012 % OUT   lon       Longitudes, restricted to defined range.
0013 % IN    lon       Original longitudes.
0014 % OPT   lonlow    Lower limit for expected longitude range. Default is 0.
0015 %       lonhigh   Upper limit for expected longitude range. Default is 360.
0016 
0017 % 2008-03-17   Created by Patrick Eriksson.
0018 
0019 
0020 function lon = shift_longitudes(lon,varargin)
0021 %
0022 [lonlow,lonhigh] = optargs( varargin, { 0, 360 } );
0023 
0024 if atmlab( 'STRICT_ASSERT' )
0025   if lonhigh - lonlow ~= 360   
0026     error(['atmlab:' mfilename], ...
0027       'Longitude range (lonhigh-lonlow) must be 360 degrees.' );  
0028   end 
0029 
0030   if any(isnan(lon(:)))
0031     warning(['atmlab:' mfilename], ...
0032         'Found nans in longitude!');
0033   end
0034 end
0035 
0036 
0037 ind = find( lon < lonlow );
0038 %
0039 while ~isempty(ind)
0040   lon(ind) = lon(ind) + 360;
0041   ind = find( lon < lonlow );
0042 end
0043 
0044 ind = find( lon > lonhigh );
0045 %
0046 while ~isempty(ind)
0047   lon(ind) = lon(ind) - 360;
0048   ind = find( lon > lonhigh );
0049 end
0050 
0051 end
0052

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005