function writectd(filename,nlines,ndepths,desc,p,t,s,pt,r0,r1,bv,t0,t1,s0,s1,o2,par,tr,fl)
%  write a ctd data to an ascii file
%  input is filename, 
%  number of data lines, number of depths,
%  descriptive strings for variables, 
%  pressure (p), temperature (t), salinity (s), potential temperature (pt), 
%  potdens0 (r0), potdens1 (r1), buoyancy frequency (bv), 
%  temp0 (t0), temp1 (t1), sal0 (s0), sal1 (s1), oxygen (o2), 
%  PAR (par), transmissivity (tr), fluorescense (fl).
%  all variables are column vectors.
%
%           get header information
fid=fopen(filename,'w');
fprintf(fid,'%5d \n',nlines);
for i=1:nlines;
   a=char(desc(i));
   fprintf(fid,'%s \n',a);
end

for i=1:ndepths

  fprintf(fid,'%5d',p(i));
  fprintf(fid,'%8.4f',t(i));
  fprintf(fid,'%8.4f',s(i));
  fprintf(fid,'%8.4f',pt(i));
  fprintf(fid,'%8.4f',r0(i));
  fprintf(fid,'%8.4f',r1(i));
  fprintf(fid,'%10.6f',bv(i));
  fprintf(fid,'%8.4f',t0(i));
  fprintf(fid,'%8.4f',t1(i));
  fprintf(fid,'%8.4f',s0(i));
  fprintf(fid,'%8.4f',s1(i));
  fprintf(fid,'%8.3f',o2(i));
  fprintf(fid,'%10.6f',par(i));
  fprintf(fid,'%7.2f',tr(i));
  fprintf(fid,'%10.6f \n',fl(i));
end

status=fclose(fid);

