source: trunk/src/showgrid.m @ 327

Last change on this file since 327 was 327, checked in by pinsard, 13 years ago

change svn properties

  • Property svn:keywords set to URL
File size: 9.1 KB
Line 
1function [result]=showgrid(lon_value, lat_value, mode)
2
3%SHOWGRID show grid on a world map
4
5%+
6%
7% ==========
8% showgrid.m
9% ==========
10%
11% .. function:: showgrid(lon_value, lat_value, mode)
12%
13% DESCRIPTION
14% ===========
15%
16%    :param lon_value: longitude array
17%    :type lon_value: 1D array
18%    :raise lon_value: required
19%
20%    :param lat_value: latitude array
21%    :type lat_value: 1D array
22%    :raise lat_value: required
23%
24%    :param mode: 'line' or 'grid'
25%    :type mode: string
26%    :raise mode: required
27%
28%    :returns: 0 if ok or -1 if error
29%    :rtype: integer
30%
31% On a new figure, plot over a world map the grid defined by **lon_value**
32% and **lat_value**.
33%
34% Dimensions of the plot is 2° larger than latitudes and longitudes given in
35% input.
36%
37% If mode is set to 'line', lon_value and lat_value are plotted as they are.
38%
39% If mode is set to 'grid', lon_value and lat_valuer are reorganized to be plot.
40%
41% EXAMPLES
42% ========
43%
44% From scratch to show grid of the simulated LAI "1" latitude and longitude:
45%
46% see demo 1
47%
48% From scratch to show grid of the simulated LAI "1" 2D latitude and longitude:
49%
50% see demo 2
51%
52% From scratch to show grid of the simulated LAI "2" latitude and longitude:
53%
54% see demo 3
55%
56% From real file MSG file
57% :file:`${PROJECT_ID}/MSG/2006/07/msg-tb108_2006-07-31_15min.nc`:
58%
59% see demo 4
60%
61% From real file AMSU
62% :file:`${PROJECT_ID}/AMSU/2006/07/amsubch5-noaa17_20060731-225107_afratl_Nadir.nc`:
63%
64% see demo 5
65%
66% From real file :file:`${PROJECT_ID}/LAI/laisen2001_float.txt`:
67%
68% see demo 6
69%
70% From scratch to show grid of the simulated EPSAT latitude and longitude:
71%
72% see demo 7
73%
74% SEE ALSO
75% ========
76%
77% :ref:`data_lai`
78% :ref:`data_msg`
79% :ref:`data_amsu`
80% :ref:`data_epsat`
81%
82% :ref:`world_map`
83%
84% :func:`simul_lai_2d`
85% :func:`read_lai_2d`
86%
87% :func:`simul_epsat`
88%
89% TODO
90% ====
91%
92% ++ check arguments (type, value)
93%
94% use reshape and meshgrid instead of loop
95%
96% lien sur traitdecote.mat
97%
98%
99% label x, y et info résolution si mode grid sur le plot
100%
101% EVOLUTIONS
102% ==========
103%
104% $Id: showgrid.m 325 2011-08-04 15:30:01Z pinsard $
105%
106% $URL$
107%
108% - fplod 20110609T094538Z aedon.locean-ipsl.upmc.fr (Darwin)
109%
110%   * demo usin simul_msg
111%
112% - fplod 20110310T144432Z cratos.locean-ipsl.upmc.fr (Linux)
113%
114%   * add demo using :func:`simul_epsat`
115%   * add references in rst header
116%
117% - fplod 20110302T172026Z aedon.locean-ipsl.upmc.fr (Darwin)
118%
119%   * adapation for matlab : can not use octave size_equal
120%
121% - fplod 20110302T085925Z aedon.locean-ipsl.upmc.fr (Darwin)
122%
123%   * test inconsistent dimensions of parameters
124%
125% - fplod 20110228T141829Z aedon.locean-ipsl.upmc.fr (Darwin)
126%
127%   * examples moved to demos
128%
129% - fplod 20101208T103621Z aedon.locean-ipsl.upmc.fr (Darwin)
130%
131%   * add some argument checking
132%
133% - fplod 20101207T082027Z adonis.locean-ipsl.upmc.fr (Linux)
134%
135%   * add some argument checking
136%
137% - fplod 20101202T133821Z aedon.locean-ipsl.upmc.fr (Darwin)
138%
139%   * add parameter information in header
140%   * laiyyyy_float.txt is replaced by laisenyyyy_float.txt (new format also)
141%
142% - fplod 20100923T154311Z aedon.locean-ipsl.upmc.fr (Darwin)
143%
144%   * add mode parameter
145%
146% - fplod 20100901T111043Z aedon.locean-ipsl.upmc.fr (Darwin)
147%
148%   * creation to point out non orthogonal grid of LAI data
149%
150%     This point can be quickly shown by::
151%
152%      $ awk ' NR > 1 {print $1}' ${PROJECT_ID}/LAI/laisen2001_float.txt > lat.txt
153%      $ awk ' NR > 1 {print $2}' ${PROJECT_ID}/LAI/laisen2001_float.txt > lon.txt
154%      octave> lat_value=load('lat.txt');
155%      octave> lon_value=load('lon.txt');
156%      octave> plot(lon_value,lat_value)
157%
158%
159%-
160%
161global application;
162%
163result=-1;
164%
165usage='result=showgrid(lon_value, lat_value, mode)';
166%
167if nargin~=3
168   disp(['Incorrect number of arguments']);
169   error(usage);
170end
171%
172arg_info=whos('lon_value');
173if ~strcmp(arg_info.class,'double')
174   disp(['Incorrect type of arg lon_value']);
175   whos lon_value
176   error(usage);
177end
178clear arg_info
179%
180arg_info=whos('lat_value');
181if ~strcmp(arg_info.class,'double')
182   disp(['Incorrect type of arg lat_value']);
183   whos lat_value
184   error(usage);
185end
186clear arg_info
187%
188arg_info=whos('mode');
189if ~strcmp(arg_info.class,'char')
190   disp(['Incorrect type of arg mode']);
191   whos mode
192   error(usage);
193end
194clear arg_info
195%
196switch mode
197   case {'line'}
198      switch application
199        case {'matlab'}
200           test_consistent=isequal(numel(lon_value), numel(lat_value));
201        case {'octave'}
202           test_consistent=size_equal(lon_value, lat_value);
203        otherwise
204           error('unknown application running');
205      end
206      if (not(test_consistent))
207         disp(['eee : inconsistent dimensions of lon_value and lat_value']);
208         whos lon_value
209         whos lat_value
210         error(usage);
211      end
212   case {'grid'}
213   otherwise
214       disp(['eee : unknown mode : ' mode]);
215       error(usage);
216end
217%
218% ++ check arguments (values)
219%
220% find min and max of latitude and longitude
221% to define axis not to close from data to be plot
222latmin=min(lat_value);
223latmax=max(lat_value);
224ymin=latmin - 2;
225ymax=latmax + 2;
226clear latmin;
227clear latmax;
228lonmin=min(lon_value);
229lonmax=max(lon_value);
230xmin=lonmin - 2;
231xmax=lonmax + 2;
232clear lonmin;
233clear lonmax;
234%
235% read world map
236load('cmgco_traitdecote.mat','Xgco','Ygco');
237%
238% initialiaze a new figure
239ifigure=gcf()+1;
240figure(ifigure);
241%
242% plot world map (black dots)
243plot(Xgco,Ygco,'k.','MarkerSize',1)
244clear Xgco;
245clear Ygco
246%
247% build x and y data from lat_value and lon_value
248switch mode
249   case {'line'}
250      xdata=lon_value;
251      ydata=lat_value;
252   case {'grid'}
253      nb_lat=size(lat_value,1);
254      nb_lon=size(lon_value,1);
255      % here we repeat each lon_value nb_lat times and
256      % we repeat lat_value nb_lon times to have two arrays xdata and ydata
257      % of the same dimension
258      %
259      for index_lon=1:nb_lon
260       index_x1=(index_lon-1)*nb_lat + 1;
261       index_x2=(index_lon)*nb_lat;
262       xdata(index_x1:index_x2)=repmat(lon_value(index_lon),nb_lat,1);
263      end
264      clear index_lon;
265      clear index_x1;
266      clear index_x2;
267      ydata=transpose(repmat(lat_value,nb_lon,1));
268      %
269      clear nb_lat;
270      clear nb_lon;
271      %
272      % +todo+this might be done with something like
273      %  [XX, YY] = meshgrid (lon_value, lat_value)
274      % xdata=reshape(XX,nb_lon*nb_lat,1)
275      % ydata=reshape(YY,nb_lon*nb_lat,1)
276      %
277   otherwise
278      error(['unknown mode ', mode]);
279end
280% overplot grid points
281hold on
282plot(xdata,ydata,'ro')
283clear xdata;
284clear ydata;
285% limit world map around latmin,latmax and lonmin, lonmax + 2 on each side
286axis([xmin xmax ymin ymax]);
287clear xmin;
288clear xmax;
289clear ymin;
290clear ymax;
291%
292% clean memory
293clear ifigure;
294%
295result=0;
296%
297end
298
299%!demo
300%! % From scratch to show grid of the simulated LAI "1" latitude and longitude::
301%! varamma_startup
302%! more off
303%! index_simulation=int8(1);
304%! [lon_value, lat_value, datestr_value, lai_value]=simul_lai(index_simulation);
305%! mode='grid';
306%! result=showgrid(lon_value, lat_value, mode);
307
308%!demo
309%! % From scratch to show grid of the simulated LAI "1" 2D latitude and longitude::
310%! varamma_startup
311%! more off
312%! index_simulation=int8(1);
313%! [lon_value, lat_value, datestr_value, lai_value]=simul_lai_2d(index_simulation);
314%! mode='line';
315%! result=showgrid(lon_value, lat_value, mode)
316
317%!demo
318%! % From scratch to show grid of the simulated LAI "2" latitude and longitude::
319%! varamma_startup
320%! more off
321%! index_simulation=int8(2);
322%! [lon_value, lat_value, datestr_value, lai_value]=simul_lai(index_simulation);
323%! mode='grid';
324%! result=showgrid(lon_value, lat_value, mode);
325
326%!demo
327%! % From real file MSG file
328%! % :file:`${PROJECT_ID}/MSG/2006/07/msg-tb108_2006-07-31_15min.nc`::
329%! varamma_startup
330%! filename=['msg-tb108_2006-07-31_15min.nc'];
331%! fullfilename=[PROJECT_ID,'MSG/2006/07/', filename];
332%! file=netcdf(fullfilename,'nowrite');
333%! lon_value=file{'LONGITUDE'};
334%! lat_value=file{'LATITUDE'};
335%! mode='grid';
336%! result=showgrid(lon_value(:),lat_value(:), mode)
337
338%!demo
339%! % From real file AMSU
340%! % :file:`${PROJECT_ID}/AMSU/2006/07/amsubch5-noaa17_20060731-225107_afratl_Nadir.nc`::
341%! varamma_startup
342%! filename=['amsubch5-noaa17_20060731-225107_afratl_Nadir.nc'];
343%! fullfilename=[PROJECT_ID,'AMSU/2006/07/', filename];
344%! file=netcdf(fullfilename,'nowrite');
345%! lon_value=file{'lon'};
346%! lat_value=file{'lat'};
347%! mode='grid';
348%! result=showgrid(lon_value(:),lat_value(:), mode)
349
350%!demo
351%!  % From real file :file:`${PROJECT_ID}/LAI/laisen2001_float.txt`::
352%! varamma_startup
353%! more off
354%! yyyy=int16(2001);
355%! [lon_value, lat_value, datestr_value, lai_value]=read_lai_2d(yyyy);
356%! mode='grid';
357%! result=showgrid(lon_value, lat_value, mode);
358
359%!demo
360%! % From scratch to show grid of the simulated EPSAT latitude and longitude::
361%! varamma_startup
362%! more off
363%! index_simulation=int8(2);
364%! [lon_value, lat_value, datejul_value, datestr_value, epsat_value]=simul_epsat(index_simulation);
365%! mode='grid';
366%! result=showgrid(lon_value, lat_value, mode)
367
368%!demo
369%! % From scratch to show grid of the simulated MSG latitude and longitude::
370%! varamma_startup
371%! more off
372%! index_simulation=int8(3);
373%! [lon_value, lat_value, datejul_value, datestr_value, epsat_value]=simul_msg(index_simulation);
374%! mode='grid';
375%! result=showgrid(lon_value, lat_value, mode)
Note: See TracBrowser for help on using the repository browser.