1 | function [] = convertnc(in) |
---|
2 | str1=strcat(in); |
---|
3 | |
---|
4 | fid=fopen(str1); |
---|
5 | mydata=textscan(fid,'%s %s %s'); |
---|
6 | L=length(mydata{1}); |
---|
7 | fclose(fid); |
---|
8 | C=char(mydata{1}); |
---|
9 | for j=1:L |
---|
10 | in=C(j,:); |
---|
11 | |
---|
12 | % load file in.mat |
---|
13 | str2 = ['load ' in]; |
---|
14 | eval(str2) |
---|
15 | %create out.nc |
---|
16 | S=strcat(in,'.nc'); |
---|
17 | out=netcdf(S,'clobber'); |
---|
18 | |
---|
19 | %création time variable |
---|
20 | [timelen,timedim]=size(time); |
---|
21 | S=datestr(time(1)); |
---|
22 | dategc=datevec(time(1)); |
---|
23 | datejd=convertjd(dategc); |
---|
24 | out('timedim')=timedim; |
---|
25 | out('timelen')=timelen; |
---|
26 | out{'time'}=ncdouble('timedim','timelen'); |
---|
27 | out{'time'}(:)=time; |
---|
28 | out{'time'}.dategc=ncchar(S); |
---|
29 | out{'time'}.datejd=datejd; |
---|
30 | |
---|
31 | %verification of the gap bewteen two consecutives dates |
---|
32 | gap=0; |
---|
33 | gap0=(time(2)-time(1)); |
---|
34 | for i=1:(timelen-1) |
---|
35 | gap=time(i+1)-time(i); |
---|
36 | gap=gap-gap0; |
---|
37 | end |
---|
38 | if gap==0 |
---|
39 | out{'time'}.samegap='yes'; |
---|
40 | out{'time'}.gap=ncdouble(1,1); |
---|
41 | out{'time'}.gap(:)=gap0; |
---|
42 | else |
---|
43 | out{'time'}.samegap='no'; |
---|
44 | end |
---|
45 | |
---|
46 | % create longitude variable |
---|
47 | [lonlen,londim]= size(lon); |
---|
48 | out('longitudesdim')=londim; |
---|
49 | out('longitudeslen')=lonlen; |
---|
50 | out{'longitudes'}=ncdouble('longitudesdim','longitudeslen'); |
---|
51 | out{'longitudes'}(:)=lon; |
---|
52 | out{'longitudes'}.units='degrees'; |
---|
53 | %create variable longitude max |
---|
54 | out('lonmaxdim')=1; |
---|
55 | out('lonmaxlen')=1; |
---|
56 | out('lonmax')='longitudesmax'; |
---|
57 | out{'lonmax'}=ncdouble('lonmaxdim','lonmaxlen'); |
---|
58 | out{'lonmax'}.units='degrees'; |
---|
59 | out{'lonmax'}(:)=lonmax; |
---|
60 | %create variable longitude min |
---|
61 | out('lonmindim')=1; |
---|
62 | out('lonminlen')=1; |
---|
63 | out('lonmin')='longitudesmin'; |
---|
64 | out{'lonmin'}=ncdouble('lonmindim','lonminlen'); |
---|
65 | out{'lonmin'}.units='degrees'; |
---|
66 | out{'lonmin'}(:)=lonmin; |
---|
67 | % create latitude variable |
---|
68 | [latlen,latdim]=size(lat); |
---|
69 | out('latitudesdim')=latdim; |
---|
70 | out('latitudeslen')=latlen; |
---|
71 | out{'latitudes'}=ncdouble('latitudesdim','latitudeslen'); |
---|
72 | out{'latitudes'}(:)=lat; |
---|
73 | out{'latitudes'}.units='degrees'; |
---|
74 | %create variable latitude max |
---|
75 | out('latmaxdim')=1; |
---|
76 | out('latmaxlen')=1; |
---|
77 | out('latmax')='latitudesmax'; |
---|
78 | out{'latmax'}=ncdouble('latmaxdim','latmaxlen'); |
---|
79 | out{'latmax'}.units='degrees'; |
---|
80 | out{'latmax'}(:)=latmax; |
---|
81 | %create variable latitude min |
---|
82 | out('latmindim')=1; |
---|
83 | out('latminlen')=1; |
---|
84 | out('latmin')='latitudesmin'; |
---|
85 | out{'latmin'}=ncdouble('latmindim','latminlen'); |
---|
86 | out{'latmin'}.units='degrees'; |
---|
87 | out{'latmin'}(:)=latmin; |
---|
88 | |
---|
89 | %create variable drifter id which is a char array in the in.mat file |
---|
90 | out('drifterdim')=1; |
---|
91 | out('drifterlen')=1; |
---|
92 | out('drifter_id')='Id_drifter'; |
---|
93 | out{'drifter_id'}=ncint('drifterdim','drifterlen'); |
---|
94 | id2=0; |
---|
95 | for i=1:length(id) |
---|
96 | id2=id2+str2num(id(i))*10^(length(id)-i); |
---|
97 | end |
---|
98 | out{'drifter_id'}(:)=id2; |
---|
99 | |
---|
100 | out = close(out); |
---|
101 | end |
---|
102 | end |
---|