% This script assumes netCDF file containing MM5 output has already been
% opened as 'fid'.
% G Mullendore

% grid information
cny = fid{'BHI_5_1'}(:); %coarse domain grid dimension in i (n-s) direction
cnx = fid{'BHI_6_1'}(:); %coarse domain grid dimension in j (e-w) direction
ny = fid{'BHI_16_1'}(:);
nx = fid{'BHI_17_1'}(:);
dom_id = fid{'BHI_13_1'}(:); %domain ID
mdom_id = fid{'BHI_14_1'}(:); %mother domain ID
cy1 = fid{'BHR_10_1'}(:); %i location in coarse domain of the domain pt (1,1)
cx1 = fid{'BHR_11_1'}(:); %j location in coarse domain of the domain pt (1,1)
my1 = fid{'BHI_18_1'}(:); %i location in mother domain of the domain pt (1,1)
mx1 = fid{'BHI_19_1'}(:); %j location in mother domain of the domain pt (1,1)
nest_level = fid{'BHI_15_1'}(:);
crat = fid{'BHI_20_1'}(:); %grid refinement ratio wrt coarse domain
mrat = fid{'BHI_21_1'}(:); %grid refinement ratio wrt mother domain
nest_comm = fid{'BHI_24_1'}(:); %one-way or two-way nest
cdx = fid{'BHR_1_1'}(:); %coarse domain dx in meters
clat_center = fid{'BHR_2_1'}(:); %degrees
clon_center = fid{'BHR_3_1'}(:); %degrees
dx = fid{'BHR_9_1'}(:);

%time
%year = fid{'BHI_5_2'}(:);
%month = fid{'BHI_6_2'}(:);
%day = fid{'BHI_7_2'}(:);
%hour = fid{'BHI_8_2'}(:);
%minute = fid{'BHI_9_2'}(:);
%sec = fid{'BHI_10_2'}(:);
foo = fid{'time'}.units(:);
year=sscanf(foo(15:18),'%i');
month=sscanf(foo(20:21),'%f');
day=sscanf(foo(23:24),'%f');
hour=sscanf(foo(26:27),'%f');
minute=sscanf(foo(29:30),'%f');
second=sscanf(foo(32:33),'%f');
start_time = datenum(year,month,day,hour,minute,second);
%start = fid{'BHR_1_14'}(:); %starting time (minutes) of domain
%cdt = fid{'BHR_2_12'}(:); %coarse domain time step in seconds
dt = fid{'BHR_1_11'}(:);

%reference state
ptop = fid{'BHR_2_2'}(:); %Pa
psfc = fid{'BHR_2_5'}(:); %Pa
Tsfc = fid{'BHR_3_5'}(:); %K
lapse = fid{'BHR_4_5'}(:); %d(t)/d(ln p)

%misc
foo = fid{'BHI_7_1'}(:);
switch foo
  case 1
    map_proj = 'lambert conformal';
  case 2
    map_proj = 'polar stereographic';
  case 3
    map_proj = 'mercator';
  otherwise
    map_proj = 'not recognized';
end
foo = fid{'BHI_22_1'}(:);
switch foo
  case 1
    smoother = '1-2-1';
  case 2
    smoother = 'smoother-desmoother';
  otherwise
    smoother = 'not recognized';
end
land_use = fid{'BHI_23_1'}(:);
restart = fid{'BHI_1_12'}(:);
restart_time = fid{'BHI_2_12'}(:);

header = 1;
