function XY=regselect(regn,c11,cmn,xunt,res,buf,ofs) % XY=REGSELECT(regn,c11,cmn,xunt,res,buf,ofs) % % Returns coordinates of a certain named specified region % % INPUT: % % regn The region name string % c11 The (lon,lat) coordinates of the top left corner % or a [lon(:)] set of coordinates for a region % cmn The (lon,lat) coordinates of the bottom right corner % or a [lat(:)] set of coordinates for a region % xunt The particuluar indices required for this region % res 0 The standard, default values % N Splined values at N times the resolution % buf Distance in degrees that the region outline will be enlarged % by BUFFERM, not necessarily integer, possibly negative % [default: 0] % ofs Offset(s) to be considered by PLOTCONT [default: none] % % OUTPUT: % % XY The requested coordinates % % Last modified by fjsimons-at-alum.mit.edu, 01/26/2012 % The directory where you keep the coordinates whereitsat=fullfile(getenv('IFILES'),'COASTS'); % Capitalize Regn=[upper(regn(1)) regn(2:end)]; % Offsets defval('ofs',0) % Revert to original name if unbuffered if res==0 && buf==0 fnpl=fullfile(whereitsat,sprintf('%s.mat',Regn)); elseif buf==0; fnpl=fullfile(whereitsat,sprintf('%s-%i.mat',Regn,res)); elseif buf~=0 fnpl=fullfile(whereitsat,sprintf('%s-%i-%g.mat',Regn,res,buf)); end % If you already have a file if exist(fnpl,'file')==2 load(fnpl) else % You are about to make a file if res==0 % First part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clf % This could be 1x2, 2x1 or 2x2 or 2x3 indeed if length(c11)<=3 && length(cmn)<=3 XY=[]; for index=1:size(c11,1) [~,handl,XY2]=plotcont(c11(index,:),cmn(index,:),[],ofs(index)); % Get rid of common NaNs XY2=XY2(~isnan(XY2(:,1)) & ~isnan(XY2(:,2)),:); delete(handl) XY=[XY ; XY2]; clear XY2 end else XY(:,1)=c11; XY(:,2)=cmn; c11=[min(XY(:,1)) max(XY(:,2))]; cmn=[max(XY(:,1)) min(XY(:,2))]; end % Get rid of common NaNs XY=XY(~isnan(XY(:,1)) & ~isnan(XY(:,2)),:); % Now make sure the distances aren't huge [X,Y]=penlift(XY(:,1),XY(:,2),3); XY=[X Y]; % Experiment with cutoff -> See "check this out" defval('xunt',1:length(XY)) XY=XY(xunt,:); % Definitely close the contour again XY=XY(~isnan(XY(:,1)) & ~isnan(XY(:,2)),:); if XY(end,:) ~= XY(1,:) XY=[XY ; XY(1,:)]; end % And definitely make this go clockwise [X2,Y2]=poly2cw(XY(:,1),XY(:,2)); XY=[X2 Y2]; clear X2 Y2 plot(XY(:,1),XY(:,2),'LineW',2,'Color','k'); axis equal % Check this out %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% hold on ; curvecheck(XY(:,1),XY(:,2),0.01); hold off else XY=bezier(eval(sprintf('%s(0)',regn)),res); end % Change the domain into a slightly larger area % Do we want to buffer out or buffer inside the curve? if buf ~= 0 if buf > 0 inout='out'; else inout='in'; end % Make some buffered coordinates and save them for later use disp('Buffering the coastlines... this may take a while'); % You might look into REDUCEM to make this easier % Note that BUFFERM has gone through quite a few revisions % The cell output is no longer supported these days [LatB,LonB]=bufferm(XY(:,2),XY(:,1),abs(buf),inout); % XY=[LonB{2}+180*[LonB{2}<0] LatB{2}]; % Note that, if due to BEZIER there might be a pinched-off loop in % the XY you will get an extra NaN and will need to watch it % If this shouldn't work, keep it all unchanged in other words try % You'll need a line for every possible version behavior % Note how POLY2CW has disappeared from BUFFERM if sign(buf)<0 || strfind(version,'2010a') % Take the last bit of non-NaNs; there might have been pinched % off sections in the original LonB=LonB(indeks(find(isnan(LonB)),'end')+1:end); LatB=LatB(indeks(find(isnan(LatB)),'end')+1:end); elseif strfind(version,'2011a') LonB=LonB(1:find(isnan(LonB))-1); LatB=LatB(1:find(isnan(LatB))-1); end catch disp('BUFFERM failed to buffer as expected') end % Periodize the right way XY=[LonB+360*any(LonB<0) LatB]; % Definitely get rid of the NaNs again? Should be overkill at this point %XY=XY(~isnan(XY(:,1)) & ~isnan(XY(:,2)),:); end % Save the file save(fnpl,'XY') end