1 % !*** tign_history ***
3 % ! A simple api for reading/writing fire histories in wrfinput files for
6 % ! 1. float tign_HIST(nx,ny) contains the fire history in the form of
7 % ! seconds from ignition at each point.
9 % ! The api takes care of all the particulars of reading/writing... it should
10 % ! be invisible to the caller. There are 3 subroutines
11 % ! contained in this api (see implementation for calling syntax):
14 % ! write_tign_history, write (or add) ignition history data to
16 % ! read_tign_history, read all history data from the
18 % ! get_grid_info, get any relevant information (such as grid size) from
22 properties(Constant,Access=protected)
23 filefmt='wrfinput_d%02i';
24 xname='west_east_subgrid';
25 yname='south_north_subgrid';
27 xatm='west_east_stag';
28 yatm='south_north_stag';
29 tign_hist_name='TIGN_G';
38 function write_tign_history(idom,tign)
39 % The subroutine writes a level function to a wrfinput file in the
42 % idom : Input integer describing the the domain number that we will
43 % write the array to. This is only to determine the file name
44 % as printf 'wrfinput_d%02i' idom.
46 % tign(nx,ny) : The fire history written to the file.
48 % Input arrays must have the correct size according the output of
51 f=tign_history.get_file_name(idom);
52 n=netcdf.open(f,'NC_WRITE');
55 tdim=netcdf.inqdimid(n,tign_history.tname);
56 xdim=netcdf.inqdimid(n,tign_history.xname);
57 ydim=netcdf.inqdimid(n,tign_history.yname);
59 vhid=netcdf.defvar(n,tign_history.tign_hist_name,tign_history.xtype,[xdim ydim tdim]);
61 vhid=netcdf.inqvarid(n,tign_history.tign_hist_name);
65 nx=tign_history.get_grid_info(idom,'nx');
66 ny=tign_history.get_grid_info(idom,'ny');
68 netcdf.putVar(n,vhid,[0 0 tign_history.write_time],[nx ny 1],tign);
71 function tign=read_tign_history(idom)
72 % The subroutine reads a level function from a wrfinput file in the
75 % idom : Input integer describing the the domain number that we will
76 % read the array from. This is only to determine the file name
77 % as printf 'wrfinput_d%02i' idom.
81 % tign(nx,ny,ntime) : The fire history from the file.
83 nx=tign_history.get_grid_info(idom,'nx');
84 ny=tign_history.get_grid_info(idom,'ny');
86 n=netcdf.open(tign_history.get_file_name(idom),'NC_NOWRITE');
87 lid=netcdf.inqvarid(n,tign_history.tign_hist_name);
88 tign=netcdf.getVar(n,lid);
89 tign=squeeze(tign(1:nx,1:ny,1));
92 function out=get_grid_info(idom,argin)
94 % This subroutine inquires a wrfinput file in the current directory about
95 % information relevant to the computation and manipulation of tign history
98 % idom : Input integer describing the the domain number that we will
99 % read the array from. This is only to determine the file name
100 % as printf 'wrfinput_d%02i' idom.
102 % argin : a string specifying what is to be returned. Current
105 % nx,ny : The dimensions of the fire grid in the given file.
107 % dx,dy : The grid resolution of the fire grid in meters.
109 % dt : The atmospheric time step in seconds.
111 % sr_x,sr_y : The atmospheric/fire grid refinement factor.
113 n=netcdf.open(tign_history.get_file_name(idom),'NC_NOWRITE');
115 ix=netcdf.inqdimid(n,tign_history.xname);
116 iy=netcdf.inqdimid(n,tign_history.yname);
117 ax=netcdf.inqdimid(n,tign_history.xatm);
118 ay=netcdf.inqdimid(n,tign_history.yatm);
119 [t,nx]=netcdf.inqdim(n,ix);
120 [t,ny]=netcdf.inqdim(n,iy);
121 [t,ax]=netcdf.inqdim(n,ax);
122 [t,ay]=netcdf.inqdim(n,ay);
135 out=netcdf.inqatt(n,netcdf.getConstant('NC_GLOBAL'),tign_history.dxname);
138 out=netcdf.inqatt(n,netcdf.getConstant('NC_GLOBAL'),tign_history.dyname);
141 out=netcdf.inqatt(n,netcdf.getConstant('NC_GLOBAL'),tign_history.dtname);
150 error('invalid input %s',argin);
157 methods(Static,Access=protected)
158 function f=get_file_name(idom)
159 f=sprintf(tign_history.filefmt,idom);
161 function check(ncerr)
163 error(netcdf.strerror(ncerr))