Friday, May 16, 2014

Tic Toc for time required

Wanted to make grids, and also be informed about the time required to complete:
Implemented tic/toc to count the time... to completion.

clear all
% file location
location = 'E:\scienceFTP\';
fn = 'PBL_2006.nc'
full_fn = [location, fn];
% information1 = ncinfo(full_fn)

lon= double(squeeze(ncread(full_fn, 'longitude')));
lat = double(squeeze(ncread(full_fn, 'latitude')));
PBL = double(squeeze(ncread(full_fn, 'PBL')));
% height = double(squeeze(ncread(full_fn, 'height')));

%Grid limits
Lat_min = 35;
Lat_max = 46;
Lon_min = -85;
Lon_max = -69;

%vector of coordinatesI want
Dlat = Lat_min:0.1:Lat_max;
Dlon = Lon_min:0.1:Lon_max;
[ilat, ilon] = meshgrid(Dlat, Dlon);

% available one
mylat = squeeze(double(lat(:,:,1)));
mylon =  squeeze(double(lon(:,:,1)));
rsdata = double(PBL);
tic
for kk = 1:size(rsdata,3);
 
    % This is isimip original
    rs1 =  (rsdata(:,:,kk));
    % [latmat1f, lonmat1f] = ndgrid(mylat, mylon);
    NEgrid(:,:,kk)  = griddata(mylat, mylon,rs1, ilat,ilon );
 
    if kk ==10
        it = toc;
    end
 
    if rem(kk,100)==20
     
        t  = toc;
        kk
               timewant = it*size(rsdata,3)/10 - t;
        disp(['time remaining = ', num2str(timewant) ]);
    end
 
 
end

save saveMAT/PBL2006.mat NEgrid ilat ilon
% later I can do the following to see the plots
latlim =([25 46]);
lonlim =([-85 -69]);

  kk = 16
 ax = worldmap(latlim, lonlim);
states = shaperead('usastatehi','UseGeoCoords', true, 'BoundingBox', [lonlim', latlim']);
geoshow(ax, states, 'FaceColor', [1 1 1]);
surfacem(ilat,ilon,NEgrid(:,:,kk));


No comments: