function nws_metar2latest % nws_metar2latest % % Last modified: Time-stamp: <2005-01-19 17:05:54 haines> % % Abstract: Get latest NWS METAR data, parse latest 48 hour obs into netCDF % files as part of the SEACOOS merged product effort. % % Usage: >> nws_metar2latest % % % Author: Sara Haines, Sept 18, 2003 % Processing: % In general, for each station want to produce a file of last 48 % hours of obs. This file is a netCDF file with agreed upon conventions (Sep % 12, 2003 -- see Celoxis Metadata Project, % http://aslnx1.oasis.unc.edu:8080/psa/servlet/project?bxn=cview&p_p_id=2139) % for metadata content, structure, format, and naming conventions. % % Uses the monthly raw METAR files archived for each station. % raw_dir = '/seacoos/data/nws_metar/raw_data'; out_nc_v20_dir = '/seacoos/data/nws_metar/proc_data/latest_v2.0'; station_info_file = '/opt/local/seacoos/bin/stations_seacoos.txt'; % get the current time (GMT), as processing time reference point especially % for auto mode. This unix call is required to get date in GMT since MATLAB % has no function to get this without hardcoding it. [e,z]=unix(['date -u ''+%d-%b-%Y %H:%M:%S''']); current_time_dn = datenum(z(1:end-1)); % show time of run for the log files fprintf(2,'\nStart time: %s\n', datestr(current_time_dn, 'dd-mmm-yyyy HH:MM:SS')); fprintf(2,['Processing latest 48 hour data from all airport stations in' ... ' SEACOOS region ...\n']); % use current time (current_time_dn) to set month and previous month strings % month_str = datestr(current_time_dn, 'mmmyy'); % e.g. Apr03 month_str = [datestr(current_time_dn, 'yyyy') '_' ... datestr(current_time_dn, 'mm')]; % e.g. 2003_04 % determine previous month string from current. Need this to make the % month transition. dv = datevec([month_str(6:7) '/01/' month_str(1:4)]); % make it 04/01/2000] prev_month_str = [datestr(datenum(dv(1),dv(2),-1,0,0,0),'yyyy') '_' ... datestr(datenum(dv(1),dv(2),-1,0,0,0),'mm')]; % e.g. 2003_04 % directory of stations x = dir([raw_dir '/*']); % remove any parent or current directories or not a directory x = struct2cell(x); x = x(1,:); whichnot = find(strcmp(x,'.')|strcmp(x,'..')); x(whichnot)=[]; [n, numstations] = size(x); info.current_time_dn = current_time_dn; info.month_str = month_str; info.prev_month_str = prev_month_str; info.raw_dir = raw_dir; info.out_nc_v20_dir = out_nc_v20_dir; % read stations_seacoos.txt and find index of station id, name, % state/country, lat, lon, elev all_lines = textread(station_info_file,'%s','delimiter','\n','whitespace',''); % for each station for i=1:numstations info.platform_name = upper(char(x(i))); info.package_name = 'metar'; fprintf(2, ['... %s\n'], char(x(i))); % find which line of station data and extract info % e.g. which_line = find(strncmp(all_lines, 'KRDU', 4)); which_line = find(strncmp(all_lines, info.platform_name, 4)); station_str = char(all_lines(which_line)); [STATION_ID, NAME, LATdeg, LATmin, LAThem, LONdeg, LONmin, LONhem, ELEV] = ... strread(station_str, '%4c %19c %d %d%c %d %d%c %d%*[^\n]'); % set metadata info to be written in netcdf files and used in some calculations info.location_name = NAME; info.location_elev = ELEV; if regexp(LAThem, 'S|s') info.location_lat = -1*(LATdeg+(LATmin/60)); else % regexp(LAThem, 'N|n') info.location_lat = LATdeg+(LATmin/60); end if regexp(LONhem, 'W|w') info.location_lon = -1*(LONdeg+(LONmin/60)); else % regexp(LONhem, 'E|e) info.location_lon = LONdeg+(LONmin/60); end info.rawdirname = [info.raw_dir '/' char(x(i))]; get_latest_metar(info); end