src/realizer_pro.f90
author Forrest Hoffman <forrest@climatemodeling.org>
Wed, 26 Sep 2007 17:50:53 -0400
changeset 0 5fda18b64dcb
permissions -rw-r--r--
Initial commit of the Fortran-90 version of the Fractal Realizer.
forrest@0
     1
program realizer
forrest@0
     2
!       program MidPtFM2d
forrest@0
     3
!
forrest@0
     4
!   fractal generator adapted from algorithm MidPointFM2D in the 
forrest@0
     5
!     Science of Fractal Images, M.F. Barnsley, R. L. Devaney
forrest@0
     6
!     B. B. Mandelbrot, H.-O. Peitgen, D. Saupe, and R. F. Voss
forrest@0
     7
!     Springer-Verlag
forrest@0
     8
!
forrest@0
     9
!  this program modified to combine multiple fractal topographies
forrest@0
    10
!     then normalize them relative to each other,
forrest@0
    11
!     and perform multiple horizontal slices
forrest@0
    12
!     to obtain requested p values for each habitat
forrest@0
    13
!     in a new synthetic realization of the landscape
forrest@0
    14
!
forrest@0
    15
!     William W. Hargrove
forrest@0
    16
!     Paul M Schwartz
forrest@0
    17
!     5/7/96
forrest@0
    18
!     (423) 241-2748
forrest@0
    19
!
forrest@0
    20
      use realizer_mod
forrest@0
    21
      implicit none
forrest@0
    22
forrest@0
    23
      integer(i4) :: P(maxN*maxN,0:maxsp+3)
forrest@0
    24
      real(r4)    :: X(0:maxN,0:maxN)
forrest@0
    25
      real(r4)    :: prob(0:maxsp)
forrest@0
    26
      real(r4)    :: ssum
forrest@0
    27
      real(r4)    :: ztemp
forrest@0
    28
      integer(i4) :: igreatest
forrest@0
    29
      integer(i4) :: hslice(0:maxsp)
forrest@0
    30
      real(r4)    :: elev(maxN*maxN)
forrest@0
    31
      real(r4)    :: H(maxN,maxsp)
forrest@0
    32
      integer(i4) :: II(0:maxN,0:maxN)
forrest@0
    33
      integer(i4) :: kcnt(0:maxsp)
forrest@0
    34
      integer(i4) :: ties(maxsp)
forrest@0
    35
      integer(i4) :: ifcnt
forrest@0
    36
      integer(i4) :: iend
forrest@0
    37
      integer(i4) :: istart
forrest@0
    38
      integer(i4) :: icnt
forrest@0
    39
      real(r4)    :: sigma
forrest@0
    40
      real(r4)    :: xmin, xmax, xmean, xss
forrest@0
    41
      real(r4)    :: range1
forrest@0
    42
      real(r4)    :: zmean
forrest@0
    43
      real(r4)    :: pfract
forrest@0
    44
      real(r4)    :: xlow
forrest@0
    45
      integer(i4) :: maxlevel
forrest@0
    46
      integer(i4) :: numpainted
forrest@0
    47
      integer(i4) :: numtied
forrest@0
    48
      integer(i4) :: numblank
forrest@0
    49
      integer(i4) :: ihighest
forrest@0
    50
      integer(i4) :: ibiggest
forrest@0
    51
      integer(i4) :: idummy
forrest@0
    52
      integer(i4) :: idtype
forrest@0
    53
      integer(i4) :: idumm
forrest@0
    54
      integer(i4) :: isum, jsum
forrest@0
    55
      integer(i4) :: ipixid
forrest@0
    56
      integer(i4) :: kount
forrest@0
    57
      integer(i4) :: i, j, k, l, m ! loop indices
forrest@0
    58
      integer(i4) :: iv, iz
forrest@0
    59
      integer(i4) :: N
forrest@0
    60
      integer :: useed                 ! user seed value
forrest@0
    61
      integer :: rsize                 ! length of array of seeds
forrest@0
    62
      integer :: ierr                  ! error
forrest@0
    63
      integer, allocatable :: iseed(:) ! array of random number seeds
forrest@0
    64
      integer(i4) :: idispvec(0:maxN*maxN)
forrest@0
    65
      character (len=1)  :: ans
forrest@0
    66
      character (len=28) :: maptitle
forrest@0
    67
      character (len=60) :: mapfile
forrest@0
    68
      character (len=10) :: mapcolor
forrest@0
    69
      character (len=40) :: fmt  ! For dynamic format strings in gfortran
forrest@0
    70
      logical :: addition, wrap, gradient, slice, invert
forrest@0
    71
      logical :: grassout, xpmout, probout, vizout
forrest@0
    72
      logical :: constraint(0:maxsp)
forrest@0
    73
!
forrest@0
    74
!  write execution script for next run
forrest@0
    75
      open (9, file='input.scr',status='unknown')
forrest@0
    76
!
forrest@0
    77
!
forrest@0
    78
! enter random number seed
forrest@0
    79
      print 196
forrest@0
    80
196   format (t10,'Do you want to enter a random number seed <Y>', &
forrest@0
    81
              /t12,' or use the system clock? [clock]')
forrest@0
    82
      read (5,97) ans
forrest@0
    83
97    format (a1)
forrest@0
    84
      if (ans .eq. 'Y' .or. ans .eq. 'y') then
forrest@0
    85
         write (9,197) ans
forrest@0
    86
197      format (a1,t20,"(enter seed or clock?)")
forrest@0
    87
         print 100
forrest@0
    88
100      format (t10,'Enter random number seed ')
forrest@0
    89
         read *, useed
forrest@0
    90
         write (9,101) useed
forrest@0
    91
101      format (i12,t20,"(random number seed)")
forrest@0
    92
      else
forrest@0
    93
21       useed = int(time8(),kind(useed))
forrest@0
    94
         if (useed .eq. 0) then
forrest@0
    95
            print *, "useed was zero."
forrest@0
    96
            go to 21
forrest@0
    97
         end if
forrest@0
    98
         print 298
forrest@0
    99
298      format (t15,'Random number seed from system clock.'/)
forrest@0
   100
         write (9,29) ans, useed
forrest@0
   101
29       format (a1,t20,"(random seed from clock = ",i12,")")
forrest@0
   102
      end if
forrest@0
   103
      ! Set the random number seed
forrest@0
   104
      call random_seed(size=rsize)
forrest@0
   105
      allocate(iseed(rsize),stat=ierr)
forrest@0
   106
      if (ierr /= 0) then
forrest@0
   107
         print *,'Error allocating iseed(rsize)'
forrest@0
   108
         stop
forrest@0
   109
      end if
forrest@0
   110
      iseed(1:rsize) = useed
forrest@0
   111
      call random_seed(put=iseed)
forrest@0
   112
!
forrest@0
   113
      print 1017, useed
forrest@0
   114
1017  format (t15,'Random number seed = ',i12/)
forrest@0
   115
!
forrest@0
   116
!
forrest@0
   117
      print 512
forrest@0
   118
512   format (t10,'Do you want to visualize', &
forrest@0
   119
              /t12, ' the synthetic landscape? <Y,N>')
forrest@0
   120
      read (5,522) ans
forrest@0
   121
522   format (a1)
forrest@0
   122
      write (9,57) ans
forrest@0
   123
57    format (a1,t20,"(visualize the landscape?)")
forrest@0
   124
      if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   125
         vizout = .true.
forrest@0
   126
      else
forrest@0
   127
         vizout = .false.
forrest@0
   128
      end if
forrest@0
   129
!
forrest@0
   130
1     print 225
forrest@0
   131
225   format (t10,'How many levels? (map is 2**levels on a side)')
forrest@0
   132
      read *, maxlevel
forrest@0
   133
!
forrest@0
   134
      N = 2**maxlevel
forrest@0
   135
      irowcols = N
forrest@0
   136
      numcells = (N+1)*(N+1)
forrest@0
   137
      if (N .gt. maxN) goto 1
forrest@0
   138
      write (9,102) maxlevel
forrest@0
   139
102   format (i3,t20,"(Number of levels)")
forrest@0
   140
!
forrest@0
   141
      print 114
forrest@0
   142
114   format (t10,'Highest data category (excluding no-data)', &
forrest@0
   143
              /t12,' in the realized synthetic landscape?')
forrest@0
   144
      read *, ihabs
forrest@0
   145
      write (9,199) ihabs
forrest@0
   146
199   format (i3,t20,"(highest data category)")
forrest@0
   147
!
forrest@0
   148
      print 232
forrest@0
   149
232   format (t10,'Will you supply external probability maps', &
forrest@0
   150
              /t12,' for any of these categories?')
forrest@0
   151
      read (5,111) ans
forrest@0
   152
111   format (a1)
forrest@0
   153
      write (9,161) ans
forrest@0
   154
161   format (a1,t20,"(supply external prob maps?)")
forrest@0
   155
!
forrest@0
   156
      do j = 0, ihabs
forrest@0
   157
         constraint(j) = .false.
forrest@0
   158
      end do
forrest@0
   159
!
forrest@0
   160
      isupply = 0
forrest@0
   161
      if (ans .eq. 'Y' .or. ans .eq. 'y') then
forrest@0
   162
!
forrest@0
   163
         print 134
forrest@0
   164
134      format (t10,'For how many categories in the synthetic', &
forrest@0
   165
                 ' landscape',/t12,' will you supply external probability', &
forrest@0
   166
                 '  maps?')
forrest@0
   167
         read *, isupply
forrest@0
   168
         write (9,189) isupply
forrest@0
   169
189      format (i3,t20,"(number of external prob maps)")
forrest@0
   170
!
forrest@0
   171
         do i = 1, isupply
forrest@0
   172
            print 216
forrest@0
   173
216         format (t10,'Constrain which map category?')
forrest@0
   174
            read *, k
forrest@0
   175
            write (9,799) k
forrest@0
   176
799         format (i3,t20,"(constrain which category?)")
forrest@0
   177
!           set constraint flag for this category
forrest@0
   178
            constraint(k) = .true.
forrest@0
   179
!
forrest@0
   180
            print 220
forrest@0
   181
220         format (t10,'Enter name of input map file (integer*4, ', &
forrest@0
   182
                    /t12,' delimited by single spaces): ')
forrest@0
   183
            read (5,230) mapfile
forrest@0
   184
230         format (a60)
forrest@0
   185
            print 2030, mapfile
forrest@0
   186
2030        format (t15,'Input map name: ',a60/)
forrest@0
   187
            write (9,231) mapfile
forrest@0
   188
231         format (a60)
forrest@0
   189
!
forrest@0
   190
            print 144
forrest@0
   191
144         format (t10, 'Invert probabilities (i.e., DEM)? <Y,N>')
forrest@0
   192
            read (5,321) ans
forrest@0
   193
321         format (a1)
forrest@0
   194
            write (9,327) ans
forrest@0
   195
327         format (a1,t20,"(invert probabilities?)")
forrest@0
   196
            if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   197
               invert = .true.
forrest@0
   198
            else
forrest@0
   199
               invert = .false.
forrest@0
   200
            end if
forrest@0
   201
!
forrest@0
   202
!           load constraint maps in proper column of P array
forrest@0
   203
!           invert probabilities if necessary, i.e., a DEM
forrest@0
   204
            Call InputMap(mapfile,P,N,k,invert)
forrest@0
   205
         end do
forrest@0
   206
!
forrest@0
   207
      end if
forrest@0
   208
!
forrest@0
   209
!
forrest@0
   210
      do iz = 0, ihabs
forrest@0
   211
         if (.not. constraint(iz)) then
forrest@0
   212
            do i = 1, maxlevel
forrest@0
   213
118            print 159, i, iz
forrest@0
   214
159            format (t10,'Input value of H for level ',i3,', category ',i3)
forrest@0
   215
               read *, H(i,iz)
forrest@0
   216
               print *, H(i,iz)
forrest@0
   217
               write (9,155) H(i,iz), i, iz
forrest@0
   218
155            format (f4.2,t20,"(value of H for level ",i2,&
forrest@0
   219
                       ", category", i3,")")
forrest@0
   220
               if (H(i,iz) .lt. 0.0 .or. H(i,iz) .gt. 1.0) goto 118
forrest@0
   221
            end do
forrest@0
   222
         end if
forrest@0
   223
664   end do
forrest@0
   224
!
forrest@0
   225
!
forrest@0
   226
      ssum = 0.0
forrest@0
   227
      do i = 1, ihabs
forrest@0
   228
115      print 116, i
forrest@0
   229
116      format (t10,'Probability for habitat ',i3)
forrest@0
   230
         read *, prob(i)
forrest@0
   231
         if (prob(i) .lt. 0.0) goto 115
forrest@0
   232
         if (prob(i) .gt. 1.0) goto 115
forrest@0
   233
         ssum = ssum + prob(i)
forrest@0
   234
         if (ssum .gt. 1.0000) then
forrest@0
   235
            print *, 'Total probability exceeds 1.0 - Re-enter'
forrest@0
   236
            ssum = ssum - prob(i)
forrest@0
   237
            goto 115
forrest@0
   238
         end if
forrest@0
   239
         write (9,151) prob(i), i
forrest@0
   240
151      format (f6.5,t20,"(probability of habitat type", i2,")")
forrest@0
   241
      end do
forrest@0
   242
!
forrest@0
   243
!     find greatest non-constraint p to make background
forrest@0
   244
      ztemp = 0._r4
forrest@0
   245
      igreatest = 0
forrest@0
   246
      do i = 0, ihabs
forrest@0
   247
         if (.not. constraint(i)) then
forrest@0
   248
            if (prob(i) .gt. ztemp) then
forrest@0
   249
               ztemp = prob(i)
forrest@0
   250
               igreatest = i
forrest@0
   251
               !print *, 'at i of ',i ,'new greatest is ', igreatest
forrest@0
   252
            end if
forrest@0
   253
         end if
forrest@0
   254
662   end do
forrest@0
   255
!
forrest@0
   256
!     zero category by difference
forrest@0
   257
      prob(0) = 1.0 - ssum
forrest@0
   258
      if (prob(0) .lt. 0.00001) prob(0) = 0.0
forrest@0
   259
      print *, 'prob(0) is  ', prob(0)
forrest@0
   260
!
forrest@0
   261
!      print *, 'igreatest is ', igreatest
forrest@0
   262
      if (prob(0) .gt. prob(igreatest)) igreatest = 0
forrest@0
   263
      print *, 'Cat ', igreatest,' will be calculated by absence'
forrest@0
   264
!
forrest@0
   265
!      The Fractal Realizer assumes that the user-requested category
forrest@0
   266
! with the greatest coverage on the landscape (the highest requested p)
forrest@0
   267
! is the background or matrix category.  In order to give the other
forrest@0
   268
! categories the greatest freedom for fractal tuning and to minimize
forrest@0
   269
! contention ties, this majority background color is computed by absence,
forrest@0
   270
! and all other categories are reclassed.  Furthermore, categories which
forrest@0
   271
! are requested but for which the requested p = 0.0 are not actually
forrest@0
   272
! computed.
forrest@0
   273
!
forrest@0
   274
!      calculate reclassed categories
forrest@0
   275
!      ihabs = 0
forrest@0
   276
!      do i = 0, ihabsmax
forrest@0
   277
!         if (i .eq. igreatest) then
forrest@0
   278
!            ireclass(0) = i  
forrest@0
   279
!            print *, 'Cat ', i,' reassigned to background'
forrest@0
   280
!            goto 215
forrest@0
   281
!         end if
forrest@0
   282
!         if (prob(i) .eq. 0.0) then
forrest@0
   283
!            print *, 'Cat ', i,' requested but not used - skipping'
forrest@0
   284
!            goto 215
forrest@0
   285
!         end if
forrest@0
   286
!         ihabs = ihabs + 1
forrest@0
   287
!         ireclass(ihabs) = i
forrest@0
   288
!         print *, 'cat ', i,' will now be cat ', ihabs
forrest@0
   289
!
forrest@0
   290
!215   end do
forrest@0
   291
!
forrest@0
   292
!
forrest@0
   293
!      do i = 0, ihabs
forrest@0
   294
!         print 2002, ireclass(i), i, prob(ireclass(i))
forrest@0
   295
!2002     format ('Original category ', i2, ' re-mapped to ', &
forrest@0
   296
!                 i2, ' with requested probability of ', f6.4)
forrest@0
   297
!      end do
forrest@0
   298
!
forrest@0
   299
      print 212
forrest@0
   300
212   format (t10,'Generate GRASS r.in.ascii file? <Y,N>')
forrest@0
   301
      read (5,222) ans
forrest@0
   302
222   format (a1)
forrest@0
   303
      write (9,27) ans
forrest@0
   304
27    format (a1,t20,"(generate GRASS input file?)")
forrest@0
   305
      if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   306
         grassout = .true.
forrest@0
   307
      else
forrest@0
   308
         grassout = .false.
forrest@0
   309
      end if
forrest@0
   310
!
forrest@0
   311
      print 122
forrest@0
   312
122   format (t10,'Generate xpm file of synthetic landscape? <Y,N>')
forrest@0
   313
      read (5,123) ans
forrest@0
   314
123   format (a1)
forrest@0
   315
      write (9,124) ans
forrest@0
   316
124   format (a1,t20,"(xpm file of realized landscape?)")
forrest@0
   317
      if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   318
         xpmout = .true.
forrest@0
   319
      else
forrest@0
   320
         xpmout = .false.
forrest@0
   321
      end if
forrest@0
   322
!
forrest@0
   323
      print 322
forrest@0
   324
322   format (t10,'Generate xpm file of fractal probability' & 
forrest@0
   325
              ' landscapes? <Y,N>')
forrest@0
   326
      read (5,323) ans
forrest@0
   327
323   format (a1)
forrest@0
   328
      write (9,324) ans
forrest@0
   329
324   format (a1,t20,"(xpm file of probability landscapes?)")
forrest@0
   330
      if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   331
         probout = .true.
forrest@0
   332
      else
forrest@0
   333
         probout = .false.
forrest@0
   334
      end if
forrest@0
   335
!
forrest@0
   336
! *****************************************************************
forrest@0
   337
!  fill P array with a separate fractal probability map
forrest@0
   338
!    for each desired habitat in the landscape
forrest@0
   339
      do iz = 0, ihabs
forrest@0
   340
         if (constraint(iz)) goto 22
forrest@0
   341
!
forrest@0
   342
!        don't bother if igreatest or no cells requested of this category
forrest@0
   343
         if (prob(iz) .eq. 0.0 .or. iz .eq. igreatest) then
forrest@0
   344
            do i = 1, numcells
forrest@0
   345
               P(i,iz) = 0
forrest@0
   346
            end do
forrest@0
   347
            goto 22
forrest@0
   348
         end if
forrest@0
   349
!
forrest@0
   350
!         print 102
forrest@0
   351
!102      format (t10,'Input the value for sigma')
forrest@0
   352
!         read *, sigma
forrest@0
   353
         sigma = 1.
forrest@0
   354
         print 103
forrest@0
   355
103      format (t10,'Input the threshold for detection (xlow) ')
forrest@0
   356
         read (5,119) xlow
forrest@0
   357
119      format (g12.6)
forrest@0
   358
         write (9,125) xlow
forrest@0
   359
125      format (f12.6,t20,"(threshold for detection (xlow))")
forrest@0
   360
         if (xlow .eq. 0) xlow = -1e30
forrest@0
   361
         print *, xlow
forrest@0
   362
         print 104
forrest@0
   363
104      format (t10,'Wrap? <Y,N>')
forrest@0
   364
         read (5,145) ans
forrest@0
   365
145      format (a1)
forrest@0
   366
         write (9,198) ans
forrest@0
   367
198      format (a1,t20,"(wrap?)")
forrest@0
   368
         if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   369
            wrap = .true.
forrest@0
   370
         else
forrest@0
   371
            wrap = .false.
forrest@0
   372
         end if
forrest@0
   373
!
forrest@0
   374
!  no gradient possible with wrap
forrest@0
   375
         if (.not. wrap) then
forrest@0
   376
            print 106
forrest@0
   377
106         format (t10,'Gradient? <Y,N>')
forrest@0
   378
            read (5,107) ans
forrest@0
   379
107         format (a1)
forrest@0
   380
            write (9,148) ans
forrest@0
   381
148         format (a1,t20,"(gradient?)")
forrest@0
   382
            if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   383
               gradient = .true.
forrest@0
   384
!
forrest@0
   385
               print 1850
forrest@0
   386
1850           format (t10,'Gradient: Initial values for four map corners')
forrest@0
   387
               print 1851
forrest@0
   388
1851           format (t10,'Northeast? ')
forrest@0
   389
               read *, northeast
forrest@0
   390
               print 1852, northeast
forrest@0
   391
1852           format (5x,g12.6)
forrest@0
   392
               write (9,135) northeast
forrest@0
   393
135            format (f12.6,t20,"(Gradient: northeast)")
forrest@0
   394
!
forrest@0
   395
               print 1853
forrest@0
   396
1853           format (t10,'Southeast? ')
forrest@0
   397
               read *, southeast
forrest@0
   398
               print 1852, southeast
forrest@0
   399
               write (9,136) southeast
forrest@0
   400
136            format (f12.6,t20,"(Gradient: southeast)")
forrest@0
   401
!
forrest@0
   402
               print 1854
forrest@0
   403
1854           format (t10,'Southwest? ')
forrest@0
   404
               read *, southwest
forrest@0
   405
               print 1852, southwest
forrest@0
   406
               write (9,137) southwest
forrest@0
   407
137            format (f12.6,t20,"(Gradient: southwest)")
forrest@0
   408
!
forrest@0
   409
               print 1855
forrest@0
   410
1855           format (t10,'Northwest? ')
forrest@0
   411
               read *, northwest
forrest@0
   412
               print 1852, northwest
forrest@0
   413
               write (9,138) northwest
forrest@0
   414
138            format (f12.6,t20,"(Gradient: northwest)")
forrest@0
   415
!
forrest@0
   416
            else
forrest@0
   417
               gradient = .false.
forrest@0
   418
            end if
forrest@0
   419
!
forrest@0
   420
         end if !wrap = .false.
forrest@0
   421
!
forrest@0
   422
!         print 111
forrest@0
   423
!111      format (t10,'Slice into discrete habitats? <Y,N>')
forrest@0
   424
!         read (5,110) ans
forrest@0
   425
!110      format (a1)
forrest@0
   426
!         if (ans .eq. 'y' .or. ans .eq. 'Y') then
forrest@0
   427
!            slice = .true.
forrest@0
   428
!         else
forrest@0
   429
!            slice = .false.
forrest@0
   430
!         end if
forrest@0
   431
!
forrest@0
   432
         slice = .false.
forrest@0
   433
!
forrest@0
   434
!         print 104
forrest@0
   435
! 104     format (t10,'Addition <Y,N>?')
forrest@0
   436
!         read (5,105) ans
forrest@0
   437
! 105     format (a1)
forrest@0
   438
!         if (ans .eq. 'y' .or. ans .eq. 'Y') then 
forrest@0
   439
!            addition = .true.
forrest@0
   440
!         else
forrest@0
   441
!            addition = .false.
forrest@0
   442
!         end if
forrest@0
   443
         addition = .false.
forrest@0
   444
!
forrest@0
   445
!  call 2d multi-fractal generator
forrest@0
   446
         print *,"Calling fractal generator for category ", iz
forrest@0
   447
         call mpfm2d(X, maxlevel, sigma, H, addition, wrap, gradient, iz)
forrest@0
   448
!
forrest@0
   449
         print *, "fractal generated"
forrest@0
   450
         xmin = 1e30
forrest@0
   451
         xmax = -1e30
forrest@0
   452
         xmean = 0.0
forrest@0
   453
         xss = 0.0
forrest@0
   454
         icnt = 0
forrest@0
   455
!
forrest@0
   456
!  obtain xmin and xmax for range normalization
forrest@0
   457
!   calculate initial raw statistics
forrest@0
   458
!   while you're at it
forrest@0
   459
         do i = 0,N
forrest@0
   460
            do j = 0,N
forrest@0
   461
               if (X(i,j) .lt. xmin) xmin = X(i,j)
forrest@0
   462
               if (X(i,j) .gt. xmax) xmax = X(i,j)
forrest@0
   463
!               xmean = xmean + X(i,j)
forrest@0
   464
!               xss = xss + X(i,j)*X(i,j)
forrest@0
   465
!              icnt = icnt+1
forrest@0
   466
            end do
forrest@0
   467
         end do
forrest@0
   468
!         xmean = xmean / icnt
forrest@0
   469
!         print 200, xmean, xss, xmin, xmax
forrest@0
   470
!200      format (/t10,'Hfract Summary'/ &
forrest@0
   471
!                  t10,'Mean =    ',g12.6 &
forrest@0
   472
!                 /t10,'Sum Sq. = ',g12.6 &
forrest@0
   473
!                 /t10,'Minimum = ',g12.6 &
forrest@0
   474
!                 /t10,'Maximum = ',g12.6)
forrest@0
   475
!
forrest@0
   476
!  rescale and normalize fractal map between 0 and 32767, inclusive
forrest@0
   477
!
forrest@0
   478
         range1 = xmax - xmin
forrest@0
   479
         do i = 0,N
forrest@0
   480
            do j = 0,N
forrest@0
   481
               iv = (i*(N+1))+j+1
forrest@0
   482
               P(iv,iz) = ((X(i,j) - xmin)/range1) * 32767
forrest@0
   483
               P(iv,ihabs+1) = i
forrest@0
   484
               P(iv,ihabs+2) = j
forrest@0
   485
!              write(10,*) P(iv,iz)
forrest@0
   486
            end do
forrest@0
   487
         end do
forrest@0
   488
         print*,'done normalizing now'
forrest@0
   489
!
forrest@0
   490
!c        write GRASS ascii map
forrest@0
   491
!         write(10,791), N
forrest@0
   492
!791      format ('north: ',i4)
forrest@0
   493
!         write(10,792)
forrest@0
   494
!792      format ('south: 0')
forrest@0
   495
!         write(10,793), N
forrest@0
   496
!793      format ('east: ',i4)
forrest@0
   497
!         write(10,794)
forrest@0
   498
!794      format ('west: 0')
forrest@0
   499
!         write(10,795), N+1
forrest@0
   500
!795      format ('rows: ',i4)
forrest@0
   501
!         write(10,796), N+1
forrest@0
   502
!796      format ('cols: ',i4)
forrest@0
   503
!         do i = 0,N
forrest@0
   504
!            write(10,*) (P((i*(N+1))+j+1,iz), j=0,N)
forrest@0
   505
!         end do
forrest@0
   506
!
forrest@0
   507
!  end of iz loop over all landscape categories in synthetic map
forrest@0
   508
22       continue
forrest@0
   509
      end do
forrest@0
   510
! **********************************************************************
forrest@0
   511
!
forrest@0
   512
!  ihabs fractal maps now installed in P matrix:
forrest@0
   513
!
forrest@0
   514
!                 ihabs cols + 3
forrest@0
   515
!		|---------------|
forrest@0
   516
!		|		|
forrest@0
   517
!		|		|
forrest@0
   518
!		|  empty cells  |
forrest@0
   519
!  mtresolved =>|		|
forrest@0
   520
!		|		|
forrest@0
   521
!   mtsplit   =>|---------------|
forrest@0
   522
!		|		|
forrest@0
   523
!		|		|
forrest@0
   524
!		|		|
forrest@0
   525
!		|		|
forrest@0
   526
!		|    singly-    |
forrest@0
   527
!		|    painted    |
forrest@0
   528
!		|		|
forrest@0
   529
!		|		|
forrest@0
   530
!		|		|
forrest@0
   531
!		|		|
forrest@0
   532
!		|		|
forrest@0
   533
!  itiedsplit =>|---------------|
forrest@0
   534
!		|		|
forrest@0
   535
!		|		|
forrest@0
   536
!		|     ties      |
forrest@0
   537
!           m =>|		|
forrest@0
   538
!		|		|
forrest@0
   539
!    numcells =>|_______________|
forrest@0
   540
!
forrest@0
   541
!  ihabs+1 column carries x-coord of cell
forrest@0
   542
!  ihabs+2 column carries y-coord of cell
forrest@0
   543
!  ihabs+3 column carries number of ties for this cell
forrest@0
   544
! 
forrest@0
   545
!
forrest@0
   546
!  initialize II array with background value for re-use as output map
forrest@0
   547
      II(:,:) = 32767
forrest@0
   548
!
forrest@0
   549
!      set paint thresholds
forrest@0
   550
      print *,"Calculating paint thresholds"
forrest@0
   551
      do i = 0,ihabs ! over all map categories
forrest@0
   552
!
forrest@0
   553
!c        don't bother if no cells requested of this cat
forrest@0
   554
         if (prob(i) .ne. 0.0) then
forrest@0
   555
!
forrest@0
   556
!            istart = 0
forrest@0
   557
!            print *, "numcells is ", numcells
forrest@0
   558
!            print *, "istart is ", istart
forrest@0
   559
!            print *, "i is ", i
forrest@0
   560
!            Call HeapSort(P,numcells,istart,i) ! sort P matrix by ith column
forrest@0
   561
!
forrest@0
   562
!
forrest@0
   563
!            next category to be painted goes to single vector for sorting
forrest@0
   564
            idispvec(0) = 0
forrest@0
   565
            do l = 1, numcells
forrest@0
   566
               idispvec(l) = P(l,i)
forrest@0
   567
            end do
forrest@0
   568
!
forrest@0
   569
!            call special vector version of Heapsort
forrest@0
   570
            istart = 1
forrest@0
   571
            Call HS2(idispvec,numcells+1,istart)
forrest@0
   572
!
forrest@0
   573
!c           diagnostic print
forrest@0
   574
!            do k=16636,16646
forrest@0
   575
!               print *, i, k, idispvec(k)
forrest@0
   576
!            end do
forrest@0
   577
!
forrest@0
   578
!            set paint threshold for this map category
forrest@0
   579
            hslice(i) = idispvec(numcells - (int((prob(i) * numcells)+.499)))
forrest@0
   580
!           for absolute constraint maps
forrest@0
   581
            if (hslice(i) .eq. 32767 .and. constraint(i)) hslice(i) = 32766
forrest@0
   582
            print *, "trying to assign ", int((prob(i) * numcells)+.499), &
forrest@0
   583
                     " cells for category", i
forrest@0
   584
            jsum = jsum + int((prob(i) * numcells)+.499)
forrest@0
   585
         end if
forrest@0
   586
33    end do ! over all map categories
forrest@0
   587
!
forrest@0
   588
      print*, 'trying to assign a total of', jsum,' cells of', numcells, &
forrest@0
   589
              ' total cells'
forrest@0
   590
!c
forrest@0
   591
!c     set paint threshold for this map category
forrest@0
   592
!      hslice(i) = P(numcells - (int((prob(i) * numcells)+.499)),i)
forrest@0
   593
!      print *, "trying to assign ", int((prob(i) * numcells)+.499), &
forrest@0
   594
!               " cells for category", i
forrest@0
   595
!      end do ! over all map categories
forrest@0
   596
!
forrest@0
   597
!      dump hslice array for checking
forrest@0
   598
      print *, 'horizontal slices at these elevations:'
forrest@0
   599
      do i = 0,ihabs
forrest@0
   600
         print *, i, hslice(i)
forrest@0
   601
      end do
forrest@0
   602
!
forrest@0
   603
!     write XPM file of fractal probability terrain aspect
forrest@0
   604
      if (probout) then
forrest@0
   605
         do iz = 0, ihabs
forrest@0
   606
            if (.not. (constraint(iz) .or. prob(iz) .eq. 0.0 .or. &
forrest@0
   607
                iz .eq. igreatest)) then
forrest@0
   608
               Call XPMRelief(P,iz,hslice(iz))
forrest@0
   609
            end if
forrest@0
   610
335      end do
forrest@0
   611
      end if
forrest@0
   612
!
forrest@0
   613
!
forrest@0
   614
      numpainted = 0
forrest@0
   615
      numtied = 0
forrest@0
   616
      numblank = 0
forrest@0
   617
!
forrest@0
   618
      print *,"Beginning tie resolution process"
forrest@0
   619
      do l = 1, numcells ! start at top of P matrix
forrest@0
   620
         idummy = 0
forrest@0
   621
         do j = 0, ihabs ! over all map categories
forrest@0
   622
!           probably don't need to do this if prob(j) .eq. 0.0
forrest@0
   623
            if (.not. (prob(j) .eq. 0.0 .or. j .eq. igreatest)) then
forrest@0
   624
!
forrest@0
   625
!              if this cell is painted this category
forrest@0
   626
               if ( P(l,j) .gt. hslice(j) ) then
forrest@0
   627
!               if ( P(l,j) .ge. hslice(j) ) then
forrest@0
   628
!
forrest@0
   629
!                 count the multiple assignments
forrest@0
   630
                  P(l,ihabs+3) = P(l,ihabs+3) + 1
forrest@0
   631
!
forrest@0
   632
!                 find the winner category for this cell
forrest@0
   633
!                 winner category has the highest probability surface
forrest@0
   634
                  if ( P(l,j) .gt. idummy ) then
forrest@0
   635
                     ihighest = j
forrest@0
   636
                     idummy = P(l,ihighest)
forrest@0
   637
                  end if
forrest@0
   638
!
forrest@0
   639
               end if ! this cell painted this category
forrest@0
   640
!
forrest@0
   641
            end if
forrest@0
   642
         end do ! over all map categories
forrest@0
   643
!         print *, "highest for cell ", l," was category", ihighest
forrest@0
   644
!
forrest@0
   645
!        keep count of each type of cell for displacement into
forrest@0
   646
!         sorted array later
forrest@0
   647
!        if singly-painted or currently tied, paint outmap with ihighest
forrest@0
   648
         if ( P(l,ihabs+3) .eq. 1) then
forrest@0
   649
!           paint this cell with the winning category
forrest@0
   650
!            print *, "painting uncontested cell", P(l,ihabs+1), &
forrest@0
   651
!                     P(l,ihabs+2)," with cat", ihighest
forrest@0
   652
!
forrest@0
   653
            numpainted = numpainted + 1
forrest@0
   654
            II( P(l,ihabs+1),P(l,ihabs+2) ) = ihighest
forrest@0
   655
         else if ( P(l,ihabs+3) .eq. 0) then
forrest@0
   656
            numblank = numblank + 1
forrest@0
   657
         else
forrest@0
   658
            numtied = numtied + 1
forrest@0
   659
!            print *, "painting tied cell", P(l,ihabs+1),P(l,ihabs+2), &
forrest@0
   660
!                     " with winning cat", ihighest
forrest@0
   661
            II( P(l,ihabs+1),P(l,ihabs+2) ) = ihighest
forrest@0
   662
         end if
forrest@0
   663
!
forrest@0
   664
      end do
forrest@0
   665
!
forrest@0
   666
!     at this point, II array has all winners and uncontested
forrest@0
   667
!     cells painted
forrest@0
   668
!
forrest@0
   669
!     sort P array into 3 sections by number of assignments
forrest@0
   670
!     ascending sort results in empty, singly-painted, and
forrest@0
   671
!     ties sections
forrest@0
   672
      print *,"Preparing to sort ties for resolution"
forrest@0
   673
!      
forrest@0
   674
!     sort by ties column
forrest@0
   675
      istart = 1
forrest@0
   676
      Call HeapSort(P,numcells,istart,ihabs+3)
forrest@0
   677
!      print *, "got back from HeapSort"
forrest@0
   678
!
forrest@0
   679
!     calculate pointers to section breaks
forrest@0
   680
      mtsplit = numblank
forrest@0
   681
      itiedsplit = numblank + numpainted
forrest@0
   682
!
forrest@0
   683
      mtresolved = mtsplit
forrest@0
   684
!
forrest@0
   685
      print *, "numblank is ", numblank
forrest@0
   686
      print *, "numtied is ", numtied
forrest@0
   687
      print *, "itiedsplit is ", itiedsplit
forrest@0
   688
      print *, "numpainted is ", numpainted
forrest@0
   689
      print *, "mtresolved and mtsplit are ", mtresolved
forrest@0
   690
forrest@0
   691
      if (numtied .gt. numblank) print*, 'WARNING: More tied cells', &
forrest@0
   692
         ' than leftover blank cells to use for tie resolution!'
forrest@0
   693
!
forrest@0
   694
!     sum multiwayness of ties and compare to number of empty cells
forrest@0
   695
      do m = itiedsplit+1, numcells
forrest@0
   696
         isum = isum + ( P(m,ihabs+3) - 1 )
forrest@0
   697
      end do
forrest@0
   698
      print *, "sum of multiwayness of ties is ", isum
forrest@0
   699
      if (isum .gt. numblank) print *, 'Warning: cells are tied more', &
forrest@0
   700
         ' ways than there are blank cells to assign!'
forrest@0
   701
!
forrest@0
   702
!      call dump_map(P)
forrest@0
   703
!
forrest@0
   704
!  sort ties into priority order for resolution
forrest@0
   705
!   by calculating and sorting on summed elevation 
forrest@0
   706
!   for all tied categories
forrest@0
   707
!
forrest@0
   708
      do m = itiedsplit+1, numcells ! over all tied
forrest@0
   709
         kount = 0
forrest@0
   710
         idummy = 0
forrest@0
   711
         do k = 0, ihabs                ! over all categories
forrest@0
   712
!
forrest@0
   713
!           probably not necessary if prob(k) .eq. 0
forrest@0
   714
            if (.not. (prob(k) .eq. 0.0 .or. k .eq. igreatest)) then
forrest@0
   715
!           if this cell is painted this category
forrest@0
   716
               if ( P(m,k) .gt. hslice(k) ) then
forrest@0
   717
!               if ( P(m,k) .ge. hslice(k) ) then
forrest@0
   718
                  kount = kount + 1          ! number of ties for this cell
forrest@0
   719
                  ties(kount) = k            ! keep categories of ties
forrest@0
   720
!
forrest@0
   721
               end if
forrest@0
   722
            end if
forrest@0
   723
933      end do
forrest@0
   724
!
forrest@0
   725
         zmean = 0.0
forrest@0
   726
         do k = 1, kount
forrest@0
   727
            zmean = zmean + P(m,ties(k))
forrest@0
   728
         end do
forrest@0
   729
!         P(m,ihabs+3) = zmean/kount
forrest@0
   730
!        try weighting priority by simple sum, not average
forrest@0
   731
!        therefore, max sum = (ihabs-1) * 32767
forrest@0
   732
!        rescale as proportion of 32767 for integer*4 array cell
forrest@0
   733
         P(m,ihabs+3) = zmean/(ihabs-1)
forrest@0
   734
!
forrest@0
   735
      end do
forrest@0
   736
!
forrest@0
   737
!     sort ties by mean priority
forrest@0
   738
      Call HeapSort(P,numtied,itiedsplit+1,ihabs+3)
forrest@0
   739
!
forrest@0
   740
!     save min and max tie priorities for gray levels in XPMTies
forrest@0
   741
      maxgray = P(numcells,ihabs+3)
forrest@0
   742
      print*, "maxgray is ", maxgray
forrest@0
   743
!
forrest@0
   744
!     generate xpm picture of tied cells
forrest@0
   745
!      colored by priority gray shades
forrest@0
   746
!      Call XPMTies(P)
forrest@0
   747
!
forrest@0
   748
!
forrest@0
   749
!     start at bottom of list (highest priority ties)
forrest@0
   750
      do m = numcells, itiedsplit+1, -1 ! over all tied
forrest@0
   751
         kount = 0
forrest@0
   752
         idummy = 0
forrest@0
   753
         do k = 0, ihabs ! over all categories
forrest@0
   754
!
forrest@0
   755
!           probably not necessary if prob(k) .eq. 0
forrest@0
   756
            if (.not. (prob(k) .eq. 0.0 .or. k .eq. igreatest)) then
forrest@0
   757
!              if this cell is painted this category
forrest@0
   758
               if ( P(m,k) .gt. hslice(k) ) then
forrest@0
   759
!               if ( P(m,k) .ge. hslice(k) ) then
forrest@0
   760
                  kount = kount + 1 ! number of ties for this  cell
forrest@0
   761
                  ties(kount) = k ! keep categories of ties
forrest@0
   762
!                 save most likely category for this cell
forrest@0
   763
                  if ( P(m,k) .gt. idummy ) then
forrest@0
   764
                     ihighest = k
forrest@0
   765
                     idummy = P(m,ihighest)
forrest@0
   766
                  end if
forrest@0
   767
               end if
forrest@0
   768
            end if
forrest@0
   769
656      end do
forrest@0
   770
!
forrest@0
   771
!
forrest@0
   772
!        resolve all ties -
forrest@0
   773
!        over all tied categories that are not the winner
forrest@0
   774
!         (which has already been painted)
forrest@0
   775
!         we need an empty cell -
forrest@0
   776
!         search the empty cell list by this cat to find next
forrest@0
   777
!         most likely available empty cell
forrest@0
   778
!
forrest@0
   779
!        empty cell list will be searched once for each tie category
forrest@0
   780
!         except the winning category
forrest@0
   781
!
forrest@0
   782
!         print *, "deciding among ", kount, " ties for cell ", m
forrest@0
   783
         do k = 1, kount ! over all ties for this cell
forrest@0
   784
            if ( ties(k) .ne. ihighest ) then ! don't re-do the winner
forrest@0
   785
!               print *, ties(k), " was a tied category for cell ", m
forrest@0
   786
!
forrest@0
   787
               ibiggest = 0
forrest@0
   788
               idummy = 0
forrest@0
   789
               do i = 1,mtresolved
forrest@0
   790
                  if (P(i,ties(k)) .gt. idummy) then
forrest@0
   791
                     ibiggest = i
forrest@0
   792
                     idummy = P(i,ties(k))
forrest@0
   793
                  end if
forrest@0
   794
               end do
forrest@0
   795
!
forrest@0
   796
               Call Interchange(P,ibiggest,mtresolved)
forrest@0
   797
!
forrest@0
   798
!               istart = 1
forrest@0
   799
!               Call HeapSort(P,mtresolved,istart,ties(k))
forrest@0
   800
!
forrest@0
   801
!              now mtresolved points to highest
forrest@0
   802
!              next available empty cell of category ties(k)
forrest@0
   803
!              paint it!
forrest@0
   804
!               print *, "painting empty cell", mtresolved," at coords ", &
forrest@0
   805
!                  P(mtresolved,ihabs+1), P(mtresolved,ihabs+2)," with prob ", &
forrest@0
   806
!                  P(mtresolved,ties(k))," with cat", ties(k), &
forrest@0
   807
!                  " for tie at cell", m
forrest@0
   808
               II( P(mtresolved,ihabs+1),P(mtresolved,ihabs+2) ) = ties(k)
forrest@0
   809
!              burn one empty
forrest@0
   810
               mtresolved = mtresolved - 1
forrest@0
   811
            end if
forrest@0
   812
!
forrest@0
   813
992      end do ! over all ties for this cell
forrest@0
   814
!         print *, "resolving ties at cell ", m
forrest@0
   815
!
forrest@0
   816
      end do ! over all tied cells
forrest@0
   817
!
forrest@0
   818
!**********************************************************************
forrest@0
   819
!
forrest@0
   820
!
forrest@0
   821
!      Call dump_map(P)
forrest@0
   822
!
forrest@0
   823
!     generate xpm picture of tied cells
forrest@0
   824
!      colored by priority gray shades
forrest@0
   825
!      and used blank cells colored in yellow
forrest@0
   826
      Call XPMTies(P)
forrest@0
   827
!
forrest@0
   828
!
forrest@0
   829
!     set background category and
forrest@0
   830
!     perform summary of realized map
forrest@0
   831
      do i = 0,N
forrest@0
   832
         do j = 0,N
forrest@0
   833
            if (II(i,j) .eq. 32767) II(i,j) = igreatest
forrest@0
   834
            kcnt(II(i,j)) = kcnt(II(i,j)) + 1
forrest@0
   835
!           write(12,*) II(i,j)
forrest@0
   836
         end do
forrest@0
   837
      end do
forrest@0
   838
!
forrest@0
   839
!     if requested,
forrest@0
   840
!      write GRASS ascii map
forrest@0
   841
      if (grassout) then
forrest@0
   842
         write(10,91), N
forrest@0
   843
91       format ('north: ',i4)
forrest@0
   844
         write(10,92)
forrest@0
   845
92       format ('south: 0')
forrest@0
   846
         write(10,93), N
forrest@0
   847
93       format ('east: ',i4)
forrest@0
   848
         write(10,94)
forrest@0
   849
94       format ('west: 0')
forrest@0
   850
         write(10,95), N+1
forrest@0
   851
95       format ('rows: ',i4)
forrest@0
   852
         write(10,96), N+1
forrest@0
   853
96       format ('cols: ',i4)
forrest@0
   854
         write(fmt,'("(",I0,"(i5,1x))")') j
forrest@0
   855
         do i = 0,N
forrest@0
   856
!            write(10,47) (II(i,j), j=0,N)
forrest@0
   857
            write(10,fmt) (II(j,i), j=0,N)
forrest@0
   858
!            write(10,47) (II(j,i), j=0,N)
forrest@0
   859
!47          format (<j>(i5,1x))
forrest@0
   860
         end do
forrest@0
   861
      end if
forrest@0
   862
!
forrest@0
   863
!     write final map to xpm file
forrest@0
   864
      if (xpmout) Call XPMMap(N,II)
forrest@0
   865
!
forrest@0
   866
      print 299
forrest@0
   867
299   format (/t10,'Actual Map Summary:'/t12,'Habitat',5x, &
forrest@0
   868
              'P',3x,'Real Cells',3x,'Real P')
forrest@0
   869
!      pfract = 0.0
forrest@0
   870
      do i = 0, ihabs
forrest@0
   871
         pfract = real(kcnt(i),kind(pfract)) / real(numcells,kind(pfract))
forrest@0
   872
         print 300, i, prob(i), kcnt(i), pfract
forrest@0
   873
300      format (t10, i6, 4x, f6.5, 2x, i6, 2x, f6.5)
forrest@0
   874
      end do
forrest@0
   875
!
forrest@0
   876
!**********************************************************************
forrest@0
   877
!
forrest@0
   878
!     visualize the synthetic landscape
forrest@0
   879
      if (vizout) then
forrest@0
   880
!
forrest@0
   881
!        print final map to screen
forrest@0
   882
         do i=0,N
forrest@0
   883
            do j=0,N
forrest@0
   884
               idispvec(j) = II(i,j)
forrest@0
   885
            end do
forrest@0
   886
!            print 199, (idispvec(j), j=0,N)
forrest@0
   887
!199         format (<N+1>(i1, 1x))
forrest@0
   888
         end do
forrest@0
   889
!
forrest@0
   890
!        print current state of P array
forrest@0
   891
!         Call print(P)
forrest@0
   892
!
forrest@0
   893
!        visualize II array
forrest@0
   894
         mapcolor = 'bobs.cmap\0'
forrest@0
   895
         maptitle = 'Fractal Landscape Realizer \0'
forrest@0
   896
         idtype = 4
forrest@0
   897
         idumm = 0
forrest@0
   898
         ipixid = -1
forrest@0
   899
!
forrest@0
   900
!   build display vector
forrest@0
   901
!  make small maps more visible by repeating cells and lines
forrest@0
   902
!         irepeat = maxN / N
forrest@0
   903
!         print *, irepeat
forrest@0
   904
         k = 0
forrest@0
   905
         do i = 0,N
forrest@0
   906
!            kstart = k
forrest@0
   907
            do j=0,N
forrest@0
   908
!               do kk = 1, irepeat
forrest@0
   909
!                  idispvec(k)=II(i,j)
forrest@0
   910
                  idispvec(k)=II(j,i)
forrest@0
   911
                  k = k+1
forrest@0
   912
!               end do ! repeating cells in this row
forrest@0
   913
            end do ! all cells in this row
forrest@0
   914
!            kend = k-1
forrest@0
   915
!c           repeat lines
forrest@0
   916
!            if (irepeat .ge. 2) then
forrest@0
   917
!               do jj = 1,irepeat-1
forrest@0
   918
!                  do kk = kstart, kend
forrest@0
   919
!                     idispvec(k) = idispvec(kk)
forrest@0
   920
!                     k = k+1
forrest@0
   921
!                  end do ! dup as many times as necessary
forrest@0
   922
!               end do ! over all repeated lines
forrest@0
   923
!            end if
forrest@0
   924
!
forrest@0
   925
         end do
forrest@0
   926
!
forrest@0
   927
!c  adjust rows and columns by multiplier
forrest@0
   928
!         isize = (N+1) * irepeat
forrest@0
   929
!         jsize = (N+1) * irepeat
forrest@0
   930
!         print *, isize, jsize
forrest@0
   931
!         ierr=DrawPixmap(ipixid, isize, jsize, idtype, idispvec,
forrest@0
   932
!         ierr=DrawPixmap(ipixid,N+1,N+1,idtype,idispvec,idumm,mapcolor, &
forrest@0
   933
!                         maptitle)
forrest@0
   934
!         print *,'ierr is', ierr
forrest@0
   935
!         print *, 'done visualizing'
forrest@0
   936
!         call sleep(500)
forrest@0
   937
!
forrest@0
   938
      end if ! if visualizing landscape
forrest@0
   939
!
forrest@0
   940
      stop
forrest@0
   941
!      end program MidPtFM2d
forrest@0
   942
end program realizer