function gatt=read_globalatts(fname) % read_globalatts: read in file of metadata for a tripod or mooring % usage : gatt=read_globalatts(fname) % % reads global attributes for an experiment from a text file (fname) % called by all data processing programs to get uniform metadata input % one argument is required- the name of the file to read- it should have % this form: % SciPi;C. Sherwood % PROJECT; ONR % EXPERIMENT; RIPPLES DRI % DESCRIPTION; Stress, SSC, and Bedforms at MVCO 12-m fine/coarse transition site % DATA_SUBTYPE; MOORED % DATA_ORIGIN; USGS WHFS Sed Trans Group % COORD_SYSTEM; GEOGRAPHIC % Conventions; PMEL/EPIC % MOORING; 836 % WATER_DEPTH; 10.99 % latitude; 41.336063 % longitude; -70.559615 % magnetic_variation; -15 % Deployment_date; 27-Aug-2007 % Recovery_date; ? % % emontgomery 10/2007 % mods krosenberger to allow ' in valf 1/2009 % % Program written in Matlab v7.4.0336 (2007a) % Program updated in Matlab 7.2.0.232 (R2006a) % Program runs through current version, Matlab 7.8.0.347 (R2009a) % % "Although this program has been used by the USGS, no warranty, % expressed or implied, is made by the USGS or the United States % Government as to the accuracy and functioning of the program % and related program material nor shall the fact of distribution % constitute any such warranty, and no responsibility is assumed % by the USGS in connection therewith." gatt=[]; if nargin ~= 1; help mfilename; return; end if (exist(fname,'file') < 2 || isempty(fname)) disp('The global attribute file name entered does not exist, please choose another.') [fname,PathName,FilterIndex] = uigetfile('*'); fname=[PathName fname]; end [field,valf]=textread(fname, '%s%s','delimiter',';'); % checks for comments ik=1; while field{ik}(1) =='%' ik=ik+1; end % now put things into the gatt structure for kk=ik:length(field) % if have a command in valf(kk) (like bench), str2num % uses eval without the ', so launches bench and ends up with numbers % replacing the intended string. % if try str2double(char(valf(kk))) NaN is returned if bad % interpretation, which isn't what's needed with logic below tmp = str2double(char(valf{kk})); FIELD = field{kk}; if(isnan(tmp)) gatt.(FIELD) = valf{kk}; else gatt.(FIELD) = tmp; end end % mooring must be a string- the rest of the numeric things should be % numbers gatt.MOORING=num2str(gatt.MOORING);