function [rmsw,nrms] = get_rms(obs,model,n1,n2)
%%
%% This program is written for comparing the TIEGCM output and data 
%% BA Emery, March 2011

% Assume model and obs are at the same times
% This code from Jiuhou Lei is the same as the code below (but faster)
rmsw = 0.;
nrms = 0;
fp=isnan(obs);
obsi=obs(~fp);
modi=model(~fp);
nrms=sum(~fp);
rmsw=sqrt(sum((obsi-modi).^2)/nrms);

% Slower code gets same results
%rmsw = 0.;
%nrms = 0;
%for i=n1:n2
%% obs(i) ~= NAN FAILS!!!
%% if (obs(i) ~= NaN)
% if ~isnan(obs(i))
%  nrms = nrms + 1;
%% calculate root mean square
%  sqw = (obs(i)-model(i))^2;
%  rmsw = rmsw + sqw;
% end
%end
%% Convert to m/s rms:
%if (nrms > 0)
% rmsw = sqrt(rmsw/nrms);
%end
%%nrms,rmsw
