%
% example Matlab script to plot a BYU SCP ciaworld map
% 
% The BYU SCO ciaworld.dat file is an ASCII 
% file consists of a list of lat,lon,pen,code values
% that describe the conceptal plotting of a pen with the pen
% "down" from the previous point to the current point when
% pen=2, and moving the pen with the pen up when pen=3.
%
%   Code  General Type
%     1    Coasts          
%     2    Add Major island
%     3    Intermed islands
%     4    Minor islands   
%     5    Double-line Rivers 
%     6    Intermit major lake
%     7    Intermit minor lake
%     8    Reefs           
%     9    Major Salt pans 
%    10    Minor Salt pans 
%    11    Lessor Canals   
%    13    Major Ice Shelve
%    14    Minor Ice Shelve
%    15    Glaciers               
%

% select and read a ciaworld file
%fname='ciaworld000.dat'; % 0 to 360 longitudes
fname='ciaworld180.dat'; % -180 to 180 longitudes
map=load(fname);

% make sure the last entry in the file is a pen up
map(length(map)+1,:)=map(length(map),:);
map(length(map)+1,3)=3;

% for convenience, extract named sub arrays
lats=map(:,1);
lons=map(:,2); 
pens=map(:,3);  % 3=move to pen up, 2=draw pen down
codes=map(:,4); % feature code shore=1, etc...

%
% plot all points in file using named sub arrays
%
figure(1); clf;
hold on;
ind=find(pens==3); % find all pen ups
n=length(ind);
for k=1:n-1
  if codes(ind(k))==1 % just plot coastlines
    plot(lons(ind(k):ind(k+1)-1),lats(ind(k):ind(k+1)-1),'k');
  else % plot everything else
    plot(lons(ind(k):ind(k+1)-1),lats(ind(k):ind(k+1)-1),'b');
  end
end
hold off;  
axis([-180 180 -90 90]);
title(fname)

% print graphic
% print -dpng ciaworld.png

