1 | function [x,y,t,M] = obs2yao(lon,lat,time,t0,dt,meshfile,floatid,filename) |
---|
2 | %[x,y,t,M] = obs2yao(lon,lat,timestep,t0,meshfile) |
---|
3 | %Convert lon,lat,time data into timestep and gridpoint number |
---|
4 | % for one float |
---|
5 | % If filename is specified, save in yao format in filename |
---|
6 | % Input : lon in degree longitude East |
---|
7 | % Ouput : lat in degree |
---|
8 | % time : number in matlab format (see datenum and datestr) |
---|
9 | % t0 : correspond to the first step time. Discard all time before t0 |
---|
10 | % dt : step time in day (6h=0.25). Discard all time that doesn not fit |
---|
11 | % meshfile : file contains the meshgrid in lon,lat (e.g. enerated by make_meshgrid) |
---|
12 | % floatid : id of the float (default is 1) |
---|
13 | % filename (optional) : filename to save x,y,t in yao format |
---|
14 | |
---|
15 | %output M : matrix in the YAO format |
---|
16 | |
---|
17 | %%%%%%%%% This function takes the name of the floater from the list and |
---|
18 | %%%%%%%%% changes it's format so it is YAO compatible. |
---|
19 | |
---|
20 | |
---|
21 | mg=load(meshfile); |
---|
22 | Nlat=length(unique(mg(:,2))); %Phi |
---|
23 | Nlong=length(unique(mg(:,1))); %Lambda |
---|
24 | GR_long=reshape(mg(:,1),Nlong,Nlat); |
---|
25 | GR_lat=reshape(mg(:,2),Nlong,Nlat); |
---|
26 | |
---|
27 | %Timestep |
---|
28 | t=time-t0; |
---|
29 | t=t/dt; |
---|
30 | t=t+1; |
---|
31 | iok=(100*round(t)==round(t*100)) & (t>0); |
---|
32 | t=t(iok); |
---|
33 | |
---|
34 | %x,y |
---|
35 | x=interp1(GR_long(:,1),1:Nlong,lon(iok)); |
---|
36 | y=interp1(GR_lat(1,:),1:Nlat,lat(iok)); |
---|
37 | |
---|
38 | |
---|
39 | %%Sauvegarde |
---|
40 | if exist('floatid')~=1 |
---|
41 | floatid=1; |
---|
42 | end |
---|
43 | |
---|
44 | %On fait le format YAO : |
---|
45 | |
---|
46 | M=nan*ones(2*length(t),4); |
---|
47 | % Column 1 (%d) : dimension (1 : lon(Yi), 2 lat(Yj)) |
---|
48 | % Column 2 (%d) : time step (from 1 to jptfl) |
---|
49 | % Column 3 (%d) : idfloat |
---|
50 | % Column 4 (%f) : grid point of the floater |
---|
51 | |
---|
52 | C1=[ones(1,length(t)) ; 2*ones(1,length(t))]; |
---|
53 | C1=C1(:); |
---|
54 | |
---|
55 | C2=repmat(t',2,1); |
---|
56 | C2=C2(:); |
---|
57 | |
---|
58 | C3=floatid*ones(2*length(t),1); |
---|
59 | |
---|
60 | C4=[x';y']; |
---|
61 | C4=C4(:); |
---|
62 | |
---|
63 | M=[C1 C2 C3 C4]; |
---|
64 | if exist('filename')==1 |
---|
65 | %filename a été spécifié, on sauvegarde |
---|
66 | |
---|
67 | save(filename,'-ascii','M'); |
---|
68 | |
---|
69 | end |
---|
70 | |
---|