source: altifloat/matlab_toolbox/obs2yao.m @ 199

Last change on this file since 199 was 137, checked in by jbrlod, 9 years ago

script_pmp : load Pierre-Marie Poulain observations

File size: 1.7 KB
Line 
1function [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
21mg=load(meshfile);
22Nlat=length(unique(mg(:,2))); %Phi
23Nlong=length(unique(mg(:,1))); %Lambda
24GR_long=reshape(mg(:,1),Nlong,Nlat);
25GR_lat=reshape(mg(:,2),Nlong,Nlat);
26
27%Timestep
28t=time-t0;
29t=t/dt;
30t=t+1;
31iok=(100*round(t)==round(t*100)) & (t>0);
32t=t(iok);
33
34%x,y
35x=interp1(GR_long(:,1),1:Nlong,lon(iok));
36y=interp1(GR_lat(1,:),1:Nlat,lat(iok));
37
38
39%%Sauvegarde
40if exist('floatid')~=1
41  floatid=1;
42end
43
44%On fait le format YAO :
45
46M=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
52C1=[ones(1,length(t)) ; 2*ones(1,length(t))];
53C1=C1(:);
54
55C2=repmat(t',2,1);
56C2=C2(:);
57
58C3=floatid*ones(2*length(t),1);
59
60C4=[x';y'];
61C4=C4(:);
62
63M=[C1 C2 C3 C4];
64if exist('filename')==1
65%filename a été spécifié, on sauvegarde
66
67save(filename,'-ascii','M');
68
69end
70
Note: See TracBrowser for help on using the repository browser.