function ROMS2SWAN(varargin); % ROMS2SWAN(varargin) - Convert ROMS grid to SWAN ASCII grid % % Function to convert a ROMS netCDF depth grid into a SWAN ASCII depth grid, % and create the SWAN curvilinear coordinates grid. % If the input is the name of a netCDF file (string), the function calls the variables % x_rho, y_rho, and h from the file; if the input is four variables, it assumes % that these are the variables x_rho, y_rho, h, and mask_rho in that order. % Files output to the ASCII filenames defined in the SWAN input file - bathymetry % goes to roms_bathy.bot, grid goes to grid_coord.grd. % % Soupy Alexander, 6/11/02 % csherwood@usgs.gov 2/10/05 if nargin == 1; ncid = netcdf(varargin{1}); x_rho = ncid{'x_rho'}(:); y_rho = ncid{'y_rho'}(:); h = ncid{'h'}(:); mask_rho = ncid{'mask_rho'}(:); elseif nargin == 4; x_rho = varargin{1}; y_rho = varargin{2}; h = varargin{3}; mask_rho = varargin{4}; else error('Improper number of inputs: input netCDF file or four variables.'); end clear ncid varargin %Replace the land positions with the flag for land (defined in the SWAN %input file) land_values = find(mask_rho == 0); h(land_values) = 9999; %x_rho(land_values) = 9999; %y_rho(land_values) = 9999; %Print the depths to the bathy file [m,n] = size(h) fid = fopen('roms_bathy.bot','w'); for index = 1:n; for index2 = 1:m; fprintf(fid,' '); fprintf(fid,'%1.6e',h(index2,index)); end fprintf(fid,'\n'); end fclose(fid); %Print the grid coordinates to the grid file fid = fopen('grid_coord.grd','w'); for index = 1:n; for index2 = 1:m; fprintf(fid,' '); fprintf(fid,'%1.6e',x_rho(index2,index)); end fprintf(fid,'\n'); end for index = 1:n; for index2 = 1:m; fprintf(fid,' '); fprintf(fid,'%1.6e',y_rho(index2,index)); end fprintf(fid,'\n'); end fclose(fid); %fprintf(fid,'%1.6e\n',x_rho'); %clear fid %fid = fopen('grid_coord.grd','a'); %fprintf(fid,'%1.6e\n',y_rho'); %fclose('all');