1 | function [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$ |
---|
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 | % |
---|
161 | global application; |
---|
162 | % |
---|
163 | result=-1; |
---|
164 | % |
---|
165 | usage='result=showgrid(lon_value, lat_value, mode)'; |
---|
166 | % |
---|
167 | if nargin~=3 |
---|
168 | disp(['Incorrect number of arguments']); |
---|
169 | error(usage); |
---|
170 | end |
---|
171 | % |
---|
172 | arg_info=whos('lon_value'); |
---|
173 | if ~strcmp(arg_info.class,'double') |
---|
174 | disp(['Incorrect type of arg lon_value']); |
---|
175 | whos lon_value |
---|
176 | error(usage); |
---|
177 | end |
---|
178 | clear arg_info |
---|
179 | % |
---|
180 | arg_info=whos('lat_value'); |
---|
181 | if ~strcmp(arg_info.class,'double') |
---|
182 | disp(['Incorrect type of arg lat_value']); |
---|
183 | whos lat_value |
---|
184 | error(usage); |
---|
185 | end |
---|
186 | clear arg_info |
---|
187 | % |
---|
188 | arg_info=whos('mode'); |
---|
189 | if ~strcmp(arg_info.class,'char') |
---|
190 | disp(['Incorrect type of arg mode']); |
---|
191 | whos mode |
---|
192 | error(usage); |
---|
193 | end |
---|
194 | clear arg_info |
---|
195 | % |
---|
196 | switch 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); |
---|
216 | end |
---|
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 |
---|
222 | latmin=min(lat_value); |
---|
223 | latmax=max(lat_value); |
---|
224 | ymin=latmin - 2; |
---|
225 | ymax=latmax + 2; |
---|
226 | clear latmin; |
---|
227 | clear latmax; |
---|
228 | lonmin=min(lon_value); |
---|
229 | lonmax=max(lon_value); |
---|
230 | xmin=lonmin - 2; |
---|
231 | xmax=lonmax + 2; |
---|
232 | clear lonmin; |
---|
233 | clear lonmax; |
---|
234 | % |
---|
235 | % read world map |
---|
236 | load('cmgco_traitdecote.mat','Xgco','Ygco'); |
---|
237 | % |
---|
238 | % initialiaze a new figure |
---|
239 | ifigure=gcf()+1; |
---|
240 | figure(ifigure); |
---|
241 | % |
---|
242 | % plot world map (black dots) |
---|
243 | plot(Xgco,Ygco,'k.','MarkerSize',1) |
---|
244 | clear Xgco; |
---|
245 | clear Ygco |
---|
246 | % |
---|
247 | % build x and y data from lat_value and lon_value |
---|
248 | switch 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]); |
---|
279 | end |
---|
280 | % overplot grid points |
---|
281 | hold on |
---|
282 | plot(xdata,ydata,'ro') |
---|
283 | clear xdata; |
---|
284 | clear ydata; |
---|
285 | % limit world map around latmin,latmax and lonmin, lonmax + 2 on each side |
---|
286 | axis([xmin xmax ymin ymax]); |
---|
287 | clear xmin; |
---|
288 | clear xmax; |
---|
289 | clear ymin; |
---|
290 | clear ymax; |
---|
291 | % |
---|
292 | % clean memory |
---|
293 | clear ifigure; |
---|
294 | % |
---|
295 | result=0; |
---|
296 | % |
---|
297 | end |
---|
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) |
---|