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


 EXAMPLE USAGE

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

 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 %
0024 % EXAMPLE USAGE
0025 %
0026 % Author(s):
0027 %    Geoff Cowles (University of Massachusetts Dartmouth)
0028 %    Pierre Cazenave (Plymouth Marine Laboratory)
0029 %    Chang Liu (University of Massachusetts Dartmouth)
0030 %
0031 % Revision history
0032 %    2012-06-15 Added support for native MATLAB NetCDF routines. Requires
0033 %    MATLAB 2010a or higher.
0034 %
0035 %==============================================================================
0036 
0037 global ftbverbose
0038 
0039 subname = 'write_FVCOM_obc_TS'
0040 if ftbverbose
0041     fprintf('\nbegin : %s \n', subname);
0042 end
0043 
0044 % check dimensions
0045 ksl = numel(zsl);
0046 
0047 % if(numel(tsl) ~= ksl)
0048 %   error('dimensions of ssl do not match zsl')
0049 % end;
0050 % if(numel(ssl) ~= ksl)
0051 %   error('dimensions of ssl do not match zsl')
0052 % end;
0053 
0054 %------------------------------------------------------------------------------
0055 % Dump to S/T profile to NetCDF file
0056 %------------------------------------------------------------------------------
0057 fprintf(['Dumping to NetCDF file: ',filename,'\n']);
0058 fprintf('Size of T/S array: %d\n',ksl);
0059 
0060 nc = netcdf.create(filename,'clobber');
0061 
0062 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'title',mytitle)
0063 netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),'history', sprintf('File created with %s from the MATLAB fvcom-toolbox', subname))
0064 
0065 % define dimensions
0066 ksl_dimid=netcdf.defDim(nc,'ksl',ksl);
0067 node_dimid=netcdf.defDim(nc,'node',nverts);
0068 time_dimid=netcdf.defDim(nc,'time',netcdf.getConstant('NC_UNLIMITED'));
0069 
0070 % define variables and attributes
0071 time_varid=netcdf.defVar(nc,'time','NC_FLOAT',time_dimid);
0072 netcdf.putAtt(nc,time_varid,'long_name','time');
0073 netcdf.putAtt(nc,time_varid,'units','days since 0.0');
0074 netcdf.putAtt(nc,time_varid,'time_zone','none');
0075 
0076 itime_varid=netcdf.defVar(nc,'Itime','NC_INT',time_dimid);
0077 netcdf.putAtt(nc,itime_varid,'units','days since 0.0');
0078 netcdf.putAtt(nc,itime_varid,'time_zone','none');
0079 
0080 itime2_varid=netcdf.defVar(nc,'Itime2','NC_INT',time_dimid);
0081 netcdf.putAtt(nc,itime2_varid,'units','msec since 00:00:00');
0082 netcdf.putAtt(nc,itime2_varid,'time_zone','none');
0083 
0084 zsl_varid=netcdf.defVar(nc,'zsl','NC_FLOAT',ksl_dimid);
0085 netcdf.putAtt(nc,zsl_varid,'long_name','standard z levels positive up');
0086 netcdf.putAtt(nc,zsl_varid,'units','m');
0087 
0088 ssl_varid=netcdf.defVar(nc,'ssl','NC_FLOAT',[node_dimid,ksl_dimid,time_dimid]);
0089 netcdf.putAtt(nc,ssl_varid,'long_name','observed_salinity_profile');
0090 netcdf.putAtt(nc,ssl_varid,'units','PSU');
0091 
0092 tsl_varid=netcdf.defVar(nc,'tsl','NC_FLOAT',[node_dimid,ksl_dimid,time_dimid]);
0093 netcdf.putAtt(nc,tsl_varid,'long_name','observed_temperature_profile');
0094 netcdf.putAtt(nc,tsl_varid,'units','C');
0095 
0096 % end definitions
0097 netcdf.endDef(nc);
0098 
0099 
0100 % write vars
0101 netcdf.putVar(nc,time_varid,0,numel(time),time);
0102 netcdf.putVar(nc,itime_varid,floor(time));
0103 netcdf.putVar(nc,itime2_varid,0,numel(time),(mod(time,1)*24*3600*1000));
0104 netcdf.putVar(nc,zsl_varid,zsl);
0105 netcdf.putVar(nc,tsl_varid,tsl);
0106 netcdf.putVar(nc,ssl_varid,ssl);
0107 
0108 
0109 % for i=1:numel(time)
0110 %     for k=1:ksl
0111 %         nc{'tsl'}(i,k,:) = tsl(k);
0112 %     end;
0113 % end;
0114 %
0115 % for i=1:numel(time)
0116 %     for k=1:ksl
0117 %         nc{'ssl'}(i,k,:) = ssl(k);
0118 %     end;
0119 % end;
0120 %
0121 % Close the NetCDF file(s)
0122 netcdf.close(nc);
0123 
0124 if ftbverbose
0125     fprintf('end   : %s \n',  subname)
0126 end
0127 
0128 
0129

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005