forked from sede-open/synthoseis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluvsim.f90
executable file
·3734 lines (3586 loc) · 122 KB
/
fluvsim.f90
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
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!-----------------------------------------------------------------------
!
! Hierarchical Fluvial Reservoir Modeling
! ***************************************
!
! The program is executed with no command line arguments. The user
! will be prompted for the name of a parameter file. The parameter
! file is described in the documentation (see the example fluvsim.par)
!
! The output file will be a GEOEAS file containing the simulated facies
! codes. The file is ordered by x,y,z, and then simulation (i.e., x
! cycles fastest, then y, then z, then realization number).
!
! Although somewhat odd, the facies coding is as follows (for input well
! conditioning...):
!
! 0 = floodplain shale
! 1 = channel sand (2 reserved for channel margin)
! 3 = levee sand
! 4 = crevasse sand
!
!
! AUTHOR: Clayton V. Deutsch DATE: Original 1996 - Revised 2000
!-----------------------------------------------------------------------
!
! Module to declare dynamic arrays in multiple subroutines:
!
module geostat
real, allocatable :: pmap(:, :, :), pmapa(:, :, :), pcurve(:, :), &
pcurvea(:, :), flwz(:, :), creprz(:, :), cx(:, :, :), cz(:), cw(:, :), &
ct(:, :, :), ccent(:, :), cprob(:), match(:), missm(:), cang(:), &
ccosa(:), csina(:), ctana(:), cxorigin(:), cyorigin(:), chx(:), &
rarray(:), crt(:, :), shiftp(:), atcut(:), atcdf(:)
integer, allocatable :: xw(:), yw(:), zw(:), fw(:), ninwint(:), &
facint(:), ixint(:, :), iyint(:, :), izint(:, :), nyc(:), ncre(:), &
crxloc(:, :), cryloc(:, :), crnum(:, :), icon(:), icoff(:), &
shiftc(:)
integer*2, allocatable :: chanind(:, :, :), channum(:, :, :), &
tchanind(:, :, :), tchannum(:, :, :), ixlotem(:, :), ixhitem(:, :), &
izlotem(:, :, :), izhitem(:), llwid(:, :), rlwid(:, :), llzlo(:, :), &
rlzlo(:, :), llbh(:, :, :), rlbh(:, :, :)
logical, allocatable :: chanon(:), cre(:, :, :), crright(:, :)
real VERSION, EPSLON, DEGTOR, fco(3), fcad(3), fcal(3), fct(3), fctu(3), &
fctul(3), fcwt(3), fcwu(3), fcwul(3), tarprop(0:4), modprop(0:4), &
flw(3), flh(3), fld(3), fcrlen(3), fcrt(3), fcrnw(3), fcrwl(3), &
fcrlat(3), creprob(3), cumprob(3), xsiz, ysiz, zsiz, xmn, xmx, ymn, &
ymx, zmn, wellmis, welltry, avgthick, sclglob, sclvert, sclarea, &
sclwell, wfac, objmin, t0, redfac, cxmin, cxmax, cymin, cymax, cdy
integer nx, ny, nz, nsim, nwd, nwint, nc, MAXW, MAXDAT, MAXC, MAXL, MAXBW, &
MAXCRE, MAXCRX, MAXCRY, MAXCPERT, MAXDIS, lin, ldbg, lgeo, &
lout, lpv, lpa, lwd, ichan, ilev, icre, idbg, mxc, niter, mnoc, &
kasas, ksas, numred, nonp, noffp, nvshift, nfct2
logical lglob, lvert, lvertng, larea, lareang, lwell
end module
program main
!-----------------------------------------------------------------------
!
! Hierarchical Fluvial Reservoir Modeling
! ***************************************
!
! Read the parameters, loop over each realization to generate, close
! output files and stop.
!
!-----------------------------------------------------------------------
use geostat
!
! Some basic initialization:
!
VERSION = 2.900
EPSLON = 1.0e-05
DEGTOR = 3.14159 / 180.0
!
! Read the parameters and data:
!
call readparm
!
! Call fluvsim for the simulation:
!
do isim = 1, nsim
write(*, *)
write(*, *) 'Working on realization number ', isim
call fluvsim
end do
close(ldbg)
close(lout)
close(lgeo)
close(lpv)
close(lpa)
close(lwd)
!
! Finished:
!
write(*, *)
write(*, 9998) VERSION
9998 format(/' FLUVSIM Version: ', f5.3, ' Finished'/)
stop
end
subroutine readparm
!-----------------------------------------------------------------------
!
! Initialization and Read Parameters
! **********************************
!
! The input parameters and data are read in from their files. Some quick
! error checking is performed and the statistics of all the variables
! being considered are written to standard output.
!
!
!
!-----------------------------------------------------------------------
use geostat
! use msflib
integer icolv(3), icola(3), test
real var(100), proptest(3)
real*8 p, acorni
character datafl*132, dbgfl*132, geofl*132, outfl*132, pcurout*132, &
pmapout*132, wellout*132, pcurvefl*132, pmapfl*132, str*132
logical testfl, inflag
!
! ACORN parameters:
!
parameter(KORDEI = 12, MAXOP1 = KORDEI + 1, MAXINT = 2**30)
common /iaco/ ixv(MAXOP1)
!
! Input/Output units used:
!
lin = 1
ldbg = 2
lgeo = 3
lout = 4
lpv = 7
lpa = 8
lwd = 9
!
! Note VERSION number:
!
write(*, 9999) VERSION
9999 format(/' FLUVSIM Version: ', f5.3/)
!
! Get the name of the parameter file - try the default name if no input:
!
str(1:1) = ' '
! call getarg(1,str)
! if(str(1:1).eq.' ')then
! write(*,*) 'Which parameter file do you want to use?'
! read (*,'(a20)') str(1:20)
! end if
if(str(1:1).eq.' ') str = 'fluvsim.par '
inquire(file = str, exist = testfl)
if(.not.testfl) then
write(*, *) 'ERROR - the parameter file does not exist,'
write(*, *) ' check for the file and try again '
write(*, *)
if(str(1:20).eq.'fluvsim.par ') then
write(*, *) ' creating a blank parameter file'
call makepar
write(*, *)
end if
stop
endif
open(lin, file = str, status = 'OLD')
!
! Find Start of Parameters:
!
1 read(lin, '(a4)', end = 98) str(1:4)
if(str(1:4).ne.'STAR') go to 1
!
! Read Input Parameters:
!
read(lin, '(a40)', err = 98) datafl
call chknam(datafl, 40)
write(*, *) ' data file = ', datafl
read(lin, *, err = 98) iwl, ixl, iyl, izl, ifl
write(*, *) ' input columns = ', iwl, ixl, iyl, izl, ifl
read(lin, *, err = 98) tmin, tmax
write(*, *) ' trimming limits = ', tmin, tmax
read(lin, *, err = 98) idbg
write(*, *) ' debugging level = ', idbg
read(lin, '(a40)', err = 98) dbgfl
call chknam(dbgfl, 40)
write(*, *) ' debugging file = ', dbgfl
open(ldbg, file = dbgfl, status = 'UNKNOWN')
read(lin, '(a40)', err = 98) geofl
call chknam(geofl, 40)
write(*, *) ' geometry file = ', geofl
read(lin, '(a40)', err = 98) outfl
call chknam(outfl, 40)
write(*, *) ' output file = ', outfl
read(lin, '(a40)', err = 98) pcurout
call chknam(pcurout, 40)
write(*, *) ' output file for vertical proportions= ', pcurout
read(lin, '(a40)', err = 98) pmapout
call chknam(pmapout, 40)
write(*, *) ' output file for areal proportions= ', pmapout
read(lin, '(a40)', err = 98) wellout
call chknam(wellout, 40)
write(*, *) ' output file for well data= ', wellout
read(lin, *, err = 98) nsim
write(*, *) ' number of realizations = ', nsim
read(lin, *, err = 98) nx, xmn, xsiz
write(*, *) ' X grid specification = ', nx, xmn, xsiz
read(lin, *, err = 98) ny, ymn, ysiz
write(*, *) ' Y grid specification = ', ny, ymn, ysiz
read(lin, *, err = 98) nz, avgthick
write(*, *) ' Z grid specification = ', nz, avgthick
zsiz = 1.0 / real(nz)
zmn = 0.5 * zsiz
allocate (flwz(nz, 3), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
read(lin, *, err = 98) ixv(1)
write(*, *) ' random number seed = ', ixv(1)
do i = 1, 1000
p = acorni(idum)
end do
read(lin, *, err = 98) i1, i2, i3, i4
write(*, *) ' Components in objective func = ', i1, i2, i3, i4
lglob = .false.
lvert = .false.
larea = .false.
lwell = .false.
if(i1.ge.1) lglob = .true.
if(i2.ge.1) lvert = .true.
if(i3.ge.1) larea = .true.
if(i4.ge.1) lwell = .true.
read(lin, *, err = 98) sclglob, sclvert, sclarea, sclwell
write(*, *) ' scaling of objective func = ', sclglob, sclvert, &
sclarea, sclwell
totwt = sclglob + sclvert + sclarea + sclwell
if(totwt.le.0.0) stop 'Weights must be greater than zero'
sclglob = sclglob / totwt
sclvert = sclvert / totwt
sclarea = sclarea / totwt
sclwell = sclwell / totwt
read(lin, *, err = 98) niter, mnoc, objmin
write(*, *) ' Number of iterations, min obj = ', niter, mnoc, objmin
read(lin, *, err = 98) t0, redfac, kasas, ksas, numred
write(*, *) ' annealing schedule = ', t0, redfac, kasas, ksas, numred
read(lin, *, err = 98) cumprob(1), cumprob(2), cumprob(3)
write(*, *) ' perturbation probabilities = ', &
cumprob(1), cumprob(2), cumprob(3)
cumprob(2) = cumprob(1) + cumprob(2)
cumprob(3) = cumprob(2) + cumprob(3)
read(lin, *, err = 98) ichan, ilev, icre
write(*, *) ' Facies types = ', ichan, ilev, icre
read(lin, *, err = 98) tarprop(1), tarprop(3), tarprop(4)
if(ilev.eq.0) tarprop(3) = 0.0
if(icre.eq.0) tarprop(4) = 0.0
write(*, *) ' Reference proportions = ', (tarprop(i), i = 1, 4)
tarprop(0) = 1.0 - (tarprop(1) + tarprop(3) + tarprop(4))
tarprop(2) = 0.0
read(lin, '(a40)', err = 98) pcurvefl
call chknam(pcurvefl, 40)
write(*, *) ' vertical proportion curve file = ', pcurvefl
read(lin, *, err = 98) itest
write(*, *) ' net-to-gross or all facies = ', itest
lvertng = .true.
if(itest.eq.1) lvertng = .false.
read(lin, *, err = 98) (icolv(i), i = 1, 3)
write(*, *) ' column numbers = ', (icolv(i), i = 1, 3)
read(lin, '(a40)', err = 98) pmapfl
call chknam(pmapfl, 40)
write(*, *) ' areal proportion map file = ', pmapfl
read(lin, *, err = 98) itest
write(*, *) ' net-to-gross or all facies = ', itest
lareang = .true.
if(itest.eq.1) lareang = .false.
read(lin, *, err = 98) (icola(i), i = 1, 3)
write(*, *) ' column numbers = ', (icola(i), i = 1, 3)
read(lin, *, err = 98) mxc
write(*, *) ' maximum number of channels = ', mxc
read(lin, *, err = 98) (fco(i), i = 1, 3)
write(ldbg, *) ' channel orientation = ', (fco(i), i = 1, 3)
read(lin, *, err = 98) (fcad(i), i = 1, 3)
write(ldbg, *) ' channel sinuosity dep = ', (fcad(i), i = 1, 3)
read(lin, *, err = 98) (fcal(i), i = 1, 3)
write(ldbg, *) ' channel sinuosity len = ', (fcal(i), i = 1, 3)
read(lin, *, err = 98) (fct(i), i = 1, 3)
write(ldbg, *) ' channel thickness = ', (fct(i), i = 1, 3)
read(lin, *, err = 98) (fctu(i), i = 1, 3)
write(ldbg, *) ' channel thickness undulation = ', (fctu(i), i = 1, 3)
read(lin, *, err = 98) (fctul(i), i = 1, 3)
write(ldbg, *) ' channel thickness undul len=', (fctul(i), i = 1, 3)
read(lin, *, err = 98) (fcwt(i), i = 1, 3)
write(ldbg, *) ' channel W/T ratio = ', (fcwt(i), i = 1, 3)
read(lin, *, err = 98) (fcwu(i), i = 1, 3)
write(ldbg, *) ' channel width undulation = ', (fcwu(i), i = 1, 3)
read(lin, *, err = 98) (fcwul(i), i = 1, 3)
write(ldbg, *) ' channel width undulation len = ', (fcwul(i), i = 1, 3)
read(lin, *, err = 98) (flw(i), i = 1, 3)
write(ldbg, *) ' levee width = ', (flw(i), i = 1, 3)
do iz = 1, nz
flwz(iz, 1) = flw(1)
flwz(iz, 2) = flw(2)
flwz(iz, 3) = flw(3)
end do
read(lin, *, err = 98) (flh(i), i = 1, 3)
write(ldbg, *) ' levee height = ', (flh(i), i = 1, 3)
read(lin, *, err = 98) (fld(i), i = 1, 3)
write(ldbg, *) ' levee depth below channel top = ', (fld(i), i = 1, 3)
read(lin, *, err = 98) (fcrlen(i), i = 1, 3)
write(ldbg, *) ' crevasse attachment length = ', (fcrlen(i), i = 1, 3)
read(lin, *, err = 98) (fcrt(i), i = 1, 3)
write(ldbg, *) ' crevasse thickness = ', (fcrt(i), i = 1, 3)
read(lin, *, err = 98) (fcrwl(i), i = 1, 3)
write(ldbg, *) ' crevasse areal dimension = ', (fcrwl(i), i = 1, 3)
write(*, *)
write(*, *) ' Finished reading parameters'
close(lin)
!
! Dynamic memory allocation:
!
!
! MAXCRE maximum number of crevasse templates
! MAXCPERT maximum number of channels turned on/off/revised during
! a perturbation iteration
! MAXCRX maximum crevasse template size in X
! MAXCRY maximum crevasse template size in Y
! MAXW maximum 1/2 width of channel (depends on width)
! MAXBW maximum levee bank width
!
MAXL = 400 * max(nx, ny) ! Modified from 2 * max(nx, ny)
MAXC = mxc + 1
! MAXCRE = 50
MAXCRE = int(nx / 3. + .5)
MAXCPERT = 10
MAXDIS = 50
! MAXCRX = 25
! MAXCRY = 15
! MAXW = 75
! MAXBW = 10
MAXCRX = int(nx / 2. + .5)
MAXCRY = int(nx / 2. + .5)
MAXW = int(nx / 3. + .5)
MAXBW = 400 * max(nx, ny) ! Modified from 2 * max(nx, ny)
allocate (pmapa(nx, ny, 3), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (pmap(nx, ny, 3), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (pcurve(nz, 3), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (pcurvea(nz, 3), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (creprz(nz, 3), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (chanind(nx, ny, nz), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (channum(nx, ny, nz), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (tchanind(nx, ny, nz), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (tchannum(nx, ny, nz), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cx(MAXC, MAXL, 7), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cz(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cw(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ct(MAXC, MAXL, 7), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ccent(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cprob(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (match(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (missm(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cang(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ccosa(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (csina(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ctana(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cxorigin(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cyorigin(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (chx(MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (rarray(MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (nyc(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ncre(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ixlotem(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ixhitem(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (izlotem(MAXC, MAXL, -MAXW:MAXW), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (izhitem(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (llwid(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (rlwid(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (llzlo(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (rlzlo(MAXC, MAXL), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (llbh(MAXC, MAXL, MAXBW), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (rlbh(MAXC, MAXL, MAXBW), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (crt(MAXC, MAXCRE), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (shiftp(MAXCPERT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (atcut(MAXDIS), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (atcdf(MAXDIS), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (crxloc(MAXC, MAXCRE), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cryloc(MAXC, MAXCRE), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (crnum(MAXC, MAXCRE), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (icon(MAXCPERT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (icoff(MAXCPERT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (shiftc(MAXCPERT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (chanon(MAXC), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (cre(MAXCRE, 0:MAXCRX, -MAXCRY:MAXCRY), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (crright(MAXC, MAXCRE), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
MAXDAT = 0
inquire(file = datafl, exist = testfl)
if(testfl.and.lwell) then
open(lin, file = datafl, status = 'OLD')
read(lin, *, err = 99)
read(lin, *, err = 99) nvari
do i = 1, nvari
read(lin, *, err = 99)
end do
52 continue
read(lin, *, err = 53, end = 53) (var(j), j = 1, nvari)
MAXDAT = MAXDAT + 1
go to 52
53 continue
end if
if(MAXDAT.le.0) MAXDAT = 1
allocate (xw(MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (yw(MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (zw(MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (fw(MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ninwint(MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (facint(MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (ixint(MAXDAT, MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (iyint(MAXDAT, MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
allocate (izint(MAXDAT, MAXDAT), stat = test)
if (test.ne.0) write(*, *) 'Error: Allocation failed: ', test
if (test.ne.0) stop
!
! Initialization. Rescale vertical coordinates to average thickness.
! Scale annealing parameters by maximum number of channels. Get
! distribution of apparent thicknesses:
!
do i = 1, 3
fct(i) = fct(i) / avgthick
fcwt(i) = fcwt(i) * avgthick
fcrt(i) = fcrt(i) / avgthick
end do
nfct2 = 1 + int(fct(2) * 0.5 / zsiz)
kasas = kasas * mxc
ksas = ksas * mxc
write(*, *)
write(*, *) ' calling getat'
call getat
write(*, *) ' finished with getat'
!
! Make sure the angles are in the right direction:
!
if(fco(1).gt.135.0) fco(1) = fco(1) - 180.0
if(fco(2).gt.135.0) fco(2) = fco(2) - 180.0
if(fco(3).gt.135.0) fco(3) = fco(3) - 180.0
if(fco(1).lt.-45.0) fco(1) = fco(1) + 180.0
if(fco(2).lt.-45.0) fco(2) = fco(2) + 180.0
if(fco(3).lt.-45.0) fco(3) = fco(3) + 180.0
!
! The limits of interest for the channels and the spacing of the slices
! that make up the channels:
!
xmx = xmn + (real(nx) - 0.5) * xsiz
ymx = ymn + (real(ny) - 0.5) * ysiz
xadd = 0.5 * xsiz + min((0.15 * (xmx - xmn)), (0.7071 * fct(2) * fcwt(2)))
write (*, *) xadd
cxmin = xmn - (0.5 * xsiz + xadd)
cxmax = xmx + xadd
yadd = 0.5 * ysiz + min((0.15 * (ymx - ymn)), (0.7071 * fct(2) * fcwt(2)))
write (*, *) yadd
cymin = ymn - (0.5 * ysiz + yadd)
cymax = ymx + yadd
cdy = 0.7071 * min(xsiz, ysiz)
ndymax = sqrt((cxmax - cxmin)**2 + (cymax - cymin)**2) / cdy
write(ldbg, 120) (xmn - 0.5 * xsiz), xmx, (ymn - 0.5 * ysiz), ymx, &
cxmin, cxmax, cymin, cymax, cdy, ndymax
write(*, 120) (xmn - 0.5 * xsiz), xmx, (ymn - 0.5 * ysiz), ymx, &
cxmin, cxmax, cymin, cymax, cdy, ndymax
120 format(/, 'Limits of model X: ', 2f10.2, &
/, ' Y: ', 2f10.2, &
/, ' outer limits X: ', 2f10.2, &
/, ' Y: ', 2f10.2, &
/, ' channel dy: ', f10.4, &
/, ' maximum ny: ', i10)
!
! Set up the crevasse templates and figure out the probability of
! one per channel:
!
if(icre.eq.1) then
write(*, *)
write(*, *) 'Establishing ', MAXCRE, ' crevasse templates'
!
! - scale input to grid units (and hard code some parameters):
!
fcrlen(1) = int(fcrlen(1) / cdy + 0.5)
fcrlen(2) = int(fcrlen(2) / cdy + 0.5)
fcrlen(3) = int(fcrlen(3) / cdy + 0.5)
fcrnw(1) = 5
fcrnw(2) = 10
fcrnw(3) = 15
fcrlat(1) = 0.5
fcrlat(2) = 0.5
fcrlat(3) = 0.5
fcrwl(1) = int(1.5 * fcrwl(1) / cdy + 0.5)
fcrwl(2) = int(1.5 * fcrwl(2) / cdy + 0.5)
fcrwl(3) = int(1.5 * fcrwl(3) / cdy + 0.5)
!
! - establish the crevasse templates and the number of crevasses:
!
call getcre
cresize = 0.0
do ic = 1, MAXCRE
do ix = 0, MAXCRX
do iy = -MAXCRY, MAXCRY
if(cre(ic, ix, iy)) cresize = cresize + &
cdy * cdy * fcrt(2) * (MAXCRX - real(ix)) / MAXCRX
end do
end do
end do
cresize = cresize / MAXCRE
chsize = 0.55 * fct(2) * fct(2) * fcwt(2) * real(ny) * cdy
creprob(2) = tarprop(4) / tarprop(1) * (chsize / cresize)
!
! Scale the number of crevasses so that the proportion works out.
!
creprob(2) = creprob(2) / 2.0
creprob(1) = creprob(2) / 1.5
creprob(3) = creprob(2) * 1.5
write(*, *) 'Average channel size: ', chsize
write(*, *) 'Average crevasse size: ', cresize
write(*, *) 'There will be about ', int(creprob(2) + 0.5), &
' crevasses per channel'
do iz = 1, nz
creprz(iz, 1) = creprob(1)
creprz(iz, 2) = creprob(2)
creprz(iz, 3) = creprob(3)
end do
end if
!
! Read the well data (if the file exists):
!
nwd = 0
nwint = 0
inquire(file = datafl, exist = testfl)
if(testfl.and.lwell) then
write(*, *)
write(*, *) 'Reading input well data'
open(lin, file = datafl, status = 'OLD')
read(lin, *, err = 99)
read(lin, *, err = 99) nvari
do i = 1, nvari
read(lin, *, err = 99)
end do
if(ixl.gt.nvari.or.iyl.gt.nvari.or.izl.gt.nvari.or.&
ifl.gt.nvari) then
write(*, *) 'ERROR: you have asked for a column number'
write(*, *) ' greater than number in well data'
stop
end if
if(ixl.le.0.or.iyl.le.0.or.izl.le.0.or.ifl.le.0) then
write(*, *) 'ERROR: you must have coordinates and'
write(*, *) ' facies in well data'
stop
end if
!
! Read all the data until the end of the file:
!
iwold = -1
ifold = -1
5 read(lin, *, end = 6, err = 99) (var(j), j = 1, nvari)
if(var(ifl).lt. tmin.or.var(ifl).ge. tmax.or.&
var(ixl).lt.cxmin.or.var(ixl).ge.cxmax.or.&
var(iyl).lt.cymin.or.var(iyl).ge.cymax.or.&
var(izl).lt. 0.0.or.var(izl).ge. 1.0) go to 5
nwd = nwd + 1
if(nwd.gt.MAXDAT) then
write(*, *) ' ERROR exceeded MAXDAT - check inc file'
stop
end if
!
! Acceptable data, assign the value, X, Y, Z coordinates, and weight:
!
iwell = var(iwl)
fw(nwd) = var(ifl)
call getindx(nx, xmn, xsiz, var(ixl), ii, inflag)
xw(nwd) = max(min(ii, nx), 1)
call getindx(ny, ymn, ysiz, var(iyl), ii, inflag)
yw(nwd) = max(min(ii, ny), 1)
call getindx(nz, zmn, zsiz, var(izl), ii, inflag)
zw(nwd) = max(min(ii, nz), 1)
!
! Check and see if this is a duplicate well interval:
!
do iii = 1, nwd - 1
if((abs(xw(nwd) - xw(iii)) + &
abs(yw(nwd) - yw(iii)) + &
abs(zw(nwd) - zw(iii))).lt.1.0) then
nwd = nwd - 1
go to 5
end if
end do
!
! Keep track of well intervals:
!
if(iwell.ne.iwold.or.fw(nwd).ne.ifold) then
nwint = nwint + 1
iwold = iwell
ifold = fw(nwd)
ninwint(nwint) = 1
facint(nwint) = ifold
ixint(nwint, 1) = xw(nwd)
iyint(nwint, 1) = yw(nwd)
izint(nwint, 1) = zw(nwd)
else
ninwint(nwint) = ninwint(nwint) + 1
ii = ninwint(nwint)
ixint(nwint, ii) = xw(nwd)
iyint(nwint, ii) = yw(nwd)
izint(nwint, ii) = zw(nwd)
end if
!
! Return for new well data:
!
go to 5
6 close(lin)
write(ldbg, 109) nwd, nwint
write(*, 109) nwd, nwint
109 format(/, ' Number of acceptable well data = ', i8, /, &
' Number of intervals for pert. = ', i8)
wfac = 20 / max(real(nwd), 1.0)
!
! Now, establish the well intervals for the perturbation mechanism:
!
iwold = -1
endif
!
! Read the vertical proportion curve (if the file exists):
!
do iz = 1, nz
do i = 1, 3
pcurve(iz, i) = 0.0
end do
end do
inquire(file = pcurvefl, exist = testfl)
if(testfl.and.lvert) then
write(*, *)
write(*, *) 'Reading vertical proportion curve data'
open(lin, file = pcurvefl, status = 'OLD')
read(lin, *, err = 97)
read(lin, *, err = 97) nvari
do i = 1, nvari
read(lin, *, err = 97)
end do
do i = 1, 3
proptest(i) = 0.0
end do
do iz = 1, nz
do i = 1, 3
pcurve(iz, i) = 0.0
end do
read(lin, *, err = 97) (var(i), i = 1, nvari)
if(lvertng) then
ii = icolv(1)
pcurve(iz, 1) = var(ii)
proptest(1) = proptest(1) + pcurve(iz, 1)
else
do i = 1, 3
ii = icolv(i)
if(i.eq.1) pcurve(iz, i) = var(ii)
if(i.eq.2.and.ilev.eq.1)&
pcurve(iz, i) = var(ii)
if(i.eq.3.and.icre.eq.1)&
pcurve(iz, i) = var(ii)
proptest(i) = proptest(i) + pcurve(iz, i)
end do
end if
end do
close(lin)
do i = 1, 3
proptest(i) = proptest(i) / real(nz)
if(proptest(i).lt.0.001) proptest(i) = 0.001
end do
do iz = 1, nz
if(lvertng) then
pcurve(iz, 1) = pcurve(iz, 1) * &
(tarprop(1) + tarprop(3) + tarprop(4)) / proptest(1)
else
pcurve(iz, 1) = pcurve(iz, 1) * &
tarprop(1) / proptest(1)
if(ilev.eq.1) pcurve(iz, 2) = pcurve(iz, 2) * &
tarprop(3) / proptest(2)
if(icre.eq.1) pcurve(iz, 3) = pcurve(iz, 3) * &
tarprop(4) / proptest(2)
end if
end do
end if
!
! Read the areal proportion map (if the file exists):
!
do iy = 1, ny
do ix = 1, nx
do i = 1, 3
pmap(ix, iy, i) = 0.0
end do
end do
end do
inquire(file = pmapfl, exist = testfl)
if(testfl.and.larea) then
write(*, *)
write(*, *) 'Reading areal proportion map data'
open(lin, file = pmapfl, status = 'OLD')
read(lin, *, err = 97)
read(lin, *, err = 97) nvari
do i = 1, nvari
read(lin, *, err = 97)
end do
do i = 1, 3
proptest(i) = 0.0
end do
do iy = 1, ny
do ix = 1, nx
do i = 1, 3
pmap(ix, iy, i) = 0.0
end do
read(lin, *, err = 97) (var(i), i = 1, nvari)
if(lareang) then
ii = icola(1)
pmap(ix, iy, 1) = var(ii)
proptest(1) = proptest(1) + pmap(ix, iy, 1)
else
do i = 1, 3
ii = icola(i)
if(i.eq.1) pmap(ix, iy, i) = var(ii)
if(i.eq.2.and.ilev.eq.1)&
pmap(ix, iy, i) = var(ii)
if(i.eq.3.and.icre.eq.1)&
pmap(ix, iy, i) = var(ii)
proptest(i) = proptest(i) + pmap(ix, iy, i)
end do
end if
end do
end do
close(lin)
do i = 1, 3
proptest(i) = proptest(i) / real(nx * ny)
if(proptest(i).lt.0.001) proptest(i) = 0.001
end do
do iy = 1, ny
do ix = 1, nx
if(lareang) then
pmap(ix, iy, 1) = pmap(ix, iy, 1) * &
(tarprop(1) + tarprop(3) + tarprop(4)) / proptest(1)
else
pmap(ix, iy, 1) = pmap(ix, iy, 1) * &
tarprop(1) / proptest(1)
if(ilev.eq.1) pmap(ix, iy, 2) = pmap(ix, iy, 2) * &
tarprop(3) / proptest(2)
if(icre.eq.1) pmap(ix, iy, 3) = pmap(ix, iy, 3) * &
tarprop(4) / proptest(2)
end if
end do
end do
end if
!
! Open the output files and write header information:
!
open(lout, file = outfl, status = 'UNKNOWN')
! write(lout,110)
! 110 format('FLUVSIM Realizations',/,'1',/,'facies code')
open(lgeo, file = geofl, status = 'UNKNOWN')
write(lgeo, 130) nx, xmn, xsiz, ny, ymn, ysiz, nz, avgthick, ilev, icre
130 format(i3, 1x, f10.2, 1x, f6.3, ' -X: nx, xmn, xsiz', /, &
i3, 1x, f10.2, 1x, f6.3, ' -Y: ny, ymn, ysiz', /, &
i3, 12x, f6.3, ' -Z: number and average thickness', /, &
i2, i2, 17x, ' -levee and crevasse (0=no, 1=yes)')
if(lvert) then
open(lpv, file = pcurout, status = 'UNKNOWN')
write(lpv, 111)
111 format('FLUVSIM Vertical Proportion Curve Output', /, '7', /, &
'Z index', /, 'target 1', /, 'actual 1', /, &
'target 2', /, 'actual 2', /, &
'target 3', /, 'actual 3')
end if
if(larea) then
open(lpa, file = pmapout, status = 'UNKNOWN')
write(lpa, 112)
112 format('FLUVSIM Areal Proportion Map Output', /, '6', /, &
'target 1', /, 'actual 1', /, &
'target 2', /, 'actual 2', /, &
'target 3', /, 'actual 3')
end if
if(lwell) then
open(lwd, file = wellout, status = 'UNKNOWN')
write(lwd, 113)
113 format('FLUVSIM Well Data Output', /, '5', /, &
'x', /, 'y', /, 'z', /, 'well data', /, 'realization')
end if
return
!
! Error in an Input File Somewhere:
!
97 stop 'ERROR in proportion files!'
98 stop 'ERROR in parameter file!'
99 stop 'ERROR in data file!'
end
subroutine fluvsim
!-----------------------------------------------------------------------
!
! Main subroutine that establishes the initial set of channels (and
! associated levee and crevasse sands), perturbs them until one of the
! stopping criteria is met, and then writes output files.
!
!
!
!
!-----------------------------------------------------------------------
use geostat
real*8 acorni
logical accept, lreport, flong
!
! ACORN parameters:
!
parameter(KORDEI = 12, MAXOP1 = KORDEI + 1, MAXINT = 2**30)
common /iaco/ ixv(MAXOP1)
!
! Initialize:
!
flong = .false.