% Extract2asc
%
%           extract a station and print values to a file
%
deprange=[-3000 0];
DataDir='/gremlin/SOGLOBEC/CruiseData/';
DepthResolution='OneMeter';
Line='grid';
zi=deprange(1):10:deprange(2)-10;

CruiseName='NBP0103';cast=29;
%CruiseName='NBP0104';cast=22;

file= [DataDir '/' CruiseName '/Ctd/' DepthResolution '/ctd' castnum(cast) '.dat'];
[nlines,ndepths,desc,p,T,S,PT,r0,r1,bv,t0,t1,s0,s1,O2,par,tr,fl] = readctd(file);

dep=-p;
si=interp1(dep,r0,zi,'linear');

figure
plot(si,zi)
title('Sigma0 vs depth')
xlabel('Density')
ylabel('Depth')

%               print values to a file
[m,nz]=size(zi);
fid=fopen(['Sig.' CruiseName '.' castnum(cast) '.asc'],'w');
for i=nz:-1:1
   fprintf(fid,'%9.4f  %9.4f  \n',zi(i),si(i));
end 
fclose(fid);

