


clear all; close all; gridfile = '~gcowles/Data/NOAA_MITSG_TKE/mtm1b.nc'; x1 = 836100; x2 = 935370; y1 = -186230; y2 = -125810; ds = 2000; fname = 'mtm1b_2km_nansound_vecs.dat';


0001 function gridvecs(gridfile,x1,x2,y1,y2,ds,thresh,fname) 0002 0003 %clear all; close all; 0004 %gridfile = '~gcowles/Data/NOAA_MITSG_TKE/mtm1b.nc'; 0005 %x1 = 836100; 0006 %x2 = 935370; 0007 %y1 = -186230; 0008 %y2 = -125810; 0009 %ds = 2000; 0010 %fname = 'mtm1b_2km_nansound_vecs.dat'; 0011 0012 % Find elements closest to a grid of points for cleaning up vector plots 0013 % 0014 % function [] = gridvecs(fname,x2,y1,y2,ds) 0015 % 0016 % DESCRIPTION: 0017 % Find elements closest to a grid of points for cleaning up vector plots 0018 % 0019 % INPUT: 0020 % gridfile: FVCOM netcdf output file containing x,y 0021 % fname: list of node numbers 0022 % x1: left side of bounding box 0023 % x2: right side of bounding box 0024 % y1: bottom of bounding box 0025 % y2: top of bounding box 0026 % ds: grid lengthscale 0027 % thresh: threshold distance in units of x. If nearest FVCOM point to the 0028 % vector grid is greater than this distance, no point is assigned. 0029 % 0030 % OUTPUT: 0031 % fname: file containing indices of node numbers where vectors should be plot 0032 % 0033 % Author(s): 0034 % Geoff Cowles (University of Massachusetts Dartmouth) 0035 % 0036 % References 0037 %============================================================================== 0038 0039 0040 % open grid file and read data 0041 if(~exist(gridfile)) 0042 error('grid file does not exist') 0043 end; 0044 0045 nc = netcdf(gridfile); 0046 x = nc{'x'}(:); 0047 y = nc{'y'}(:); 0048 nVerts = numel(x); 0049 fprintf('number of nodes in the mesh %d\n',nVerts); 0050 nc = close(nc); 0051 0052 % create the grid 0053 [X,Y] = meshgrid(x1:ds:x2,y1:ds:y2); 0054 [il,jl] = size(X); 0055 node = zeros(il*jl,1); 0056 cnt = 0; 0057 for i=1:il 0058 for j=1:jl 0059 xloc = X(i,j); 0060 yloc = Y(i,j); 0061 dist = sqrt( (x-xloc).^2 + (y-yloc).^2); 0062 [mind,imin] = min(dist); 0063 if(mind < thresh); 0064 cnt = cnt + 1; 0065 node(cnt) = imin; 0066 end; 0067 end; 0068 end; 0069 node = node(1:cnt); 0070 0071 % dump the list 0072 fid = fopen(fname,'w'); 0073 for i=1:cnt 0074 fprintf(fid,'%d\n',node(i)); 0075 end; 0076 fclose(fid);