% LISST100Xnc2txt convert LISST time series data from netCDF EPIC to ASCII % % function lisst = LISST100Xnc2txt(ncFile) % ncFile = the netCDF file with LISST time series data % the .txt file columns are % 1:6 YYYY MM DD HH MM SS % 7:38 Volume concentration (in ul/l) for size class 1 through 32 % 39 Laser transmission Sensor, mW % 40 Battery voltage % 41 Laser Reference sensor in mW % 42 Computed $ 43 Pressure in db % 44 Temperature in degrees C % 45 Computed Beam-C in units of 1/m % Written by Marinna Martini 5/4/06 % U.S. Geological Survey Woods Hole Science Center function LISST100Xnc2txt(ncFile) % get the current SVN version- the value is automatically obtained in svn % is the file's svn.keywords which is set to "Revision" rev_info = 'SVN $Revision$'; disp(sprintf('%s %s running',mfilename,rev_info)) disp(sprintf('%s now running %s',mfilename,rev_info)) if ~exist('ncFile','var'), ncFile = ''; end % get the data file if ~exist(ncFile,'file'), FilterSpec(1,:) = {'*.nc','*.nc netCDF LISST data file'}; [fname, pathname] = uigetfile(FilterSpec, 'Pick a LISST data file'); if isequal(fname,0) || isequal(pathname,0) disp('User pressed cancel') return end ncFile = fullfile(pathname, fname); end disp(['User selected netCDF data file ', ncFile]) % make sure this is a time series experiment, not a settling experiment [pathstr,fname] = fileparts(ncFile); ascFile = fullfile(pathstr,[fname '.txt']); disp(sprintf('Exporting data to %s', ascFile)) fid = fopen(ascFile,'w'); nc = netcdf(ncFile,'nowrite'); nrecs = length(nc{'time'}(:)); % write out metadata fprintf(fid, '$ project = %s\n', nc.PROJECT(:)); fprintf(fid, '$ experiment = %s\n', nc.EXPERIMENT(:)); fprintf(fid, '$ mooring = %s\n', nc.MOORING(:)); fprintf(fid, '$ depth = %f\n', nc.WATER_DEPTH(:)); fprintf(fid, '$ latitude = %f\n', nc.latitude(:)); fprintf(fid, '$ longitude = %f\n', nc.longitude(:)); fprintf(fid, '$ instrument = %s\n', nc.INST_TYPE(:)); fprintf(fid, '$ serial number = %s\n', nc{'ring_data'}.serial_number(:)); fprintf(fid, '$ raw data file = %s\n', nc.original_data_file(:)); fprintf(fid, '$ field calibration file = %s\n', nc{'field_zscat'}.calibration_file(:)); fprintf(fid, '$ factory calibration file = %s\n', nc{'factory_zscat'}.calibration_file(:)); fprintf(fid, '$ detector calibration file = %s\n', nc{'ring_data'}.calibration_file(:)); fprintf(fid, '$ column descriptions\n'); fprintf(fid, '$ 1:6 YYYY MM DD HH MM SS\n'); fprintf(fid, '$ 7:38 Volume concentration (in ul/l) for size class 1 through 32\n'); fprintf(fid, '$ 39 Laser transmission Sensor, mW\n'); fprintf(fid, '$ 40 Battery voltage \n'); fprintf(fid, '$ 41 Laser Reference sensor in mW\n'); fprintf(fid, '$ 42 Computed percent Optical transmission over path\n'); fprintf(fid, '$ 43 Pressure in db\n'); fprintf(fid, '$ 44 Temperature in degrees C\n'); fprintf(fid, '$ 45 Computed Beam-C in units of 1/m\n'); fprintf(fid, '$ Size classes in %s\n',nc{'size'}.units(:)); fprintf(fid, '$ '); for idx = 1:32, fprintf(fid,'%d ',idx); end fprintf(fid, '\n'); fprintf(fid, '$ '); for idx = 1:32, fprintf(fid,'%f ',nc{'size'}(idx)); end fprintf(fid, '\n'); % we are reading line by line so that large time series will not overwhelm % computer memory. But it does take longer than load() tic; for ncidx = 1:nrecs, tj = nc{'time'}(ncidx,1,1,1)+nc{'time2'}(ncidx,1,1,1)./(24*3600*1000); fprintf(fid,'%4d %2d %2d %2d %2d %2d ',gregoria(tj)); fprintf(fid,'%f ',nc{'vconc'}(ncidx,:)); fprintf(fid,'%f ',nc{'ltrans'}(ncidx,1,1,1)); fprintf(fid,'%f ',nc{'batt'}(ncidx,1,1,1)); fprintf(fid,'%f ',nc{'lref'}(ncidx,1,1,1)); fprintf(fid,'%f ',nc{'ptrans'}(ncidx,1,1,1)); fprintf(fid,'%f ',nc{'P_1'}(ncidx,1,1,1)); fprintf(fid,'%f ',nc{'T_20'}(ncidx,1,1,1)); fprintf(fid,'%f ',nc{'ATTN_55'}(ncidx,1,1,1)); fprintf(fid, '\n'); if ncidx<50 && ~rem(ncidx,10), disp(sprintf('Finished sample #%d %4.2f min elapsed',ncidx,toc./60)), end if ncidx>50 && ~rem(ncidx,100), disp(sprintf('Finished sample #%d %4.2f min elapsed',ncidx,toc./60)), end end disp(sprintf('%d samples exported to ascii file',ncidx)) fclose(fid); close(nc); return