function netcdf_eco(p) % NETCDF_eco - create a netcdf file from the eco data % % Use as: netcdf_eco(p) % % Inputs: p = contains property information, i.e. filenames, mooring name, etc % RPM % 20 Jul 2004 %=========== % Open File %=========== try, % Write to log file fid=fopen([p.ldir,'/',p.log],'at+'); fprintf(fid,'%s\n',[' 5. NETCDF_ECO: ' datestr(now), ' ', p.name]); fclose(fid); ncFilename = [p.ndir,'/',p.netcdffile]; outfile = netcdf(ncFilename, 'clobber'); % outfile is a netcdf object if isempty(outfile) error(['Unable to create netcdf file: ' ncFilename]); end % % Read the eco.data Filename=[p.ddir,'/',p.datafile]; eco = load(Filename); if eco < 0 error(['Unable to open data file:' Filename]) end % assign vars offset=0; if strcmp(p.ecotype,'ecobb') offset=1; end ecosdn = eco(:,3); ecocal = eco(:,8); ecoraw = eco(:,10 + offset); %================================================================= % Construct Netcdf schema for a single microcat on eqpac moorings %================================================================= [Year Month Day] = datevec(now); dateS = sprintf('%02i/%02i/%04i', Month, Day, Year); outfile.conventions ='COARDS/PMEL-EPIC'; outfile.directory = '/hosts/tornado/vol/vol0/ssdsdata/ecocimt/'; outfile.creationDate = dateS; outfile.lastModified = dateS; fprintf(1,'Creating netcdf schema') outfile.project = p.project; outfile.mooring = p.mooring; outfile.inst_type = p.name; outfile.description = [p.name,', ',p.longname,' mooring data from WetLabs ECO sensor']; outfile.source='MBARI, Center for Integrated Marine Technology'; outfile.data_info='Contact Francisco Chavez chfr@mbari.org'; outfile.file_info='Contact Reiko Michisaki reiko@mbari.org'; outfile.data_cmnt='Data calibrated according to WetLabs calculations, www.wetlabs.com'; outfile.var_desc=['Calibrated values as ',p.longname,' ',p.units,' from raw counts.']; outfile.missing_value=-999; outfile.FillValue_ =-999; lon = str2num(p.longitude); if lon < 0 lonS = [num2str(abs(lon)) 'W']; else lonS = [num2str(lon) 'E']; end lat = str2num(p.latitude); if lat < 0 latS = [num2str(abs(lat)) 'S']; else latS = [num2str(lat) 'N']; end outfile.longitude = lonS; outfile.latitude = latS; outfile.waterDepth = p.waterdepth; outfile.keywords = [p.project,' mooring,',p.mooring,',',p.name,',',p.longname, ', ',p.ecotype]; outfile.instumentType = [p.name,' ',p.ecotype]; outfile('latitude') = 1; % Dimension outfile{'latitude'} = ncdouble('latitude'); % Specify Co-ordinate variable dimensions outfile{'latitude'}.long_name = 'Latitude'; outfile{'latitude'}.units = 'degrees_north'; outfile{'latitude'}.symbol = 'lat'; outfile{'latitude'}(:) = lat; outfile('longitude') = 1; % Dimension outfile{'longitude'} = ncdouble('longitude'); % Specify Co-ordinate variable dimensions outfile{'longitude'}.long_name = 'Longitude'; outfile{'longitude'}.units = 'degrees_west'; outfile{'longitude'}.symbol = 'lon'; outfile{'longitude'}(:) = lon; outfile('depth') = 1; % Dimension outfile{'depth'} = ncdouble('depth'); % Specify Co-ordinate variable dimensions outfile{'depth'}.long_name = 'Depth'; outfile{'depth'}.units = 'meters'; outfile{'depth'}.positive = 'down'; outfile{'depth'}(:) = 0; outfile('time') = 0; % Define Unlimited dimension outfile{'time'} = ncdouble('time'); outfile{'time'}.long_name = 'time GMT'; outfile{'time'}.units = 'seconds since 1970-01-01 00:00:00'; outfile{'time'}.symbol = 'GMT'; outfile{'raw'} = ncfloat('time','depth','longitude','latitude'); outfile{'raw'}.long_name = [p.name,': uncalibrated data']; outfile{'raw'}.units = 'counts'; outfile{'raw'}.symbol = [p.ecotype,' Raw']; outfile{'raw'}.valid_range = -999,p.raw_max; outfile{'raw'}.FillValue_ = -999; outfile{'raw'}.missing_value = -999; outfile{'ecocal'} = ncfloat('time','depth','longitude','latitude'); outfile{'ecocal'}.long_name = [p.name,': calibrated data']; outfile{'ecocal'}.units = p.units; outfile{'ecocal'}.symbol = [p.ecotype,' Cal']; outfile{'ecocal'}.FillValue_ = -999; outfile{'ecocal'}.missing_value = -999; outfile{'time'}(1:length(ecosdn)) = sdn2utc(ecosdn); %outfile{'siam_time'}(:) = ecosiam; outfile{'raw'}(:) = ecoraw; outfile{'ecocal'}(:) = ecocal; ncquit(outfile); [r,c]=size(ecosdn); fprintf(1,['Netcdf file created: ',datestr(ecosdn(1)),' to ',datestr(ecosdn(r))]) catch, % Something went wrong, capture error message and write to log file [LASTMSG, LASTID] = lasterr; disp(['** PROCESSING HALTED** Error: ',LASTMSG]); disp([' Last ID: ', LASTID]); fid=fopen([p.ldir,'/',p.log],'at+'); fprintf(fid,'%s\n',['NETCDF_ECO']); fprintf(fid,'%s\n',[' **PROCESSING HALTED** Error: ', LASTMSG ]); fprintf(fid,'%s\n',[' Last ID: ', LASTID ]); fprintf(fid,'%s\n',':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'); fprintf(fid,'\n'); fclose(fid); %exit; end