path(path,'/home/foltz/matlab/mexnc');
path(path,'/home/foltz/matlab/netcdf2');
path(path,'/home/foltz/matlab/netcdf2/mexnc');
path(path,'/home/foltz/matlab/netcdf2/netcdf_toolbox');
path(path,'/home/foltz/matlab/netcdf2/netcdf_toolbox/netcdf');
path(path,'/home/foltz/matlab/netcdf2/netcdf_toolbox/netcdf/ncsource');
path(path,'/home/foltz/matlab/netcdf2/netcdf_toolbox/netcdf/nctype');
path(path,'/home/foltz/matlab/netcdf2/netcdf_toolbox/netcdf/ncutility');
path(path,'/home/foltz/matlab/netcdf2/snctools');

mo='apr17';
%loc={'0n23w','4n23w','12n23w','21n23w'};
%loc={'12n38w','8n38w'};
%loc={'0n23w','4n23w','12n23w','21n23w'};
%loc={'4n90e','8n90e','12n90e','15n90e'};
%loc={'0n23w','4n23w','12n23w','21n23w','4n38w','8n38w','12n38w','15n38w','20n38w','0n35w',...
%'0n10w','0n0e','6s10w','10s10w','19s34w','14s32w','8s30w'};
%loc={'4n38w','8n38w','12n38w','15n38w','20n38w'};
loc={'0n23w'};

end_dy=[2017 4 30];
%beg_dy=[2003 10 1];
beg_dy=[1997 1 1];
add_dy=2454423-datenum(2007,11,18);	% add this much to datenum(day) to get netcdf day number

for z=1:length(loc)

    swr2=ncread(['/home/foltz/pirata/temp/t' loc{z} '_dy.cdf'],'T_20');
    depth=ncread(['/home/foltz/pirata/temp/t' loc{z} '_dy.cdf'],'depth');
    cdf_dy=ncread(['/home/foltz/pirata/temp/t' loc{z} '_dy.cdf'],'time');
	%ncid=netcdf(['/home/foltz/pirata/temp/t' loc{z} '_dy.cdf'],'nowrite');
	swr=-9999*ones(datenum(end_dy)-datenum(beg_dy)+1,length(depth));
	%cdf_dy=ncid{'time'}(:);
	file_dy1=cdf_dy(1)-add_dy-datenum(beg_dy)+1;
	swr(file_dy1:file_dy1+length(cdf_dy)-1,:)=rot90(squeeze(swr2(1,1,:,:)),-1);
	
    
    depth
	%close(ncid);
	swr(find(swr>10000))=-9999;
	

	fwrite(fopen(['/home/foltz/pirata/temp/' mo '/temp_dy_' loc{z} '.dat'],'w'),rot90(swr),'float');
	
    
end
