function []=create(cdf,v,vnames,lat,lon,start,dt,wdepth,idepth,units)
%CREATE  creates netCDF time series from data with even time base
%
% USAGE: []=create(cdf,v,vnames,lat,lon,start,dt,wdepth,idepth,units)
%
% where:
%  cdf  = cdf file name to file to be created
%  v = matrix of time series in columns
%  vnames = character matrix with names of variables, 1 per row
%  lat  = latitude
%  lon  = longitude
%  start = [yyyy mm dd hh mi sc] 
%  dt    = time interval in seconds
%
[m,n]=size(v);
[mm,nn]=size(vnames);
if(mm~=n),
  disp(' must have a name for each variable')
  return
end
% create netCDF file
cdfid=mexcdf('create',cdf,'NC_CLOBBER');
%
% define dimension
dimid=mexcdf('dimdef',cdfid,'cycles',m);
% define variables
timeid=mexcdf('vardef',cdfid,'time','NC_LONG',1,dimid);
mexcdf('attput',cdfid,timeid,'units','char',-1,'seconds');
for i=1:n,
  vname=vnames(i,:);
  vind=min(find(vname==' '));
  if(length(vind)>0),
    vname=vname(1:vind-1);
  end
  varid(i)=mexcdf('vardef',cdfid,vname,'NC_FLOAT',1,dimid);
  mexcdf('attput',cdfid,varid(i),'units','CHAR',-1,units(i,:));
% specify valid_range based on the min and max values of the good data
  vr1=ming(v(:,i));
  vr2=maxg(v(:,i));
  mexcdf('attput',cdfid,varid(i),'valid_range','FLOAT',2,[vr1 vr2]);
  mexcdf('attput',cdfid,varid(i),'instrument_depth','float',1,idepth(i));
end
% put in lat and lon
mexcdf('attput',cdfid,'GLOBAL','latitude','FLOAT',1,lat);
mexcdf('attput',cdfid,'GLOBAL','longitude','FLOAT',1,lon);
mexcdf('attput',cdfid,'GLOBAL','water_depth','FLOAT',1,wdepth);
%
mexcdf('attput',cdfid,'GLOBAL','base_date','SHORT',3,start(1:3));
t0=start(4)*3600+start(5)*60+start(6);
t=[t0:dt:t0+dt*(m-1)];
mexcdf('endef',cdfid);
%
% put data in variables
for i=1:n,
  v(:,i)=replace(v(:,i),NaN,1.e17);
  mexcdf('varput',cdfid,varid(i),0,m,v(:,i));
end
mexcdf('varput',cdfid,timeid,0,m,t);
mexcdf('close',cdfid);
