function get_latest(info) % get_latest(info) % % Last modified: Time-stamp: <2005-01-20 10:32:38 haines> % % Abstract: Function that loads temporary latest raw data from NOS, parses obs, % subset to last 48 hours, and saves netCDF % % Usage: get_latest(info) % Processing steps % (1) read data from stripped text file from earlier screen-scrape % (Data is nicely formatted text file so no editing necessary) % (2) set NaN to values used for no-data (e.g. -99.9, -999.9) % (3) Since this data has predicted WL data there is data into the future % we must only get everything older than current date and time. % (4) calculate u, v, seallevel pressure (if needed), and time stuff and % temperature conversions % (5) change all NaN's to missing_value for netcdf % (6) create new file of global attributes, dimensions, and variables % (7) save (ncclose) file % Author: Sara Haines, Sep 18, 2003 % Raw data looks like this (without column header) % Date/Time Pre. Obs. Res. Wsp. Wdr. Wgt. Bar. Air Water % (Local Time) (ft.) (ft.) (ft.) (kts.)(true)(kts.)(mb.)(F) (F) % 11/30/2003 09:18:00 EST 2.01 0.35 -1.66 17 241 19 1014.7 -99.9 47.2 % 11/30/2003 09:48:00 EST 2.47 0.93 -1.54 -999 -999 -999 -999.9 -99.9 -99.9 fid = fopen(info.rawdirname); tline = fgetl(fid); fclose(fid); file_ok = isempty(regexp(tline, '[S|s]orry')); % (1) read data from stripped text file if file_ok format_str = '%d/%d/%d %d:%d:%d %s %f %f %f %f %f %f %f %f %f'; [mm, dd, yyyy, HH, MM, SS, TZ_str, ... pre_wl, obs_wl, res_wl, wi_spd, wi_dir, wi_gst, baro, atemp, wtemp] = ... textread(info.rawdirname, format_str); % param names to use and associated missing value from posted data params = {'pre_wl', 'obs_wl', 'res_wl', ... 'wi_spd', 'wi_dir', 'wi_gst', ... 'baro', 'atemp', 'wtemp'}; missing_value = [-99.99, -99.99, -99.99, ... -999, -999, -999, ... -999.9, -99.9, -99.9]; % (2) replace missing values with NaN for i=1:length(params) param_str = char(params(i)); eval(['which_miss = find(' param_str ' == ' num2str(missing_value(i)) ');']) eval([param_str '(which_miss) = ones(size(which_miss))*NaN;']) end % Adjust timezone of data to UTC TZ_type = {'AST', 'EST', 'CST', 'MST', 'PST', 'YST', 'AKST', 'HST', ... 'ADT', 'EDT', 'CDT', 'MDT', 'PDT', 'AKDT'}; hours_from_UTC = [4, 5, 6, 7, 8, 9, 9, 10, ... 3, 4, 5, 6, 7, 8]; TZ = zeros(size(TZ_str)); % assume UTC until shifted for i=1:length(TZ_type) type_str = char(TZ_type(i)); eval(['which_zone = find(strcmp(TZ_str,''' type_str '''));']) eval(['TZ(which_zone) = ones(size(which_zone))*' int2str(hours_from_UTC(i)) ';']) end % calculate datenum adjusted to UTC dn = datenum(yyyy,mm,dd,HH+TZ,MM,SS); % (3) get only last 2 days (based on UTC) two_days_ago = info.current_time_dn-2; % datenum is in units of days which_latest = find(two_days_ago<=dn & dn0 have_wind = 1; else have_wind = 0; end if length(which_wl)>0 have_wl = 1; else have_wl = 0; end if length(which_sst)>0 have_sst = 1; else have_sst = 0; end % have_data = have_wind | have_sst | have_wl; have_data = have_wind | have_sst; % (5) change all Nan to missing value (-9999) for i=1:length(params) param_str = char(params(i)); eval(['which_nan = find(isnan(' param_str '));']) eval([param_str '(which_nan) = ones(size(which_nan))*-9999;']) end % delete old netcdf file of latest data if exist(ncfile_v20, 'file') delete(ncfile_v20); end % one or more obs in desired time period? have_dn = exist('dn'); if have_dn have_latest = length(dn)>0; else have_latest = 0; end % (5) create new file of global attributes, dimensions, and variables % if have data then create new netcdf file and populate if have_data & have_latest if have_wind | have_sst | have_wl fprintf(2, ['... ... writing %s\n'], ncfile_v20); nc = netcdf(ncfile_v20, 'clobber'); netcdf_create_v20; nc = close(nc); end end %