1 | function [result]=write_lai(lon_value, lat_value, datestr_value, lai_value) |
---|
2 | |
---|
3 | %WRITE_LAI write LAI file from LAI 3D array and associated arrays lat, lon, date |
---|
4 | |
---|
5 | % |
---|
6 | %+ |
---|
7 | % |
---|
8 | % =========== |
---|
9 | % write_lai.m |
---|
10 | % =========== |
---|
11 | % |
---|
12 | % .. function:: write_lai(lon_value, lat_value, datestr_value, lai_value) |
---|
13 | % |
---|
14 | % DESCRIPTION |
---|
15 | % =========== |
---|
16 | % |
---|
17 | % :param lon_value: longitude array |
---|
18 | % :type lon_value: 1D array of floats |
---|
19 | % :raise lon_value: required |
---|
20 | % |
---|
21 | % :param lat_value: latitude array |
---|
22 | % :type lat_value: 1D array of floats |
---|
23 | % :raise lat_value: required |
---|
24 | % |
---|
25 | % :param datestr_value: date (yyyymmdd) array |
---|
26 | % :type datestr_value: 1D array of strings |
---|
27 | % :raise datestr_value: required |
---|
28 | % |
---|
29 | % :param lai_value: LAI array |
---|
30 | % :type lai_value: 1D array of floats |
---|
31 | % :raise lai_value: required |
---|
32 | % |
---|
33 | % Write in a file :file:`${PROJECT_OD}/LAI/laisen{yyyy}_write_lai_float.txt` contents |
---|
34 | % of 3D array of **lai_value** for each date in **datestr_value** |
---|
35 | % on each grid point defined by **lon_value** and **lat_value**. |
---|
36 | % |
---|
37 | % **datestr_value** are supposed to be in the same year. |
---|
38 | % |
---|
39 | % EXAMPLES |
---|
40 | % ======== |
---|
41 | % |
---|
42 | % From scratch to write some simulated LAI values in |
---|
43 | % :file:`${PROJECT_OD}/LAI/laisen2001_write_lai_float.txt`:: |
---|
44 | % |
---|
45 | % $ octave |
---|
46 | % octave> varamma_startup |
---|
47 | % octave> more off |
---|
48 | % octave> index_simulation=1; |
---|
49 | % octave> [lon_value, lat_value, datestr_value, lai_value]=simul_lai(index_simulation); |
---|
50 | % octave> result=write_lai(lon_value, lat_value, datestr_value, lai_value); |
---|
51 | % |
---|
52 | % From real file :file:`${PROJECT_ID}/LAI/laisen2001_float.txt`:: |
---|
53 | % |
---|
54 | % $ octave |
---|
55 | % octave> varamma_startup |
---|
56 | % octave> more off |
---|
57 | % octave> yyyy=2001; |
---|
58 | % octave> [lon_value, lat_value, datestr_value, lai_value]=read_lai(yyyy); |
---|
59 | % octave> result=write_lai(lon_value, lat_value, datestr_value, lai_value); |
---|
60 | % |
---|
61 | % SEE ALSO |
---|
62 | % ======== |
---|
63 | % |
---|
64 | % :ref:`guide data LAI <data_lai>` |
---|
65 | % |
---|
66 | % :func:`simul_lai` |
---|
67 | % :func:`read_lai` |
---|
68 | % |
---|
69 | % TODO |
---|
70 | % ==== |
---|
71 | % |
---|
72 | % ++ check arguments (type, size, value) |
---|
73 | % |
---|
74 | % status de retour |
---|
75 | % |
---|
76 | % EVOLUTIONS |
---|
77 | % ========== |
---|
78 | % |
---|
79 | % $Id: write_lai.m 325 2011-08-04 15:30:01Z pinsard $ |
---|
80 | % |
---|
81 | % $URL$ |
---|
82 | % |
---|
83 | % - fplod 20101202T142947Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
84 | % |
---|
85 | % * new terminology and new format |
---|
86 | % * add parameter information in header |
---|
87 | % |
---|
88 | % - fplod 20100826T120800Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
89 | % |
---|
90 | % * creation because |
---|
91 | % |
---|
92 | % - real files are big (193 Mo) so need some small LAI |
---|
93 | % data to test scientific application |
---|
94 | % - real files are no readable by :program:`QGIS` so we have to prepare |
---|
95 | % migration |
---|
96 | % |
---|
97 | %- |
---|
98 | |
---|
99 | global PROJECT_OD; |
---|
100 | |
---|
101 | result=-1; |
---|
102 | |
---|
103 | % ++ check arguments (type, size, values) |
---|
104 | nb_lat=size(lat_value,2); |
---|
105 | nb_lon=size(lon_value,2); |
---|
106 | nb_datestr=size(datestr_value,2); |
---|
107 | |
---|
108 | % calculate doy |
---|
109 | datenum_value=zeros(nb_datestr,1); |
---|
110 | datenum_value(:)=NaN; |
---|
111 | for index_datestr=1:nb_datestr |
---|
112 | datenum_value(index_datestr)=datenum(datestr_value(index_datestr,:),'yyyymmdd'); |
---|
113 | end |
---|
114 | yyyy_strvalue=datestr(datenum_value(1),'yyyy'); |
---|
115 | yyyy_floatvalue=str2double(datestr(datenum_value(1),'yyyy')); |
---|
116 | doy_value=datenum_value(:) - datenum(yyyy_floatvalue,1,1) + 1; |
---|
117 | |
---|
118 | % build LAI ASCII filename to be written |
---|
119 | fullfilename=[PROJECT_OD 'LAI/laisen' num2str(yyyy_floatvalue) '_' mfilename '_float.txt']; |
---|
120 | disp(['iii : opening for writing ', fullfilename]); |
---|
121 | fid=fopen(fullfilename,'w'); |
---|
122 | % |
---|
123 | % write header with days of year |
---|
124 | format_header=['Y,X' repmat(',%3.3d',1,nb_datestr) '\n']; |
---|
125 | fprintf(fid, format_header,doy_value(:)') |
---|
126 | % |
---|
127 | % write data (lat, lon, lai) |
---|
128 | format_data=['%7.3f,%8.3f' repmat(',%4.2f',1,nb_datestr) '\n']; |
---|
129 | for index_lat=nb_lat:-1:1 |
---|
130 | for index_lon=1:nb_lon |
---|
131 | value_lat = lat_value(index_lat); |
---|
132 | value_lon = lon_value(index_lon); |
---|
133 | fprintf(fid,format_data,value_lat,value_lon,lai_value(:,index_lat,index_lon)); |
---|
134 | end |
---|
135 | end |
---|
136 | fclose(fid); |
---|
137 | % |
---|
138 | result=0; |
---|
139 | % |
---|
140 | end |
---|