driver.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882
  1. /*
  2. ************************************************************
  3. * MODULE: r.le.patch/driver.c *
  4. * Version 5.0 Nov. 1, 2001 *
  5. * *
  6. * AUTHOR: W.L. Baker, University of Wyomirng *
  7. * BAKERWL@UWYO.EDU *
  8. * *
  9. * PURPOSE: To analyze attributes of patches in a landscape *
  10. * driver.c opens input and output files, and calls *
  11. * the moving window, unit, and whole map drivers *
  12. * *
  13. * COPYRIGHT: (C) 2001 by W.L. Baker *
  14. * *
  15. * This program is free software under the GNU General *
  16. * Public License(>=v2). Read the file COPYING that comes *
  17. * with GRASS for details *
  18. * *
  19. ************************************************************/
  20. #include <grass/config.h>
  21. #include "patch.h"
  22. /* DEFINE GLOBAL VARIABLES */
  23. int ntype = 0, finput, n_scale = 1, n_unit = 1, size_cl_no = 0, *recl_count,
  24. shape_cl_no = 0;
  25. static int para1, para2, para3, para4, para5;
  26. float *shape_PA, *shape_CPA, *shape_RCC, *size_cl, **recl_tb;
  27. extern struct CHOICE *choice;
  28. char cmdbuf[100];
  29. RASTER_MAP_TYPE data_type;
  30. /*
  31. Variables:
  32. GLOBAL:
  33. ntype = the number of attribute groups if by gp measures are
  34. calculated
  35. finput = the raster map to be analyzed
  36. n_scale = the number of sampling scales
  37. n_unit = the number of sampling units
  38. para1 = set to 1 if by gp measures are chosen
  39. para2 = set to 1 if size classes are chosen
  40. para3 = set to 1 if perimeter-area shape index classes are chosen
  41. para4 = set to 1 if corrected perimeter-area shape index classes are
  42. chosen
  43. para5 = set to 1 if related circumscribing circle shape index classes
  44. are chosen
  45. shape_PA[] = array to hold the perimeter-area shape index classes
  46. shape_CPA[] = array to hold the corrected perimeter-area shape index
  47. classes
  48. shape_RCC[] = array to hold the related circumscribing circle shape index
  49. classes
  50. size_cl[] = array to hold the size classes
  51. recl_tb[][]= array to hold the attribute groups
  52. data_type = the type of raster map: integer, floating point, or double
  53. */
  54. /* RUN R.LE.PATCH IN FOREGROUND */
  55. void patch_fore()
  56. {
  57. fputs("\nR.LE.PATCH IS WORKING....;\n\n", stderr);
  58. /* check for input raster map and open it; this
  59. map remains open on finput while all the programs
  60. run, so it is globally available */
  61. if (0 > (finput = Rast_open_old(choice->fn, G_mapset()))) {
  62. fprintf(stderr, "\n");
  63. fprintf(stderr,
  64. " ******* *************************************************\n");
  65. fprintf(stderr,
  66. " The raster map you specified with the 'map=' parameter \n");
  67. fprintf(stderr,
  68. " was not found in your mapset. \n");
  69. fprintf(stderr,
  70. " ********************************************************\n");
  71. exit(EXIT_FAILURE);
  72. }
  73. /* determine whether the raster map is integer
  74. (CELL_TYPE),floating point (FCELL_TYPE), or
  75. double (DCELL_TYPE) and make globally available */
  76. else
  77. data_type = Rast_map_type(choice->fn, G_mapset());
  78. /* if using a moving window, get the parameters,
  79. and start the moving window driver */
  80. if (choice->wrum == 'm') {
  81. get_para();
  82. mv_driver();
  83. if (para1 || para2 || para3 || para4 || para5)
  84. free_para();
  85. }
  86. /* get the parameters; if using the whole raster map
  87. as the sampling area, start the whole region driver;
  88. if using sampling units, start the sampling unit
  89. driver */
  90. else {
  91. get_para();
  92. open_files();
  93. if (choice->wrum != 'u')
  94. whole_reg_driver();
  95. else
  96. unit_driver();
  97. if (para1 || para2 || para3 || para4 || para5)
  98. free_para();
  99. }
  100. /* when everything is done, close the raster map
  101. and print a completion message */
  102. Rast_close(finput);
  103. fputs("\nR.LE.PATCH IS DONE; ", stderr);
  104. if (choice->wrum != 'm')
  105. fputs("OUTPUT FILES IN SUBDIRECTORY \"r.le.out\"\n", stderr);
  106. return;
  107. }
  108. /* SETUP THE OUTPUT FILES WHEN SAM=W,U,R */
  109. void open_files()
  110. {
  111. FILE *fp;
  112. char path[GPATH_MAX];
  113. int i;
  114. if (choice->att[1] || choice->att[2] || choice->att[3] || choice->att[4]) {
  115. fp = fopen0("r.le.out/a1-4.out", "w");
  116. fprintf(fp,
  117. "Scale Unit MN. PIXEL ATT. S.D. PIXEL ATT. MN. PATCH ATT. S.D. PATCH ATT.\n");
  118. fclose(fp);
  119. }
  120. if (choice->att[5]) {
  121. fp = fopen0("r.le.out/a5.out", "w");
  122. fprintf(fp, " COVER (FRACTION) BY GROUP\n");
  123. fprintf(fp, "Scale Unit ");
  124. for (i = 0; i < ntype; i++)
  125. fprintf(fp, " Group[%2d]", i + 1);
  126. fprintf(fp, "\n");
  127. fclose(fp);
  128. }
  129. if (choice->att[6]) {
  130. fp = fopen0("r.le.out/a6.out", "w");
  131. fprintf(fp, " DENSITY BY GROUP\n");
  132. fprintf(fp, "Scale Unit ");
  133. for (i = 0; i < ntype; i++)
  134. fprintf(fp, " Group[%2d]", i + 1);
  135. fprintf(fp, "\n");
  136. fclose(fp);
  137. }
  138. if (choice->att[7]) {
  139. fp = fopen0("r.le.out/a7.out", "w");
  140. fprintf(fp, "Scale Unit TOTAL DENSITY\n");
  141. fclose(fp);
  142. }
  143. if (choice->att[8]) {
  144. fp = fopen0("r.le.out/a8.out", "w");
  145. fprintf(fp, "Scale Unit EFF. MESH NUM.\n");
  146. fclose(fp);
  147. }
  148. if (choice->size[1] || choice->size[2]) {
  149. fp = fopen0("r.le.out/s1-2.out", "w");
  150. fprintf(fp,
  151. "Scale Unit MN. PATCH SIZE S.D. PATCH SIZE -- in pixels\n");
  152. fclose(fp);
  153. }
  154. if (choice->size[3]) {
  155. fp = fopen0("r.le.out/s3.out", "w");
  156. fprintf(fp, " MEAN PATCH SIZE BY GROUP -- in pixels\n");
  157. fprintf(fp, "Scale Unit ");
  158. for (i = 0; i < ntype; i++)
  159. fprintf(fp, " Group[%2d]", i + 1);
  160. fprintf(fp, "\n");
  161. fclose(fp);
  162. }
  163. if (choice->size[4]) {
  164. fp = fopen0("r.le.out/s4.out", "w");
  165. fprintf(fp, " S.D. PATCH SIZE BY GROUP -- in pixels\n");
  166. fprintf(fp, "Scale Unit ");
  167. for (i = 0; i < ntype; i++)
  168. fprintf(fp, " Group[%2d]", i + 1);
  169. fprintf(fp, "\n");
  170. fclose(fp);
  171. }
  172. if (choice->size[5]) {
  173. fp = fopen0("r.le.out/s5.out", "w");
  174. fprintf(fp,
  175. " NUMBER OF PATCHES BY SIZE CLASS -- in pixels\n");
  176. fprintf(fp, "Scale Unit ");
  177. for (i = 0; i < size_cl_no; i++)
  178. fprintf(fp, " Class[%2d]", i + 1);
  179. fprintf(fp, "\n");
  180. fclose(fp);
  181. }
  182. if (choice->size[6]) {
  183. fp = fopen0("r.le.out/s6.out", "w");
  184. fprintf(fp,
  185. " NUMBER OF PATCHES BY SIZE CLASS BY GROUP -- in pixels\n");
  186. fprintf(fp, "Scale Unit ");
  187. for (i = 0; i < size_cl_no; i++)
  188. fprintf(fp, " Class[%2d]", i + 1);
  189. fprintf(fp, "\n");
  190. fclose(fp);
  191. }
  192. if (choice->size[7] || choice->size[8]) {
  193. fp = fopen0("r.le.out/s7-8.out", "w");
  194. fprintf(fp, "Scale Unit EFF. MESH SIZE DEG. LAND. DIV.\n");
  195. fclose(fp);
  196. }
  197. if (choice->core[1] || choice->core[2] ||
  198. choice->core[3] || choice->core[4]) {
  199. fp = fopen0("r.le.out/c1-4.out", "w");
  200. fprintf(fp,
  201. "Scale Unit MEAN CORE SIZE S.D. CORE SIZE MEAN EDGE SIZE S.D. EDGE SIZE\n");
  202. fclose(fp);
  203. }
  204. if (choice->core[5]) {
  205. fp = fopen0("r.le.out/c5.out", "w");
  206. fprintf(fp, " MEAN CORE SIZE BY GROUP -- in pixels\n");
  207. fprintf(fp, "Scale Unit ");
  208. for (i = 0; i < ntype; i++)
  209. fprintf(fp, " Group[%2d]", i + 1);
  210. fprintf(fp, "\n");
  211. fclose(fp);
  212. }
  213. if (choice->core[6]) {
  214. fp = fopen0("r.le.out/c6.out", "w");
  215. fprintf(fp, " S.D. CORE SIZE BY GROUP -- in pixels\n");
  216. fprintf(fp, "Scale Unit ");
  217. for (i = 0; i < ntype; i++)
  218. fprintf(fp, " Group[%2d]", i + 1);
  219. fprintf(fp, "\n");
  220. fclose(fp);
  221. }
  222. if (choice->core[7]) {
  223. fp = fopen0("r.le.out/c7.out", "w");
  224. fprintf(fp, " MEAN EDGE SIZE BY GROUP -- in pixels\n");
  225. fprintf(fp, "Scale Unit ");
  226. for (i = 0; i < ntype; i++)
  227. fprintf(fp, " Group[%2d]", i + 1);
  228. fprintf(fp, "\n");
  229. fclose(fp);
  230. }
  231. if (choice->core[8]) {
  232. fp = fopen0("r.le.out/c8.out", "w");
  233. fprintf(fp, " S.D. EDGE SIZE BY GROUP -- in pixels\n");
  234. fprintf(fp, "Scale Unit ");
  235. for (i = 0; i < ntype; i++)
  236. fprintf(fp, " Group[%2d]", i + 1);
  237. fprintf(fp, "\n");
  238. fclose(fp);
  239. }
  240. if (choice->core[9]) {
  241. fp = fopen0("r.le.out/c9c.out", "w");
  242. fprintf(fp,
  243. " NUMBER OF PATCH CORES BY SIZE CLASS -- in pixels\n");
  244. fprintf(fp, "Scale Unit ");
  245. for (i = 0; i < size_cl_no; i++)
  246. fprintf(fp, " Class[%2d]", i + 1);
  247. fprintf(fp, "\n");
  248. fclose(fp);
  249. fp = fopen0("r.le.out/c9e.out", "w");
  250. fprintf(fp,
  251. " NUMBER OF PATCH EDGES BY SIZE CLASS -- in pixels\n");
  252. fprintf(fp, "Scale Unit ");
  253. for (i = 0; i < size_cl_no; i++)
  254. fprintf(fp, " Class[%2d]", i + 1);
  255. fprintf(fp, "\n");
  256. fclose(fp);
  257. }
  258. if (choice->core[10]) {
  259. fp = fopen0("r.le.out/c10c.out", "w");
  260. fprintf(fp,
  261. " NUMBER OF PATCH CORES BY SIZE CLASS BY GROUP -- in pixels\n");
  262. fprintf(fp, "Scale Unit ");
  263. for (i = 0; i < size_cl_no; i++)
  264. fprintf(fp, " Class[%2d]", i + 1);
  265. fprintf(fp, "\n");
  266. fclose(fp);
  267. fp = fopen0("r.le.out/c10e.out", "w");
  268. fprintf(fp,
  269. " NUMBER OF PATCH EDGES BY SIZE CLASS BY GROUP -- in pixels\n");
  270. fprintf(fp, "Scale Unit ");
  271. for (i = 0; i < size_cl_no; i++)
  272. fprintf(fp, " Class[%2d]", i + 1);
  273. fprintf(fp, "\n");
  274. fclose(fp);
  275. }
  276. if (choice->shape[1] || choice->shape[2]) {
  277. fp = fopen0("r.le.out/h1-2.out", "w");
  278. fprintf(fp, "Scale Unit MN. PATCH SHAPE SD. PATCH SHAPE\n");
  279. fclose(fp);
  280. }
  281. if (choice->shape[3]) {
  282. fp = fopen0("r.le.out/h3.out", "w");
  283. fprintf(fp, " MEAN PATCH SHAPE BY GROUP\n");
  284. fprintf(fp, "Scale Unit ");
  285. for (i = 0; i < ntype; i++)
  286. fprintf(fp, " Group[%2d]", i + 1);
  287. fprintf(fp, "\n");
  288. fclose(fp);
  289. }
  290. if (choice->shape[4]) {
  291. fp = fopen0("r.le.out/h4.out", "w");
  292. fprintf(fp, " S.D. PATCH SHAPE BY GROUP\n");
  293. fprintf(fp, "Scale Unit ");
  294. for (i = 0; i < ntype; i++)
  295. fprintf(fp, " Group[%2d]", i + 1);
  296. fprintf(fp, "\n");
  297. fclose(fp);
  298. }
  299. if (choice->shape[5]) {
  300. fp = fopen0("r.le.out/h5.out", "w");
  301. fprintf(fp, " NO. OF PATCHES BY SHAPE INDEX CLASS\n");
  302. fprintf(fp, "Scale Unit ");
  303. for (i = 0; i < shape_cl_no; i++)
  304. fprintf(fp, " Class[%2d]", i + 1);
  305. fprintf(fp, "\n");
  306. fclose(fp);
  307. }
  308. if (choice->shape[6]) {
  309. fp = fopen0("r.le.out/h6.out", "w");
  310. fprintf(fp,
  311. " NO. OF PATCHES BY SHAPE INDEX CLASS BY GROUP\n");
  312. fprintf(fp, "Scale Unit ");
  313. for (i = 0; i < shape_cl_no; i++)
  314. fprintf(fp, " Class[%2d]", i + 1);
  315. fprintf(fp, "\n");
  316. fclose(fp);
  317. }
  318. if (choice->boundary[1] || choice->boundary[2] ||
  319. choice->boundary[3] || choice->boundary[4]) {
  320. fp = fopen0("r.le.out/n1-4.out", "w");
  321. fprintf(fp,
  322. "Scale Unit MEAN TWIST NUM. SD. TWIST NUM. MN. OMEGA INDEX SD. OMEGA INDEX\n");
  323. fclose(fp);
  324. }
  325. if (choice->perim[1] || choice->perim[2] || choice->perim[3]) {
  326. fp = fopen0("r.le.out/p1-3.out", "w");
  327. fprintf(fp,
  328. "Scale Unit SUM PERIMETER MEAN PERIMETER S.D. PERIMETER -- in pixels\n");
  329. fclose(fp);
  330. }
  331. if (choice->perim[4]) {
  332. fp = fopen0("r.le.out/p4.out", "w");
  333. fprintf(fp,
  334. " SUM OF PERIMETERS BY GROUP -- in pixels\n");
  335. fprintf(fp, "Scale Unit ");
  336. for (i = 0; i < ntype; i++)
  337. fprintf(fp, " Group[%2d]", i + 1);
  338. fprintf(fp, "\n");
  339. fclose(fp);
  340. }
  341. if (choice->perim[5]) {
  342. fp = fopen0("r.le.out/p5.out", "w");
  343. fprintf(fp, " MEAN PERIMETER BY GROUP -- in pixels\n");
  344. fprintf(fp, "Scale Unit ");
  345. for (i = 0; i < ntype; i++)
  346. fprintf(fp, " Group[%2d]", i + 1);
  347. fprintf(fp, "\n");
  348. fclose(fp);
  349. }
  350. if (choice->perim[6]) {
  351. fp = fopen0("r.le.out/p6.out", "w");
  352. fprintf(fp, " S.D. PERIMETER BY GROUP -- in pixels\n");
  353. fprintf(fp, "Scale Unit ");
  354. for (i = 0; i < ntype; i++)
  355. fprintf(fp, " Group[%2d]", i + 1);
  356. fprintf(fp, "\n");
  357. fclose(fp);
  358. }
  359. if (strcmp(choice->out, "") && choice->wrum != 'm') {
  360. sprintf(path, "r.le.out/%s", choice->out);
  361. fp = fopen0(path, "w");
  362. if (!strcmp(choice->out, "head"))
  363. fprintf(fp, "sc- un- center patch\
  364. core edge shape index twist omega\n");
  365. fprintf(fp, "ale it num att row col size\
  366. size size per P/A CP/A RCC number index\n");
  367. fclose(fp);
  368. }
  369. return;
  370. }
  371. /* OPEN R.LE OUTPUT FILE, WITH ERROR TRAP */
  372. FILE *fopen0(char *name, char *flag)
  373. {
  374. FILE *fp;
  375. if (!(fp = fopen(name, flag))) {
  376. fprintf(stderr, "\n");
  377. fprintf(stderr, " ******************************************\n");
  378. fprintf(stderr, " Can't open output file \"%s\" \n",
  379. name);
  380. fprintf(stderr, " Do you have write permission in r.le.out \n");
  381. fprintf(stderr, " subdirectory? \n");
  382. fprintf(stderr, " ******************************************\n");
  383. }
  384. return fp;
  385. }
  386. /* OPEN INPUT FILE, WITH ERROR TRAP */
  387. FILE *fopen1(char *name, char *flag)
  388. {
  389. FILE *fp;
  390. if (!(fp = fopen(name, flag))) {
  391. fprintf(stderr, "\n");
  392. fprintf(stderr,
  393. " ******************************************************\n");
  394. fprintf(stderr,
  395. " You chose a moving window or sampling units analysis \n");
  396. fprintf(stderr,
  397. " but r.le.patch can't find file \"%s\" \n",
  398. name);
  399. fprintf(stderr,
  400. " which defines the moving window or sampling units \n");
  401. fprintf(stderr,
  402. " First use r.le.setup to define a moving window or \n");
  403. fprintf(stderr,
  404. " sampling units to make this file \n");
  405. fprintf(stderr,
  406. " ******************************************************\n");
  407. exit(EXIT_FAILURE);
  408. }
  409. return fp;
  410. }
  411. /* OPEN INPUT FILE, WITH ERROR TRAP */
  412. FILE *fopen2(char *name, char *flag)
  413. {
  414. FILE *fp;
  415. if (!(fp = fopen(name, flag))) {
  416. fprintf(stderr, "\n");
  417. fprintf(stderr,
  418. " **************************************************\n");
  419. fprintf(stderr,
  420. " You chose a 'by gp' or 'by class' analysis \n");
  421. fprintf(stderr,
  422. " but r.le.patch can't find file \"%s\" \n",
  423. name);
  424. fprintf(stderr,
  425. " which defines the attribute groups or classes \n");
  426. fprintf(stderr,
  427. " First use r.le.setup to create this file \n");
  428. fprintf(stderr,
  429. " **************************************************\n");
  430. exit(EXIT_FAILURE);
  431. }
  432. return fp;
  433. }
  434. /* MOVING WINDOW DRIVER PROG. */
  435. void mv_driver()
  436. {
  437. register int i, j;
  438. int nr, nc, u_w, u_l, x0, y0, d, fmask, m, p;
  439. double *row_buf, *tmp_buf, *tmp_buf2, **buff = NULL;
  440. int a1, a2, a3, a4, a5, a6, a7, a8, s1, s2, s3, s4, s5, s6, s7, s8, c1,
  441. c2, c3, c4, c5, c6, c7, c8, c9, c10, h1, h2, h3, h4, h5, h6, p1, p2,
  442. p3, p4, p5, p6, n1, n2, n3, n4, b;
  443. long finished_time;
  444. float radius;
  445. struct Cell_head wind;
  446. char *nulltmp;
  447. /* variables:
  448. nr = #rows in search area minus height of mov. wind.
  449. nc = #cols. in search area minus width of mov. wind.
  450. u_w = width of mov. wind. in cells
  451. u_l = width of mov. wind. in cells
  452. x0 = starting column for upper L corner of mov. wind.
  453. y0 = starting row for upper L corner of mov. wind.
  454. row = row for moving-window center
  455. col = column for moving-window center
  456. *row_buf = temporary array that holds one row of the
  457. raster map that is being analyzed
  458. *tmp_buf = temporary array that holds one moving wind.
  459. measure for a single row
  460. **buff = temporary array that holds the set of chosen
  461. measures for a row
  462. radius = radius of the sampling unit, if circles are used
  463. */
  464. /* open the appropriate output moving window
  465. maps. All maps currently are double,
  466. rather than floating point or int */
  467. if (choice->att[1]) {
  468. if (G_find_raster("a1", G_mapset()) != NULL) {
  469. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a1,a1bak");
  470. system(cmdbuf);
  471. }
  472. a1 = Rast_open_new("a1", DCELL_TYPE);
  473. }
  474. if (choice->att[2]) {
  475. if (G_find_raster("a2", G_mapset()) != NULL) {
  476. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a2,a2bak");
  477. system(cmdbuf);
  478. }
  479. a2 = Rast_open_new("a2", DCELL_TYPE);
  480. }
  481. if (choice->att[3]) {
  482. if (G_find_raster("a3", G_mapset()) != NULL) {
  483. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a3,a3bak");
  484. system(cmdbuf);
  485. }
  486. a3 = Rast_open_new("a3", DCELL_TYPE);
  487. }
  488. if (choice->att[4]) {
  489. if (G_find_raster("a4", G_mapset()) != NULL) {
  490. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a4,a4bak");
  491. system(cmdbuf);
  492. }
  493. a4 = Rast_open_new("a4", DCELL_TYPE);
  494. }
  495. if (choice->att[5]) {
  496. if (G_find_raster("a5", G_mapset()) != NULL) {
  497. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a5,a5bak");
  498. system(cmdbuf);
  499. }
  500. a5 = Rast_open_new("a5", DCELL_TYPE);
  501. }
  502. if (choice->att[6]) {
  503. if (G_find_raster("a6", G_mapset()) != NULL) {
  504. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a6,a6bak");
  505. system(cmdbuf);
  506. }
  507. a6 = Rast_open_new("a6", DCELL_TYPE);
  508. }
  509. if (choice->att[7]) {
  510. if (G_find_raster("a7", G_mapset()) != NULL) {
  511. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a7,a7bak");
  512. system(cmdbuf);
  513. }
  514. a7 = Rast_open_new("a7", DCELL_TYPE);
  515. }
  516. if (choice->att[8]) {
  517. if (G_find_raster("a8", G_mapset()) != NULL) {
  518. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=a8,a8bak");
  519. system(cmdbuf);
  520. }
  521. a8 = Rast_open_new("a8", DCELL_TYPE);
  522. }
  523. if (choice->size[1]) {
  524. if (G_find_raster("s1", G_mapset()) != NULL) {
  525. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s1,s1bak");
  526. system(cmdbuf);
  527. }
  528. s1 = Rast_open_new("s1", DCELL_TYPE);
  529. }
  530. if (choice->size[2]) {
  531. if (G_find_raster("s2", G_mapset()) != NULL) {
  532. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s2,s2bak");
  533. system(cmdbuf);
  534. }
  535. s2 = Rast_open_new("s2", DCELL_TYPE);
  536. }
  537. if (choice->size[3]) {
  538. if (G_find_raster("s3", G_mapset()) != NULL) {
  539. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s3,s3bak");
  540. system(cmdbuf);
  541. }
  542. s3 = Rast_open_new("s3", DCELL_TYPE);
  543. }
  544. if (choice->size[4]) {
  545. if (G_find_raster("s4", G_mapset()) != NULL) {
  546. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s4,s4bak");
  547. system(cmdbuf);
  548. }
  549. s4 = Rast_open_new("s4", DCELL_TYPE);
  550. }
  551. if (choice->size[5]) {
  552. if (G_find_raster("s5", G_mapset()) != NULL) {
  553. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s5,s5bak");
  554. system(cmdbuf);
  555. }
  556. s5 = Rast_open_new("s5", DCELL_TYPE);
  557. }
  558. if (choice->size[6]) {
  559. if (G_find_raster("s6", G_mapset()) != NULL) {
  560. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s6,s6bak");
  561. system(cmdbuf);
  562. }
  563. s6 = Rast_open_new("s6", DCELL_TYPE);
  564. }
  565. if (choice->size[7]) {
  566. if (G_find_raster("s7", G_mapset()) != NULL) {
  567. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s7,s7bak");
  568. system(cmdbuf);
  569. }
  570. s7 = Rast_open_new("s7", DCELL_TYPE);
  571. }
  572. if (choice->size[8]) {
  573. if (G_find_raster("s8", G_mapset()) != NULL) {
  574. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=s8,s8bak");
  575. system(cmdbuf);
  576. }
  577. s8 = Rast_open_new("s8", DCELL_TYPE);
  578. }
  579. if (choice->core[1]) {
  580. if (G_find_raster("c1", G_mapset()) != NULL) {
  581. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c1,c1bak");
  582. system(cmdbuf);
  583. }
  584. c1 = Rast_open_new("c1", DCELL_TYPE);
  585. }
  586. if (choice->core[2]) {
  587. if (G_find_raster("c2", G_mapset()) != NULL) {
  588. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c2,c2bak");
  589. system(cmdbuf);
  590. }
  591. c2 = Rast_open_new("c2", DCELL_TYPE);
  592. }
  593. if (choice->core[3]) {
  594. if (G_find_raster("c3", G_mapset()) != NULL) {
  595. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c3,c3bak");
  596. system(cmdbuf);
  597. }
  598. c3 = Rast_open_new("c3", DCELL_TYPE);
  599. }
  600. if (choice->core[4]) {
  601. if (G_find_raster("c4", G_mapset()) != NULL) {
  602. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c4,c4bak");
  603. system(cmdbuf);
  604. }
  605. c4 = Rast_open_new("c4", DCELL_TYPE);
  606. }
  607. if (choice->core[5]) {
  608. if (G_find_raster("c5", G_mapset()) != NULL) {
  609. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c5,c5bak");
  610. system(cmdbuf);
  611. }
  612. c5 = Rast_open_new("c5", DCELL_TYPE);
  613. }
  614. if (choice->core[6]) {
  615. if (G_find_raster("c6", G_mapset()) != NULL) {
  616. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c6,c6bak");
  617. system(cmdbuf);
  618. }
  619. c6 = Rast_open_new("c6", DCELL_TYPE);
  620. }
  621. if (choice->core[7]) {
  622. if (G_find_raster("c7", G_mapset()) != NULL) {
  623. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c7,c7bak");
  624. system(cmdbuf);
  625. }
  626. c7 = Rast_open_new("c7", DCELL_TYPE);
  627. }
  628. if (choice->core[8]) {
  629. if (G_find_raster("c8", G_mapset()) != NULL) {
  630. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c8,c8bak");
  631. system(cmdbuf);
  632. }
  633. c8 = Rast_open_new("c8", DCELL_TYPE);
  634. }
  635. if (choice->core[9]) {
  636. if (G_find_raster("c9", G_mapset()) != NULL) {
  637. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c9,c9bak");
  638. system(cmdbuf);
  639. }
  640. c9 = Rast_open_new("c9", DCELL_TYPE);
  641. }
  642. if (choice->core[10]) {
  643. if (G_find_raster("c10", G_mapset()) != NULL) {
  644. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=c10,c10bak");
  645. system(cmdbuf);
  646. }
  647. c10 = Rast_open_new("c10", DCELL_TYPE);
  648. }
  649. if (choice->shape[1]) {
  650. if (G_find_raster("h1", G_mapset()) != NULL) {
  651. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=h1,h1bak");
  652. system(cmdbuf);
  653. }
  654. h1 = Rast_open_new("h1", DCELL_TYPE);
  655. }
  656. if (choice->shape[2]) {
  657. if (G_find_raster("h2", G_mapset()) != NULL) {
  658. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=h2,h2bak");
  659. system(cmdbuf);
  660. }
  661. h2 = Rast_open_new("h2", DCELL_TYPE);
  662. }
  663. if (choice->shape[3]) {
  664. if (G_find_raster("h3", G_mapset()) != NULL) {
  665. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=h3,h3bak");
  666. system(cmdbuf);
  667. }
  668. h3 = Rast_open_new("h3", DCELL_TYPE);
  669. }
  670. if (choice->shape[4]) {
  671. if (G_find_raster("h4", G_mapset()) != NULL) {
  672. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=h4,h4bak");
  673. system(cmdbuf);
  674. }
  675. h4 = Rast_open_new("h4", DCELL_TYPE);
  676. }
  677. if (choice->shape[5]) {
  678. if (G_find_raster("h5", G_mapset()) != NULL) {
  679. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=h5,h5bak");
  680. system(cmdbuf);
  681. }
  682. h5 = Rast_open_new("h5", DCELL_TYPE);
  683. }
  684. if (choice->shape[6]) {
  685. if (G_find_raster("h6", G_mapset()) != NULL) {
  686. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=h6,h6bak");
  687. system(cmdbuf);
  688. }
  689. h6 = Rast_open_new("h6", DCELL_TYPE);
  690. }
  691. if (choice->boundary[1]) {
  692. if (G_find_raster("n1", G_mapset()) != NULL) {
  693. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=n1,n1bak");
  694. system(cmdbuf);
  695. }
  696. n1 = Rast_open_new("n1", DCELL_TYPE);
  697. }
  698. if (choice->boundary[2]) {
  699. if (G_find_raster("n2", G_mapset()) != NULL) {
  700. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=n2,n2bak");
  701. system(cmdbuf);
  702. }
  703. n2 = Rast_open_new("n2", DCELL_TYPE);
  704. }
  705. if (choice->boundary[3]) {
  706. if (G_find_raster("n3", G_mapset()) != NULL) {
  707. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=n3,n3bak");
  708. system(cmdbuf);
  709. }
  710. n3 = Rast_open_new("n3", DCELL_TYPE);
  711. }
  712. if (choice->boundary[4]) {
  713. if (G_find_raster("n4", G_mapset()) != NULL) {
  714. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=n4,n4bak");
  715. system(cmdbuf);
  716. }
  717. n4 = Rast_open_new("n4", DCELL_TYPE);
  718. }
  719. if (choice->perim[1]) {
  720. if (G_find_raster("p1", G_mapset()) != NULL) {
  721. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=p1,p1bak");
  722. system(cmdbuf);
  723. }
  724. p1 = Rast_open_new("p1", DCELL_TYPE);
  725. }
  726. if (choice->perim[2]) {
  727. if (G_find_raster("p2", G_mapset()) != NULL) {
  728. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=p2,p2bak");
  729. system(cmdbuf);
  730. }
  731. p2 = Rast_open_new("p2", DCELL_TYPE);
  732. }
  733. if (choice->perim[3]) {
  734. if (G_find_raster("p3", G_mapset()) != NULL) {
  735. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=p3,p3bak");
  736. system(cmdbuf);
  737. }
  738. p3 = Rast_open_new("p3", DCELL_TYPE);
  739. }
  740. if (choice->perim[4]) {
  741. if (G_find_raster("p4", G_mapset()) != NULL) {
  742. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=p4,p4bak");
  743. system(cmdbuf);
  744. }
  745. p4 = Rast_open_new("p4", DCELL_TYPE);
  746. }
  747. if (choice->perim[5]) {
  748. if (G_find_raster("p5", G_mapset()) != NULL) {
  749. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=p5,p5bak");
  750. system(cmdbuf);
  751. }
  752. p5 = Rast_open_new("p5", DCELL_TYPE);
  753. }
  754. if (choice->perim[6]) {
  755. if (G_find_raster("p6", G_mapset()) != NULL) {
  756. sprintf(cmdbuf, "%s %s", "g.rename -o", "rast=p6,p6bak");
  757. system(cmdbuf);
  758. }
  759. p6 = Rast_open_new("p6", DCELL_TYPE);
  760. }
  761. /* get the moving window parameters */
  762. read_mwind(&u_w, &u_l, &nc, &nr, &x0, &y0, &radius);
  763. /* check for an unacceptable
  764. moving-window size */
  765. if (nc < 1 || nr < 1) {
  766. fprintf(stderr, "\n");
  767. fprintf(stderr,
  768. " *******************************************************\n");
  769. fprintf(stderr,
  770. " The moving window size specified in file r.le.para/ \n");
  771. fprintf(stderr,
  772. " move_wind is less than 1 row or column. Check this \n");
  773. fprintf(stderr,
  774. " file or redefine the moving window using r.le.setup. \n");
  775. fprintf(stderr,
  776. " *******************************************************\n");
  777. exit(EXIT_FAILURE);
  778. }
  779. /* check for an unacceptable
  780. search area and clip it */
  781. G_get_set_window(&wind);
  782. if (wind.rows < nr + y0 || wind.cols < nc + x0) {
  783. fprintf(stderr, "\n");
  784. fprintf(stderr,
  785. " *******************************************************\n");
  786. fprintf(stderr,
  787. " Moving window search area in file r.le.para/move_wind \n");
  788. fprintf(stderr,
  789. " does not match the dimensions of the current region. \n");
  790. fprintf(stderr,
  791. " You must either rerun r.le.setup to make a new \n");
  792. fprintf(stderr,
  793. " r.le.para/move_wind file or reset the region to match \n");
  794. fprintf(stderr,
  795. " the r.le.para/move_wind file \n");
  796. fprintf(stderr,
  797. " *******************************************************\n");
  798. exit(EXIT_FAILURE);
  799. }
  800. /* set the d parameter for the
  801. performance meter */
  802. if (nr * nc > 10000)
  803. d = nr * nc / 1000;
  804. else if (nr * nc > 2500)
  805. d = nr * nc / 100;
  806. else
  807. d = 10;
  808. /* return a value > 0 to fmask if
  809. there is a MASK present */
  810. fprintf(stderr,
  811. "If a MASK is not present (see r.mask) a beep may sound and a\n");
  812. fprintf(stderr,
  813. " warning may be printed or appear in a window; ignore this warning.\n");
  814. fprintf(stderr, "If a MASK is present there will be no warning.\n");
  815. fmask = Rast_open_old("MASK", G_mapset());
  816. fprintf(stderr, "\n");
  817. /* allocate memory for the buffer that
  818. will hold the set of 42 possible
  819. measures for a row */
  820. buff = (double **)G_calloc(nc + 1, sizeof(double *));
  821. /* allocate memory for each of 42 measures */
  822. for (p = 0; p < nc + 1; p++)
  823. buff[p] = (double *)G_calloc(42, sizeof(double));
  824. /* allocate memory for a buffer to hold
  825. a row of the MASK, if there is a MASK */
  826. if (fmask > 0)
  827. row_buf = Rast_allocate_buf(CELL_TYPE);
  828. /* main loop for clipping & measuring
  829. using the moving-window */
  830. for (i = 0; i < nr; i++) {
  831. /* zero the measure buffer before
  832. filling it again */
  833. for (m = 0; m < nc + 1; m++) {
  834. for (p = 0; p < 42; p++)
  835. *(*(buff + m) + p) = 0.0;
  836. }
  837. /* if there is a MASK, then read in
  838. a row of MASK - this part skips
  839. cells with the value "0" in the
  840. MASK to speed up the moving window
  841. process */
  842. if (fmask > 0) {
  843. Rast_zero_buf(row_buf, CELL_TYPE);
  844. Rast_get_row_nomask(fmask, row_buf, y0 + i + u_l / 2,
  845. CELL_TYPE);
  846. /* for each cell whose value is "1"
  847. in MASK */
  848. for (j = 0; j < nc; j++) {
  849. /* display #cells left to do */
  850. if (i == 0 && j == 0)
  851. fprintf(stdout, "TOTAL WINDOWS = %8d\n", nr * nc);
  852. meter(nr * nc, (i * nc + (j + 1)), d);
  853. /* call the cell clip driver */
  854. if (row_buf[x0 + j + u_w / 2])
  855. cell_clip_drv(x0 + j, y0 + i, u_w, u_l, buff, j, radius);
  856. }
  857. }
  858. /* if there is no MASK, then clip
  859. and measure at every cell */
  860. else {
  861. for (j = 0; j < nc; j++) {
  862. /* display #cells left to do */
  863. if (i == 0 && j == 0)
  864. fprintf(stdout, "TOTAL WINDOWS = %8d\n", nr * nc);
  865. meter(nr * nc, (i * nc + (j + 1)), d);
  866. /* call the cell clip driver. This routine will clip
  867. the rectangle at x0 + j, y0 + i and u_w X u_l wide
  868. (or in a circle with radius), and put the results
  869. for each chosen moving windown measure in buff;
  870. note that the center of the moving window is not
  871. at x0 + j, y0 + i, but at x0 + j + u_w/2, y0 + i +
  872. u_l/2 */
  873. cell_clip_drv(x0 + j, y0 + i, u_w, u_l, buff, j, radius);
  874. }
  875. }
  876. /* copy the chosen measures into a temporary row
  877. buffer which is then fed into the chosen output
  878. maps; the map location is adjusted to the center
  879. of the moving window */
  880. tmp_buf = Rast_allocate_buf(DCELL_TYPE);
  881. nulltmp = Rast_allocate_null_buf();
  882. if (choice->att[1]) {
  883. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  884. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  885. if (i == 0) {
  886. for (b = 0; b < u_l / 2; b++)
  887. Rast_put_d_row(a1, tmp_buf);
  888. }
  889. if (i < nr) {
  890. for (m = 0; m < nc; m++) {
  891. if (*(*(buff + m) + 0) > -BIG)
  892. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 0);
  893. }
  894. Rast_put_d_row(a1, tmp_buf);
  895. }
  896. if (i == nr - 1) {
  897. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  898. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  899. for (b = 0; b < u_l / 2; b++)
  900. Rast_put_d_row(a1, tmp_buf2);
  901. G_free(tmp_buf2);
  902. }
  903. }
  904. if (choice->att[2]) {
  905. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  906. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  907. if (i == 0) {
  908. for (b = 0; b < u_l / 2; b++)
  909. Rast_put_d_row(a2, tmp_buf);
  910. }
  911. if (i < nr) {
  912. for (m = 0; m < nc; m++) {
  913. if (*(*(buff + m) + 1) > -BIG)
  914. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 1);
  915. }
  916. Rast_put_d_row(a2, tmp_buf);
  917. }
  918. if (i == nr - 1) {
  919. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  920. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  921. for (b = 0; b < u_l / 2; b++)
  922. Rast_put_d_row(a2, tmp_buf2);
  923. G_free(tmp_buf2);
  924. }
  925. }
  926. if (choice->att[3]) {
  927. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  928. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  929. if (i == 0) {
  930. for (b = 0; b < u_l / 2; b++)
  931. Rast_put_d_row(a3, tmp_buf);
  932. }
  933. if (i < nr) {
  934. for (m = 0; m < nc; m++) {
  935. if (*(*(buff + m) + 2) > -BIG)
  936. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 2);
  937. }
  938. Rast_put_d_row(a3, tmp_buf);
  939. }
  940. if (i == nr - 1) {
  941. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  942. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  943. for (b = 0; b < u_l / 2; b++)
  944. Rast_put_d_row(a3, tmp_buf2);
  945. G_free(tmp_buf2);
  946. }
  947. }
  948. if (choice->att[4]) {
  949. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  950. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  951. if (i == 0) {
  952. for (b = 0; b < u_l / 2; b++)
  953. Rast_put_d_row(a4, tmp_buf);
  954. }
  955. if (i < nr) {
  956. for (m = 0; m < nc; m++) {
  957. if (*(*(buff + m) + 3) > -BIG)
  958. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 3);
  959. }
  960. Rast_put_d_row(a4, tmp_buf);
  961. }
  962. if (i == nr - 1) {
  963. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  964. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  965. for (b = 0; b < u_l / 2; b++)
  966. Rast_put_d_row(a4, tmp_buf2);
  967. G_free(tmp_buf2);
  968. }
  969. }
  970. if (choice->att[5]) {
  971. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  972. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  973. if (i == 0) {
  974. for (b = 0; b < u_l / 2; b++)
  975. Rast_put_d_row(a5, tmp_buf);
  976. }
  977. if (i < nr) {
  978. for (m = 0; m < nc; m++) {
  979. if (*(*(buff + m) + 4) > -BIG)
  980. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 4);
  981. }
  982. Rast_put_d_row(a5, tmp_buf);
  983. }
  984. if (i == nr - 1) {
  985. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  986. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  987. for (b = 0; b < u_l / 2; b++)
  988. Rast_put_d_row(a5, tmp_buf2);
  989. G_free(tmp_buf2);
  990. }
  991. }
  992. if (choice->att[6]) {
  993. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  994. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  995. if (i == 0) {
  996. for (b = 0; b < u_l / 2; b++)
  997. Rast_put_d_row(a6, tmp_buf);
  998. }
  999. if (i < nr) {
  1000. for (m = 0; m < nc; m++) {
  1001. if (*(*(buff + m) + 5) > -BIG)
  1002. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 5);
  1003. }
  1004. Rast_put_d_row(a6, tmp_buf);
  1005. }
  1006. if (i == nr - 1) {
  1007. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1008. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1009. for (b = 0; b < u_l / 2; b++)
  1010. Rast_put_d_row(a6, tmp_buf2);
  1011. G_free(tmp_buf2);
  1012. }
  1013. }
  1014. if (choice->att[7]) {
  1015. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1016. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1017. if (i == 0) {
  1018. for (b = 0; b < u_l / 2; b++)
  1019. Rast_put_d_row(a7, tmp_buf);
  1020. }
  1021. if (i < nr) {
  1022. for (m = 0; m < nc; m++) {
  1023. if (*(*(buff + m) + 6) > -BIG)
  1024. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 6);
  1025. }
  1026. Rast_put_d_row(a7, tmp_buf);
  1027. }
  1028. if (i == nr - 1) {
  1029. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1030. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1031. for (b = 0; b < u_l / 2; b++)
  1032. Rast_put_d_row(a7, tmp_buf2);
  1033. G_free(tmp_buf2);
  1034. }
  1035. }
  1036. if (choice->size[1]) {
  1037. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1038. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1039. if (i == 0) {
  1040. for (b = 0; b < u_l / 2; b++)
  1041. Rast_put_d_row(s1, tmp_buf);
  1042. }
  1043. if (i < nr) {
  1044. for (m = 0; m < nc; m++) {
  1045. if (*(*(buff + m) + 7) > -BIG)
  1046. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 7);
  1047. }
  1048. Rast_put_d_row(s1, tmp_buf);
  1049. }
  1050. if (i == nr - 1) {
  1051. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1052. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1053. for (b = 0; b < u_l / 2; b++)
  1054. Rast_put_d_row(s1, tmp_buf2);
  1055. G_free(tmp_buf2);
  1056. }
  1057. }
  1058. if (choice->size[2]) {
  1059. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1060. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1061. if (i == 0) {
  1062. for (b = 0; b < u_l / 2; b++)
  1063. Rast_put_d_row(s2, tmp_buf);
  1064. }
  1065. if (i < nr) {
  1066. for (m = 0; m < nc; m++) {
  1067. if (*(*(buff + m) + 8) > -BIG)
  1068. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 8);
  1069. }
  1070. Rast_put_d_row(s2, tmp_buf);
  1071. }
  1072. if (i == nr - 1) {
  1073. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1074. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1075. for (b = 0; b < u_l / 2; b++)
  1076. Rast_put_d_row(s2, tmp_buf2);
  1077. G_free(tmp_buf2);
  1078. }
  1079. }
  1080. if (choice->size[3]) {
  1081. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1082. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1083. if (i == 0) {
  1084. for (b = 0; b < u_l / 2; b++)
  1085. Rast_put_d_row(s3, tmp_buf);
  1086. }
  1087. if (i < nr) {
  1088. for (m = 0; m < nc; m++) {
  1089. if (*(*(buff + m) + 9) > -BIG)
  1090. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 9);
  1091. }
  1092. Rast_put_d_row(s3, tmp_buf);
  1093. }
  1094. if (i == nr - 1) {
  1095. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1096. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1097. for (b = 0; b < u_l / 2; b++)
  1098. Rast_put_d_row(s3, tmp_buf2);
  1099. G_free(tmp_buf2);
  1100. }
  1101. }
  1102. if (choice->size[4]) {
  1103. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1104. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1105. if (i == 0) {
  1106. for (b = 0; b < u_l / 2; b++)
  1107. Rast_put_d_row(s4, tmp_buf);
  1108. }
  1109. if (i < nr) {
  1110. for (m = 0; m < nc; m++) {
  1111. if (*(*(buff + m) + 10) > -BIG)
  1112. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 10);
  1113. }
  1114. Rast_put_d_row(s4, tmp_buf);
  1115. }
  1116. if (i == nr - 1) {
  1117. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1118. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1119. for (b = 0; b < u_l / 2; b++)
  1120. Rast_put_d_row(s4, tmp_buf2);
  1121. G_free(tmp_buf2);
  1122. }
  1123. }
  1124. if (choice->size[5]) {
  1125. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1126. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1127. if (i == 0) {
  1128. for (b = 0; b < u_l / 2; b++)
  1129. Rast_put_d_row(s5, tmp_buf);
  1130. }
  1131. if (i < nr) {
  1132. for (m = 0; m < nc; m++) {
  1133. if (*(*(buff + m) + 11) > -BIG)
  1134. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 11);
  1135. }
  1136. Rast_put_d_row(s5, tmp_buf);
  1137. }
  1138. if (i == nr - 1) {
  1139. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1140. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1141. for (b = 0; b < u_l / 2; b++)
  1142. Rast_put_d_row(s5, tmp_buf2);
  1143. G_free(tmp_buf2);
  1144. }
  1145. }
  1146. if (choice->size[6]) {
  1147. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1148. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1149. if (i == 0) {
  1150. for (b = 0; b < u_l / 2; b++)
  1151. Rast_put_d_row(s6, tmp_buf);
  1152. }
  1153. if (i < nr) {
  1154. for (m = 0; m < nc; m++) {
  1155. if (*(*(buff + m) + 12) > -BIG)
  1156. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 12);
  1157. }
  1158. Rast_put_d_row(s6, tmp_buf);
  1159. }
  1160. if (i == nr - 1) {
  1161. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1162. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1163. for (b = 0; b < u_l / 2; b++)
  1164. Rast_put_d_row(s6, tmp_buf2);
  1165. G_free(tmp_buf2);
  1166. }
  1167. }
  1168. if (choice->core[1]) {
  1169. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1170. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1171. if (i == 0) {
  1172. for (b = 0; b < u_l / 2; b++)
  1173. Rast_put_d_row(c1, tmp_buf);
  1174. }
  1175. if (i < nr) {
  1176. for (m = 0; m < nc; m++) {
  1177. if (*(*(buff + m) + 13) > -BIG)
  1178. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 13);
  1179. }
  1180. Rast_put_d_row(c1, tmp_buf);
  1181. }
  1182. if (i == nr - 1) {
  1183. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1184. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1185. for (b = 0; b < u_l / 2; b++)
  1186. Rast_put_d_row(c1, tmp_buf2);
  1187. G_free(tmp_buf2);
  1188. }
  1189. }
  1190. if (choice->core[2]) {
  1191. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1192. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1193. if (i == 0) {
  1194. for (b = 0; b < u_l / 2; b++)
  1195. Rast_put_d_row(c2, tmp_buf);
  1196. }
  1197. if (i < nr) {
  1198. for (m = 0; m < nc; m++) {
  1199. if (*(*(buff + m) + 14) > -BIG)
  1200. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 14);
  1201. }
  1202. Rast_put_d_row(c2, tmp_buf);
  1203. }
  1204. if (i == nr - 1) {
  1205. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1206. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1207. for (b = 0; b < u_l / 2; b++)
  1208. Rast_put_d_row(c2, tmp_buf2);
  1209. G_free(tmp_buf2);
  1210. }
  1211. }
  1212. if (choice->core[3]) {
  1213. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1214. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1215. if (i == 0) {
  1216. for (b = 0; b < u_l / 2; b++)
  1217. Rast_put_d_row(c3, tmp_buf);
  1218. }
  1219. if (i < nr) {
  1220. for (m = 0; m < nc; m++) {
  1221. if (*(*(buff + m) + 15) > -BIG)
  1222. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 15);
  1223. }
  1224. Rast_put_d_row(c3, tmp_buf);
  1225. }
  1226. if (i == nr - 1) {
  1227. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1228. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1229. for (b = 0; b < u_l / 2; b++)
  1230. Rast_put_d_row(c3, tmp_buf2);
  1231. G_free(tmp_buf2);
  1232. }
  1233. }
  1234. if (choice->core[4]) {
  1235. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1236. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1237. if (i == 0) {
  1238. for (b = 0; b < u_l / 2; b++)
  1239. Rast_put_d_row(c4, tmp_buf);
  1240. }
  1241. if (i < nr) {
  1242. for (m = 0; m < nc; m++) {
  1243. if (*(*(buff + m) + 16) > -BIG)
  1244. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 16);
  1245. }
  1246. Rast_put_d_row(c4, tmp_buf);
  1247. }
  1248. if (i == nr - 1) {
  1249. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1250. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1251. for (b = 0; b < u_l / 2; b++)
  1252. Rast_put_d_row(c4, tmp_buf2);
  1253. G_free(tmp_buf2);
  1254. }
  1255. }
  1256. if (choice->core[5]) {
  1257. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1258. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1259. if (i == 0) {
  1260. for (b = 0; b < u_l / 2; b++)
  1261. Rast_put_d_row(c5, tmp_buf);
  1262. }
  1263. if (i < nr) {
  1264. for (m = 0; m < nc; m++) {
  1265. if (*(*(buff + m) + 17) > -BIG)
  1266. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 17);
  1267. }
  1268. Rast_put_d_row(c5, tmp_buf);
  1269. }
  1270. if (i == nr - 1) {
  1271. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1272. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1273. for (b = 0; b < u_l / 2; b++)
  1274. Rast_put_d_row(c5, tmp_buf2);
  1275. G_free(tmp_buf2);
  1276. }
  1277. }
  1278. if (choice->core[6]) {
  1279. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1280. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1281. if (i == 0) {
  1282. for (b = 0; b < u_l / 2; b++)
  1283. Rast_put_d_row(c6, tmp_buf);
  1284. }
  1285. if (i < nr) {
  1286. for (m = 0; m < nc; m++) {
  1287. if (*(*(buff + m) + 18) > -BIG)
  1288. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 18);
  1289. }
  1290. Rast_put_d_row(c6, tmp_buf);
  1291. }
  1292. if (i == nr - 1) {
  1293. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1294. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1295. for (b = 0; b < u_l / 2; b++)
  1296. Rast_put_d_row(c6, tmp_buf2);
  1297. G_free(tmp_buf2);
  1298. }
  1299. }
  1300. if (choice->core[7]) {
  1301. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1302. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1303. if (i == 0) {
  1304. for (b = 0; b < u_l / 2; b++)
  1305. Rast_put_d_row(c7, tmp_buf);
  1306. }
  1307. if (i < nr) {
  1308. for (m = 0; m < nc; m++) {
  1309. if (*(*(buff + m) + 19) > -BIG)
  1310. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 19);
  1311. }
  1312. Rast_put_d_row(c7, tmp_buf);
  1313. }
  1314. if (i == nr - 1) {
  1315. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1316. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1317. for (b = 0; b < u_l / 2; b++)
  1318. Rast_put_d_row(c7, tmp_buf2);
  1319. G_free(tmp_buf2);
  1320. }
  1321. }
  1322. if (choice->core[8]) {
  1323. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1324. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1325. if (i == 0) {
  1326. for (b = 0; b < u_l / 2; b++)
  1327. Rast_put_d_row(c8, tmp_buf);
  1328. }
  1329. if (i < nr) {
  1330. for (m = 0; m < nc; m++) {
  1331. if (*(*(buff + m) + 20) > -BIG)
  1332. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 20);
  1333. }
  1334. Rast_put_d_row(c8, tmp_buf);
  1335. }
  1336. if (i == nr - 1) {
  1337. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1338. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1339. for (b = 0; b < u_l / 2; b++)
  1340. Rast_put_d_row(c8, tmp_buf2);
  1341. G_free(tmp_buf2);
  1342. }
  1343. }
  1344. if (choice->core[9]) {
  1345. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1346. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1347. if (i == 0) {
  1348. for (b = 0; b < u_l / 2; b++)
  1349. Rast_put_d_row(c9, tmp_buf);
  1350. }
  1351. if (i < nr) {
  1352. for (m = 0; m < nc; m++) {
  1353. if (*(*(buff + m) + 21) > -BIG)
  1354. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 21);
  1355. }
  1356. Rast_put_d_row(c9, tmp_buf);
  1357. }
  1358. if (i == nr - 1) {
  1359. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1360. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1361. for (b = 0; b < u_l / 2; b++)
  1362. Rast_put_d_row(c9, tmp_buf2);
  1363. G_free(tmp_buf2);
  1364. }
  1365. }
  1366. if (choice->core[10]) {
  1367. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1368. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1369. if (i == 0) {
  1370. for (b = 0; b < u_l / 2; b++)
  1371. Rast_put_d_row(c10, tmp_buf);
  1372. }
  1373. if (i < nr) {
  1374. for (m = 0; m < nc; m++) {
  1375. if (*(*(buff + m) + 22) > -BIG)
  1376. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 22);
  1377. }
  1378. Rast_put_d_row(c10, tmp_buf);
  1379. }
  1380. if (i == nr - 1) {
  1381. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1382. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1383. for (b = 0; b < u_l / 2; b++)
  1384. Rast_put_d_row(c10, tmp_buf2);
  1385. G_free(tmp_buf2);
  1386. }
  1387. }
  1388. if (choice->shape[1]) {
  1389. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1390. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1391. if (i == 0) {
  1392. for (b = 0; b < u_l / 2; b++)
  1393. Rast_put_d_row(h1, tmp_buf);
  1394. }
  1395. if (i < nr) {
  1396. for (m = 0; m < nc; m++) {
  1397. if (*(*(buff + m) + 23) > -BIG)
  1398. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 23);
  1399. }
  1400. Rast_put_d_row(h1, tmp_buf);
  1401. }
  1402. if (i == nr - 1) {
  1403. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1404. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1405. for (b = 0; b < u_l / 2; b++)
  1406. Rast_put_d_row(h1, tmp_buf2);
  1407. G_free(tmp_buf2);
  1408. }
  1409. }
  1410. if (choice->shape[2]) {
  1411. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1412. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1413. if (i == 0) {
  1414. for (b = 0; b < u_l / 2; b++)
  1415. Rast_put_d_row(h2, tmp_buf);
  1416. }
  1417. if (i < nr) {
  1418. for (m = 0; m < nc; m++) {
  1419. if (*(*(buff + m) + 24) > -BIG)
  1420. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 24);
  1421. }
  1422. Rast_put_d_row(h2, tmp_buf);
  1423. }
  1424. if (i == nr - 1) {
  1425. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1426. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1427. for (b = 0; b < u_l / 2; b++)
  1428. Rast_put_d_row(h2, tmp_buf2);
  1429. G_free(tmp_buf2);
  1430. }
  1431. }
  1432. if (choice->shape[3]) {
  1433. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1434. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1435. if (i == 0) {
  1436. for (b = 0; b < u_l / 2; b++)
  1437. Rast_put_d_row(h3, tmp_buf);
  1438. }
  1439. if (i < nr) {
  1440. for (m = 0; m < nc; m++) {
  1441. if (*(*(buff + m) + 25) > -BIG)
  1442. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 25);
  1443. }
  1444. Rast_put_d_row(h3, tmp_buf);
  1445. }
  1446. if (i == nr - 1) {
  1447. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1448. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1449. for (b = 0; b < u_l / 2; b++)
  1450. Rast_put_d_row(h3, tmp_buf2);
  1451. G_free(tmp_buf2);
  1452. }
  1453. }
  1454. if (choice->shape[4]) {
  1455. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1456. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1457. if (i == 0) {
  1458. for (b = 0; b < u_l / 2; b++)
  1459. Rast_put_d_row(h4, tmp_buf);
  1460. }
  1461. if (i < nr) {
  1462. for (m = 0; m < nc; m++) {
  1463. if (*(*(buff + m) + 26) > -BIG)
  1464. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 26);
  1465. }
  1466. Rast_put_d_row(h4, tmp_buf);
  1467. }
  1468. if (i == nr - 1) {
  1469. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1470. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1471. for (b = 0; b < u_l / 2; b++)
  1472. Rast_put_d_row(h4, tmp_buf2);
  1473. G_free(tmp_buf2);
  1474. }
  1475. }
  1476. if (choice->shape[5]) {
  1477. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1478. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1479. if (i == 0) {
  1480. for (b = 0; b < u_l / 2; b++)
  1481. Rast_put_d_row(h5, tmp_buf);
  1482. }
  1483. if (i < nr) {
  1484. for (m = 0; m < nc; m++) {
  1485. if (*(*(buff + m) + 27) > -BIG)
  1486. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 27);
  1487. }
  1488. Rast_put_d_row(h5, tmp_buf);
  1489. }
  1490. if (i == nr - 1) {
  1491. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1492. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1493. for (b = 0; b < u_l / 2; b++)
  1494. Rast_put_d_row(h5, tmp_buf2);
  1495. G_free(tmp_buf2);
  1496. }
  1497. }
  1498. if (choice->shape[6]) {
  1499. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1500. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1501. if (i == 0) {
  1502. for (b = 0; b < u_l / 2; b++)
  1503. Rast_put_d_row(h6, tmp_buf);
  1504. }
  1505. if (i < nr) {
  1506. for (m = 0; m < nc; m++) {
  1507. if (*(*(buff + m) + 28) > -BIG)
  1508. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 28);
  1509. }
  1510. Rast_put_d_row(h6, tmp_buf);
  1511. }
  1512. if (i == nr - 1) {
  1513. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1514. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1515. for (b = 0; b < u_l / 2; b++)
  1516. Rast_put_d_row(h6, tmp_buf2);
  1517. G_free(tmp_buf2);
  1518. }
  1519. }
  1520. if (choice->boundary[1]) {
  1521. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1522. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1523. if (i == 0) {
  1524. for (b = 0; b < u_l / 2; b++)
  1525. Rast_put_d_row(n1, tmp_buf);
  1526. }
  1527. if (i < nr) {
  1528. for (m = 0; m < nc; m++) {
  1529. if (*(*(buff + m) + 29) > -BIG)
  1530. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 29);
  1531. }
  1532. Rast_put_d_row(n1, tmp_buf);
  1533. }
  1534. if (i == nr - 1) {
  1535. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1536. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1537. for (b = 0; b < u_l / 2; b++)
  1538. Rast_put_d_row(n1, tmp_buf2);
  1539. G_free(tmp_buf2);
  1540. }
  1541. }
  1542. if (choice->perim[1]) {
  1543. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1544. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1545. if (i == 0) {
  1546. for (b = 0; b < u_l / 2; b++)
  1547. Rast_put_d_row(p1, tmp_buf);
  1548. }
  1549. if (i < nr) {
  1550. for (m = 0; m < nc; m++) {
  1551. if (*(*(buff + m) + 30) > -BIG)
  1552. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 30);
  1553. }
  1554. Rast_put_d_row(p1, tmp_buf);
  1555. }
  1556. if (i == nr - 1) {
  1557. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1558. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1559. for (b = 0; b < u_l / 2; b++)
  1560. Rast_put_d_row(p1, tmp_buf2);
  1561. G_free(tmp_buf2);
  1562. }
  1563. }
  1564. if (choice->perim[2]) {
  1565. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1566. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1567. if (i == 0) {
  1568. for (b = 0; b < u_l / 2; b++)
  1569. Rast_put_d_row(p2, tmp_buf);
  1570. }
  1571. if (i < nr) {
  1572. for (m = 0; m < nc; m++) {
  1573. if (*(*(buff + m) + 31) > -BIG)
  1574. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 31);
  1575. }
  1576. Rast_put_d_row(p2, tmp_buf);
  1577. }
  1578. if (i == nr - 1) {
  1579. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1580. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1581. for (b = 0; b < u_l / 2; b++)
  1582. Rast_put_d_row(p2, tmp_buf2);
  1583. G_free(tmp_buf2);
  1584. }
  1585. }
  1586. if (choice->perim[3]) {
  1587. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1588. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1589. if (i == 0) {
  1590. for (b = 0; b < u_l / 2; b++)
  1591. Rast_put_d_row(p3, tmp_buf);
  1592. }
  1593. if (i < nr) {
  1594. for (m = 0; m < nc; m++) {
  1595. if (*(*(buff + m) + 32) > -BIG)
  1596. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 32);
  1597. }
  1598. Rast_put_d_row(p3, tmp_buf);
  1599. }
  1600. if (i == nr - 1) {
  1601. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1602. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1603. for (b = 0; b < u_l / 2; b++)
  1604. Rast_put_d_row(p3, tmp_buf2);
  1605. G_free(tmp_buf2);
  1606. }
  1607. }
  1608. if (choice->perim[4]) {
  1609. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1610. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1611. if (i == 0) {
  1612. for (b = 0; b < u_l / 2; b++)
  1613. Rast_put_d_row(p4, tmp_buf);
  1614. }
  1615. if (i < nr) {
  1616. for (m = 0; m < nc; m++) {
  1617. if (*(*(buff + m) + 33) > -BIG)
  1618. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 33);
  1619. }
  1620. Rast_put_d_row(p4, tmp_buf);
  1621. }
  1622. if (i == nr - 1) {
  1623. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1624. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1625. for (b = 0; b < u_l / 2; b++)
  1626. Rast_put_d_row(p4, tmp_buf2);
  1627. G_free(tmp_buf2);
  1628. }
  1629. }
  1630. if (choice->perim[5]) {
  1631. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1632. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1633. if (i == 0) {
  1634. for (b = 0; b < u_l / 2; b++)
  1635. Rast_put_d_row(p5, tmp_buf);
  1636. }
  1637. if (i < nr) {
  1638. for (m = 0; m < nc; m++) {
  1639. if (*(*(buff + m) + 34) > -BIG)
  1640. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 34);
  1641. }
  1642. Rast_put_d_row(p5, tmp_buf);
  1643. }
  1644. if (i == nr - 1) {
  1645. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1646. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1647. for (b = 0; b < u_l / 2; b++)
  1648. Rast_put_d_row(p5, tmp_buf2);
  1649. G_free(tmp_buf2);
  1650. }
  1651. }
  1652. if (choice->perim[6]) {
  1653. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1654. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1655. if (i == 0) {
  1656. for (b = 0; b < u_l / 2; b++)
  1657. Rast_put_d_row(p6, tmp_buf);
  1658. }
  1659. if (i < nr) {
  1660. for (m = 0; m < nc; m++) {
  1661. if (*(*(buff + m) + 35) > -BIG)
  1662. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 35);
  1663. }
  1664. Rast_put_d_row(p6, tmp_buf);
  1665. }
  1666. if (i == nr - 1) {
  1667. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1668. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1669. for (b = 0; b < u_l / 2; b++)
  1670. Rast_put_d_row(p6, tmp_buf2);
  1671. G_free(tmp_buf2);
  1672. }
  1673. }
  1674. if (choice->att[8]) {
  1675. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1676. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1677. if (i == 0) {
  1678. for (b = 0; b < u_l / 2; b++)
  1679. Rast_put_d_row(a8, tmp_buf);
  1680. }
  1681. if (i < nr) {
  1682. for (m = 0; m < nc; m++) {
  1683. if (*(*(buff + m) + 36) > -BIG)
  1684. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 36);
  1685. }
  1686. Rast_put_d_row(a8, tmp_buf);
  1687. }
  1688. if (i == nr - 1) {
  1689. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1690. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1691. for (b = 0; b < u_l / 2; b++)
  1692. Rast_put_d_row(a8, tmp_buf2);
  1693. G_free(tmp_buf2);
  1694. }
  1695. }
  1696. if (choice->size[7]) {
  1697. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1698. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1699. if (i == 0) {
  1700. for (b = 0; b < u_l / 2; b++)
  1701. Rast_put_d_row(s7, tmp_buf);
  1702. }
  1703. if (i < nr) {
  1704. for (m = 0; m < nc; m++) {
  1705. if (*(*(buff + m) + 37) > -BIG)
  1706. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 37);
  1707. }
  1708. Rast_put_d_row(s7, tmp_buf);
  1709. }
  1710. if (i == nr - 1) {
  1711. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1712. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1713. for (b = 0; b < u_l / 2; b++)
  1714. Rast_put_d_row(s7, tmp_buf2);
  1715. G_free(tmp_buf2);
  1716. }
  1717. }
  1718. if (choice->size[8]) {
  1719. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1720. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1721. if (i == 0) {
  1722. for (b = 0; b < u_l / 2; b++)
  1723. Rast_put_d_row(s8, tmp_buf);
  1724. }
  1725. if (i < nr) {
  1726. for (m = 0; m < nc; m++) {
  1727. if (*(*(buff + m) + 38) > -BIG)
  1728. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 38);
  1729. }
  1730. Rast_put_d_row(s8, tmp_buf);
  1731. }
  1732. if (i == nr - 1) {
  1733. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1734. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1735. for (b = 0; b < u_l / 2; b++)
  1736. Rast_put_d_row(s8, tmp_buf2);
  1737. G_free(tmp_buf2);
  1738. }
  1739. }
  1740. if (choice->boundary[2]) {
  1741. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1742. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1743. if (i == 0) {
  1744. for (b = 0; b < u_l / 2; b++)
  1745. Rast_put_d_row(n2, tmp_buf);
  1746. }
  1747. if (i < nr) {
  1748. for (m = 0; m < nc; m++) {
  1749. if (*(*(buff + m) + 39) > -BIG)
  1750. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 39);
  1751. }
  1752. Rast_put_d_row(n2, tmp_buf);
  1753. }
  1754. if (i == nr - 1) {
  1755. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1756. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1757. for (b = 0; b < u_l / 2; b++)
  1758. Rast_put_d_row(n2, tmp_buf2);
  1759. G_free(tmp_buf2);
  1760. }
  1761. }
  1762. if (choice->boundary[3]) {
  1763. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1764. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1765. if (i == 0) {
  1766. for (b = 0; b < u_l / 2; b++)
  1767. Rast_put_d_row(n3, tmp_buf);
  1768. }
  1769. if (i < nr) {
  1770. for (m = 0; m < nc; m++) {
  1771. if (*(*(buff + m) + 40) > -BIG)
  1772. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 40);
  1773. }
  1774. Rast_put_d_row(n3, tmp_buf);
  1775. }
  1776. if (i == nr - 1) {
  1777. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1778. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1779. for (b = 0; b < u_l / 2; b++)
  1780. Rast_put_d_row(n3, tmp_buf2);
  1781. G_free(tmp_buf2);
  1782. }
  1783. }
  1784. if (choice->boundary[4]) {
  1785. Rast_zero_buf(tmp_buf, DCELL_TYPE);
  1786. Rast_set_null_value(tmp_buf, x0 + nc + u_w, DCELL_TYPE);
  1787. if (i == 0) {
  1788. for (b = 0; b < u_l / 2; b++)
  1789. Rast_put_d_row(n4, tmp_buf);
  1790. }
  1791. if (i < nr) {
  1792. for (m = 0; m < nc; m++) {
  1793. if (*(*(buff + m) + 41) > -BIG)
  1794. *(tmp_buf + (x0 + m + u_w / 2)) = *(*(buff + m) + 41);
  1795. }
  1796. Rast_put_d_row(n4, tmp_buf);
  1797. }
  1798. if (i == nr - 1) {
  1799. tmp_buf2 = Rast_allocate_buf(DCELL_TYPE);
  1800. Rast_set_null_value(tmp_buf2, x0 + nc + u_w, DCELL_TYPE);
  1801. for (b = 0; b < u_l / 2; b++)
  1802. Rast_put_d_row(n4, tmp_buf2);
  1803. G_free(tmp_buf2);
  1804. }
  1805. }
  1806. G_free(tmp_buf);
  1807. }
  1808. time(&finished_time);
  1809. fprintf(stdout, "\nACTUAL COMPLETION = %s",
  1810. asctime(localtime(&finished_time)));
  1811. fflush(stdout);
  1812. /* free the memory allocated for the
  1813. mask and other buffer */
  1814. if (fmask > 0)
  1815. G_free(row_buf);
  1816. for (p = 0; p < nc + 1; p++)
  1817. G_free(buff[p]);
  1818. G_free(buff);
  1819. /* close the raster maps, set the
  1820. color table for the new raster
  1821. map and compress the map */
  1822. if (choice->att[1]) {
  1823. Rast_close(a1);
  1824. set_colors("a1");
  1825. sprintf(cmdbuf, "%s %s", "r.compress", "a1");
  1826. system(cmdbuf);
  1827. }
  1828. if (choice->att[2]) {
  1829. Rast_close(a2);
  1830. set_colors("a2");
  1831. sprintf(cmdbuf, "%s %s", "r.compress", "a2");
  1832. system(cmdbuf);
  1833. }
  1834. if (choice->att[3]) {
  1835. Rast_close(a3);
  1836. set_colors("a3");
  1837. sprintf(cmdbuf, "%s %s", "r.compress", "a3");
  1838. system(cmdbuf);
  1839. }
  1840. if (choice->att[4]) {
  1841. Rast_close(a4);
  1842. set_colors("a4");
  1843. sprintf(cmdbuf, "%s %s", "r.compress", "a4");
  1844. system(cmdbuf);
  1845. }
  1846. if (choice->att[5]) {
  1847. Rast_close(a5);
  1848. set_colors("a5");
  1849. sprintf(cmdbuf, "%s %s", "r.compress", "a5");
  1850. system(cmdbuf);
  1851. }
  1852. if (choice->att[6]) {
  1853. Rast_close(a6);
  1854. set_colors("a6");
  1855. sprintf(cmdbuf, "%s %s", "r.compress", "a6");
  1856. system(cmdbuf);
  1857. }
  1858. if (choice->att[7]) {
  1859. Rast_close(a7);
  1860. set_colors("a7");
  1861. sprintf(cmdbuf, "%s %s", "r.compress", "a7");
  1862. system(cmdbuf);
  1863. }
  1864. if (choice->att[8]) {
  1865. Rast_close(a8);
  1866. set_colors("a8");
  1867. sprintf(cmdbuf, "%s %s", "r.compress", "a8");
  1868. system(cmdbuf);
  1869. }
  1870. if (choice->size[1]) {
  1871. Rast_close(s1);
  1872. set_colors("s1");
  1873. sprintf(cmdbuf, "%s %s", "r.compress", "s1");
  1874. system(cmdbuf);
  1875. }
  1876. if (choice->size[2]) {
  1877. Rast_close(s2);
  1878. set_colors("s2");
  1879. sprintf(cmdbuf, "%s %s", "r.compress", "s2");
  1880. system(cmdbuf);
  1881. }
  1882. if (choice->size[3]) {
  1883. Rast_close(s3);
  1884. set_colors("s3");
  1885. sprintf(cmdbuf, "%s %s", "r.compress", "s3");
  1886. system(cmdbuf);
  1887. }
  1888. if (choice->size[4]) {
  1889. Rast_close(s4);
  1890. set_colors("s4");
  1891. sprintf(cmdbuf, "%s %s", "r.compress", "s4");
  1892. system(cmdbuf);
  1893. }
  1894. if (choice->size[5]) {
  1895. Rast_close(s5);
  1896. set_colors("s5");
  1897. sprintf(cmdbuf, "%s %s", "r.compress", "s5");
  1898. system(cmdbuf);
  1899. }
  1900. if (choice->size[6]) {
  1901. Rast_close(s6);
  1902. set_colors("s6");
  1903. sprintf(cmdbuf, "%s %s", "r.compress", "s6");
  1904. system(cmdbuf);
  1905. }
  1906. if (choice->size[7]) {
  1907. Rast_close(s7);
  1908. set_colors("s7");
  1909. sprintf(cmdbuf, "%s %s", "r.compress", "s7");
  1910. system(cmdbuf);
  1911. }
  1912. if (choice->size[8]) {
  1913. Rast_close(s8);
  1914. set_colors("s8");
  1915. sprintf(cmdbuf, "%s %s", "r.compress", "s8");
  1916. system(cmdbuf);
  1917. }
  1918. if (choice->core[1]) {
  1919. Rast_close(c1);
  1920. set_colors("c1");
  1921. sprintf(cmdbuf, "%s %s", "r.compress", "c1");
  1922. system(cmdbuf);
  1923. }
  1924. if (choice->core[2]) {
  1925. Rast_close(c2);
  1926. set_colors("c2");
  1927. sprintf(cmdbuf, "%s %s", "r.compress", "c2");
  1928. system(cmdbuf);
  1929. }
  1930. if (choice->core[3]) {
  1931. Rast_close(c3);
  1932. set_colors("c3");
  1933. sprintf(cmdbuf, "%s %s", "r.compress", "c3");
  1934. system(cmdbuf);
  1935. }
  1936. if (choice->core[4]) {
  1937. Rast_close(c4);
  1938. set_colors("c4");
  1939. sprintf(cmdbuf, "%s %s", "r.compress", "c4");
  1940. system(cmdbuf);
  1941. }
  1942. if (choice->core[5]) {
  1943. Rast_close(c5);
  1944. set_colors("c5");
  1945. sprintf(cmdbuf, "%s %s", "r.compress", "c5");
  1946. system(cmdbuf);
  1947. }
  1948. if (choice->core[6]) {
  1949. Rast_close(c6);
  1950. set_colors("c6");
  1951. sprintf(cmdbuf, "%s %s", "r.compress", "c6");
  1952. system(cmdbuf);
  1953. }
  1954. if (choice->core[7]) {
  1955. Rast_close(c7);
  1956. set_colors("c7");
  1957. sprintf(cmdbuf, "%s %s", "r.compress", "c7");
  1958. system(cmdbuf);
  1959. }
  1960. if (choice->core[8]) {
  1961. Rast_close(c8);
  1962. set_colors("c8");
  1963. sprintf(cmdbuf, "%s %s", "r.compress", "c8");
  1964. system(cmdbuf);
  1965. }
  1966. if (choice->core[9]) {
  1967. Rast_close(c9);
  1968. set_colors("c9");
  1969. sprintf(cmdbuf, "%s %s", "r.compress", "c9");
  1970. system(cmdbuf);
  1971. }
  1972. if (choice->core[10]) {
  1973. Rast_close(c10);
  1974. set_colors("c10");
  1975. sprintf(cmdbuf, "%s %s", "r.compress", "c10");
  1976. system(cmdbuf);
  1977. }
  1978. if (choice->shape[1]) {
  1979. Rast_close(h1);
  1980. set_colors("h1");
  1981. sprintf(cmdbuf, "%s %s", "r.compress", "h1");
  1982. system(cmdbuf);
  1983. }
  1984. if (choice->shape[2]) {
  1985. Rast_close(h2);
  1986. set_colors("h2");
  1987. sprintf(cmdbuf, "%s %s", "r.compress", "h2");
  1988. system(cmdbuf);
  1989. }
  1990. if (choice->shape[3]) {
  1991. Rast_close(h3);
  1992. set_colors("h3");
  1993. sprintf(cmdbuf, "%s %s", "r.compress", "h3");
  1994. system(cmdbuf);
  1995. }
  1996. if (choice->shape[4]) {
  1997. Rast_close(h4);
  1998. set_colors("h4");
  1999. sprintf(cmdbuf, "%s %s", "r.compress", "h4");
  2000. system(cmdbuf);
  2001. }
  2002. if (choice->shape[5]) {
  2003. Rast_close(h5);
  2004. set_colors("h5");
  2005. sprintf(cmdbuf, "%s %s", "r.compress", "h5");
  2006. system(cmdbuf);
  2007. }
  2008. if (choice->shape[6]) {
  2009. Rast_close(h6);
  2010. set_colors("h6");
  2011. sprintf(cmdbuf, "%s %s", "r.compress", "h6");
  2012. system(cmdbuf);
  2013. }
  2014. if (choice->boundary[1]) {
  2015. Rast_close(n1);
  2016. set_colors("n1");
  2017. sprintf(cmdbuf, "%s %s", "r.compress", "n1");
  2018. system(cmdbuf);
  2019. }
  2020. if (choice->boundary[2]) {
  2021. Rast_close(n2);
  2022. set_colors("n2");
  2023. sprintf(cmdbuf, "%s %s", "r.compress", "n2");
  2024. system(cmdbuf);
  2025. }
  2026. if (choice->boundary[3]) {
  2027. Rast_close(n3);
  2028. set_colors("n3");
  2029. sprintf(cmdbuf, "%s %s", "r.compress", "n3");
  2030. system(cmdbuf);
  2031. }
  2032. if (choice->boundary[4]) {
  2033. Rast_close(n4);
  2034. set_colors("n4");
  2035. sprintf(cmdbuf, "%s %s", "r.compress", "n4");
  2036. system(cmdbuf);
  2037. }
  2038. if (choice->perim[1]) {
  2039. Rast_close(p1);
  2040. set_colors("p1");
  2041. sprintf(cmdbuf, "%s %s", "r.compress", "p1");
  2042. system(cmdbuf);
  2043. }
  2044. if (choice->perim[2]) {
  2045. Rast_close(p2);
  2046. set_colors("p2");
  2047. sprintf(cmdbuf, "%s %s", "r.compress", "p2");
  2048. system(cmdbuf);
  2049. }
  2050. if (choice->perim[3]) {
  2051. Rast_close(p3);
  2052. set_colors("p3");
  2053. sprintf(cmdbuf, "%s %s", "r.compress", "p3");
  2054. system(cmdbuf);
  2055. }
  2056. if (choice->perim[4]) {
  2057. Rast_close(p4);
  2058. set_colors("p4");
  2059. sprintf(cmdbuf, "%s %s", "r.compress", "p4");
  2060. system(cmdbuf);
  2061. }
  2062. if (choice->perim[5]) {
  2063. Rast_close(p5);
  2064. set_colors("p5");
  2065. sprintf(cmdbuf, "%s %s", "r.compress", "p5");
  2066. system(cmdbuf);
  2067. }
  2068. if (choice->perim[6]) {
  2069. Rast_close(p6);
  2070. set_colors("p6");
  2071. sprintf(cmdbuf, "%s %s", "r.compress", "p6");
  2072. system(cmdbuf);
  2073. }
  2074. Rast_close(fmask);
  2075. return;
  2076. }
  2077. /* SET COLOR TABLE FOR MOVING WINDOW
  2078. OUTPUT MAPS TO G-Y-R */
  2079. void set_colors(char *name)
  2080. {
  2081. struct Colors colors;
  2082. struct FPRange fprange;
  2083. Rast_read_fp_range(name, G_mapset(), &fprange);
  2084. Rast_make_gyr_fp_colors(&colors, fprange.min, fprange.max);
  2085. Rast_write_colors(name, G_mapset(), &colors);
  2086. return;
  2087. }
  2088. /* READ IN THE MOVING WINDOW PARAMETERS */
  2089. void read_mwind(int *uw, int *ul, int *nc, int *nr, int *x0, int *y0,
  2090. float *radius)
  2091. {
  2092. FILE *fp;
  2093. int ww, wl;
  2094. char *buf;
  2095. fp = fopen1("r.le.para/move_wind", "r");
  2096. buf = G_malloc(513);
  2097. fgets(buf, 512, fp);
  2098. sscanf(buf, "%d%d", uw, ul);
  2099. fgets(buf, 512, fp);
  2100. sscanf(buf, "%f", radius);
  2101. fgets(buf, 512, fp);
  2102. sscanf(buf, "%d%d", &ww, &wl);
  2103. fgets(buf, 512, fp);
  2104. sscanf(buf, "%d%d", x0, y0);
  2105. *nc = ww - *uw + 1;
  2106. *nr = wl - *ul + 1;
  2107. G_free(buf);
  2108. fclose(fp);
  2109. return;
  2110. }
  2111. /* PERFORMANCE METER - DISPLAYS
  2112. THE PROGRESS OF THE MOVING WINDOW
  2113. AS A COUNT AND ESTIMATED COMPLETION
  2114. TIME WHILE THE PROGRAM RUNS */
  2115. void meter(int n, int i, int div)
  2116. {
  2117. long current_time, time_left, elapsed, complete;
  2118. static long start;
  2119. float window_time;
  2120. static int k = 0;
  2121. char done[30];
  2122. int d;
  2123. if (i <= 1) {
  2124. time(&start);
  2125. }
  2126. if (i < 10)
  2127. d = 1;
  2128. else
  2129. d = div;
  2130. if (k > 2000) {
  2131. if (G_fseek(stdout, 0L, 0))
  2132. G_fatal_error("Can't reset the \"stdout\", exit.\n");
  2133. k = 0;
  2134. }
  2135. if ((n - i) % d == 0) {
  2136. time(&current_time);
  2137. elapsed = current_time - start;
  2138. window_time = ((float)elapsed) / (i + 1);
  2139. time_left = (long)((n - i) * window_time);
  2140. complete = current_time + time_left;
  2141. strncpy(done, asctime(localtime(&complete)), 24);
  2142. done[24] = '\0';
  2143. fprintf(stdout, "WINDOWS LEFT = %8d EST. COMPLETION = %s\r",
  2144. (n - i), done);
  2145. fflush(stdout);
  2146. k++;
  2147. }
  2148. return;
  2149. }
  2150. /* READ IN THE PARAMETERS FOR
  2151. GROUPS & CLASSES */
  2152. void get_para()
  2153. {
  2154. register int i, j, k;
  2155. float *tmp;
  2156. int counter;
  2157. /*
  2158. Variables:
  2159. GLOBAL:
  2160. para1 = set to 1 if by gp measures are chosen
  2161. para2 = set to 1 if size classes are chosen
  2162. para3 = set to 1 if perimeter-area shape index classes are chosen
  2163. para4 = set to 1 if corrected perimeter-area shape index classes are chosen
  2164. para5 = set to 1 if related circumscribing circle shape index classes are
  2165. chosen
  2166. */
  2167. /* set the parameter flags to 0 */
  2168. para1 = para2 = para3 = para4 = para5 = 0;
  2169. /* read the reclass table for attribute gps */
  2170. if (choice->att[5] || choice->att[6] || choice->size[3] || choice->size[4]
  2171. || choice->size[6] || choice->core[5] || choice->core[6]
  2172. || choice->core[7] || choice->core[8] || choice->core[10]
  2173. || choice->shape[3] || choice->shape[4] || choice->shape[6]
  2174. || choice->perim[4] || choice->perim[5] || choice->perim[6]) {
  2175. para1 = 1;
  2176. recl_tb = (float **)G_calloc(25, sizeof(float *));
  2177. tmp = (float *)G_calloc(50, sizeof(float));
  2178. if (choice->wrum == 'm')
  2179. k = 1;
  2180. else
  2181. k = 25;
  2182. recl_count = (int *)G_calloc(k, sizeof(int));
  2183. for (i = 0; i < k; i++) {
  2184. read_para("recl_tb", i + 1, tmp, &counter);
  2185. if (counter < 2)
  2186. break;
  2187. recl_tb[i] = (float *)G_malloc(50 * sizeof(float));
  2188. for (j = 0; j < counter; j++) {
  2189. recl_tb[i][j] = tmp[j];
  2190. }
  2191. recl_count[i] = counter;
  2192. }
  2193. if (choice->wrum == 'm')
  2194. ntype = 1;
  2195. else
  2196. ntype = i;
  2197. G_free(tmp);
  2198. if (!ntype) {
  2199. fprintf(stderr, "\n");
  2200. fprintf(stderr,
  2201. " ********************************************************\n");
  2202. fprintf(stderr,
  2203. " The attribute group file (r.le.para/recl_tb) seems to \n");
  2204. fprintf(stderr,
  2205. " be incorrect as no attribute groups were found. Check \n");
  2206. fprintf(stderr,
  2207. " this file or make it again using r.le.setup. \n");
  2208. fprintf(stderr,
  2209. " ********************************************************\n");
  2210. exit(EXIT_FAILURE);
  2211. }
  2212. }
  2213. /* read the size classes */
  2214. if (choice->size[5] || choice->size[6] || choice->core[9] ||
  2215. choice->core[10]) {
  2216. para2 = 1;
  2217. size_cl = (float *)G_calloc(20, sizeof(float));
  2218. read_line("size", 1, -999, NULL, size_cl, &size_cl_no);
  2219. }
  2220. /* read shape index classes */
  2221. if (choice->Mx[1] && (choice->shape[5] || choice->shape[6])) {
  2222. para3 = 1;
  2223. shape_PA = (float *)G_calloc(20, sizeof(float));
  2224. read_line("shape_PA", 1, -999, NULL, shape_PA, &shape_cl_no);
  2225. }
  2226. else if (choice->Mx[2] && (choice->shape[5] || choice->shape[6])) {
  2227. para4 = 1;
  2228. shape_CPA = (float *)G_calloc(20, sizeof(float));
  2229. read_line("shape_CPA", 1, -999, NULL, shape_CPA, &shape_cl_no);
  2230. }
  2231. else if (choice->Mx[3] && (choice->shape[5] || choice->shape[6])) {
  2232. para5 = 1;
  2233. shape_RCC = (float *)G_calloc(20, sizeof(float));
  2234. read_line("shape_RCC", 1, -999, NULL, shape_RCC, &shape_cl_no);
  2235. }
  2236. return;
  2237. }
  2238. /* RELEASE GLOBAL MEMORY */
  2239. void free_para()
  2240. {
  2241. register int i;
  2242. if (para1) {
  2243. for (i = 0; i < ntype; i++)
  2244. G_free(recl_tb[i]);
  2245. G_free(recl_tb);
  2246. G_free(recl_count);
  2247. }
  2248. if (para2)
  2249. G_free(size_cl);
  2250. if (para3)
  2251. G_free(shape_PA);
  2252. if (para4)
  2253. G_free(shape_CPA);
  2254. if (para5)
  2255. G_free(shape_RCC);
  2256. return;
  2257. }
  2258. /* COUNT HOW MANY ATTRIBUTES ARE IN ONE
  2259. LINE OF THE RECL_TB FILE, WHICH DEFINES
  2260. ATTRIBUTE GROUPS */
  2261. void read_para(char *name, int line, float *value, int *count)
  2262. {
  2263. FILE *fp;
  2264. int i = 0, cnt = 1;
  2265. char *buf, path[GPATH_MAX];
  2266. /* VARIABLES
  2267. Incoming
  2268. name = always "recl_tb"
  2269. line = the line of the recl_tb file to be read
  2270. value = an array of 50 values, each of which is a
  2271. count of the number of attributes on the line;
  2272. this is the array returned to the calling program
  2273. count = ??
  2274. Internal
  2275. fp = pointer to recl_tb file
  2276. i = counter for moving through buf array
  2277. cnt = count of number of attributes on this line
  2278. buf = buffer to hold one line of recl_tb
  2279. path = the relative path to the recl_tb file
  2280. */
  2281. /* open the recl_tb, allocate enough memory,
  2282. then read one line of the recl_tb into
  2283. the buffer; then close the recl_tb */
  2284. sprintf(path, "r.le.para/%s", name);
  2285. fp = fopen2(path, "r");
  2286. buf = G_malloc(256);
  2287. while (fgets(buf, 256, fp) && i < line - 1)
  2288. i++;
  2289. fclose(fp);
  2290. /* go through the line of the recl_tb character
  2291. by character */
  2292. for (i = 0;; i++) {
  2293. /* if "e" of "end" is found or an "=" sign is found, then
  2294. quit and set value to 1 */
  2295. if (*(buf + i) == 'e' || *(buf + i) == '=')
  2296. break;
  2297. /* if "t" of "thru" is found, set the corresponding element
  2298. of the value array to -999, add one to cnt, then
  2299. jump to the next character after "thru" */
  2300. else if (*(buf + i) == 't') {
  2301. *(value + cnt) = -999;
  2302. cnt++;
  2303. i += 4;
  2304. }
  2305. /* if a number is found, then scan it into the
  2306. corresponding element in the value array */
  2307. else if (isdigit(*(buf + i))) {
  2308. sscanf(buf + i, "%f", value + cnt);
  2309. while (isdigit(*(buf + i)))
  2310. i++;
  2311. cnt++;
  2312. }
  2313. }
  2314. *count = (float)cnt;
  2315. G_free(buf);
  2316. return;
  2317. }
  2318. /* READ IN ONE CLASS LINE */
  2319. void read_line(char *name, int line, int n, int *value, int *fvalue,
  2320. int *number_classes)
  2321. {
  2322. FILE *fp;
  2323. int i;
  2324. char path[GPATH_MAX], *buf;
  2325. sprintf(path, "r.le.para/%s", name);
  2326. fp = fopen2(path, "r");
  2327. buf = G_malloc(256);
  2328. for (i = 0; i < line - 1; i++)
  2329. fgets(buf, 256, fp);
  2330. G_free(buf);
  2331. if (n > 0)
  2332. for (i = 0; i < n; i++)
  2333. fscanf(fp, "%d", value + i);
  2334. else {
  2335. for (i = 1;; i++) {
  2336. fscanf(fp, "%f", (float *)fvalue + i);
  2337. if (fvalue[i] <= -999) {
  2338. *number_classes = i - 1;
  2339. break;
  2340. }
  2341. }
  2342. if (3 > (fvalue[0] = (float)i)) {
  2343. buf = G_malloc(40);
  2344. sprintf(buf,
  2345. "\n No data in file\"%s\"; use r.le.setup to make file\n",
  2346. path);
  2347. G_fatal_error(buf);
  2348. G_free(buf);
  2349. }
  2350. }
  2351. fclose(fp);
  2352. return;
  2353. }
  2354. /* READ IN SAMPLING UNIT PARAMETERS
  2355. AND RUN R.LE.PATCH */
  2356. void unit_driver()
  2357. {
  2358. int top, left, u_w, u_l, nscl, nu, fd;
  2359. char *buf, unitname[10], istr[3];
  2360. register int i, j, k, m;
  2361. struct Cell_head wind;
  2362. FILE *fp;
  2363. CELL **units, *unit_buf;
  2364. float radius = 0.0;
  2365. G_get_set_window(&wind);
  2366. fp = fopen1("r.le.para/units", "r");
  2367. buf = G_malloc(513);
  2368. /* get the number of scales */
  2369. fgets(buf, 512, fp);
  2370. sscanf(buf, "%d", &nscl);
  2371. /* dynamically allocate storage for the buffer
  2372. that will hold the map of the sampling units */
  2373. if (choice->units) {
  2374. units = (CELL **) G_calloc(wind.rows + 3, sizeof(CELL *));
  2375. for (i = 0; i < wind.rows + 3; i++)
  2376. units[i] = (CELL *) G_calloc(wind.cols + 3, sizeof(CELL));
  2377. }
  2378. /* for each scale */
  2379. for (i = 0; i < nscl; i++) {
  2380. n_scale = i + 1;
  2381. fgets(buf, 512, fp);
  2382. sscanf(buf, "%d", &nu);
  2383. /* get the width and length */
  2384. fgets(buf, 512, fp);
  2385. sscanf(buf, "%d%d", &u_w, &u_l);
  2386. /* get the radius to see if sampling
  2387. units are circles */
  2388. fgets(buf, 512, fp);
  2389. sscanf(buf, "%f", &radius);
  2390. /* if units map was chosen, zero it,
  2391. then copy the number of the map
  2392. to the end of the word "units" */
  2393. if (choice->units) {
  2394. for (k = 0; k < wind.rows + 3; k++) {
  2395. for (m = 0; m < wind.cols + 3; m++)
  2396. *(*(units + k) + m) = 0;
  2397. }
  2398. if (i == 0)
  2399. strcpy(istr, "1");
  2400. else if (i == 1)
  2401. strcpy(istr, "2");
  2402. else if (i == 2)
  2403. strcpy(istr, "3");
  2404. else if (i == 3)
  2405. strcpy(istr, "4");
  2406. else if (i == 4)
  2407. strcpy(istr, "5");
  2408. else if (i == 5)
  2409. strcpy(istr, "6");
  2410. else if (i == 6)
  2411. strcpy(istr, "7");
  2412. else if (i == 7)
  2413. strcpy(istr, "8");
  2414. else if (i == 8)
  2415. strcpy(istr, "9");
  2416. else if (i == 9)
  2417. strcpy(istr, "10");
  2418. else if (i == 10)
  2419. strcpy(istr, "11");
  2420. else if (i == 11)
  2421. strcpy(istr, "12");
  2422. else if (i == 12)
  2423. strcpy(istr, "13");
  2424. else if (i == 13)
  2425. strcpy(istr, "14");
  2426. else if (i == 14)
  2427. strcpy(istr, "15");
  2428. else if (i > 14) {
  2429. fprintf(stderr, "\n");
  2430. fprintf(stderr,
  2431. " ***************************************************\n");
  2432. fprintf(stderr,
  2433. " You cannot choose more than 15 scales \n");
  2434. fprintf(stderr,
  2435. " ***************************************************\n");
  2436. exit(EXIT_FAILURE);
  2437. }
  2438. }
  2439. /* for each unit */
  2440. for (j = 0; j < nu; j++) {
  2441. n_unit = j + 1;
  2442. fgets(buf, 512, fp);
  2443. sscanf(buf, "%d%d", &left, &top);
  2444. /* call cell_clip driver */
  2445. run_clip(wind.cols, wind.rows, u_w, u_l, left, top, units, j,
  2446. radius);
  2447. }
  2448. /* if a map of the sampling units
  2449. was requested */
  2450. if (choice->units) {
  2451. strcpy(unitname, "units_");
  2452. strcat(unitname, istr);
  2453. fd = Rast_open_new(unitname, CELL_TYPE);
  2454. unit_buf = Rast_allocate_buf(CELL_TYPE);
  2455. for (k = 1; k < wind.rows + 1; k++) {
  2456. Rast_zero_buf(unit_buf, CELL_TYPE);
  2457. Rast_set_null_value(unit_buf, wind.cols + 1, CELL_TYPE);
  2458. for (m = 1; m < wind.cols + 1; m++) {
  2459. if (*(*(units + k) + m))
  2460. *(unit_buf + m - 1) = *(*(units + k) + m);
  2461. }
  2462. Rast_put_row(fd, unit_buf, CELL_TYPE);
  2463. }
  2464. Rast_close(fd);
  2465. G_free(unit_buf);
  2466. }
  2467. }
  2468. if (choice->units) {
  2469. for (m = 0; m < wind.rows + 3; m++)
  2470. G_free(units[m]);
  2471. G_free(units);
  2472. }
  2473. G_free(buf);
  2474. fclose(fp);
  2475. return;
  2476. }
  2477. /* CHECK FOR OUT-OF MAP UNIT, THEN
  2478. CALL CELL CLIP DRIVER */
  2479. void run_clip(int ncols, int nrows, int u_w, int u_l, int left, int top,
  2480. CELL ** units, int id, float radius)
  2481. {
  2482. int i, j;
  2483. double center_row, center_col;
  2484. double dist;
  2485. G_sleep_on_error(0);
  2486. /* check unit */
  2487. if (ncols < left + u_w || nrows < top + u_l) {
  2488. fprintf(stderr, "\n");
  2489. fprintf(stderr,
  2490. " ******************************************************\n");
  2491. fprintf(stderr,
  2492. " Sampling units do not fit within the current region. \n");
  2493. fprintf(stderr,
  2494. " Either correct the region or redo the sampling unit \n");
  2495. fprintf(stderr,
  2496. " selection using r.le.setup. This error message came \n");
  2497. fprintf(stderr,
  2498. " from an analysis of the r.le.para/units file and the \n");
  2499. fprintf(stderr,
  2500. " current region setting. \n");
  2501. fprintf(stderr,
  2502. " ******************************************************\n");
  2503. exit(EXIT_FAILURE);
  2504. }
  2505. if (choice->units) {
  2506. if (radius) {
  2507. center_row = ((double)(top + 1) + ((double)u_l - 1) / 2);
  2508. center_col = ((double)(left + 1) + ((double)u_w - 1) / 2);
  2509. for (i = top + 1; i < top + 1 + u_l; i++) {
  2510. for (j = left + 1; j < left + 1 + u_w; j++) {
  2511. dist =
  2512. sqrt(((double)i - center_row) * ((double)i -
  2513. center_row) +
  2514. ((double)j - center_col) * ((double)j -
  2515. center_col));
  2516. if (dist < radius)
  2517. *(*(units + i) + j) = id + 1;
  2518. }
  2519. }
  2520. }
  2521. else {
  2522. for (i = top + 1; i < top + 1 + u_l; i++) {
  2523. for (j = left + 1; j < left + 1 + u_w; j++)
  2524. *(*(units + i) + j) = id + 1;
  2525. }
  2526. }
  2527. }
  2528. cell_clip_drv(left, top, u_w, u_l, NULL, 0, radius);
  2529. return;
  2530. }
  2531. /* CLIP THE REGION, THEN
  2532. RUN R.LE.PATCH */
  2533. void whole_reg_driver()
  2534. {
  2535. register int i, j;
  2536. int regcnt, found, fr, nrows, ncols;
  2537. REGLIST *ptrfirst, *ptrthis, *ptrnew;
  2538. CELL *row_buf;
  2539. nrows = Rast_window_rows();
  2540. ncols = Rast_window_cols();
  2541. n_scale = 1;
  2542. if (choice->wrum != 'r') {
  2543. cell_clip_drv(0, 0, ncols, nrows, NULL, 0, 0.0);
  2544. }
  2545. else {
  2546. regcnt = 0;
  2547. fr = Rast_open_old(choice->reg, G_mapset());
  2548. row_buf = Rast_allocate_buf(CELL_TYPE);
  2549. for (i = 0; i < nrows; i++) {
  2550. Rast_zero_buf(row_buf, CELL_TYPE);
  2551. Rast_get_row(fr, row_buf, i, CELL_TYPE);
  2552. for (j = 0; j < ncols; j++) {
  2553. if (*(row_buf + j) > 0) {
  2554. if (regcnt == 0)
  2555. ptrfirst = (REGLIST *) NULL;
  2556. ptrthis = ptrfirst;
  2557. found = 0;
  2558. while (ptrthis) {
  2559. if (*(row_buf + j) == ptrthis->att) {
  2560. if (j < ptrthis->w)
  2561. ptrthis->w = j;
  2562. if (j > ptrthis->e)
  2563. ptrthis->e = j;
  2564. if (i < ptrthis->n)
  2565. ptrthis->n = i;
  2566. if (i > ptrthis->s)
  2567. ptrthis->s = i;
  2568. found = 1;
  2569. }
  2570. ptrthis = ptrthis->next;
  2571. }
  2572. if (!found) {
  2573. ptrnew = (REGLIST *) G_calloc(1, sizeof(REGLIST));
  2574. if (ptrfirst == (REGLIST *) NULL)
  2575. ptrfirst = ptrthis = ptrnew;
  2576. else {
  2577. ptrthis = ptrfirst;
  2578. while (ptrthis->next != (REGLIST *) NULL)
  2579. ptrthis = ptrthis->next;
  2580. ptrthis->next = ptrnew;
  2581. ptrthis = ptrnew;
  2582. }
  2583. ptrthis->att = *(row_buf + j);
  2584. ptrthis->n = i;
  2585. ptrthis->s = i;
  2586. ptrthis->e = j;
  2587. ptrthis->w = j;
  2588. regcnt++;
  2589. }
  2590. }
  2591. }
  2592. }
  2593. n_unit = 0;
  2594. ptrthis = ptrfirst;
  2595. while (ptrthis) {
  2596. n_unit = ptrthis->att;
  2597. cell_clip_drv(ptrthis->w, ptrthis->n, ptrthis->e - ptrthis->w + 1,
  2598. ptrthis->s - ptrthis->n + 1, NULL, ptrthis->att,
  2599. 0.0);
  2600. ptrthis = ptrthis->next;
  2601. }
  2602. Rast_close(fr);
  2603. G_free(row_buf);
  2604. G_free(ptrnew);
  2605. }
  2606. return;
  2607. }