%make surface U for decadal means
  %%%%% Now grab the zonal winds
  clear all;close all;
  t_step=10;
dir='F:\trace\U\';
fil={'trace.01.22000-20001BP.cam2.h0.U.0000101-0200012.nc';  
'trace.02.20000-19001BP.cam2.h0.U.0200101-0300012.nc';  
'trace.03.19000-18501BP.cam2.h0.U.0300101-0350012.nc';  
'trace.04.18500-18401BP.cam2.h0.U.0350101-0360012.nc';  
'trace.05.18400-17501BP.cam2.h0.U.0360101-0450012.nc';  
'trace.06.17500-17001BP.cam2.h0.U.0450101-0500012.nc';  
'trace.07.17000-16001BP.cam2.h0.U.0500101-0600012.nc';  
'trace.08.16000-15001BP.cam2.h0.U.0600101-0700012.nc';  
'trace.09.15000-14901BP.cam2.h0.U.0700101-0710012.nc';  
'trace.10.14900-14351BP.cam2.h0.U.0710101-0765012.nc';  
'trace.11.14350-13871BP.cam2.h0.U.0765101-0813012.nc';  
'trace.12.13870-13101BP.cam2.h0.U.0813101-0890012.nc';  
'trace.13.13100-12901BP.cam2.h0.U.0890101-0910012.nc';  
'trace.14.12900-12501BP.cam2.h0.U.0910101-0950012.nc';  
'trace.15.12500-12001BP.cam2.h0.U.0950101-1000012.nc';  
'trace.16.12000-11701BP.cam2.h0.U.1000101-1030012.nc';  
'trace.17.11700-11301BP.cam2.h0.U.1030101-1070012.nc';  
'trace.18.11300-10801BP.cam2.h0.U.1070101-1120012.nc';  
'trace.19.10800-10201BP.cam2.h0.U.1120101-1180012.nc';  
'trace.20.10200-09701BP.cam2.h0.U.1180101-1230012.nc';  
'trace.21.09700-09201BP.cam2.h0.U.1230101-1280012.nc';  
'trace.22.09200-08701BP.cam2.h0.U.1280101-1330012.nc';  
'trace.23.08700-08501BP.cam2.h0.U.1330101-1350012.nc';  
'trace.24.08500-08001BP.cam2.h0.U.1350101-1400012.nc';  
'trace.25.08000-07601BP.cam2.h0.U.1400101-1440012.nc';  
'trace.26.07600-07201BP.cam2.h0.U.1440101-1480012.nc';  
'trace.27.07200-06701BP.cam2.h0.U.1480101-1530012.nc';  
'trace.28.06700-06201BP.cam2.h0.U.1530101-1580012.nc';  
'trace.29.06200-05701BP.cam2.h0.U.1580101-1630012.nc';  
'trace.30.05700-05001BP.cam2.h0.U.1630101-1700012.nc';  
'trace.31.05000-04001BP.cam2.h0.U.1700101-1800012.nc';  
'trace.32.04000-03201BP.cam2.h0.U.1800101-1880012.nc';  
'trace.33.03200-02401BP.cam2.h0.U.1880101-1960012.nc';  
'trace.34.02400-01401BP.cam2.h0.U.1960101-2060012.nc';  
'trace.35.01400-00401BP.cam2.h0.U.2060101-2160012.nc';  
'trace.36.400BP-1990CE.cam2.h0.U.2160101-2204012.nc'; };   
off=0;
NF=length(fil);
ilev=26; %vertical level to grab
for n=1:NF;
    n
    tic
FIL=[dir char(fil(n,:))];
%ncdisp(FIL);

t=ncread(FIL, 'time', [1], [Inf]); NT=length(t);
lon=ncread(FIL, 'lon', [1], [Inf]); N=length(lon);
lat=ncread(FIL,'lat', [1], [Inf]); NN=length(lat);
lev=ncread(FIL,'lev', [1], [Inf]); NL=length(lev);
year=rounddown(t*1000);
month=round(12*(t*1000-(year)));
if n == 36; %the times are just a little fubarred
    year=g2c((-400:39)'*ones(1,12));
    month=g2c( ((1:12)'*ones(1,length(-4000:39)))')
end


yrs=min(year):t_step:max(year); NY=length(yrs);
cut=20;
don=find(lat>=0 & lat <= cut);
dos=find(lat<=0 & lat >= -cut);

for ny=1:NY;
    [n ny]
     do = find( year >= yrs(ny) & year < yrs(ny)+t_step );
     U(off+ny,1:NN, 1:N)= squeeze(mean(squeeze(permute(ncread(FIL, 'U', [1 1 ilev min(do)], [Inf Inf 1 length(do)]), [4 3 2 1]))));
end
off=off+NY;
clear u
[min(year) max(year) off]
toc
end