1 | function [Yao_uv,mask1] = aviso2yao( aviso_netcdf, meshmask,outfile,outmask,convlon) |
---|
2 | % [Yao_uv,mask1] = aviso2yao( aviso_netcdf, meshmask,outfile,outmask) |
---|
3 | % Read AVISO file aviso_netcdf_file and save to be read by read_bck (time step=1) |
---|
4 | % Interpolate on meshmask (meshmask : two columns lon,lat) |
---|
5 | % Column 1 : time step (=1) |
---|
6 | % Column 2 : lon (Yi) |
---|
7 | % Column 3 : lat (Yj) |
---|
8 | % Column 4 : u value |
---|
9 | % Column 5 : v value |
---|
10 | % Values u and v are unitless |
---|
11 | |
---|
12 | |
---|
13 | % Usually use: |
---|
14 | % Nlat=58; %Phi |
---|
15 | % Nlong=87; %Lambda |
---|
16 | % aviso_netcdf='../../data/AVISO/dt_med_allsat_madt_uv_20130828_20140704.nc' |
---|
17 | |
---|
18 | % meshmask='../obs_float/meshgrid3.dat' |
---|
19 | % outfile='../obs_float/uv_bck_20130828.dat'; |
---|
20 | % outmask='../obs_float/mask_20130828.dat'; |
---|
21 | |
---|
22 | write_u=1; |
---|
23 | if ~exist('convlon') |
---|
24 | convlon=true; |
---|
25 | end |
---|
26 | |
---|
27 | |
---|
28 | %for plotting |
---|
29 | |
---|
30 | |
---|
31 | %The grid in degrees |
---|
32 | meshgrid2=load(meshmask); |
---|
33 | Nlong=length(unique(meshgrid2(:,1))); |
---|
34 | Nlat=length(unique(meshgrid2(:,2))); |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | GR_long=reshape(meshgrid2(:,1),Nlong,Nlat); %will give a Nlong by Nlat matrix |
---|
39 | %containing the long of the points |
---|
40 | |
---|
41 | GR_lat=reshape(meshgrid2(:,2),Nlong,Nlat); %will give a Nlong by Nlat matrix |
---|
42 | %containing the lat of the points |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | %-----------The velocities U and V---------------------------------------% |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | %Load directly from AVISO folder where the u s for the whole mediterranean: |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | U=ncread(aviso_netcdf,'u'); |
---|
58 | V=ncread(aviso_netcdf,'v'); |
---|
59 | lon=ncread(aviso_netcdf,'lon'); |
---|
60 | lat=ncread(aviso_netcdf,'lat'); |
---|
61 | |
---|
62 | [LAT,LON]=meshgrid(lat,lon); %C'est à l'envers à cause de matlab |
---|
63 | |
---|
64 | if convlon |
---|
65 | %Conversion des longitudes |
---|
66 | LON=LON-360; |
---|
67 | end |
---|
68 | |
---|
69 | %Conversion des vitesses inutile (malgré le champ scale_factor, ce que je trouve bizarre, |
---|
70 | %mais les ordres de grandeurs semblent bon |
---|
71 | |
---|
72 | Uint=interp2(LAT,LON,U,GR_lat,GR_long,'nearest'); |
---|
73 | Vint=interp2(LAT,LON,V,GR_lat,GR_long,'nearest'); |
---|
74 | |
---|
75 | |
---|
76 | mask_u=isfinite(Uint); |
---|
77 | mask_v=isfinite(Vint); |
---|
78 | mask=mask_u.*mask_v; |
---|
79 | |
---|
80 | mask1=mask(:); |
---|
81 | |
---|
82 | if (exist('outmask') & ~isempty(outmask)) |
---|
83 | dlmwrite(outmask,mask1,'precision',1); |
---|
84 | end |
---|
85 | |
---|
86 | %Masked velocity are zero |
---|
87 | Uint(mask==0)=0; |
---|
88 | Vint(mask==0)=0; |
---|
89 | |
---|
90 | |
---|
91 | %change grid from degrees to uniteless |
---|
92 | |
---|
93 | R_earth=6371229; %in meters |
---|
94 | delta_x=zeros(Nlong,Nlat); |
---|
95 | delta_y=zeros(Nlong,Nlat); |
---|
96 | |
---|
97 | for ilon=1:Nlong-1; |
---|
98 | for jlat=1:Nlat-1; |
---|
99 | |
---|
100 | delta_x(ilon,jlat)=R_earth*(2*pi/360)*(GR_long(ilon+1,jlat)-GR_long(ilon,jlat))... |
---|
101 | .*cos(2*pi*GR_lat(ilon,jlat)/360); |
---|
102 | delta_y(ilon,jlat)=R_earth*(2*pi/360)*(GR_lat(ilon,jlat+1)-GR_lat(ilon,jlat)); |
---|
103 | |
---|
104 | |
---|
105 | end |
---|
106 | end |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | delta_x(Nlong,1:Nlat)=delta_x(Nlong-1,1:Nlat); |
---|
111 | delta_y(Nlong,1:Nlat)=delta_y(Nlong-1,1:Nlat); |
---|
112 | |
---|
113 | |
---|
114 | delta_x(1:Nlong,Nlat)=delta_x(1:Nlong,Nlat-1); |
---|
115 | delta_y(1:Nlong,Nlat)=delta_y(1:Nlong,Nlat-1); |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | %choose UTRUE=Ufirst week |
---|
120 | |
---|
121 | uu=Uint./delta_x; %u has units of pers second |
---|
122 | vv=Vint./delta_y; |
---|
123 | |
---|
124 | %Choose Uback=Uafter 3days |
---|
125 | |
---|
126 | |
---|
127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
128 | |
---|
129 | |
---|
130 | %%%%%%%%%%%%%%%%%%%PUT U in YAO format%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
131 | %%Transpose everything |
---|
132 | |
---|
133 | |
---|
134 | %create a Nlat*Nlong by 5 matrix first |
---|
135 | u_yao1=reshape(uu', Nlong*Nlat,1); |
---|
136 | v_yao1=reshape(vv', Nlong*Nlat,1); |
---|
137 | |
---|
138 | %cd1=[]; for k=1:Nlong; cd1=[cd1; k*ones(Nlat,1)]; end |
---|
139 | %cd2=repmat([1:1:Nlat].',Nlong,1); |
---|
140 | |
---|
141 | cd_lon=repmat([1:Nlong],Nlat,1); |
---|
142 | cd_lat=repmat([1:Nlat]',1,Nlong); |
---|
143 | |
---|
144 | |
---|
145 | Yao_uv=[ ones(Nlong*Nlat,1) cd_lon(:) cd_lat(:) u_yao1 v_yao1]; |
---|
146 | |
---|
147 | if (write_u==1 & exist('outfile') & ~isempty(outfile)) |
---|
148 | |
---|
149 | dlmwrite(outfile,Yao_uv,'\t'); |
---|
150 | |
---|
151 | end; |
---|
152 | |
---|
153 | |
---|
154 | end |
---|
155 | |
---|