Changeset 6642


Ignore:
Timestamp:
11/23/10 10:42:38 (14 years ago)
Author:
Mathieu Morlighem
Message:

Some fixing in lat long overlay

Location:
issm/trunk/src/m/model/plot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/model/plot/applyoptions.m

    r6638 r6642  
    5454end
    5555
    56 %latlon
    57 %Must be done here so that it uses the same xlim and ylim as plot_overlay
    58 %these are changed by axis that follows
    59 if ~strcmpi(getfieldvalue(options,'latlon','off'),'off')
    60         latlonoverlay(options);
    61 end
    62 
    6356%axis
    6457set(gca,'FontSize',fontsize);
     
    8275        ylim(getfieldvalue(options,'ylim'));
    8376end
     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
     81if ~strcmpi(getfieldvalue(options,'latlon','off'),'off')
     82        latlonoverlay(md,options);
     83end
     84
    8485
    8586%zlim
  • issm/trunk/src/m/model/plot/latlonoverlay.m

    r6582 r6642  
    1 function latlonoverlay(options)
     1function latlonoverlay(md,options)
    22%LATLONOVERLAY - overlay latitude and longitude lines on current figure
    33%
     
    2020if ~iscell(latlon),
    2121        if ischar(latlon) & strcmpi(latlon,'on'),
    22                 latstep=3;
    23                 lonstep=3;
     22                %defaults
     23                latstep=3; lonstep=3;
    2424                resolution=0.1;
    2525                color=[1 1 1];
    26         else
    27                 return;
    28         end
     26        else return; end
    2927else
    3028        if length(latlon)<2
    3129                error('latlonoverlay error message: at least 2 arguments are required, or use ''on'' option.');
    3230        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};
    4935end
    5036
    5137%2: numbering
    5238if ~iscell(numbering) & isnan(numbering),
    53         numbering=0;
     39        numbering=false;
    5440else
    5541        if ~iscell(numbering),
    5642                if strcmpi(char(numbering),'on'),
    57                         latgap=2;
    58                         longap=2;
     43                        %defaults
     44                        latgap=2; longap=2;
    5945                        colornumber=color;
    60                         latangle=0;
    61                         lonangle=0;
    62                         numbering=1;
     46                        latangle=0; lonangle=0;
     47                        numbering=true;
    6348                else
    64                         numbering=0;
     49                        numbering=false;
    6550                end
    6651        else
    67                 latgap=numbering{1};
    68                 longap=numbering{2};
     52                latgap=numbering{1}; longap=numbering{2};
    6953                colornumber=numbering{3};
    70                 latangle=numbering{4};
    71                 lonangle=numbering{5};
    72                 numbering=1;
     54                latangle=numbering{4}; lonangle=numbering{5};
     55                numbering=true;
    7356        end
    7457end
    7558
    7659%Find lat and lon that fit within the bounds of our image.
    77 lat=-90:resolution:0;
    78 lon=0:resolution:360;
     60if length(md.lat)~=md.numberofgrids,  error('model field ''lat'' is empty'); end
     61if length(md.long)~=md.numberofgrids, error('model field ''lon'' is empty'); end
    7962
    80 xlimits=xlim;
    81 ylimits=ylim;
     63%what are the x and y limits
     64xlimits=getfieldvalue(options,'xlim',xlim);
     65ylimits=getfieldvalue(options,'ylim',ylim);
    8266
    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
     68for lat=-90:latstep:90
     69        longitudes=0:resolution:360;
     70        latitudes =lat*ones(size(longitudes));
    9371
    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
    9979
    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);
    12084
    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));
    12489
    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');
    13596
    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);
    164101                end
    165102
    166103        end
    167104end
     105
     106%lon
     107for 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
     146end
     147
     148%Back to original limits
     149xlim(xlimits);
     150ylim(ylimits);
Note: See TracChangeset for help on using the changeset viewer.