| 1 |
enderton |
1.1 |
function data = DiagLoadMNC(fln,dat,dad,grd,iter,filesuffix); |
| 2 |
|
|
|
| 3 |
|
|
% Function: DiagLoad |
| 4 |
|
|
% Author: Daniel Enderton |
| 5 |
|
|
% |
| 6 |
|
|
% Input Fields: |
| 7 |
|
|
% |
| 8 |
|
|
% Field Type (Brief) Description |
| 9 |
|
|
% ----------------------------------------------------------------------- |
| 10 |
|
|
% fln string Field name |
| 11 |
|
|
% dat string Data type ('Tav', 'Int',...) |
| 12 |
|
|
% dad string Data directory. |
| 13 |
|
|
% grd string Grid data directory. |
| 14 |
|
|
% iter string Iterations for analysis. |
| 15 |
|
|
% filesuffix string Field name suffix ('tave','',...) |
| 16 |
|
|
% |
| 17 |
|
|
% Output Fields: |
| 18 |
|
|
% |
| 19 |
|
|
% Field Type (Brief) Description |
| 20 |
|
|
% ----------------------------------------------------------------------- |
| 21 |
|
|
% data cell array Loaded data. |
| 22 |
|
|
% datatime array Model time of data in months. |
| 23 |
|
|
% |
| 24 |
|
|
% Descripton: |
| 25 |
|
|
% This function loads MNC data. The field to load is defined by 'fln'. |
| 26 |
|
|
% Typically, whatever 'fln' is set to is the fields that is read in, |
| 27 |
|
|
% though the AIM physics parameters in a noteable exception to this. The |
| 28 |
|
|
% data must be all located in the folder specified by 'dad', and this |
| 29 |
|
|
% string must end with a '/', and similarly for the grid data. |
| 30 |
|
|
|
| 31 |
|
|
|
| 32 |
|
|
% Load parameters (here only general diagnostics). |
| 33 |
|
|
DiagGenParam; |
| 34 |
|
|
|
| 35 |
|
|
|
| 36 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 |
|
|
% Read in data % |
| 38 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 39 |
|
|
|
| 40 |
|
|
% Generally, the data is read in by using the 'rdmds' function (see MITgcm) |
| 41 |
|
|
% with FNAME as [fln,filesuffix], and ITER = iter. There are some |
| 42 |
|
|
% exceptions, such as the AIM physics parameters. Some of the fields then |
| 43 |
|
|
% require some immediate manipulation. Examples are U (instantaneous) and |
| 44 |
|
|
% uVel (time-averaged) which are immediately converted to a lat-lon grid |
| 45 |
|
|
% because the 'U' and 'V' files of the cube-sphere do NOT correspond to the |
| 46 |
|
|
% typical zonal and meridional winds. Some other fields, such as 'KEpri' |
| 47 |
|
|
% require some simple calculations which are immediately done. |
| 48 |
|
|
|
| 49 |
|
|
if isequal(dat,'Tav') |
| 50 |
|
|
if isequal(fln,'phiHyd') |
| 51 |
|
|
ncroot = 'phiHyd.'; |
| 52 |
|
|
filesuffix = ''; |
| 53 |
|
|
else |
| 54 |
|
|
ncroot = 'tave.'; |
| 55 |
|
|
end |
| 56 |
|
|
elseif isequal(dat,'Int') |
| 57 |
|
|
ncroot = 'state.'; |
| 58 |
|
|
else |
| 59 |
|
|
error(['Unrecognized DataType: ',dat]); |
| 60 |
|
|
end |
| 61 |
|
|
|
| 62 |
|
|
if ismember(fln,fields2D) |
| 63 |
|
|
data = zeros([length(iter),hres,faces*hres]); |
| 64 |
|
|
elseif ismember(fln,fields3D) |
| 65 |
|
|
if ismember(fln,{'U','uVel'}) |
| 66 |
|
|
data = zeros([length(iter),vres,hres,faces*hres+1]); |
| 67 |
|
|
elseif ismember(fln,{'V','vVel'}) |
| 68 |
|
|
data = zeros([length(iter),vres,hres+1,faces*hres]); |
| 69 |
|
|
else |
| 70 |
|
|
data = zeros([length(iter),vres,hres,faces*hres]); |
| 71 |
|
|
end |
| 72 |
|
|
else |
| 73 |
|
|
error(['Unrecognized field name: ',fln]); |
| 74 |
|
|
end |
| 75 |
|
|
|
| 76 |
|
|
ncdir = dir(dad); |
| 77 |
|
|
datafound = zeros(size(iter)); |
| 78 |
|
|
for ifile = 1:length(ncdir) |
| 79 |
|
|
ncfile = ncdir(ifile).name; |
| 80 |
|
|
if ~isempty(strfind(ncfile,ncroot)) |
| 81 |
|
|
nc=netcdf([dad,ncfile],'read'); |
| 82 |
|
|
it = nc{'iter'}(:); |
| 83 |
|
|
face = nc.('tile_number')(:); |
| 84 |
|
|
xindex = [hres*(face-1)+1:hres*face]; |
| 85 |
|
|
[mncindex,dataindex] = ismember(it,iter); |
| 86 |
|
|
if sum(mncindex) > 0 |
| 87 |
|
|
dataindex = dataindex(find(dataindex)); |
| 88 |
|
|
mncindex = find(mncindex); |
| 89 |
|
|
datafound(dataindex) = datafound(dataindex) + 1; |
| 90 |
|
|
mncdata = nc{[fln,filesuffix]}; |
| 91 |
|
|
if ismember(fln,fields2D) |
| 92 |
|
|
data(dataindex,:,xindex) = mncdata(mncindex,1:hres,1:hres); |
| 93 |
|
|
elseif ismember(fln,fields3D) |
| 94 |
|
|
if ismember(fln,{'U','uVel'}) |
| 95 |
|
|
data = zeros([length(iter),vres,hres,faces*(hres+1)]); |
| 96 |
|
|
data(dataindex,:,:,xindex) = mncdata(mncindex,:,1:hres,1:hres); |
| 97 |
|
|
elseif ismember(fln,{'V','vVel'}) |
| 98 |
|
|
data(dataindex,:,:,xindex) = mncdata(mncindex,:,:,:); |
| 99 |
|
|
else |
| 100 |
|
|
data(dataindex,:,:,xindex) = mncdata(mncindex,:,1:hres,1:hres); |
| 101 |
|
|
end |
| 102 |
|
|
end |
| 103 |
|
|
end |
| 104 |
|
|
close(nc); |
| 105 |
|
|
end |
| 106 |
|
|
end |
| 107 |
|
|
|
| 108 |
|
|
|
| 109 |
|
|
if ~( isequal(datafound, faces*ones(size(iter))) | ... |
| 110 |
|
|
isequal(datafound,2*faces*ones(size(iter))) ) % Embarassing fix!!! |
| 111 |
|
|
disp(['Iterations desired: ',mat2str(iter)]); |
| 112 |
|
|
disp(['Faces per iteration: ',mat2str(datafound)]); |
| 113 |
|
|
error(['Missing Data! (See output above for details).']); |
| 114 |
|
|
end |
| 115 |
|
|
|
| 116 |
|
|
data = permute(data,[length(size(data)):-1:1]); |