Home > omviz > readgrid.m

readgrid

PURPOSE ^

READGRID reads the ECOM "model_grid" file

SYNOPSIS ^

function [d,x,y,i,j,xx,yy,h,data,str]=readgrid(modgridfile);

DESCRIPTION ^

  READGRID reads the ECOM "model_grid" file

  Usage (1):  [d,x,y]=readgrid(modgridfile);
  where d = depth grid array
        x = array of x locations of grid centers
        y = array of y locations of grid centers
  
  or  [d,x,y,i,j,xx,yy,h,data,str]=readgrid(modgridfile);
 
       [i,j,xx,yy,h] = column vectors of i,j,x,y,h from model_grid
        data = all the data columns following the header 
        str = cell array of strings that make up the header

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [d,x,y,i,j,xx,yy,h,data,str]=readgrid(modgridfile);
0002 %  READGRID reads the ECOM "model_grid" file
0003 %
0004 %  Usage (1):  [d,x,y]=readgrid(modgridfile);
0005 %  where d = depth grid array
0006 %        x = array of x locations of grid centers
0007 %        y = array of y locations of grid centers
0008 %
0009 %  or  [d,x,y,i,j,xx,yy,h,data,str]=readgrid(modgridfile);
0010 %
0011 %       [i,j,xx,yy,h] = column vectors of i,j,x,y,h from model_grid
0012 %        data = all the data columns following the header
0013 %        str = cell array of strings that make up the header
0014  
0015 fid=fopen(modgridfile);
0016 
0017 % read two comments lines at beginning of model_grid
0018 
0019 str{1}=fgetl(fid);
0020 str{2}=fgetl(fid);
0021 
0022 str{3}=fgetl(fid);  % number of sigma level
0023 nsigma=str2num(str{3});  %number of sigma layers
0024 for i=1:nsigma;
0025   j=3+i;
0026   str{j}=fgetl(fid);
0027   sigma(i)=str2num(str{j});
0028 end
0029 str{j+1}=fgetl(fid);  %comment line
0030 
0031 %read grid size
0032 str{j+2}=fgetl(fid);
0033 n=sscanf(str{j+2},'%d %d');
0034 im=n(1);
0035 jm=n(2);
0036 
0037 nt=im*jm;
0038 
0039 data=fscanf(fid,'%f',[10,nt]);
0040 data=data';
0041 fclose(fid);
0042 
0043 land=-99999;
0044 
0045 i=data(:,1);
0046 j=data(:,2);
0047 h=data(:,5);
0048 xx=data(:,9);
0049 yy=data(:,10);
0050 
0051 for k=1:nt;
0052   ii=i(k);
0053   jj=j(k);
0054   d(ii,jj)=h(k);
0055   x(ii,jj)=xx(k);
0056   y(ii,jj)=yy(k);
0057 end
0058 ind=find(d==-99999.);
0059 d(ind)=d(ind)*nan;

Generated on Thu 01-Dec-2005 08:50:35 by m2html © 2003