function [] = convertnc(in) 
str1=strcat(in);

fid=fopen(str1);
mydata=textscan(fid,'%s %s %s');
L=length(mydata{1});
fclose(fid);
C=char(mydata{1});
for j=1:L
    in=C(j,:);
      
% load file in.mat
str2 = ['load ' in];
eval(str2)
%create out.nc
S=strcat(in,'.nc');
out=netcdf(S,'clobber');

%création time variable
[timelen,timedim]=size(time);
S=datestr(time(1));
dategc=datevec(time(1));
datejd=convertjd(dategc);
out('timedim')=timedim;
out('timelen')=timelen;
out{'time'}=ncdouble('timedim','timelen');
out{'time'}(:)=time;
out{'time'}.dategc=ncchar(S);
out{'time'}.datejd=ncdouble(datejd);

%verification of the gap bewteen two consecutives dates
gap=0;
gap0=(time(2)-time(1));
for i=1:(timelen-1)
    gap=time(i+1)-time(i);
    gap=gap-gap0;
end
if gap==0 
    out{'time'}.samegap='yes';
    out{'time'}.gap=ncdouble(gap0);
else
    out{'time'}.samegap='no';
end
    
% create longitude variable
[lonlen,londim]= size(lon);     
out('longitudesdim')=londim;
out('longitudeslen')=lonlen;
out{'longitudes'}=ncdouble('longitudesdim','longitudeslen');
out{'longitudes'}(:)=lon;
out{'longitudes'}.units='degrees';
%create variable longitude max 
out('lonmaxdim')=1;
out('lonmaxlen')=1;
out('lonmax')='longitudesmax';
out{'lonmax'}=ncdouble('lonmaxdim','lonmaxlen');
out{'lonmax'}.units='degrees';
out{'lonmax'}(:)=lonmax;
%create variable longitude min
out('lonmindim')=1;
out('lonminlen')=1;
out('lonmin')='longitudesmin';
out{'lonmin'}=ncdouble('lonmindim','lonminlen');
out{'lonmin'}.units='degrees';
out{'lonmin'}(:)=lonmin;
% create latitude variable
[latlen,latdim]=size(lat);
out('latitudesdim')=latdim;
out('latitudeslen')=latlen;
out{'latitudes'}=ncdouble('latitudesdim','latitudeslen');
out{'latitudes'}(:)=lat;
out{'latitudes'}.units='degrees';
%create variable latitude max 
out('latmaxdim')=1;
out('latmaxlen')=1;
out('latmax')='latitudesmax';
out{'latmax'}=ncdouble('latmaxdim','latmaxlen');
out{'latmax'}.units='degrees';
out{'latmax'}(:)=latmax;
%create variable latitude min
out('latmindim')=1;
out('latminlen')=1;
out('latmin')='latitudesmin';
out{'latmin'}=ncdouble('latmindim','latminlen');
out{'latmin'}.units='degrees';
out{'latmin'}(:)=latmin;

%create variable drifter id which is a char array in the in.mat file
out('drifterdim')=1;
out('drifterlen')=1;
out('drifter_id')='Id_drifter';
out{'drifter_id'}=ncint('drifterdim','drifterlen');
id2=0;
for i=1:length(id) 
    id2=id2+str2num(id(i))*10^(length(id)-i);
end
out{'drifter_id'}(:)=id2;

out = close(out);
end 
end
