function st=read_cmb(filename)
%function st=read_cmb(filename)
%
%to read variables into workspace of gui menu
%from a standard matlab format file containing
%a structure called st

fid=fopen(filename);

line='*';
while (strcmp(line(1),'*') | strcmp(line(1),'#'))
line=fgetl(fid);
end

%now the line loaded is the first line

matrix=str2num(line);
submatrix=fscanf(fid, '%f %f %f %f %f %f %f %f %f %f %f %f %f', [13 inf])';

matrix=[matrix; submatrix];

badflag=find(matrix(:,1)<10e-20|matrix(:,2)<10e-20|matrix(:,3)<10e-20|matrix(:,4)<10e-20);
matrix(badflag,1)=nan;
goodflag=find(~isnan(matrix(:,1)));
matrix=matrix(goodflag,:);

%Now assign the variables from the matrix
st.ctdprs=matrix(:,1);
st.ctdtmp1=matrix(:,2);	%collecting two temperatures
st.ctdtmp2=matrix(:,3);
st.ctdcon1=matrix(:,4);	%collecting two conductivities
st.ctdcon2=matrix(:,5);
st.o2.curr=matrix(:,6);
st.o2.temp=matrix(:,7);
st.o2.dOCdT=matrix(:,8);	%collecting two oxygens
st.o2.MLL=matrix(:,9);
st.ctdsal1=matrix(:,10); %corresponding to two cond.
st.ctdsal2=matrix(:,11);

st.ctdptmp1=sw_ptmp(st.ctdsal1,st.ctdtmp1,st.ctdprs,0);
st.ctdptmp2=sw_ptmp(st.ctdsal2,st.ctdtmp2,st.ctdprs,0);
st.ctdpden1=sw_pden(st.ctdsal1,st.ctdtmp1,st.ctdprs,0);
st.ctdpden2=sw_pden(st.ctdsal2,st.ctdtmp2,st.ctdprs,0);
st.ctdsig11=sw_pden(st.ctdsal1,st.ctdtmp1,st.ctdprs,1000);
st.ctdsig12=sw_pden(st.ctdsal2,st.ctdtmp2,st.ctdprs,1000);
st.ctdsig21=sw_pden(st.ctdsal1,st.ctdtmp1,st.ctdprs,2000);
st.ctdsig22=sw_pden(st.ctdsal2,st.ctdtmp2,st.ctdprs,2000);
st.ctdsig31=sw_pden(st.ctdsal1,st.ctdtmp1,st.ctdprs,3000);
st.ctdsig32=sw_pden(st.ctdsal2,st.ctdtmp2,st.ctdprs,3000);
st.ctdsig41=sw_pden(st.ctdsal1,st.ctdtmp1,st.ctdprs,4000);
st.ctdsig42=sw_pden(st.ctdsal2,st.ctdtmp2,st.ctdprs,4000);

[st.grd.salt,st.grd.ptmp]=meshgrid([32:.5:39],[0:2:30]);
st.grd.pden=sw_pden(st.grd.salt,st.grd.ptmp,zeros(size(st.grd.ptmp)),0);
st.grd.pden=st.grd.pden-1000;
