function OUT = prcout_(IN,flag) % PRCOUT_ - Process Eqpac data from READOUT_ % NOTE: The time field in the input structure X must be named TIME_TAG and the % structure must also have the first field named Filename. % Brian Schlining % 13 Jan 1998 if nargin < 2 flag = 0; end %========================================================================= % Need the date, down to the Minute, to find the ~15 1 sec readings taken % every 15 minutes %========================================================================= [Year, Month, Day, Hour, Minute, Second] = datevec(IN.TIME_TAG); OUT.Filename = IN.Filename; % hang onto the filename Fields = fieldnames(IN); % Get all the field names NumOfFields = length(Fields); % Count the number of fields NumOfPoints = length(IN.TIME_TAG); % Count the number of readings n = 1; % Counter for the start of each 15 minute data set m = 1; % The position we're writing the data to fprintf(1,'\n(PRCOUT_)') OK = 1; while OK % Preallocate LOTS of memory on the first run through the infinite while loop. If % this isn't done the program is REALLY SLOW. Here we're allocating a structure % the same size as IN and filling it with NaN's if m == 1 for i = 2:NumOfFields OUT = setfield(OUT,{1},Fields{i},{1:NumOfPoints,1},NaN); end end switch flag case 0 % average the data from every 15 minutes % Find all data points that occur during any given minute j = find(Year == Year(n) & Month == Month(n) & Day == Day(n) & ... Hour == Hour(n) & Minute == Minute(n)); % Get the data that occurs during each minute, take its average and then % write it out to the new structure, OUT. for i = 2:NumOfFields f = getfield(IN,Fields{i},{j}); f = mean(f); OUT = setfield(OUT,Fields{i},{m,1},f); end n = n + length(j); % position for the next set of replicates m = m + 1; % position index for OUT case 1 % Create a daily average for data between 10am and 2pm % Find all data points between 10:00 and 14:00 for each day % At some point we'll need to flag this if not enough data % points occur during this period j = find(Year == Year(n) & Month == Month(n) & Day == Day(n) & ... Hour >= 10 & Hour <= 14); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Almost: need to see if the time's in the out files are GMT or local % and readjust Hour accordingly %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% k = find(Year == Year(n) & Month == Month(n) & Day == Day(n)); if ~isempty(j) % Get the data that occurs during each minute, take its average and then % write it out to the new structure, OUT. for i = 2:NumOfFields f = getfield(IN,Fields{i},{j}); f = mean(f); OUT = setfield(OUT,Fields{i},{m,1},f); end n = n + length(k); m = m + 1; fprintf(1, 'Line %6i: ~isempty(j)\n',n) elseif isempty(j) & ~isempty(k) n = n + length(k)'; fprintf(1, 'Line %6i: isempty(j) & ~isempty(k)\n',n) else n = n + 1; fprintf(1,'Line: %6i: isempty(j) & isempty(k)\n',n) end end if ~rem(m,200) fprintf(1,'.') end % Exit the loop when the end of the data is reached. if n > NumOfPoints fprintf(1,'\n') % Remove all the trailing NaN's before returning OUT NotNaN = find(~isnan(OUT.TIME_TAG)); for i = 2:NumOfFields f = getfield(OUT,Fields{i},{NotNaN}); OUT = setfield(OUT,Fields{i},f); end return % Exit end end