%function []=writegrid(grid,file);
%  writes grid to file
%   usage:   writegrid(ngrid,'ngrid.dat.4');
%
file='ngrid.dat.6';
z2=replace(z,nan,-99999.);
ngrid(:,5)=z2(:);
fid=fopen(file,'w');
fprintf(fid,'%4d%4d%10.2f%10.2f%10.2f%7.1f%7.1f%5.2f%16.8e%16.8e\n',ngrid');
fclose(fid);
