function [time,wtrTemp] = airTemp2inflowTemp(inFileName,outFileName,ndayAvg) % function [time,wtrTemp] = airTemp2inflowTemp(inFileName,outFileName,ndayAvg) % % funcion to read ELCOM input AIR_TEMP bc file and convert to WATER_TMP by % averaging over a certain time period % % Inputs: % inFileName : bc file containig air temp data % outFileName : name of bc file to create % ndayAvg : number of days to average ove (optional - default is 4) % Outputs % time : time column in CWR Format % wtrTemp : water temperature column % % Uses: % CWRdate2matlab.m % readELCOMinputFile.m % readELCOMinputFileHeader.m % line2strs.m % % Written by C. Dallimore 27 July 04 % Set averaging length if nargin == 3 elseif nargin == 2 ndayAvg = 4; else disp('Incorrect number of arguments to airTemp2inflowTemp') ierr =1; time = []; wtrTemp = []; return end % Read file [data,data_type,bcset_no,n_data,file_type]=readELCOMinputFile(inFileName); % Check ile is normal bc file if (~strcmp(file_type,'BC')) error ('File is not BC File') return end cwrTimeIn = data(:,1); timeIn = CWRdate2matlab(cwrTimeIn); % get air temp column ind=strmatch('AIR_TEMP',data_type,'exact'); if (isempty(ind)) error ('File does not contain air temperature') return else airTemp= data(:,ind); end ndays = floor(max(timeIn))-floor(min(timeIn))+1; day0 = floor(min(timeIn)); timeOut = []; for i=1:ndays timeOut(i) = day0+i; pts = find((timeIn < timeOut(i)) & (timeIn > timeOut(i)-ndayAvg)); wtrTemp(i) = mean(airTemp(pts)); end % Set minimum to 3o pts = find(wtrTemp<3); wtrTemp(pts) = 3; % Convert back to CWR Date time = matlab2CWRdate(timeOut); % Write to file fout = fopen(outFileName,'w'); fprintf(fout,'! ------------------------------------------------------------- !\n'); fprintf(fout,'! Matlab generated inflow temp file !\n'); fprintf(fout,['! Average of ',int2str(ndayAvg),' days of air temp data !\n']); fprintf(fout,'! ------------------------------------------------------------- !\n'); fprintf(fout,'1 data sets\n'); fprintf(fout,'0 seconds between data\n'); fprintf(fout,' 0 need to put bc\n'); fprintf(fout,' TIME WTR_TEMP\n'); tmpData = [time; wtrTemp]; fprintf(fout,'%12.3f %5.1f\n',tmpData); fclose (fout);