function [Lon,Lat,U,V,TT] = loadRUWRFFile_150m_asl(fnames,varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LOADRUWRFFILE
% Description:
%
% This function generates a regular linear monotonic rectangular grid from
% RUWRF NetCDF files.
%
% INPUT:
% fnames: is a list of RUWRF output filenames
%
% n: is the number of grid points on both axes of the regular linear
%    monotonic rectangular grid
%
%USAGE:
%
%fnames{1} = '/Users/seroka/Research/Data/RUWRF/wrfout_d01_2012-09-06_15:00:00_r';
%fnames{2} = '/Users/seroka/Research/Data/RUWRF/wrfout_d01_2012-09-06_16:00:00_r';
%
%[Lon,Lat,U,V,TT] = loadRUWRFFile(fnames);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: loadRUWRFFILE.m 001 2015-06-09, Erick Fredj $
%
% Copyright (C) 2015 Erick Fredj
% License: GPL (Gnu Public License)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%default parameters
n = 350;

nfns = length(fnames); %number of file names

%memory allocation
U = nan(n,n,nfns);
V = nan(n,n,nfns);
TT = nan(1,nfns);

%loop over all the RUWRF netcdf files
for i=1:nfns
    
    filename = fnames{i};
    
    xlong           = ncread(filename,'XLONG');
    xlat            = ncread(filename,'XLAT');
    u             = ncread(filename,'Ur150m');
    v             = ncread(filename,'Vr150m');
    times           = char(ncread(filename,'Times')');     
    
    TT(i) = datenum(times,'yyyy-mm-dd_HH:MM:SS');
    
    xlong=double(xlong);
    xlat = double(xlat);
    u=double(u);
    v=double(v);
    

    %define a regular linear monotonic grid
    lonmin = min(min(xlong));
    lonmax = max(max(xlong));
    latmin = min(min(xlat));
    latmax = max(max(xlat));

    lon = linspace(lonmin,lonmax,n);
    lat = linspace(latmin,latmax,n);
    [Lon,Lat] = meshgrid(lon,lat);
    
    Usi = scatteredInterpolant(xlong(:),xlat(:),u(:));
    U(:,:,i)=Usi(Lon,Lat);

    Vsi = scatteredInterpolant(xlong(:),xlat(:),v(:));
    V(:,:,i)=Vsi(Lon,Lat);

end

end
