function data = read_dof (fname)

% reads DOF file and saves it to matlab

nline_data = 7;



fid = fopen(fname,'r');

nline = 0;

while 1

    tline = fgetl(fid);

    if ~ischar(tline),   break,   end    

    if strcmp(tline(1),'o')

        nline = nline + 1;

        if nline >= nline_data

            data.index(nline-nline_data+1) = str2num(tline( 3:10));

            data.type (nline-nline_data+1) = str2num(tline(12:15));

    

            data.lon  (nline-nline_data+1) = str2num(tline(17:25));

            data.lat  (nline-nline_data+1) = str2num(tline(26:34));

        

            data.value(nline-nline_data+1) = str2num(tline(47:57));

            data.sdev (nline-nline_data+1) = str2num(tline(58:64));

            data.bmean(nline-nline_data+1) = str2num(tline(65:75));

            data.sdev2(nline-nline_data+1) = str2num(tline(75:end));

        end

    end

end

fclose(fid);

save ('dof_obs.mat','data');

return



% plot(data.ssh);

latlim = [18 32];

lonlim = [118 134];

coast = load('/project/p1150/M-bench/lib/coastline_files/world.dat');

hold on

plot(115, 18,'ro','MarkerSize',4,'MarkerFaceColor','r');

plot(115, 18,'k^','MarkerSize',7,'MarkerFaceColor','b');

legend('MCSST','SHIP SST');

plot(coast(:,1), coast(:,2),'k');



ind_ship  = find(data.type == 3 | data.type == 5);

ind_mcsst = find(data.type == 57);



plot_sparse_data_layer(data.lon(ind_mcsst),data.lat(ind_mcsst),data.value(ind_mcsst),0, [26 31], [4 4], ['o' 'o'], NaN,jet(254));

plot_sparse_data_layer(data.lon(ind_ship),data.lat(ind_ship),data.value(ind_ship),0, [26 31], [7 7], ['^' '^'], 'k',jet(254));



set(gca,'XLim',lonlim,'YLim',latlim);

colorbar;

title ('SST OBS, DOF file');

xlabel('LONGITUDE, EAST ^o');

ylabel('LATITUDE, NORTH ^o');

