source: altifloat/matlab_toolbox/aviso2yao.m @ 160

Last change on this file since 160 was 139, checked in by jbrlod, 9 years ago

add functionalities to mask the model experiment

File size: 3.3 KB
Line 
1function [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
22write_u=1;
23if ~exist('convlon')
24    convlon=true;
25end
26
27 
28%for plotting
29
30
31%The grid in degrees
32meshgrid2=load(meshmask);
33Nlong=length(unique(meshgrid2(:,1)));
34Nlat=length(unique(meshgrid2(:,2)));
35
36
37
38GR_long=reshape(meshgrid2(:,1),Nlong,Nlat); %will give a Nlong by Nlat matrix
39%containing the long of the points
40
41GR_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
57U=ncread(aviso_netcdf,'u');
58V=ncread(aviso_netcdf,'v');
59lon=ncread(aviso_netcdf,'lon');
60lat=ncread(aviso_netcdf,'lat');
61
62[LAT,LON]=meshgrid(lat,lon); %C'est à l'envers à cause de matlab
63
64if convlon
65%Conversion des longitudes
66LON=LON-360;
67end
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
72Uint=interp2(LAT,LON,U,GR_lat,GR_long,'nearest');
73Vint=interp2(LAT,LON,V,GR_lat,GR_long,'nearest');
74
75
76mask_u=isfinite(Uint);
77mask_v=isfinite(Vint);
78mask=mask_u.*mask_v;
79
80mask1=mask(:);
81
82if (exist('outmask') & ~isempty(outmask))
83dlmwrite(outmask,mask1,'precision',1);
84end
85
86%Masked velocity are zero
87Uint(mask==0)=0;
88Vint(mask==0)=0;
89
90
91%change grid from degrees to uniteless
92
93R_earth=6371229; %in meters
94delta_x=zeros(Nlong,Nlat);
95delta_y=zeros(Nlong,Nlat);
96
97for 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   
105end
106end
107
108
109
110delta_x(Nlong,1:Nlat)=delta_x(Nlong-1,1:Nlat);
111delta_y(Nlong,1:Nlat)=delta_y(Nlong-1,1:Nlat);
112
113
114delta_x(1:Nlong,Nlat)=delta_x(1:Nlong,Nlat-1);
115delta_y(1:Nlong,Nlat)=delta_y(1:Nlong,Nlat-1);
116
117
118
119%choose UTRUE=Ufirst week
120
121uu=Uint./delta_x; %u has units of pers second
122vv=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
135u_yao1=reshape(uu', Nlong*Nlat,1);
136v_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
141cd_lon=repmat([1:Nlong],Nlat,1);
142cd_lat=repmat([1:Nlat]',1,Nlong);
143
144
145Yao_uv=[ ones(Nlong*Nlat,1)  cd_lon(:) cd_lat(:)  u_yao1 v_yao1];
146
147if (write_u==1 & exist('outfile') & ~isempty(outfile))
148
149dlmwrite(outfile,Yao_uv,'\t');
150
151end;
152
153
154end
155
Note: See TracBrowser for help on using the repository browser.