function [nt,dayfrac,vperpe,vperpn,uiav,viav,wiav,tnav,tiav,teav,neav,nmax,hmax,tec,nz,ht,htne,htte,htti,htmid,httn,htui,htvi,htwi] = get_netein_nc(Fname,ht1,ht2,ii,jj,deginc,degdec)

% open .nc file Fname
    nc=netcdf(Fname,'nowrite');

clear height
clear tn
clear ti
clear te
clear ne
clear ui
clear vi
clear wi
pi = 3.14159;

    time=nc{'mtime'}(:);        % (day, ut_hour, ut_min)
    dayfrac=time(:,1)+time(:,2)/24.+time(:,3)/1440.;
    height=nc{'ZG'}(:);
    lev=nc{'lev'}(:);
% Units are m/s for ExB components
    ui=nc{'UI_ExB'}(:);
    vi=nc{'VI_ExB'}(:);
    wi=nc{'WI_ExB'}(:);
    tn=nc{'TN'}(:);
    ti=nc{'TI'}(:);
    te=nc{'TE'}(:);
    ne=nc{'NE'}(:); 
    nmf2=nc{'NMF2'}(:);
    hmf2=nc{'HMF2'}(:);
    tecarr=nc{'TEC'}(:);
    close(nc)
    
    clear nc

nt = length(dayfrac);
nz = length(lev);

for it=1:nt
temn=0.;
nk = 0;
temui = 0.;
temvi = 0.;
temwi = 0.;
teme = 0.;
temi = 0.;
temne = 0.;
% Convert from cm-3 to m-3
nmax(it) = nmf2(it,jj,ii)*1.e+6;
hmax(it) = hmf2(it,jj,ii);
% Convert from cm-2 to m-2
tec(it) = tecarr(it,jj,ii)*1.e+4;
% Find mean between ht1 and ht2 (in cm)
% Tn, Un, and composition are on midpts between ZG levels, but for a mean, this is not too important
   for kk=1:nz
% Convert from cm to km
    ht(kk,it) = height(it,kk,jj,ii)*1.e-5;
% Get ht at mid-pts for Tn, Ti, Te (Un, Composition, etc)
    if (kk < nz)
     htmid(kk,it) = 0.5*(height(it,kk,jj,ii)+height(it,kk+1,jj,ii))*1.e-5;
     htui(kk,it) = ui(it,kk,jj,ii);
     htvi(kk,it) = vi(it,kk,jj,ii);
     htwi(kk,it) = wi(it,kk,jj,ii);
     httn(kk,it) = tn(it,kk,jj,ii);
     htte(kk,it) = te(it,kk,jj,ii);
     htti(kk,it) = ti(it,kk,jj,ii);
    end
% Convert from cm-3 to m-3
    htne(kk,it) = ne(it,kk,jj,ii)*1.e+6;
    if (height(it,kk,jj,ii) >= ht1 & height(it,kk,jj,ii) <= ht2) 
     temui = temui + ui(it,kk,jj,ii);
     temvi = temvi + vi(it,kk,jj,ii);
     temwi = temwi + wi(it,kk,jj,ii);
     temn = temn + tn(it,kk,jj,ii);
     temi = temi + ti(it,kk,jj,ii);
     teme = teme + te(it,kk,jj,ii);
     temne = temne + ne(it,kk,jj,ii);
     nk = nk + 1;
    end
   end
 uiav(it) = temui/nk;
 viav(it) = temvi/nk;
 wiav(it) = temwi/nk;
 tnav(it) = temn/nk;
 tiav(it) = temi/nk;
 teav(it) = teme/nk;
% Convert from cm-3 to m-3
 neav(it) = temne*1.e+6/nk;
% Calculate VperpE,N ion velocities from geog Ui,Vi,Wi using deginc,dec
 vperpe(it) = cos(degdec*pi/180.)*uiav(it) + sin(degdec*pi/180.)*viav(it);
 horizvin = cos(degdec*pi/180.)*viav(it) - sin(degdec*pi/180.)*uiav(it);
 vperpn(it) = sin(deginc*pi/180.)*horizvin + cos(deginc*pi/180.)*wiav(it);
end

    clear time

