Home > RPSstuff > write_topo_cf.m

write_topo_cf

PURPOSE ^

WRITE_TOPO_CF: Writes 2D topo/bathy data to CF-compliant NetCDF file

SYNOPSIS ^

function []=write_topo_cf(ncfile,z,lon,lat);

DESCRIPTION ^

 WRITE_TOPO_CF: Writes 2D topo/bathy data to CF-compliant NetCDF file
 so it can be visualized in tools like Unidata's IDV
u  Usage: write_topo_cf(ncfile,z,lon,lat);
        ncfile = name of netcdf file for output
         lon = longitude (west negative)
         lat = latitude (north positive)
         z = z dependent variable (topo grid, bathy grid)
 if pcolor(z,x,y) looks good (not flipped or rotated), then use this routine
 to write out the data to netCDF

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function []=write_topo_cf(ncfile,z,lon,lat);
0002 % WRITE_TOPO_CF: Writes 2D topo/bathy data to CF-compliant NetCDF file
0003 % so it can be visualized in tools like Unidata's IDV
0004 %u  Usage: write_topo_cf(ncfile,z,lon,lat);
0005 %        ncfile = name of netcdf file for output
0006 %         lon = longitude (west negative)
0007 %         lat = latitude (north positive)
0008 %         z = z dependent variable (topo grid, bathy grid)
0009 % if pcolor(z,x,y) looks good (not flipped or rotated), then use this routine
0010 % to write out the data to netCDF
0011 %
0012 
0013 % Rich Signell (rsignell@usgs.gov)
0014 % July 11, 2005
0015 
0016 nc=netcdf(ncfile,'clobber');
0017 
0018 [ny,nx]=size(z);
0019 % define dimensions
0020 nc('x')=nx;
0021 nc('y')=ny;
0022 
0023 % define variables
0024 nc{'z'}=ncfloat('y','x');
0025 [m,n]=size(lon);
0026 
0027 if(min(m,n)==1),
0028 % lon,lat are 1D
0029   nc{'lon'}=ncfloat('x');
0030   nc{'lat'}=ncfloat('y');
0031 else
0032 % lon,lat are 2D
0033   nc{'lon'}=ncfloat('y','x');
0034   nc{'lat'}=ncfloat('y','x');
0035 end
0036 nc{'z'}.coordinates='lon lat';
0037 nc{'lon'}.units='degree_east';
0038 nc{'lat'}.units='degree_north';
0039 nc{'z'}.units='meter';
0040 nc.Conventions='CF-1.0';
0041 
0042 % fill variables with data
0043 nc{'lon'}(:)=lon;
0044 nc{'lat'}(:)=lat;
0045 nc{'z'}(:)=z;
0046 
0047 close(nc);

Generated on Wed 30-Nov-2005 14:45:02 by m2html © 2003