!rm ctd.xyz
  var1='temp';
  var2='salt';
  var3='dens';
  var4='trans';
 
sta=stations;
[m,n]=size(sta);
mexcdf('setopts',0);
for j=1:m
  cdfid=mexcdf('open',sta(j,:),'nowrite');
  wdepth(j)=mexcdf('attget',cdfid,'global','WATER_DEPTH');
  lat(j)=mexcdf('varget1',cdfid,'latitude',0);
  lon(j)=-(mexcdf('varget1',cdfid,'longitude',0));
  [depnam,dlen]=mexcdf('diminq',cdfid,'depth');
  depth=mexcdf('varget',cdfid,'depth',0,dlen);
  corner=[0 0 0 0];
  edge=[1 dlen 1  1];

  u1=mexcdf('varget',cdfid,var1,corner,edge);
  lab1=mexcdf('attget',cdfid,var1,'long_name');
  xlab1=mexcdf('attget',cdfid,var1,'units');

  u2=mexcdf('varget',cdfid,var2,corner,edge);
  lab2=mexcdf('attget',cdfid,var2,'long_name');
  xlab2=mexcdf('attget',cdfid,var2,'units');

  u3=mexcdf('varget',cdfid,var3,corner,edge);
  lab3=mexcdf('attget',cdfid,var3,'long_name');
  xlab3=mexcdf('attget',cdfid,var3,'units');

  u4=mexcdf('varget',cdfid,var4,corner,edge);
  lab4=mexcdf('attget',cdfid,var4,'long_name');
  xlab4=mexcdf('attget',cdfid,var4,'units');

  rcode=mexcdf('close',cdfid);
  llon=lon(j)*ones(1,dlen);
  llat=lat(j)*ones(1,dlen);
% if(lon(j) < -69.5 & lat(j)> 41.5),
   data=[llon(:) llat(:) depth(:) u1(:) u2(:) u3(:) u4(:)];
   save tmp.dat data /ascii
   !cat tmp.dat >> ctd.xyz 
%  end
end
data=[lon(:) lat(:) wdepth(:)];
save bathy.dat data /ascii
