function [ output_args ] = make_obs( listename, timeneeded )

%%%%%%%%% This function takes the name of the floater from the list and
%%%%%%%%% changes it's format so it is YAO compatible.

dirnem='../nemed/';
nemlist=listename;
format long
fid=fopen([dirnem nemlist]);
count=1;
float_obs=[];
index=[];
while 1
            tline = fgetl(fid);
                 disp(tline)
            if ~ischar(tline), break, end
            lon=ncread([dirnem tline],'longitudes');
            lat=ncread([dirnem tline],'latitudes');
            pdt=ncread([dirnem tline],'time');
            
            M=zeros(size(lat,1),4);
            M(:,1)=count;
            M(:,2)=pdt/365.25;
            M(:,3)=lon;
            M(:,4)=lat;
            [m1,n1]=size(M);
            index=[index;m1]
            float_obs=[float_obs;M];
            count=count+1;
end

[m,n]=size(float_obs)
fclose(fid);

    
   firstcol=ones(m,1);
    
    float_obs(:,5)=float_obs(:,1);
    float_obs(:,1)=ones(m,1);
    float_obs(:,6)=float_obs(:,3);
    float_obs(:,3)=float_obs(:,5);
    float_obs(:,7)=float_obs(:,4);
    float_obs(:,4)=float_obs(:,6);
    
    

    
    
    outfile='../obs_float/nemed_observations.dat';
format long
 files=fopen(outfile,'w');
 fprintf(files,'%d %d %d %f\n',float_obs(:,1:4)');
 
     float_obs(:,1)=firstcol+1;

 fprintf(files,'%d %d %d %f\n',float_obs(:,[1,2,3,7])');

 fclose(files);
 
 
load ../obs_float/meshgrid2.dat

Nlat=58; %Phi
Nlong=87; %Lambda
GR_long=reshape(meshgrid2(:,1),Nlong,Nlat); 
GR_lat=reshape(meshgrid2(:,2),Nlong,Nlat); 
load ../obs_float/nemed_observations.dat
I=find(nemed_observations(:,1)==1);
xi=interp1(GR_long(:,1),1:Nlong,nemed_observations(I,end));
xi(1:10)
I=find(nemed_observations(:,1)==2);
yi=interp1(GR_lat(1,:),1:Nlat,nemed_observations(I,end));

    float_obs(:,1)=firstcol;

    float_obs(:,4)=xi;
    float_obs(:,7)=yi;

    
 outfile='../obs_float/nemed_observations_2.dat';
format long
 files=fopen(outfile,'w');
 fprintf(files,'%d %d %d %f\n',float_obs(:,1:4)');
 
     float_obs(:,1)=firstcol+1;

 fprintf(files,'%d %d %d %f\n',float_obs(:,[1,2,3,7])');

 fclose(files);
 
  outfile='../obs_float/oneandfive.dat';
  load ../obs_float/nemed_observations_2.dat;
   files=fopen(outfile,'w');

 I1=find(nemed_observations_2(:,3)==1);
 I2=find(nemed_observations_2(:,3)==2);
 I3=find(nemed_observations_2(:,3)==3);
 s1=length(I1)
 S1=s1/2;
 s2=length(I2);
 S2=s2/2;
 s3=length(I3);
 S3=s3/2;

 I=[I1(1:timeneeded) I2(1:timeneeded) I3(1:timeneeded) I1(S1+1:S1+timeneeded) I2(S2+1:S2+timeneeded) I3(S3+1:S3+timeneeded)];

 fprintf(files,'%d %d %d %f\n',nemed_observations_2(I,[1,2,3,4])');

 fclose(files);
 
outfile='../obs_float/oneandfive_final.dat';
load ../obs_float/oneandfive.dat;
[m,n]=size(oneandfive)


    count=1;
    for s=1:m/6
        oneandfive(s,2)=count;
        oneandfive(s+m/6,2)=count;
        oneandfive(s+2*m/6,2)=count;
        oneandfive(s+3*m/6,2)=count;
        oneandfive(s+4*m/6,2)=count;
        oneandfive(s+5*m/6,2)=count;

      
        count=count+3;
    
    
    end

fid=fopen(outfile,'w');
fprintf(fid,'%d %d %d %f\n',oneandfive(:,1:4)');



outfile='../obs_float/obs_float_test.dat';
load ../obs_float/oneandfive_final.dat;
[d,f]=size(oneandfive_final)
floater1=zeros(d,f);
count1=1;


for i=1:d/2
        floater(count1,:)=oneandfive_final(i,:);
        floater(count1+1,:)=oneandfive_final(i+d/2,:);
    

        count1=count1+2;
   
end


fid=fopen(outfile,'w');
fprintf(fid,'%d %d %d %f\n',floater(1:timeneeded*4,:)');
fclose(fid);

outfile='../obs_float/third_observation.dat';
load ../obs_float/oneandfive_final.dat;
[d,f]=size(oneandfive_final)
floater1=zeros(d,f);
count1=1;


for i=1:d/2
        floater(count1,:)=oneandfive_final(i,:);
        floater(count1+1,:)=oneandfive_final(i+d/2,:);
    

        count1=count1+2;
   
end


fid=fopen(outfile,'w');
fprintf(fid,'%d %d %d %f\n',floater(timeneeded*4+1:end,:)');
fclose(fid);


outfile='../obs_float/init.dat';
load ../obs_float/oneandfive_final.dat;
[d,f]=size(oneandfive_final)
floater1=zeros(d,f);
count1=1;


for i=1:d/2
        floater(count1,:)=oneandfive_final(i,:);
        floater(count1+1,:)=oneandfive_final(i+d/2,:);
    

        count1=count1+2;
   
end


fid=fopen(outfile,'w');
fprintf(fid,'%d %d %d %f\n',floater');
fclose(fid);


end

