Changeset 6642
- Timestamp:
- 11/23/10 10:42:38 (14 years ago)
- Location:
- issm/trunk/src/m/model/plot
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/model/plot/applyoptions.m
r6638 r6642 54 54 end 55 55 56 %latlon57 %Must be done here so that it uses the same xlim and ylim as plot_overlay58 %these are changed by axis that follows59 if ~strcmpi(getfieldvalue(options,'latlon','off'),'off')60 latlonoverlay(options);61 end62 63 56 %axis 64 57 set(gca,'FontSize',fontsize); … … 82 75 ylim(getfieldvalue(options,'ylim')); 83 76 end 77 78 %latlon 79 %Must be done here (before xlim and ylim??) so that it uses the same xlim and ylim as plot_overlay 80 %these are changed by axis that follows 81 if ~strcmpi(getfieldvalue(options,'latlon','off'),'off') 82 latlonoverlay(md,options); 83 end 84 84 85 85 86 %zlim -
issm/trunk/src/m/model/plot/latlonoverlay.m
r6582 r6642 1 function latlonoverlay( options)1 function latlonoverlay(md,options) 2 2 %LATLONOVERLAY - overlay latitude and longitude lines on current figure 3 3 % … … 20 20 if ~iscell(latlon), 21 21 if ischar(latlon) & strcmpi(latlon,'on'), 22 latstep=3;23 l onstep=3;22 %defaults 23 latstep=3; lonstep=3; 24 24 resolution=0.1; 25 25 color=[1 1 1]; 26 else 27 return; 28 end 26 else return; end 29 27 else 30 28 if length(latlon)<2 31 29 error('latlonoverlay error message: at least 2 arguments are required, or use ''on'' option.'); 32 30 end 33 if length(latlon)==2, 34 latstep=latlon{1}; 35 lonstep=latlon{2}; 36 resolution=0.1; 37 color=[1 1 1]; 38 elseif length(latlon)==3, 39 latstep=latlon{1}; 40 lonstep=latlon{2}; 41 resolution=latlon{3}; 42 color=[1 1 1]; 43 else 44 latstep=latlon{1}; 45 lonstep=latlon{2}; 46 resolution=latlon{3}; 47 color=latlon{4}; 48 end 31 if length(latlon)>3, color=latlon{4}; else color=[1 1 1]; end 32 if length(latlon)>2, resolution=latlon{3}; else resolution=0.1;end 33 latstep=latlon{1}; 34 lonstep=latlon{2}; 49 35 end 50 36 51 37 %2: numbering 52 38 if ~iscell(numbering) & isnan(numbering), 53 numbering= 0;39 numbering=false; 54 40 else 55 41 if ~iscell(numbering), 56 42 if strcmpi(char(numbering),'on'), 57 latgap=2;58 l ongap=2;43 %defaults 44 latgap=2; longap=2; 59 45 colornumber=color; 60 latangle=0; 61 lonangle=0; 62 numbering=1; 46 latangle=0; lonangle=0; 47 numbering=true; 63 48 else 64 numbering= 0;49 numbering=false; 65 50 end 66 51 else 67 latgap=numbering{1}; 68 longap=numbering{2}; 52 latgap=numbering{1}; longap=numbering{2}; 69 53 colornumber=numbering{3}; 70 latangle=numbering{4}; 71 lonangle=numbering{5}; 72 numbering=1; 54 latangle=numbering{4}; lonangle=numbering{5}; 55 numbering=true; 73 56 end 74 57 end 75 58 76 59 %Find lat and lon that fit within the bounds of our image. 77 lat=-90:resolution:0; 78 lon=0:resolution:360; 60 if length(md.lat)~=md.numberofgrids, error('model field ''lat'' is empty'); end 61 if length(md.long)~=md.numberofgrids, error('model field ''lon'' is empty'); end 79 62 80 xlimits=xlim; 81 ylimits=ylim; 63 %what are the x and y limits 64 xlimits=getfieldvalue(options,'xlim',xlim); 65 ylimits=getfieldvalue(options,'ylim',ylim); 82 66 83 for i=1:length(lon), 84 if(rem(lon(i),lonstep)==0) 85 latitudes=lat'; 86 longitudes=lon(i)*ones(length(latitudes),1); 87 [x,y]=ll2xy(latitudes,longitudes,-1); 88 pos=find(x<=xlimits(2) & x>=xlimits(1) & y<=ylimits(2) & y>=ylimits(1)); 89 if length(pos)<=1, 90 continue; 91 end 92 x=x(pos);y=y(pos); 67 %lat 68 for lat=-90:latstep:90 69 longitudes=0:resolution:360; 70 latitudes =lat*ones(size(longitudes)); 93 71 94 l=line(x,y,'Color',color); 95 if numbering, 96 if latlonclick 97 disp(['Specifiy where to put number for longitude ' num2str(lon(i))]); 98 [xcorner,ycorner]=ginput(1); 72 if strcmpi(md.hemisphere,'n'), 73 if lat<0, continue; end 74 [x,y]=ll2xy(latitudes,longitudes,+1,45,70); 75 elseif strcmpi(md.hemisphere,'s'), 76 if lat>0, continue; end 77 [x,y]=ll2xy(latitudes,longitudes,-1, 0,71); 78 else error('field hemisphere should either be ''n'' or ''s'''); end 99 79 100 %Find nearest point on this profile corresponding to (xcorner,ycorner): 101 ind=find_point(x,y,xcorner,ycorner); xcorner=x(ind); ycorner=y(ind); 102 else 103 ind=round(9*length(x)/10); xcorner=x(ind); ycorner=y(ind); 104 end 105 if length(x(1:ind))>10, 106 xcorner2=x(ind-10); ycorner2=y(ind-10); 107 else 108 xcorner2=x(ind-1); ycorner2=y(ind-1); 109 end 110 angle=mod((180)/pi*atan2((ycorner2-ycorner),(xcorner2-xcorner))+lonangle,360); 111 112 if (xcorner>xlimits(1) & xcorner<xlimits(2) & ycorner>ylimits(1) & ycorner<ylimits(2)), 113 th=text(xcorner,ycorner,[num2str(lon(i)) '^{\circ}']);set(th,'Color',colornumber,'Rotation',angle,'FontSize',fontsize,'HorizontalAlignment','center','VerticalAlignment','middle'); 114 115 %erase line and redraw it in two parts, to leave space for latitude number 116 delete(l); 117 line(x(1:ind-longap),y(1:ind-longap),'Color',color);hold on; 118 line(x(ind+longap:end),y(ind+longap:end),'Color',color); 119 end 80 pos=find(x<=xlimits(2) & x>=xlimits(1) & y<=ylimits(2) & y>=ylimits(1)); 81 if length(pos)<=1, continue; end 82 x=x(pos);y=y(pos); 83 l=line(x,y,'Color',color); 120 84 121 end 122 end 123 end 85 if numbering, 86 ind=round(9*length(x)/10); 87 xcorner=x(ind); ycorner=y(ind); 88 xcorner2=x(max(ind-10,1)); ycorner2=y(max(ind-10,1)); 124 89 125 for i=1:length(lat), 126 if(rem(lat(i),latstep)==0) 127 longitudes=lon'; 128 latitudes=lat(i)*ones(length(longitudes),1); 129 [x,y]=ll2xy(latitudes,longitudes,-1); 130 pos=find(x<=xlimits(2) & x>=xlimits(1) & y<=ylimits(2) & y>=ylimits(1)); 131 if length(pos)<=1, 132 continue; 133 end 134 x=x(pos);y=y(pos); 90 if (xcorner>xlimits(1) & xcorner<xlimits(2) & ycorner>ylimits(1) & ycorner<ylimits(2)), 91 angle=mod((180)/pi*atan2((ycorner2-ycorner),(xcorner2-xcorner))+latangle,360); 92 if lat<0, label=[num2str(abs(lat)) '^{\circ}S']; 93 else label=[num2str(abs(lat)) '^{\circ}N']; end 94 th=text(xcorner,ycorner,label); 95 set(th,'Color',colornumber,'Rotation',angle,'FontSize',fontsize,'HorizontalAlignment','center','VerticalAlignment','middle'); 135 96 136 l=line(x,y,'Color',color); 137 138 if numbering, 139 if latlonclick 140 disp(['Specifiy where to put number for latitude ' num2str(lat(i))]); 141 [xcorner,ycorner]=ginput(1); 142 143 %Find nearest point on this profile corresponding to (xcorner,ycorner): 144 ind=find_point(x,y,xcorner,ycorner); xcorner=x(ind); ycorner=y(ind); 145 else 146 ind=round(9*length(x)/10); xcorner=x(ind); ycorner=y(ind); 147 end 148 if length(x(1:ind))>10, 149 xcorner2=x(ind-10); ycorner2=y(ind-10); 150 else 151 xcorner2=x(ind-1); ycorner2=y(ind-1); 152 end 153 angle=mod((180)/pi*atan2((ycorner2-ycorner),(xcorner2-xcorner))+latangle,360); 154 155 if (xcorner>xlimits(1) & xcorner<xlimits(2) & ycorner>ylimits(1) & ycorner<ylimits(2)), 156 th=text(xcorner,ycorner,[num2str(lat(i)) '^{\circ}']);set(th,'Color',colornumber,'Rotation',angle,'FontSize',fontsize,'HorizontalAlignment','center','VerticalAlignment','middle'); 157 158 %erase line and redraw it in two parts, to leave space for latitude number 159 delete(l); 160 line(x(1:ind-latgap),y(1:ind-latgap),'Color',color);hold on; 161 line(x(ind+latgap:end),y(ind+latgap:end),'Color',color); 162 end 163 97 %erase line and redraw it in two parts, to leave space for latitude number 98 delete(l); 99 line(x(1:ind-latgap),y(1:ind-latgap),'Color',color);hold on; 100 line(x(ind+latgap:end),y(ind+latgap:end),'Color',color); 164 101 end 165 102 166 103 end 167 104 end 105 106 %lon 107 for lon=-180:lonstep:180 108 109 if strcmpi(md.hemisphere,'n'), 110 latitudes =0:resolution:90; 111 longitudes=lon*ones(size(latitudes)); 112 [x,y]=ll2xy(latitudes,longitudes,+1,45,70); 113 elseif strcmpi(md.hemisphere,'s'), 114 latitudes =-90:resolution:0; 115 longitudes=lon*ones(size(latitudes)); 116 [x,y]=ll2xy(latitudes,longitudes,-1, 0,71); 117 else 118 error('field hemisphere should either be ''n'' or ''s'''); 119 end 120 121 122 pos=find(x<=xlimits(2) & x>=xlimits(1) & y<=ylimits(2) & y>=ylimits(1)); 123 if length(pos)<=1, continue; end 124 x=x(pos);y=y(pos); 125 l=line(x,y,'Color',color); 126 127 if numbering, 128 ind=round(9*length(x)/10); 129 xcorner=x(ind); ycorner=y(ind); 130 xcorner2=x(max(ind-10,1)); ycorner2=y(max(ind-10,1)); 131 132 if (xcorner>xlimits(1) & xcorner<xlimits(2) & ycorner>ylimits(1) & ycorner<ylimits(2)), 133 angle=mod((180)/pi*atan2((ycorner2-ycorner),(xcorner2-xcorner))+lonangle,360); 134 if lon<0, label=[num2str(abs(lon)) '^{\circ}W']; 135 else label=[num2str(abs(lon)) '^{\circ}E']; end 136 th=text(xcorner,ycorner,label); 137 set(th,'Color',colornumber,'Rotation',angle,'FontSize',fontsize,'HorizontalAlignment','center','VerticalAlignment','middle'); 138 139 %erase line and redraw it in two parts, to leave space for latitude number 140 delete(l); 141 line(x(1:ind-longap),y(1:ind-longap),'Color',color);hold on; 142 line(x(ind+longap:end),y(ind+longap:end),'Color',color); 143 end 144 145 end 146 end 147 148 %Back to original limits 149 xlim(xlimits); 150 ylim(ylimits);
Note:
See TracChangeset
for help on using the changeset viewer.