由于ncread(MEX文件)

时间:2015-08-04 12:22:49

标签: matlab runtime mex netcdf

我是这个论坛的新手,所以请告诉我,如果我忘记了相关信息或使用了不常见的格式!

所以我的问题如下: 我目前正在撰写学士论文,因此我必须使用ncread阅读大型.nc文件。这样做绝对好,尽管有一些较大的文件需要一些时间。我知道,我可以使用start中的countncread参数修剪要读取的数据。

我写了一个函数,它读取位于我硬盘上的两个nc文件(大小为360x170x1460)。这些文件每个都是11GB大,因此由于内存使用过多,我最初无法运行该功能。我开始在start中使用countncread参数来加快进程(从6分钟到3秒)。 我从这些文件中读取的部分是所有时间步长(1460)的地理经度,纬度(360x170)元组。这非常有效。

经过几次运行,有时甚至在第一次运行时,我的运行时间非常长。使用profiler我设法识别我的功能的耗时部分。事实证明," netcdf \ private \ netcdflib(MEX-file)"总共耗费360秒约357秒。

现在出现了奇怪的部分,取决于我想要访问哪个坐标元组,脚本从3秒跳到6分钟。例: 我将该功能称为位置A,我等待6分钟并获得所需的结果。然后我使用clear all close all并运行相同位置A的函数,但这次运行时间约为3秒。然后我使用clear all close all并调用位置B的函数,并再次运行大约6分钟。 这种行为似乎随着我调用函数的方式而改变...将其评估为一个部分(无clearclose)或从单独的脚本(使用之前的clear进行调用) close。但这种行为有些不可预测。

这是功能:

function [cnt] = BA_HS_TP(lon,lat,kind,path,out_path,cnt)

lon = lon + 181;
lat = lat + 81;

switch kind
      case 'WAVE'
    tmp1 = squeeze(squeeze(ncread([path 'HS_1981-2011.nc'],'Hs',[lon,lat,1],[1,1,inf])));
    tmp2 = squeeze(squeeze(ncread([path 'PP_1981-2011.nc'],'WAVE_PP',[lon,lat,1],[1,1,inf])));
    x_string = 'Combined wave peak period [s]';
    y_string = 'Combined wave significant wave height [m]';


 cmap = load('Histogram_cmap.mat'); % load custom colormap, in order to show the low probability variations in the Hist


tmpp = double([tmp1,tmp2]);
figure(cnt);
hist3(tmpp);
view(70,40);
[n,c] = hist3(tmpp); cnt = cnt + 1;
Anzahl = sum(sum(n));
figure(cnt);
contourf(c{2}, c{1}, n/Anzahl,500);
set(gca,'ydir','reverse');
set(gca,'xaxislocation','top');
shading flat;
caxis([0 1]);
colormap(cmap.map);
cb = colorbar;
ylabel(cb,'relative frequency');
xlabel(x_string);
ylabel(y_string);

% output to excel
xlswrite([out_path num2str(lon-181) 'East_' num2str(lat-81) 'North.xlsx'],n/Anzahl);
cnt = cnt + 1;
end 

这是调用脚本:

%% Hs vs Tp plot of any coordiante tuple
tic
if(exist('cnt','var')==0);
    cnt = 1;
end

path = 'E:\Tobias\Daten\';
output_path = 'Z:\Studienarbeiten\Kleine_Tobias\';
kind = 'WAVE'; % WAVE , SEA , SWELL
lon = -37; % deg East; real, phys. coordinate
lat = 46; % deg North; real, phys. coordiante
[cnt] = BA_HS_TP(lon,lat,kind,path,output_path,cnt);
toc

0 个答案:

没有答案