/* ----------------------------------------------------------------------- /* Program: RAINSAST.AML /* Purpose: Creates GRIDS of daily precipitation (10e-3 cm/d) /* Before this AML runs IDW (inverse distance weight) it /* selects all stations that have precipitation depth record /* for a given day (set of stations selected can vary from /* day to day. /* Runs only in GRID /* ----------------------------------------------------------------------- /* Usage: &r RAINSAST /* {YES|NO} /* Arguments: (input) /* (yr = 93) /* fm, fd = from year, from month /* tm, td = to year, to month /* wgrid = a grid for seting the GRID window /* xcell = cellsize of the new grids /* xdat = point coverage that contains data /* yes|no = yes - include records with values = 0 /* no - exclude records and stations that have 0 /* (default) /* Temporary: xxxxx1 /* Globals: /* Locals: templ, nitem, nit, mt,dy, selec (variables) /* ----------------------------------------------------------------------- /* Calls: /* ----------------------------------------------------------------------- /* Notes: Data are stored in PAT (point). Each record is related to /* gaging stations. The following naming convention is used /* for items: myymmdd, where m indicates monthly values, /* yy = year, mm = month,dd = day for example item that /* stores the records for 13 March 1976 has the name p760313 /* ----------------------------------------------------------------------- /* History: Coded by Pawel Mizgalewicz 08/08/96 /* /* ----------------------------------------------------------------------- &args fm fd tm td wgrid xcell xdat zero &severity &error &routine bailout &if [SHOW PROGRAM] <> GRID &then ; &return This only runs in GRID. &if [null %xdat%] &then &do &call usage &return &end &if [null %zero%] &then ; &s zero = YES &s xx = [translate %zero%] &select %xx% &when NO &s klm = gt &when YES &s klm = ge &otherwise &do &call usage &return &end &end /* select /* ========== settings !!! ================ /* year: 93 &s yr = 93 &s templ = pyy0m0d &s nitem0 = [subst %templ% yy %yr% ] /* unit convertion factor: /* 1 inch = 24.5 mm = 0.0245 m (mm are mutipied by 1000 /* to preserve accuracy when converted to INTEGER) /* To get the results back to mm, the grids need to be /* divided by 1000 &s cfac = 24500 /* ======================================== &messages &off /* ====== set the window and the cell size =========== setwindow %wgrid% setcell %xcell% &DO mt = %fm% &to %tm% &if %mt% lt 10 &then &sv nitem1 = [subst %nitem0% m %mt% ] &else &sv nitem1 = [subst %nitem0% 0m %mt% ] &DO dy = 1 &to 31 &s ab = [calc %mt% = %fm%] AND [calc %dy% lt %fd%] &s bb = [calc %mt% = %tm%] AND [calc %dy% gt %td%] &s cc = %ab% OR %bb% &IF NOT %cc% &THEN &do &if %dy% lt 10 &then &sv nitem = [subst %nitem1% d %dy% ] &else &sv nitem = [subst %nitem1% 0d %dy% ] &type %nitem% /* check if the item exists &s iexists = [iteminfo %xdat% -point %nitem% -exists] &if %iexists% &then &do /* &s namit%nit% = %nitem% &sv selec = res %nitem% %klm% 0 &type selecting stations %selec% arc reselect %xdat% xxxxx1 point %selec% ~ n n &end arc build xxxxx1 point %nitem% = int ( %cfac% * idw ( xxxxx1, %nitem% ) ) kill xxxxx1 all &end &end &end &messages &on &return /*------------- &routine USAGE /*------------- &type Usage: &r RAINSAST &type {YES|NO} &return &inform /*------------- &routine EXIT /*------------- /* delete all temporary files: &if [exists xxxxx1 -COVER] &then ; kill xxxxx1 all &messages &on &return /*-------------- &routine BAILOUT /*-------------- &severity &error &ignore &call exit &return &warning An error has occurred in SELDATA.AML /* ----------------------------------------------------------------------- /* EXAMPLE OF APPLICATION /* ----------------------------------------------------------------------- /* /* input /* &s data = $HOME/flood/precip/poinmap/prec50 /* point coverage /* &s wgrid = $HOME/flood/dem/buf50g /grid window sample /* grid /* &run rainsast 1 1 1 4 %wgrid% 2000 %data% YES /* q /* &return /* return from the example AML /* ----------------------------------------------------------------------- &r rs 1 1 1 4 ~/flood/dem/buf50g 2000 ~/flood/precip/poinmap/prec50 YES