function [status]= OTS_met_out(OTS_file,meta,dstruct)
 % the variables are passed in dstruct, the metadata is 
 % all in the struct meta.
 
 % cf checker errors 050330
 % Cant find the problem with:
 % Checking variable: depth, time, lat, lon
 % ERROR: axis attribute inconsistent with coordinate 
 %        type as deduced from units and/or positive


% argos data is depth(1)
  nz=1;
  nt=length(dstruct.time);
  nc = netcdf(OTS_file, 'clobber');
  if isempty(nc),
    status = -1; return, end

nc.data_type = ncchar(meta.global.data_type);
nc.conventions = ncchar(meta.global.conventions);
nc.netcdf_version = ncchar(meta.global.netcdf_version);
nc.format_version = ncchar(meta.global.format_version);
nc.institution = ncchar(meta.global.institution);
nc.source = ncchar(meta.global.source);
nc.naming_authority = ncchar(meta.global.naming_authority);
nc.cdm_data_type = ncchar(meta.global.cdm_data_type);
nc.data_assembly_center = ncchar(meta.global.data_assembly_center);
nc.qc_manual = ncchar(meta.global.qc_manual);
nc.distribution_statement = ncchar(meta.global.distribution_statement);
nc.institution_references = ncchar(meta.global.institution_references);

nc.date_creation = ncchar(meta.global.date_creation);
nc.date_update = ncchar(meta.global.date_update);
nc.data_mode = ncchar(meta.global.data_mode);
nc.update_interval = ncchar(meta.global.update_interval);
nc.quality_control_indicator = ncchar(meta.global.quality_control_indicator);
nc.quality_index = ncchar(meta.global.quality_index);

nc.history = ncchar(meta.global.history);
nc.comment = ncchar(meta.global.comment);
nc.time_coverage_start = ncchar(meta.global.time_coverage_start);
nc.time_coverage_end = ncchar(meta.global.time_coverage_end);
nc.platform_code = ncchar(meta.global.platform_code);
nc.site_code = ncchar(meta.global.site_code);
nc.wmo_platform_code = ncchar(meta.global.wmo_platform_code);
nc.title =ncchar(meta.global.title);
nc.summary =ncchar(meta.global.summary);
nc.pi_name = ncchar(meta.global.pi_name);
nc.references = ncchar(meta.global.references);
nc.citation = ncchar(meta.global.citation);
nc.area =ncchar(meta.global.area);
nc.geospatial_lat_min = ncchar(meta.global.geospatial_lat_min);
nc.geospatial_lat_max = ncchar(meta.global.geospatial_lat_max);
nc.geospatial_lon_min = ncchar(meta.global.geospatial_lon_min);
nc.geospatial_lon_max = ncchar(meta.global.geospatial_lon_max);
nc.geospatial_vertical_min = ncchar(meta.global.geospatial_vertical_min);
nc.geospatial_vertical_max = ncchar(meta.global.geospatial_vertical_max);
nc.Instrument_type =ncchar(meta.global.Instrument_type);
nc.Instrument_reference = ncchar(meta.global.Instrument_reference);
nc.FILL_FLAG = nclong(0);
nc.author = ncchar(meta.global.author);
nc.contact = ncchar(meta.global.contact);
   
% nc.SN = ncchar(meta.global.SN);
%% Dimensions:

  nc('time') = 0;
  nc('depth') = 1;
  nc('latitude') = 1;
  nc('longitude') = 1;

%% Variables and attributes:
%%   coordinate variables:

%  925:D  :Water Depth :depth:m:f10.1:
%  1214:Hght:INST Height: hght:m:F10.4:Height of instrument
  nc{'time'} = ncdouble('time');
  nc{'time'}.standard_name = ncchar('time') ;
  nc{'time'}.long_name = ncchar('time') ;
  nc{'time'}.units = ncchar('days since 1950-01-01T00:00:00Z');
  nc{'time'}.FillValue_ =  ncdouble(1.0e35);
  nc{'time'}.format = ncchar('16.8f');
  nc{'time'}.valid_min = ncdouble(dstruct.time(1));
  nc{'time'}.valid_max = ncdouble(dstruct.time(end));
  nc{'time'}.QC_indicator = ncshort(8);
  nc{'time'}.QC_procedure = ncshort(5);
  nc{'time'}.axis = ncchar('T') ;

  nc{'depth'} = ncfloat('depth');
  nc{'depth'}.standard_name = ncchar('depth') ;
  nc{'depth'}.long_name = ncchar('measurement depth') ;
  nc{'depth'}.units = ncchar('meters');
  nc{'depth'}.format = ncchar('10.3f');
  nc{'depth'}.positive = ncchar('down');
  nc{'depth'}.axis = ncchar( 'Z') ;
  nc{'depth'}.FillValue_ = ncdouble(1.0e35);
  nc{'depth'}.valid_min = ncdouble(min(dstruct.depth));
  nc{'depth'}.valid_max = ncdouble(max(dstruct.depth));
  nc{'depth'}.QC_indicator = ncshort(7);
  nc{'depth'}.QC_procedure = ncshort(0);
  nc{'depth'}.comment = ncchar('surface data; nominal depth == 0');

  nc{'latitude'} = ncfloat('latitude');
  nc{'latitude'}.standard_name = ncchar('latitude') ;
  nc{'latitude'}.long_name = ncchar('latitude') ;
  nc{'latitude'}.units = ncchar('degrees_north');
  nc{'latitude'}.format = ncchar('10.4f');
  nc{'latitude'}.FillValue_ =  ncfloat(1.0e35);
  nc{'latitude'}.valid_min = -90 ;
  nc{'latitude'}.valid_max = 90 ;
  nc{'latitude'}.axis =ncchar( 'Y') ;
  nc{'latitude'}.QC_indicator = ncshort(7);
  nc{'latitude'}.QC_procedure = ncshort(0);
  nc{'latitude'}.comment = ncchar('nominal position');
  
  nc{'longitude'} = ncfloat('longitude');
  nc{'longitude'}.standard_name = ncchar('longitude') ;
  nc{'longitude'}.long_name = ncchar('longitude') ;    
  nc{'longitude'}.units = ncchar('degrees_east');
  nc{'longitude'}.format = ncchar('10.4f');
  nc{'longitude'}.FillValue_ =  ncfloat(1.0e35);
  nc{'longitude'}.valid_min = -180 ;
  nc{'longitude'}.valid_max = 180 ;
  nc{'longitude'}.axis = ncchar('X') ; 
  nc{'longitude'}.QC_indicator = ncshort(7);
  nc{'longitude'}.QC_procedure = ncshort(0);
  nc{'longitude'}.comment = ncchar('nominal position');

%%    record variables:

%  nc{'AIRT'} = ncfloat('time', 'depth', 'latitude', 'longitude');
  nc{'AIRT'} = ncfloat('time', 'depth');
  nc{'AIRT'}.standard_name = ncchar('air_temperature');
  nc{'AIRT'}.long_name = ncchar('air temperature');
  nc{'AIRT'}.units = ncchar('degree_C');
  nc{'AIRT'}.format = ncchar('8.2f');
  nc{'AIRT'}.FillValue_ = ncfloat(1.0e35);
  nc{'AIRT'}.valid_min = ncfloat(floor(min(dstruct.AIRT))) ;
  nc{'AIRT'}.valid_max = ncfloat(ceil(max(dstruct.AIRT))) ;

  nc{'ATMS'} = ncfloat('time', 'depth');
  nc{'ATMS'}.standard_name = ncchar('air_pressure_at_sea_level');
  nc{'ATMS'}.long_name = ncchar('barometric pressure');
  nc{'ATMS'}.units = ncchar('millibars');
  nc{'ATMS'}.format = ncchar('9.2f');
  nc{'ATMS'}.FillValue_ = ncfloat(1.0e35);
  nc{'ATMS'}.valid_min = ncfloat(floor(min(dstruct.ATMS))) ;
  nc{'ATMS'}.valid_max = ncfloat(ceil(max(dstruct.ATMS))) ;

  nc{'RELH'} = ncfloat('time', 'depth');
  nc{'RELH'}.standard_name = ncchar('relative_humidity');
  nc{'RELH'}.long_name = ncchar('relative humidity');
  nc{'RELH'}.units = ncchar('percent');
  nc{'RELH'}.format = ncchar('8.2f');
  nc{'RELH'}.FillValue_ = ncfloat(1.0e35);
  nc{'RELH'}.valid_min = ncfloat(floor(min(dstruct.RELH))) ;
  nc{'RELH'}.valid_max = ncfloat(ceil(max(dstruct.RELH))) ;

  nc{'LW'} = ncfloat('time', 'depth');
  nc{'LW'}.standard_name = ncchar('surface_downwelling_longwave_flux_in_air ');
  nc{'LW'}.long_name = ncchar('longwave radiation');
  nc{'LW'}.units = ncchar('W m-2');
  nc{'LW'}.format = ncchar('8.2f');
  nc{'LW'}.FillValue_ = ncfloat(1.0e35);
  nc{'LW'}.valid_min = ncfloat(floor(min(dstruct.LW))) ;
  nc{'LW'}.valid_max = ncfloat(ceil(max(dstruct.LW))) ;

  % 962:Rr :Rain Rate      
  nc{'RAIN'} = ncfloat('time', 'depth');
  nc{'RAIN'}.standard_name = ncchar('rainfall_rate');
  nc{'RAIN'}.long_name = ncchar('precipitation rate');
  nc{'RAIN'}.units = ncchar('mm/hour');
  nc{'RAIN'}.format = ncchar('6.1f');
  nc{'RAIN'}.FillValue_ = ncfloat(1.0e35);
  nc{'RAIN'}.valid_min = ncfloat(floor(min(dstruct.RAIN))) ;
  nc{'RAIN'}.valid_max = ncfloat(ceil(max(dstruct.RAIN))) ;    
  
  nc{'TEMP'} = ncfloat('time', 'depth');
  nc{'TEMP'}.standard_name = ncchar('sea_water_temperature');
  nc{'TEMP'}.long_name = ncchar('sea temperature');
  nc{'TEMP'}.units = ncchar('degree_C');
  nc{'TEMP'}.format = ncchar('9.4f');
  nc{'TEMP'}.FillValue_ = ncfloat(1.0e35);
  nc{'TEMP'}.valid_min = ncfloat(floor(min(dstruct.TEMP))) ;
  nc{'TEMP'}.valid_max = ncfloat(ceil(max(dstruct.TEMP))) ;
 
  nc{'SW'} = ncfloat('time', 'depth');
  nc{'SW'}.standard_name = ncchar('surface_downwelling_shortwave_flux_in_air');
  nc{'SW'}.long_name = ncchar('shortwave radiation');
  nc{'SW'}.units = ncchar('W m-2');
  nc{'SW'}.format = ncchar('9.2f');
  nc{'SW'}.FillValue_ = ncfloat(1.0e35);
  nc{'SW'}.valid_min = ncfloat(floor(min(dstruct.SW))) ;
  nc{'SW'}.valid_max = ncfloat(ceil(max(dstruct.SW))) ;

  nc{'UWND'} = ncfloat('time', 'depth');
  nc{'UWND'}.standard_name = ncchar('eastward_wind');
  nc{'UWND'}.long_name = ncchar('wind_velocity_east');
  nc{'UWND'}.units = ncchar('meters/second');
  nc{'UWND'}.format = ncchar('8.2f');
  nc{'UWND'}.FillValue_ = ncfloat(1.0e35);
  nc{'UWND'}.valid_min = ncfloat(floor(min(dstruct.UWND))) ;
  nc{'UWND'}.valid_max = ncfloat(ceil(max(dstruct.UWND))) ;
  nc{'UWND'}.magnetic_correction = ncfloat(meta.variable.UWND.magnetic_correction) ;

  nc{'VWND'} = ncfloat('time', 'depth');
  nc{'VWND'}.standard_name = ncchar('northward_wind');
  nc{'VWND'}.long_name = ncchar('wind velocity north');
  nc{'VWND'}.units = ncchar('meters/second');
  nc{'VWND'}.format = ncchar('8.2f');
  nc{'VWND'}.FillValue_ = ncfloat(1.0e35);
  nc{'VWND'}.valid_min = ncfloat(floor(min(dstruct.VWND))) ;
  nc{'VWND'}.valid_max = ncfloat(ceil(max(dstruct.VWND))) ;
  nc{'VWND'}.magnetic_correction = ncfloat(meta.variable.VWND.magnetic_correction) ;

  nc{'PSAL'} = ncfloat('time', 'depth');
  nc{'PSAL'}.standard_name = ncchar('sea_water_salinity');
  nc{'PSAL'}.long_name = ncchar('salinity');
  nc{'PSAL'}.units = ncchar('1');
  nc{'PSAL'}.format = ncchar('9.4f');
  nc{'PSAL'}.FillValue_ = ncfloat(1.0e35);
  nc{'PSAL'}.valid_min = ncfloat(floor(min(dstruct.PSAL))) ;
  nc{'PSAL'}.valid_max = ncfloat(ceil(max(dstruct.PSAL))) ;

  % SNs
  nc{'AIRT'}.SN = ncchar(meta.variable.AIRT.SN);
  nc{'RELH'}.SN = ncchar(meta.variable.RELH.SN);
  nc{'ATMS'}.SN = ncchar(meta.variable.ATMS.SN);
  nc{'TEMP'}.SN = ncchar(meta.variable.TEMP.SN);
  nc{'UWND'}.SN = ncchar(meta.variable.UWND.SN);
  nc{'VWND'}.SN = ncchar(meta.variable.VWND.SN);
  nc{'SW'}.SN = ncchar(meta.variable.SW.SN);
  nc{'LW'}.SN = ncchar(meta.variable.LW.SN);
  nc{'RAIN'}.SN = ncchar(meta.variable.RAIN.SN);
  nc{'PSAL'}.SN = ncchar(meta.variable.TEMP.SN);
  
  % sensor heights
  nc{'AIRT'}.sensor_height = ncfloat(meta.variable.AIRT.sensor_height);
  nc{'RELH'}.sensor_height = ncfloat(meta.variable.RELH.sensor_height);
  nc{'ATMS'}.sensor_height = ncfloat(meta.variable.ATMS.sensor_height);
  nc{'TEMP'}.sensor_height = ncfloat(meta.variable.TEMP.sensor_height);
  nc{'UWND'}.sensor_height = ncfloat(meta.variable.UWND.sensor_height);
  nc{'VWND'}.sensor_height = ncfloat(meta.variable.VWND.sensor_height);
  nc{'SW'}.sensor_height = ncfloat(meta.variable.SW.sensor_height);
  nc{'LW'}.sensor_height = ncfloat(meta.variable.LW.sensor_height);
  nc{'RAIN'}.sensor_height = ncfloat(meta.variable.RAIN.sensor_height);
  nc{'PSAL'}.sensor_height = ncfloat(meta.variable.TEMP.sensor_height);
  
  % cell_methods
  nc{'AIRT'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'RELH'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'ATMS'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'TEMP'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'UWND'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'VWND'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'SW'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'LW'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'RAIN'}.cell_methods = ncchar(meta.variable.cell_methods);
  nc{'PSAL'}.cell_methods = ncchar(meta.variable.cell_methods);

  %QC
  nc{'AIRT'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'RELH'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'ATMS'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'TEMP'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'UWND'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'VWND'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'SW'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'LW'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'RAIN'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  nc{'PSAL'}.QC_indicator = ncshort(meta.variable.QC_indicator);
  
  nc{'AIRT'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'RELH'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'ATMS'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'TEMP'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'UWND'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'VWND'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'SW'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'LW'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'RAIN'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  nc{'PSAL'}.QC_procedure = ncshort(meta.variable.QC_procedure);
  
  endef(nc)

  nc{'depth'}(1) = dstruct.depth;
  nc{'latitude'}(1)=dstruct.lat;
  nc{'longitude'}(1)=dstruct.lon;
  nc{'time'}(1:nt) = dstruct.time;
  nc{'AIRT'}(1:nt) = dstruct.AIRT;
  nc{'ATMS'}(1:nt) = dstruct.ATMS;
  nc{'RELH'}(1:nt) = dstruct.RELH;
  nc{'LW'}(1:nt) = dstruct.LW;
  nc{'RAIN'}(1:nt) = dstruct.RAIN;
  nc{'PSAL'}(1:nt) = dstruct.PSAL;
  nc{'TEMP'}(1:nt) = dstruct.TEMP;
  nc{'SW'}(1:nt) = dstruct.SW;
  nc{'UWND'}(1:nt) = dstruct.UWND;
  nc{'VWND'}(1:nt) = dstruct.VWND;
  
  close(nc)
  status = 1;
