-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrowth.c
976 lines (871 loc) · 27 KB
/
growth.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
/*******************************************************************************
MODULE: growth.c
CONTAINING SYSTEM: SLEUTH-3r (based on SLEUTH Model 3.0 Beta)
(Slope, Land-cover, Exclusion, Urbanization,
Transportation, and Hillshade)
also known as UGM 3.0 Beta (for Urban Growth Model)
VERSION: SLEUTH-3r [Includes Version D features]
REVISION DATE: August 31, 2006a
[Annotations added August 19, 2009]
PURPOSE:
This module provides functions which control growth over a series
of years. driver.c calls this module for each Monte Carlo
iteration, and this module in turn calls spread.c for each
year.
NOTES:
MODIFICATIONS:
TO DO:
**************************************************************************/
#define GROWTH_MODULE
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "coeff_obj.h"
#include "igrid_obj.h"
#include "pgrid_obj.h"
#include "landclass_obj.h"
#include "globals.h"
#include "input.h"
#include "output.h"
#include "utilities.h"
#include "growth.h"
#include "spread.h"
#include "random.h"
#include "deltatron.h"
#include "ugm_macros.h"
#include "proc_obj.h"
#include "scenario_obj.h"
#include "memory_obj.h"
#include "transition_obj.h"
#include "color_obj.h"
#include "timer_obj.h"
#include "gdif_obj.h"
#include "timer_obj.h"
#include "stats_obj.h"
/*****************************************************************************\
*******************************************************************************
** **
** SCCS ID **
** **
*******************************************************************************
\*****************************************************************************/
char growth_c_sccs_id[] = "@(#)growth.c 1.629 12/4/00";
/*****************************************************************************\
*******************************************************************************
** **
** STATIC FUNCTION PROTOTYPES **
** **
*******************************************************************************
\*****************************************************************************/
static
void grw_non_landuse (GRID_P z_ptr);
static
void grw_landuse_init (GRID_P deltatron_ptr,
GRID_P land1_ptr);
static
void grw_landuse (
GRID_P land1_ptr,
int num_growth_pix);
static void grw_completion_status (FILE * fp);
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: cumulate_roads
** PURPOSE: routine for handling road accumulation and output
** AUTHOR: Irenee Dubourg
** PROGRAMMER: Irenee Dubourg, ESTP Institut de Recherche en Constructibilite
** CREATION DATE: 05/24/2022
** DESCRIPTION:
**
**
*/
static void
cumulate_roads(GRID_P road_state_ptr)
{
char func[] = "cumulate_roads";
char command[2 * MAX_FILENAME_LEN + 20];
GRID_P workspace;
int num_monte_carlo;
char road_name[] = "_roads_";
char temp_gif_filename[MAX_FILENAME_LEN];
char output_gif_filename[MAX_FILENAME_LEN];
GRID_P cumulate_road_state;
int i;
FUNC_INIT;
workspace = mem_GetWGridPtr(__FILE__, func, __LINE__);
num_monte_carlo = scen_GetMonteCarloIterations();
assert(workspace != NULL);
assert(road_state_ptr != NULL);
cumulate_road_state = workspace;
if (proc_GetProcessingType() != CALIBRATING)
{
if (proc_GetCurrentMonteCarlo() == 0)
{
/*
*
* ZERO OUT THE ROAD ACCUMULATION GRID
*
*/
util_init_grid(cumulate_road_state, 0);
}
else
{
/*
*
* READ IN THE ROAD ACCUMULATION GRID
*
*/
sprintf(temp_gif_filename, "%scumulate_roads.year_%u",
scen_GetOutputDir(), proc_GetCurrentYear());
inp_slurp(temp_gif_filename, /* IN */
cumulate_road_state, /* OUT */
memGetBytesPerGridRound()); /* IN */
}
/*
*
* ACCUMULATE ROADS OVER MONTE CARLOS
*
*/
sprintf(output_gif_filename, "%s%s%s%u_%u_%u.gif",
scen_GetOutputDir(),
igrid_GetLocation(),
road_name,
proc_GetCurrentYear(),
proc_GetCurrentMonteCarlo());
util_output_gif_grid(road_state_ptr, output_gif_filename);
for (i = 0; i < mem_GetTotalPixels(); i++)
{
if (road_state_ptr[i] > 0)
{
cumulate_road_state[i]++;
}
}
if (proc_GetCurrentMonteCarlo() == num_monte_carlo - 1)
{
/*
*
* NORMALIZE ACCULUMLATED GRIDS
*
*/
for (i = 0; i < mem_GetTotalPixels(); i++)
{
cumulate_road_state[i] =
255 * cumulate_road_state[i] / num_monte_carlo;
}
sprintf(output_gif_filename, "%s%s%s%u.gif",
scen_GetOutputDir(),
igrid_GetLocation(),
road_name,
proc_GetCurrentYear());
util_output_gif_grid(cumulate_road_state, output_gif_filename);
if (proc_GetCurrentMonteCarlo() != 0)
{
sprintf(command, "rm %s", temp_gif_filename);
system(command);
}
}
else
{
/*
*
* DUMP ACCULUMLATED GRIDS TO DISK
*
*/
sprintf(temp_gif_filename, "%scumulate_roads.year_%u",
scen_GetOutputDir(), proc_GetCurrentYear());
out_dump(temp_gif_filename,
cumulate_road_state,
memGetBytesPerGridRound());
}
}
workspace = mem_GetWGridFree(__FILE__, func, __LINE__, workspace);
FUNC_END;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: grw_grow
** PURPOSE: loop over simulated years
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
void
grw_grow(GRID_P z_ptr, GRID_P land1_ptr, GRID_P road_state_ptr)
{
char func[] = "grw_grow";
char gif_filename[MAX_FILENAME_LEN];
char date_str[4];
GRID_P deltatron_ptr;
GRID_P seed_ptr;
GRID_P seed_road_ptr;
GRID_P delta;
int total_pixels;
float average_slope;
int num_growth_pix = 0;
int sng;
int sdg;
int sdc;
int og;
int rt;
int pop;
int debugcount;
/** D. Donato 8/17/2006 Added to deal with cumulative growth **/
int i, nrows, ncols;
short *zgrwth_row;
short *zgrwth_col;
int zgrwth_count;
/** D. Donato 8/17/2006 Added to deal with cumulative growth **/
/* D.D. 8/18/2006 */
int row, col, colindex;
short *ExcPixRow;
short *ExcPixCol;
short *UrbPixRow;
short *UrbPixCol;
/* D.D. 8/18/2006 */
FUNC_INIT;
timer_Start (GRW_GROWTH);
total_pixels = mem_GetTotalPixels ();
nrows = igrid_GetNumRows ();
ncols = igrid_GetNumCols ();
deltatron_ptr = pgrid_GetDeltatronPtr ();
assert (total_pixels > 0);
assert (deltatron_ptr != NULL);
/** D.D. 8/29/2006 Added to speed up clearing of delta grid. **/
delta = mem_GetWGridPtr (__FILE__, func, __LINE__);
util_init_grid(delta, (PIXEL)0);
/** D.D. 8/29/2006 Added to speed up clearing of delta grid. **/
if (proc_GetProcessingType () == PREDICTING)
{
proc_SetCurrentYear (scen_GetPredictionStartDate ());
}
else
{
proc_SetCurrentYear (igrid_GetUrbanYear (0));
}
seed_road_ptr = igrid_GetRoadGridPtrByYear(__FILE__, func, __LINE__, proc_GetCurrentYear());
pgrid_SetRoadStatePixelCount(igrid_GetIGridRoadPixelCount(proc_GetCurrentYear()));
util_copy_grid(seed_road_ptr, road_state_ptr);
/** D. Donato 8/17/2006 Added to deal with cumulative growth **/
zgrwth_row = (short *) mem_GetGRZrowptr();
zgrwth_col = (short *) mem_GetGRZcolptr();
zgrwth_count = mem_GetGRZcount();
if (zgrwth_count == 0) {util_init_grid (z_ptr, 0);}
else
{
for (i=0; i<zgrwth_count; i++)
{
z_ptr[OFFSET(zgrwth_row[i], zgrwth_col[i])] = 0;
}
mem_SetGRZcount(0); zgrwth_count = 0;
}
/** D. Donato 8/17/2006 Added to deal with cumulative growth **/
if (scen_GetDoingLanduseFlag ())
{
grw_landuse_init (deltatron_ptr,
land1_ptr);
}
/** D.D. 8/18/2006 Use the UrbPix array to condition z_ptr more efficiently. ***
seed_ptr = igrid_GetUrbanGridPtr (__FILE__, func, __LINE__, 0);
util_condition_gif (total_pixels,
seed_ptr,
GT,
0,
z_ptr,
PHASE0G);
seed_ptr = igrid_GridRelease (__FILE__, func, __LINE__, seed_ptr);
*** D.D. 8/18/2006 **/
seed_ptr = igrid_GetUrbanGridPtr (__FILE__, func, __LINE__, 0);
UrbPixRow = igrid_GetUrbPixRowPtr();
UrbPixCol = igrid_GetUrbPixColPtr();
colindex = 0;
zgrwth_count = 0;
for (row=0; row<nrows; row++)
{
if (UrbPixRow[row] > 0)
{
for (col=0; col<UrbPixRow[row]; col++)
{
if (seed_ptr[OFFSET(row, UrbPixCol[colindex])] > 0)
{
z_ptr[OFFSET(row, UrbPixCol[colindex])] = PHASE0G;
zgrwth_row[zgrwth_count] = row;
zgrwth_col[zgrwth_count] = UrbPixCol[colindex];
zgrwth_count++;
}
colindex++;
}
}
}
mem_SetGRZcount(zgrwth_count);
mem_SetGRZpointer(z_ptr);
seed_ptr = igrid_GridRelease (__FILE__, func, __LINE__, seed_ptr);
/** D.D. 8/18/2006 Use the UrbPix array to condition z_ptr more efficiently. **/
if (scen_GetEchoFlag ())
{
printf ("\n%s %u ******************************************\n",
__FILE__, __LINE__);
if (proc_GetProcessingType () == CALIBRATING)
{
printf ("%s %u Run = %u of %u (%8.1f percent complete)\n",
__FILE__, __LINE__,
proc_GetCurrentRun (), proc_GetTotalRuns (),
(100.0 * proc_GetCurrentRun ()) / proc_GetTotalRuns ());
}
printf ("%s %u Monte Carlo = %u of %u\n", __FILE__, __LINE__,
proc_GetCurrentMonteCarlo () + 1, scen_GetMonteCarloIterations ());
fprintf (stdout, "%s %u proc_GetCurrentYear=%u\n",
__FILE__, __LINE__, proc_GetCurrentYear ());
fprintf (stdout, "%s %u proc_GetStopYear=%u\n",
__FILE__, __LINE__, proc_GetStopYear ());
}
if (scen_GetLogFlag ())
{
if (scen_GetLogProcessingStatusFlag () > 0)
{
scen_Append2Log ();
grw_completion_status (scen_GetLogFP ());
scen_CloseLog ();
}
}
while (proc_GetCurrentYear () < proc_GetStopYear ())
{
/*
*
* INCREMENT CURRENT YEAR
*
*/
proc_IncrementCurrentYear ();
if (scen_GetEchoFlag ())
{
fprintf (stdout, " %u", proc_GetCurrentYear ());
fflush (stdout);
if (((proc_GetCurrentYear () + 1) % 10) == 0)
{
fprintf (stdout, "\n");
fflush (stdout);
}
if (proc_GetCurrentYear () == proc_GetStopYear ())
{
fprintf (stdout, "\n");
fflush (stdout);
}
}
if (scen_GetLogFlag ())
{
if (scen_GetLogProcessingStatusFlag () > 1)
{
scen_Append2Log ();
fprintf (scen_GetLogFP (), " %u", proc_GetCurrentYear ());
if (((proc_GetCurrentYear () + 1) % 10) == 0)
{
fprintf (scen_GetLogFP (), "\n");
fflush (scen_GetLogFP ());
}
if (proc_GetCurrentYear () == proc_GetStopYear ())
{
fprintf (scen_GetLogFP (), "\n");
fflush (scen_GetLogFP ());
}
scen_CloseLog ();
}
}
/*
*
* APPLY THE CELLULAR AUTOMATON RULES FOR THIS YEAR
*
*/
sng = 0;
sdg = 0;
sdc = 0;
og = 0;
rt = 0;
pop = 0;
timer_Start (SPREAD_TOTAL_TIME);
spr_spread (&average_slope,
&num_growth_pix,
&sng,
&sdc,
&og,
&rt,
&pop,
delta, /** D.D. 8/29/2006 **/
z_ptr,
road_state_ptr);
timer_Stop (SPREAD_TOTAL_TIME);
stats_SetSNG (sng);
stats_SetSDG (sdg);
stats_SetSDG (sdc);
stats_SetOG (og);
stats_SetRT (rt);
stats_SetPOP (pop);
if (scen_GetViewGrowthTypesFlag ())
{
sprintf (gif_filename, "%sz_growth_types_%u_%u_%u.gif",
scen_GetOutputDir (), proc_GetCurrentRun (),
proc_GetCurrentMonteCarlo (), proc_GetCurrentYear ());
sprintf (date_str, "%u", proc_GetCurrentYear ());
gdif_WriteGIF (z_ptr,
color_GetColortable (GROWTH_COLORTABLE),
gif_filename,
date_str,
255);
}
if (scen_GetDoingLanduseFlag ())
{
grw_landuse (land1_ptr, num_growth_pix);
}
else
{
grw_non_landuse (z_ptr);
}
cumulate_roads(road_state_ptr);
/** D.D. 8/18/2006 Use the UrbPix array to condition z_ptr more efficiently. ***
seed_ptr = igrid_GetUrbanGridPtr (__FILE__, func, __LINE__, 0);
util_condition_gif (total_pixels,
seed_ptr,
GT,
0,
z_ptr,
PHASE0G);
seed_ptr = igrid_GridRelease (__FILE__, func, __LINE__, seed_ptr);
*** D.D. 8/18/2006 **/
/*** D.D. 8/21/2006 Disabled because it seems unnecessary. ***
**********************************************************************************
seed_ptr = igrid_GetUrbanGridPtr (__FILE__, func, __LINE__, 0);
UrbPixRow = igrid_GetUrbPixRowPtr();
UrbPixCol = igrid_GetUrbPixColPtr();
colindex=0;
debugcount=0;
for (row=0; row<nrows; row++)
{
if (UrbPixRow[row] > 0)
{
for (col=0; col<UrbPixRow[row]; col++)
{
if (seed_ptr[OFFSET(row, UrbPixCol[colindex])] > 0)
{
if (z_ptr[OFFSET(row, UrbPixCol[colindex])] != PHASE0G) debugcount++;
z_ptr[OFFSET(row, UrbPixCol[colindex])] = PHASE0G;
}
colindex++;
}
}
}
printf("||===>> Count of z_ptr pixels no longer set to PHASE0G : %8d\n", debugcount);
seed_ptr = igrid_GridRelease (__FILE__, func, __LINE__, seed_ptr);
**********************************************************************************
*** D.D. 8/21/2006 **/
/** D.D. 8/18/2006 Use the UrbPix array to condition z_ptr more efficiently. **/
/*
*
* DO STATISTICS
*
*/
stats_Update (num_growth_pix);
/*
*
* DO SELF MODIFICATION
*
*/
coeff_SelfModication (stats_GetGrowthRate (), stats_GetPercentUrban ());
coeff_WriteCurrentCoeff ();
}
delta = mem_GetWGridFree (__FILE__, func, __LINE__, delta);
timer_Stop (GRW_GROWTH);
FUNC_END;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: grw_landuse_init
** PURPOSE: initial variables for doing landuse
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
static
void
grw_landuse_init (GRID_P deltatron_ptr, /* OUT */
GRID_P land1_ptr) /* OUT */
{
char func[] = "grw_landuse_init";
int i;
int total_pixels;
GRID_P landuse0_ptr;
GRID_P landuse1_ptr;
FUNC_INIT;
total_pixels = mem_GetTotalPixels ();
assert (deltatron_ptr != NULL);
assert (land1_ptr != NULL);
assert (total_pixels > 0);
/*
*
* INITIALIZE DELTATRON GRID TO ZERO
*
*/
for (i = 0; i < total_pixels; i++)
{
deltatron_ptr[i] = 0;
}
/*
*
* IF PREDICTING USE LANDUSE 1 AS THE STARTING LANDUSE
* ELSE USE LANDUSE 0 AS THE STARTING LANDUSE
*
*/
if (proc_GetProcessingType () == PREDICTING)
{
landuse1_ptr = igrid_GetLanduseGridPtr (__FILE__, func, __LINE__, 1);
assert (landuse1_ptr != NULL);
for (i = 0; i < total_pixels; i++)
{
land1_ptr[i] = landuse1_ptr[i];
}
landuse1_ptr = igrid_GridRelease (__FILE__, func, __LINE__, landuse1_ptr);
}
else
{
landuse0_ptr = igrid_GetLanduseGridPtr (__FILE__, func, __LINE__, 0);
assert (landuse0_ptr != NULL);
for (i = 0; i < total_pixels; i++)
{
land1_ptr[i] = landuse0_ptr[i];
}
landuse0_ptr = igrid_GridRelease (__FILE__, func, __LINE__, landuse0_ptr);
}
FUNC_END;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: grw_landuse
** PURPOSE: routine for handling landuse type of processing
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
static
void
grw_landuse (
GRID_P land1_ptr, /* OUT */
int num_growth_pix /* IN */
)
{
char func[] = "grw_landuse";
char gif_filename[MAX_FILENAME_LEN];
char date_str[4];
int ticktock;
int landuse0_year;
int landuse1_year;
int urban_code;
int *new_indices;
Classes *landuse_classes;
Classes *class_indices;
GRID_P background_ptr;
GRID_P grw_landuse_ws1;
GRID_P deltatron_ptr;
GRID_P z_ptr;
GRID_P deltatron_workspace1;
GRID_P slp_ptr;
GRID_P land2_ptr;
double *class_slope;
double *ftransition;
FUNC_INIT;
ticktock = proc_GetCurrentYear ();
landuse0_year = igrid_GetLanduseYear (0);
landuse1_year = igrid_GetLanduseYear (1);
urban_code = landclass_GetUrbanCode ();
new_indices = landclass_GetNewIndicesPtr ();
landuse_classes = landclass_GetClassesPtr ();
class_indices = landclass_GetReducedClassesPtr ();
background_ptr = igrid_GetBackgroundGridPtr (__FILE__, func, __LINE__);
grw_landuse_ws1 = mem_GetWGridPtr (__FILE__, func, __LINE__);
deltatron_workspace1 = mem_GetWGridPtr (__FILE__, func, __LINE__);
slp_ptr = igrid_GetSlopeGridPtr (__FILE__, func, __LINE__);
deltatron_ptr = pgrid_GetDeltatronPtr ();
z_ptr = pgrid_GetZPtr ();
land2_ptr = pgrid_GetLand2Ptr ();
class_slope = trans_GetClassSlope ();
ftransition = trans_GetFTransition ();
assert (ticktock >= 0);
assert (z_ptr != NULL);
assert (urban_code > 0);
assert (new_indices != NULL);
assert (landuse_classes != NULL);
assert (class_indices != NULL);
assert (grw_landuse_ws1 != NULL);
assert (deltatron_workspace1 != NULL);
assert (deltatron_ptr != NULL);
assert (land1_ptr != NULL);
assert (land2_ptr != NULL);
assert (slp_ptr != NULL);
assert (class_slope != NULL);
assert (ftransition != NULL);
/* influence land use */
if (ticktock >= landuse0_year)
{
/*
*
* PLACE THE NEW URBAN SIMULATION INTO THE LAND USE IMAGE
*
*/
util_condition_gif (mem_GetTotalPixels (),
z_ptr,
GT,
0,
land1_ptr,
urban_code);
delta_deltatron (new_indices, /* IN */
landuse_classes, /* IN */
class_indices, /* IN */
deltatron_workspace1, /* MOD */
deltatron_ptr, /* IN/OUT */
land1_ptr, /* IN */
land2_ptr, /* OUT */
slp_ptr, /* IN */
num_growth_pix, /* IN */
class_slope, /* IN */
ftransition); /* IN */
/*
*
* SWITCH THE OLD AND THE NEW
*
*/
util_copy_grid (land2_ptr,
land1_ptr);
}
if ((proc_GetProcessingType () == PREDICTING) ||
(proc_GetProcessingType () == TESTING) &&
(proc_GetLastMonteCarloFlag ()))
{
/*
*
* WRITE LAND1 GIF TO FILE
*
*/
sprintf (gif_filename, "%s%s_land_n_urban.%u.gif",
scen_GetOutputDir (), igrid_GetLocation (), proc_GetCurrentYear ());
sprintf (date_str, "%u", proc_GetCurrentYear ());
gdif_WriteGIF (land1_ptr,
color_GetColortable (LANDUSE_COLORTABLE),
gif_filename,
date_str,
255);
}
/*
*
* COMPUTE FINAL MATCH STATISTIC FOR LANDUSE
*
*/
if (proc_GetCurrentYear () == landuse1_year)
{
util_condition_gif (mem_GetTotalPixels (),
z_ptr,
GT,
0,
land1_ptr,
urban_code);
}
background_ptr =
igrid_GridRelease (__FILE__, func, __LINE__, background_ptr);
grw_landuse_ws1 =
mem_GetWGridFree (__FILE__, func, __LINE__, grw_landuse_ws1);
deltatron_workspace1 =
mem_GetWGridFree (__FILE__, func, __LINE__, deltatron_workspace1);
slp_ptr = igrid_GridRelease (__FILE__, func, __LINE__, slp_ptr);
FUNC_END;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: grw_non_landuse
** PURPOSE: routine for handling non landuse processing
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
static void
grw_non_landuse (GRID_P z_ptr)
{
char func[] = "grw_non_landuse";
char command[2 * MAX_FILENAME_LEN + 20];
GRID_P workspace1;
GRID_P workspace2;
int num_monte_carlo;
char name[] = "_urban_";
char gif_filename[MAX_FILENAME_LEN];
GRID_P cumulate_monte_carlo;
int i;
FUNC_INIT;
workspace1 = mem_GetWGridPtr (__FILE__, func, __LINE__);
workspace2 = mem_GetWGridPtr (__FILE__, func, __LINE__);
num_monte_carlo = scen_GetMonteCarloIterations ();
assert (workspace1 != NULL);
assert (workspace2 != NULL);
assert (z_ptr != NULL);
cumulate_monte_carlo = workspace1;
if (proc_GetProcessingType () != CALIBRATING)
{
if (proc_GetCurrentMonteCarlo () == 0)
{
/*
*
* ZERO OUT THE ACCUMULATION GRID
*
*/
util_init_grid (cumulate_monte_carlo, 0);
}
else
{
/*
*
* READ IN THE ACCUMULATION GRID
*
*/
sprintf (gif_filename, "%scumulate_monte_carlo.year_%u",
scen_GetOutputDir (), proc_GetCurrentYear ());
inp_slurp (gif_filename, /* IN */
cumulate_monte_carlo, /* OUT */
memGetBytesPerGridRound ()); /* IN */
}
/*
*
* ACCUMULATE Z OVER MONTE CARLOS
*
*/
for (i = 0; i < mem_GetTotalPixels (); i++)
{
if (z_ptr[i] > 0)
{
cumulate_monte_carlo[i]++;
}
}
if (proc_GetCurrentMonteCarlo () == num_monte_carlo - 1)
{
if (proc_GetProcessingType () == TESTING)
{
util_condition_gif (mem_GetTotalPixels (), /* IN */
z_ptr, /* IN */
GT, /* IN */
0, /* IN */
cumulate_monte_carlo, /* IN/OUT */
100); /* IN */
}
else
{
/*
*
* NORMALIZE ACCULUMLATED GRID
*
*/
for (i = 0; i < mem_GetTotalPixels (); i++)
{
cumulate_monte_carlo[i] =
100 * cumulate_monte_carlo[i] / num_monte_carlo;
}
}
util_WriteZProbGrid (cumulate_monte_carlo, name);
if (proc_GetCurrentMonteCarlo () != 0)
{
sprintf (command, "rm %s", gif_filename);
system (command);
}
}
else
{
/*
*
* DUMP ACCULUMLATED GRID TO DISK
*
*/
sprintf (gif_filename, "%scumulate_monte_carlo.year_%u",
scen_GetOutputDir (), proc_GetCurrentYear ());
out_dump (gif_filename,
cumulate_monte_carlo,
memGetBytesPerGridRound ());
}
}
workspace1 = mem_GetWGridFree (__FILE__, func, __LINE__, workspace1);
workspace2 = mem_GetWGridFree (__FILE__, func, __LINE__, workspace2);
FUNC_END;
}
/******************************************************************************
*******************************************************************************
** FUNCTION NAME: grw_completion_status
** PURPOSE: write completion status on FILE* fp
** AUTHOR: Keith Clarke
** PROGRAMMER: Tommy E. Cathey of NESC (919)541-1500
** CREATION DATE: 11/11/1999
** DESCRIPTION:
**
**
*/
static void
grw_completion_status (FILE * fp)
{
int total_mc;
int total_mc_executed;
int wd1;
int wd2;
char buf1[25];
char buf2[25];
char buf3[25];
char buf4[25];
float complete;
float elapsed_sec;
float est_execution_time;
float est_remaining_sec;
char elapsed_sec_f[15];
char est_remaining_sec_f[15];
total_mc =
(scen_GetMonteCarloIterations () * proc_GetTotalRuns ()) / glb_npes;
total_mc_executed = scen_GetMonteCarloIterations () *
proc_GetNumRunsExecThisCPU () + proc_GetCurrentMonteCarlo ();
complete = (float) total_mc_executed / (float) total_mc;
complete = MIN (complete, 1.0);
elapsed_sec = timer_Read (TOTAL_TIME) / 1000;
est_remaining_sec = 0.0;
sprintf (buf1, "%15u", proc_GetTotalRuns ());
sprintf (buf2, "%15u", proc_GetCurrentRun ());
util_trim (buf1);
wd1 = strlen (buf1);
sprintf (buf3, "%15u", scen_GetMonteCarloIterations ());
sprintf (buf4, "%15u", proc_GetCurrentMonteCarlo ());
util_trim (buf3);
wd2 = strlen (buf3);
#if 1
fprintf (fp, "%s %u Run= %s of %s MC=%s of %s ",
__FILE__, __LINE__,
&buf2[15 - wd1], buf1,
&buf4[15 - wd2], buf3);
#else
fprintf (fp, "%s %u Run= %u of %u MC=%u of %u ",
__FILE__, __LINE__,
proc_GetCurrentRun (), proc_GetTotalRuns (),
proc_GetCurrentMonteCarlo (), scen_GetMonteCarloIterations ());
#endif
if (complete > 0.0)
{
est_execution_time = elapsed_sec / complete;
est_remaining_sec = (est_execution_time - elapsed_sec);
timer_Format (elapsed_sec_f, (unsigned int) elapsed_sec);
timer_Format (est_remaining_sec_f, (unsigned int) est_remaining_sec);
fprintf (fp,
"%7.3f%% complete; Elapsed=%s ; ETC=%s\n",
100.0 * complete, elapsed_sec_f,
est_remaining_sec_f);
}
else
{
fprintf (fp, "\n");
}
}