function ncwrite_AWACWvsr(WAVE) %companion function to AWACWvs2nc to write out the waves %parameters calculated by Quickwave press = WAVE.data(:,3); %calculate water level and mean water depth WL = press + WAVE.metadata.transducer_offset_from_bottom; depth = mean(WL); %now write a netcdf file outfile = strcat([WAVE.metadata.filename 'Wvs-r.nc']); nc = netcdf(outfile,'clobber'); %put global attributes from User metadata into file Uatts = fieldnames(WAVE.metadata); for i = 1:length(Uatts) nc.(Uatts{i}) = WAVE.metadata.(Uatts{i}); end %now put global attributes from instrument metadata into file Iatts = fieldnames(WAVE.instmeta); for i = 1:length(Iatts) nc.(Iatts{i}) = WAVE.instmeta.(Iatts{i}); end nc.WATER_DEPTH = ncdouble(depth); if isfield(WAVE,'rawdata') [N,M] = size(WAVE.rawdata); elseif isfield(WAVE,'ast') [N,M] = size(WAVE.ast); else return end theFillValue = 1e35; short_fill_val = -32768; %Time is the record dimension nc('time') = 0; nc('depth') = 1; nc('lat') = 1; nc('lon') = 1; nc{'time'} = nclong('time'); nc{'time'}(1:N) = WAVE.time; nc{'time'}.FORTRAN_format = ncchar('F10.2'); nc{'time'}.units = ncchar('True Julian Day'); nc{'time'}.type = ncchar('UNEVEN'); nc{'time'}.epic_code = nclong(624); nc{'time'}.FillValue_ = short_fill_val; nc{'time2'} = nclong('time') ; nc{'time2'}(1:N) = WAVE.time2; nc{'time2'}.FORTRAN_format = ncchar('F10.2'); nc{'time2'}.units = ncchar('msec since 0:00 GMT'); nc{'time2'}.type = ncchar('UNEVEN'); nc{'time2'}.epic_code = nclong(624); nc{'time2'}.FillValue_ = short_fill_val; nc{'lat'} = ncfloat('lat'); nc{'lat'}(:) = WAVE.metadata.latitude; nc{'lat'}.FORTRAN_format = ncchar('F10.4'); nc{'lat'}.units = ncchar('degree_north'); nc{'lat'}.type = ncchar('EVEN'); nc{'lat'}.epic_code = nclong(500); nc{'lon'} = ncfloat('lon'); nc{'lon'}(:) = WAVE.metadata.longitude; nc{'lon'}.FORTRAN_format = ncchar('F10.4'); nc{'lon'}.units = ncchar('degree_east'); nc{'lon'}.type = ncchar('EVEN'); nc{'lon'}.epic_code = nclong(502); nc{'depth'} = ncfloat('depth'); nc{'depth'}(:) = depth; nc{'depth'}.FORTRAN_format = ncchar('F10.2'); nc{'depth'}.units = ncchar('m'); nc{'depth'}.type = ncchar('EVEN'); nc{'depth'}.epic_code = nclong(3); nc{'depth'}.long_name = ncchar('mean water depth'); nc{'depth'}.blanking_distance = nclong(WAVE.instmeta.BlankingDistance); nc{'depth'}.bin_size = ncdouble(WAVE.instmeta.CellSize); nc{'depth'}.transducer_offset_from_bottom = WAVE.metadata.transducer_offset_from_bottom; if isfield(WAVE,'rawdata') [j,k,l] = size(WAVE.rawdata); nc('burst') = j; nc('sample') = k; nc('beam') = 3; nc{'press'}=ncshort('time','sample','depth'); nc{'press'}(1:j,1:k,1) = WAVE.rawdata(:,:,3); nc{'press'}.name=ncchar('press'); nc{'press'}.long_name=ncchar('Pressure Sensor Derived Depth (mm)'); nc{'press'}.generic_name=ncchar('pressure time series'); nc{'press'}.units=ncchar('mm'); nc{'press'}.FORTRAN_format=ncchar('F10.2'); nc{'press'}.FillValue_ = ncshort(short_fill_val); nc{'press'}.minimum = ncfloat(0); nc{'press'}.maximum = ncfloat(0); nc{'strk1'}=ncshort('burst','sample','depth'); nc{'strk1'}(1:j,1:k,1) = WAVE.rawdata(:,:,4); nc{'strk1'}.name=ncchar('strk1'); nc{'strk1'}.long_name=ncchar('Along-Beam Surface Track Distance 1(m) (Beam4)'); nc{'strk1'}.generic_name=ncchar('surface track time series'); nc{'strk1'}.units=ncchar('m'); nc{'strk1'}.FORTRAN_format=ncchar('F10.2'); nc{'strk1'}.FillValue_ = ncshort(short_fill_val); nc{'strk1'}.minimum = ncfloat(0); nc{'strk1'}.maximum = ncfloat(0); nc{'strk2'}=ncshort('burst','sample','depth'); nc{'strk2'}(1:j,1:k,1) = WAVE.rawdata(:,:,5); nc{'strk2'}.name=ncchar('strk2'); nc{'strk2'}.long_name=ncchar('Along-Beam Surface Track Distance 2(m) (Beam4)'); nc{'strk2'}.generic_name=ncchar('surface track time series'); nc{'strk2'}.units=ncchar('m'); nc{'strk2'}.FORTRAN_format=ncchar('F10.2'); nc{'strk2'}.FillValue_ = ncshort(short_fill_val); nc{'strk2'}.minimum = ncfloat(0); nc{'strk2'}.maximum = ncfloat(0); nc{'vel'}=ncshort('burst','sample','beam'); nc{'vel'}(1:j,1:k,1:3) = WAVE.rawdata(:,:,8:10); nc{'vel'}.long_name=ncchar('Along-Beam Velocity of Surface Bin (m/s)'); nc{'vel'}.generic_name=ncchar('velocity time series'); nc{'vel'}.units=ncchar('m/s'); nc{'vel'}.bin_size=WAVE.instmeta.CellSize(:); nc{'vel'}.FORTRAN_format=ncchar('F10.2'); nc{'vel'}.FillValue_ = ncshort(short_fill_val); nc{'vel'}.minimum = ncfloat(0); nc{'vel'}.maximum = ncfloat(0); end if isfield(WAVE,'ast') [j,k,l] = size(WAVE.ast); nc('burst') = j; nc('sample') = k; nc{'strk'}=ncshort('burst','sample','depth'); nc{'strk'}(1:j,1:k) = WAVE.ast(:,:,3); nc{'strk'}.name=ncchar('strk1'); nc{'strk'}.long_name=ncchar('Despiked Along-Beam Surface Track Distance (m) (Beam4)'); nc{'strk'}.generic_name=ncchar('surface track time series'); nc{'strk'}.units=ncchar('m'); nc{'strk'}.FORTRAN_format=ncchar('F10.2'); nc{'strk'}.FillValue_ = ncshort(short_fill_val); nc{'strk'}.minimum = ncfloat(0); nc{'strk'}.maximum = ncfloat(0); nc{'strk'}.note = ('Time series of acoustic surface track that has been despiked and cleaned by Nortek'); end close(nc) disp(['Finished writing raw wave timeseries to ' outfile]);