function asos = importASOS(filename, dataLines) %IMPORTFILE Import data from a text file % ASOS = IMPORTFILE(FILENAME) reads data from text file FILENAME for % the default selection. Returns the data as a table. % % ASOS = IMPORTFILE(FILE, DATALINES) reads data for the specified row % interval(s) of text file FILENAME. Specify DATALINES as a positive % scalar integer or a N-by-2 array of positive scalar integers for % dis-contiguous row intervals. % % Example: % asos = importASOS("D:\DorianRP\asos.txt", [1, Inf]); % % See also READTABLE. % % Auto-generated by MATLAB on 11-Dec-2019 13:04:36 %% Input handling % If dataLines is not specified, define defaults if nargin < 2 dataLines = [2, Inf]; end %% Setup the Import Options and import the data opts = delimitedTextImportOptions("NumVariables", 31); % Specify range and delimiter opts.DataLines = dataLines; opts.Delimiter = ","; % Specify column names and types opts.VariableNames = ["station", "valid", "lon", "lat", "tmpf", "dwpf", "relh", "drct", "sknt", "p01i", "alti", "mslp", "vsby", "gust", "skyc1", "skyc2", "skyc3", "skyc4", "skyl1", "skyl2", "skyl3", "skyl4", "wxcodes", "ice_accretion_1hr", "ice_accretion_3hr", "ice_accretion_6hr", "peak_wind_gust", "peak_wind_drct", "peak_wind_time", "feel", "metar"]; opts.VariableTypes = ["categorical", "datetime", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "double", "categorical", "categorical", "categorical", "categorical", "double", "double", "double", "double", "categorical", "double", "double", "double", "double", "double", "double", "double", "string"]; % Specify file level properties opts.ExtraColumnsRule = "ignore"; opts.EmptyLineRule = "read"; % Specify variable properties opts = setvaropts(opts, "metar", "WhitespaceRule", "preserve"); opts = setvaropts(opts, ["station", "skyc1", "skyc2", "skyc3", "skyc4", "wxcodes", "metar"], "EmptyFieldRule", "auto"); opts = setvaropts(opts, "valid", "InputFormat", "yyyy-MM-dd HH:mm"); opts = setvaropts(opts, ["tmpf", "dwpf", "relh", "p01i", "mslp", "gust", "skyl1", "skyl2", "skyl3", "skyl4", "ice_accretion_1hr", "ice_accretion_3hr", "ice_accretion_6hr", "peak_wind_gust", "peak_wind_drct", "peak_wind_time", "feel"], "TrimNonNumeric", true); opts = setvaropts(opts, ["tmpf", "dwpf", "relh", "p01i", "mslp", "gust", "skyl1", "skyl2", "skyl3", "skyl4", "ice_accretion_1hr", "ice_accretion_3hr", "ice_accretion_6hr", "peak_wind_gust", "peak_wind_drct", "peak_wind_time", "feel"], "ThousandsSeparator", ","); % Import the data asos = readtable(filename, opts); end