Home > fvcom_prepro > write_FVCOM_obs_TS.m

write_FVCOM_obs_TS

PURPOSE ^

Dump observation profile of T/S to netcdf file to initialize

SYNOPSIS ^

function write_FVCOM_obs_TS(time,zsl,nverts,tsl,ssl,filename,mytitle)

DESCRIPTION ^

 Dump observation profile of T/S to netcdf file to initialize
 stratification in FVCOM

 function write_FVCOM_obs_TS(jday,zsl,nverts,tsl,ssl,filename,mytitle) 

 DESCRIPTION:
    Generate a NetCDF file containing vertical profile of T/S for FVCOM 

 INPUT 
   jday= modified julian day or initial model time
   zsl = zcoordinate of observations, positive up 
   nverts = number of vertices in the mesh**
   tsl = temperature at level k (C)
   ssl = salinity at level k (PSU)
   filename  = filename to which to dump data
   mytitle   = global attribute 

 OUTPUT:
    NetCDF file: filename

 **in this script the temp/sal profiles are assumed to be constant at each
 node

 EXAMPLE USAGE

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)
    Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history
    2012-06-15 Added support for native MATLAB NetCDF routines. Requires
    MATLAB 2010a or higher.
   
==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function write_FVCOM_obs_TS(time,zsl,nverts,tsl,ssl,filename,mytitle) 
0002 
0003 % Dump observation profile of T/S to netcdf file to initialize
0004 % stratification in FVCOM
0005 %
0006 % function write_FVCOM_obs_TS(jday,zsl,nverts,tsl,ssl,filename,mytitle)
0007 %
0008 % DESCRIPTION:
0009 %    Generate a NetCDF file containing vertical profile of T/S for FVCOM
0010 %
0011 % INPUT
0012 %   jday= modified julian day or initial model time
0013 %   zsl = zcoordinate of observations, positive up
0014 %   nverts = number of vertices in the mesh**
0015 %   tsl = temperature at level k (C)
0016 %   ssl = salinity at level k (PSU)
0017 %   filename  = filename to which to dump data
0018 %   mytitle   = global attribute
0019 %
0020 % OUTPUT:
0021 %    NetCDF file: filename
0022 %
0023 % **in this script the temp/sal profiles are assumed to be constant at each
0024 % node
0025 %
0026 % EXAMPLE USAGE
0027 %
0028 % Author(s):
0029 %    Geoff Cowles (University of Massachusetts Dartmouth)
0030 %    Pierre Cazenave (Plymouth Marine Laboratory)
0031 %
0032 % Revision history
0033 %    2012-06-15 Added support for native MATLAB NetCDF routines. Requires
0034 %    MATLAB 2010a or higher.
0035 %
0036 %==============================================================================
0037 
0038 
0039 % check dimensions
0040 ksl = numel(zsl);
0041 
0042 if(numel(tsl) ~= ksl)
0043   error('dimensions of ssl do not match zsl')
0044 end;
0045 if(numel(ssl) ~= ksl)
0046   error('dimensions of ssl do not match zsl')
0047 end;
0048 
0049 %------------------------------------------------------------------------------
0050 % Dump to S/T profile to NetCDF file
0051 %------------------------------------------------------------------------------
0052 fprintf('Dumping to NetCDF file: \n',filename);
0053 fprintf('Size of T/S array: \n',ksl);
0054 
0055 nc = netcdf.create(filename,'clobber');
0056 
0057 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',mytitle)
0058 
0059 % define dimensions
0060 ksl_dimid=netcdf.defDim(nc,'ksl',ksl);
0061 node_dimid=netcdf.defDim(nc,'ksl',nverts);
0062 time_dimid=netcdf.defDim(nc,'ksl',netcdf.getConstant('NC_UNLIMITED'));
0063 
0064 % define variables and attributes
0065 time_varid=netcdf.defVar(nc,'time','NC_FLOAT',time_dimid);
0066 netcdf.putAtt(nc,time_varid,'long_name','time');
0067 netcdf.putAtt(nc,time_varid,'units','days since 0.0');
0068 netcdf.putAtt(nc,time_varid,'time_zone','none');
0069 
0070 itime_varid=netcdf.defVar(nc,'time','NC_INT',time_dimid);
0071 netcdf.putAtt(nc,itime_varid,'units','days since 0.0');
0072 netcdf.putAtt(nc,itime_varid,'time_zone','none');
0073 
0074 itime2_varid=netcdf.defVar(nc,'Itime','NC_INT',time_dimid);
0075 netcdf.putAtt(nc,itime2_varid,'units','msec since 00:00:00');
0076 netcdf.putAtt(nc,itime2_varid,'time_zone','none');
0077 
0078 zsl_varid=netcdf.defVar(nc,'Itime2','NC_FLOAT',ksl_dimid);
0079 netcdf.putAtt(nc,zsl_varid,'long_name','standard z levels positive up');
0080 netcdf.putAtt(nc,zsl_varid,'units','m');
0081 
0082 % TODO: Check order of dimensions here
0083 ssl_varid=netcdf.defVar(nc,'time','NC_FLOAT',[time_dimid,ksl_dimid,node_dimid]);
0084 netcdf.putAtt(nc,ssl_varid,'long_name','observed_salinity_profile');
0085 netcdf.putAtt(nc,ssl_varid,'units','PSU');
0086 
0087 tsl_varid=netcdf.defVar(nc,'time','NC_FLOAT',[time_dimid,ksl_dimid,node_dimid]);
0088 netcdf.putAtt(nc,tsl_varid,'long_name','observed_temperature_profile');
0089 netcdf.putAtt(nc,tsl_varid,'units','C');
0090 
0091 % end definitions
0092 netcdf.endDef(nc);
0093 
0094 
0095 % write vars
0096 netcdf.putVar(nc,time_varid,time*ones(1,nverts));
0097 netcdf.putVar(nc,itime_varid,floor(time)*ones(1,nverts));
0098 netcdf.putVar(nc,itime2_varid,(mod(time,1)*24*3600*1000)*ones(1,nverts));
0099 netcdf.putVar(nc,zsl_varid,zsl);
0100 
0101 
0102 for i=1:numel(time)
0103     for k=1:ksl
0104         nc{'tsl'}(i,k,:) = tsl(k); 
0105     end;
0106 end;
0107 
0108 for i=1:numel(time)
0109     for k=1:ksl
0110         nc{'ssl'}(i,k,:) = ssl(k);
0111     end;
0112 end;
0113 
0114 ierr = close(nc);
0115 
0116 
0117 
0118 
0119

Generated on Tue 18-Dec-2012 12:37:31 by m2html © 2005