forked from markjessell/functionNoddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.c
4785 lines (4322 loc) · 157 KB
/
block.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
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ======================================================================
** PLEASE READ AND NOTE **
This file is used for both the sequential and parallel versions
of Noddy, MAKE SURE any changes that are made are compatible
with both version of Noddy.
You may use the _MPL defined symbol to conditionally compile
code that is only associated with a particular version of Noddy.
_MPL is defined only for the MASPAR Parallel verion of Noddy.
THANK-YOU FOR YOUR ATTENTION
====================================================================== */
#ifndef _MPL
#include "xvt.h"
#else
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#endif
#include "noddy.h"
#include <math.h>
#define DEBUG(X)
#define DEBUGX(X)
#define VERSION_TOLERANCE 0.01
#define TOLERANCE 0.0001
#define STRAT_LIMIT 100
/* ********************************** */
/* External Globals used in this file */
extern GEOLOGY_OPTIONS geologyOptions;
extern GEOPHYSICS_OPTIONS geophysicsOptions;
extern int TopoRow, TopoCol;
extern double TopomapXW, TopomapYW, TopomapXE, TopomapYE;
extern double **topographyMap;
extern int batchExecution;
#if XVT_CC_PROTO
extern void Remfind(double *, int, LAYER_PROPERTIES *, int, int, double *, double *, double *, double *, double *);
extern int planeIntersect (double *, double *, double, double, double, double, double, double);
extern void Anifind(double *, int, LAYER_PROPERTIES *, int, int, double *, double *, double *, double *, double *);
extern int assignLayerInBlockModels (LAYER_PROPERTIES ***, int, int,
int, int, LAYER_PROPERTIES **, int , int ,
short ***, float ***, float ***, float ***,
float ***, float ***, float ***, float ***,
float ***, float ***, float ***, float ***);
extern double fault(double [10][4], FAULT_OPTIONS *);
extern double plug (double [10][4], PLUG_OPTIONS *);
extern double dyke (double [10][4], DYKE_OPTIONS *);
extern int forwardModel (int, int, double, double, double, double *, double *, double *);
#else
extern void Remfind();
extern int planeIntersect ();
extern void Anifind();
extern int assignLayerInBlockModels ();
extern double fault();
extern double plug ();
extern double dyke ();
extern int forwardModel ();
#endif
/* ************************* */
/* Globals used in this file */
#if XVT_CC_PROTO
COLOR ***convertFloatBlockDataToColors(float ***, int, int, int, COLOR *, int);
COLOR ***convertIntBlockDataToColors(int ***, int, int, int, COLOR *, int);
int readBlockHeader (char *, int *, int *, int *, int *, int *,
double *, double *, double *, double *, double *, double *,
double *, double *, double *);
int readBlockFile (char *, int ***, int *, int, int, int, float [121],
float [121][4], double [121][4], double [121],
double [121], int [121], int *, int *,
double *, double *, double *, double *, double *, double *,
BLOCK_VIEW_OPTIONS *, GEOPHYSICS_OPTIONS *);
void calcBlockModel (int ***, double ***, STORY **, double **, double, double,
int *, int, int, int, float [121],
float [121][4], double [121][4], double [121],
double [121], int [121], int *, int *, char *);
int calcBlockLayer(LAYER_PROPERTIES ***, int, int, double,
double, double, int, int, int, LAYER_PROPERTIES **,
int, int, int, int, short ***, float ***,
float ***, float ***, float ***, float ***,
float ***, float ***, float ***, float ***,
float ***,float ***);
COLOR ***calcBlockDiagramColors(double, double, double, int, int, int, double, int, LAYER_PROPERTIES **);
int calcReverseSection(double, double, double, double,
double, double, double, double ****, STORY ***, int *, int *);
COLOR **calcBlockSectionColors(double, double, double, double,
double, double, double, int *, int *);
int **calcBlockSectionIndexs(double, double, double, double,
double, double, double, int *, int *);
LAYER_PROPERTIES ***calcBlockSection(double, double, double, double,
double, double, double, int *, int *);
float ***calcBlockPropertiesData (PROPERTY_TYPE, double, double, double, double, int, int, int);
int calcDeformRemanence(LAYER_PROPERTIES ***, double ***,
STORY **, int, int, float **, float **);
int calcDeformAnisotropy(LAYER_PROPERTIES ***, double ***,
STORY **, int, int, float **, float **, float **);
int calcAlterationZone(LAYER_PROPERTIES ***, double ***, STORY **,
int, int, int, int, LAYER_PROPERTIES **, float ***,
float ***, float ***, float ***, float ***, float ***,
float ***, float ***, float ***, float ***, float ***);
int writeBlockFile(int ***, char *, int, int, int, int,
int, float [121], float [121][4], double [121][4],
double [121], double [121], int [121], int, int);
int writeBlockDiagramFile (int ***, char *, int, int, int, int);
int writeGeologyBlockFile (int ***, char *, int, int, int, int);
int readGeoBlockHeader (FILE *, int *, int *, int *, double *, char *);
int writeDicerBlockFile (int ***, char *, int, int, int, int);
void initBlockModelProfile (double ***, STORY **, int, int,
double, double, double, double, double);
void initBlockModelDicer (double ***, STORY **, int, int, int,
double, double, double);
void initBlockModelAnomMap (double ***, STORY **, int, int, int,
double, double, double);
LAYER_PROPERTIES *calcBlockPixel(double, double, double, int, int,
float *, float *, int, float *, float *, float *);
void calcAndSaveBlock (char *, char *, int, int, int);
void DoSaveBlockDicer (char *);
int writeBlockHeaderToFile (char *, int, int **, double, double, double,
double, double, double, int, int *, int, double, double,
double, int, int, int, int, int, int, LAYER_PROPERTIES **);
int write3DBlockToFile (char *, char ***, int, int, int, int);
int write3DIregBlockToFile (char *, char ***, int, int **, int);
int write2DBlockToFile (char *, char **, int, int, int);
int write2DBlock (FILE *, char **, int, int, int);
int writeLineThroughBlock (char *, double **, int);
int readBlockHeaderFromFile (char *, int *, int ***, double *, double *, double *,
double *, double *, double *, int *, int **, int *, double *, double *,
double *, int *, int *, int *, int *, int *, int*, LAYER_PROPERTIES **);
int read3DBlockFromFile (char *, char ***, int, int, int, int);
int read3DIregBlockFromFile (char *, char ***, int, int **, int);
int read2DBlockFromFile (char *, char **, int, int, int);
int read2DBlock (FILE *, char **, int, int, int);
int convertOldBlkToNewBlk (FILE_SPEC *, FILE_SPEC *, int, int, int);
int extractXYZFromFile (FILE_SPEC *, int, int, int, double, double, double,
double ***, int *);
int extractXYZHeader (FILE_SPEC *, int *);
double distanceToContact (double, double, double, OBJECT *);
int distanceToVector (double, OBJECT *, double *, double *, double *);
static int applyAlterations (double,
PROFILE_OPTIONS *, int, int, int, float ***,
float ***, float ***, float ***, float ***, float ***,
float ***, float ***, float ***, float ***, float ***);
#else
COLOR ***convertFloatBlockDataToColors();
COLOR ***convertIntBlockDataToColors();
int readBlockHeader ();
int readBlockFile ();
void calcBlockModel ();
int calcBlockLayer();
COLOR ***calcBlockDiagramColors();
COLOR **calcBlockSectionColors();
int **calcBlockSectionIndexs();
LAYER_PROPERTIES ***calcBlockSection();
float ***calcBlockPropertiesData ();
int calcDeformRemanence();
int calcDeformAnisotropy();
int calcAlterationZone();
LAYER_PROPERTIES *calcBlockPixel();
int writeBlockFile();
int writeGeologyBlockFile();
int readGeoBlockHeader ();
int writeDicerBlockFile();
void initBlockModelProfile ();
void initBlockModelDicer ();
void initBlockModelAnomMap ();
void calcAndSaveBlock ();
void DoSaveBlockDicer ();
int writeBlockHeaderToFile ();
int write3DBlockToFile ();
int write3DIregBlockToFile ();
int write2DBlockToFile ();
int write2DBlock ();
int writeLineThroughBlock ();
int readBlockHeaderFromFile ();
int read3DBlockFromFile ();
int read3DIregBlockFromFile ();
int read2DBlockFromFile ();
int read2DBlock ();
int convertOldBlkToNewBlk ();
int extractXYZFromFile ();
int extractXYZHeader ();
double distanceToContact ();
int distanceToVector ();
static int applyAlterations ();
#endif
/* ======================================================================
FUNCTION convertFloatBlockDataToColors
DESCRIPTION
Convert a data format to colors
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
COLOR ***
#if XVT_CC_PROTO
convertFloatBlockDataToColors(float ***blockValueData, int nx, int ny, int nz,
COLOR *lut, int numColors)
#else
convertFloatBlockDataToColors(blockValueData, nx, ny, nz, lut, numColors)
float ***blockValueData;
int nx, ny, nz;
COLOR *lut;
int numColors;
#endif
{
COLOR ***blockColorData = NULL;
double minValue, maxValue;
double valueInc, value;
int x, y, z, index;
if (!blockValueData || !lut)
return (blockColorData);
if (!(blockColorData = (COLOR ***) create3DArray(nz, nx, ny, sizeof(COLOR))))
return (blockColorData);
minValue = maxValue = (double) blockValueData[0][0][0];
for (z = 0; z < nz; z++)
{
for (x = 0; x < nx; x++)
{
for (y = 0; y < ny; y++)
{
value = (double) blockValueData[z][x][y];
if (value < minValue)
minValue = value;
else if (value > maxValue)
maxValue = value;
}
}
}
valueInc = (maxValue - minValue)/ ((double) numColors);
for (z = 0; z < nz; z++)
{
for (x = 0; x < nx; x++)
{
for (y = 0; y < ny; y++)
{
index = (int) floor (((double) blockValueData[z][x][ny-y-1] - minValue)/valueInc);
if (index < 0)
index = 0;
else if (index > numColors-1)
index = numColors-1;
blockColorData[z][x][y] = lut[index];
}
}
}
return (blockColorData);
}
/* ======================================================================
FUNCTION convertIntBlockDataToColors
DESCRIPTION
Convert a data format to colors
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
COLOR ***
#if XVT_CC_PROTO
convertIntBlockDataToColors(int ***blockValueData, int nx, int ny, int nz,
COLOR *lut, int numColors)
#else
convertIntBlockDataToColors(blockValueData, nx, ny, nz, lut, numColors)
int ***blockValueData;
int nx, ny, nz;
COLOR *lut;
int numColors;
#endif
{
COLOR ***blockColorData = NULL;
double minValue, maxValue;
double valueInc, value;
int x, y, z, index;
if (!blockValueData || !lut)
return (blockColorData);
if (!(blockColorData = (COLOR ***) create3DArray(nz, nx, ny, sizeof(COLOR))))
return (blockColorData);
minValue = maxValue = (double) blockValueData[0][0][0];
for (z = 0; z < nz; z++)
{
for (x = 0; x < nx; x++)
{
for (y = 0; y < ny; y++)
{
value = (double) blockValueData[z][x][y];
if (value < minValue)
minValue = value;
else if (value > maxValue)
maxValue = value;
}
}
}
valueInc = (maxValue - minValue)/ ((double) numColors);
for (z = 0; z < nz; z++)
{
for (x = 0; x < nx; x++)
{
for (y = 0; y < ny; y++)
{
index = (int) floor (((double) blockValueData[z][x][y] - minValue)/valueInc);
if (index < 0) index = 0;
else if (index > numColors-1) index = numColors-1;
blockColorData[z][x][y] = lut[index];
}
}
}
return (blockColorData);
}
/* ======================================================================
FUNCTION calcBlockLayer
DESCRIPTION
Calc the block a given layer height
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
int
#if XVT_CC_PROTO
calcBlockLayer(LAYER_PROPERTIES ***blockLayer, int nx, int ny,
double xLoc, double yLoc, double zLoc, int blockSize, int useTopo,
int numProps, LAYER_PROPERTIES **rockProps, int deformRemanence,
int deformAnisotropy, int alterationZones, int zIndex, short ***indexData,
float ***densityData, float ***magSusData, float ***remSusDecData,
float ***remSusAziData, float ***remSusStrData, float ***aniSusDipData,
float ***aniSusDDirData, float ***aniSusPitchData,float ***aniSusAxis1Data,
float ***aniSusAxis2Data,float ***aniSusAxis3Data)
#else
calcBlockLayer(blockLayer, nx, ny, xLoc, yLoc, zLoc, blockSize, useTopo,
numProps, rockProps, deformRemanence, deformAnisotropy,
alterationZones, zIndex, indexData, densityData, magSusData,
remSusDecData, remSusAziData, remSusStrData,
aniSusDipData, aniSusDDirData, aniSusPitchData,
aniSusAxis1Data, aniSusAxis2Data, aniSusAxis3Data)
LAYER_PROPERTIES ***blockLayer;
int nx, ny;
double xLoc, yLoc, zLoc;
int blockSize, useTopo, numProps;
LAYER_PROPERTIES **rockProps;
int deformRemanence, deformAnisotropy, alterationZones, zIndex;
short ***indexData;
float ***densityData, ***magSusData, ***remSusDecData,
***remSusAziData, ***remSusStrData, ***aniSusDipData,
***aniSusDDirData, ***aniSusPitchData, ***aniSusAxis1Data,
***aniSusAxis2Data, ***aniSusAxis3Data;
#endif
{
int numEvents = countObjects(NULL_WIN);
unsigned int rockType;
int eventIndex;
double zLocBase;
int x, y;
double ***xyzLoc = NULL, **topoOverlay = NULL;
STORY **histoire = NULL;
zLocBase = (double) zLoc - blockSize;
/* NOTE all the +1's on array dimensions and
** Index's is because the original reverseEvents
** call that is still used requires the xyzLoc
** and historie arrays to start at 1 (a hang over
** from when this code was in "Fortran" no less.
** Anyway the xyz Locations are also from index 1
** that is why xyzLoc has a third dim of 4 and not 3
*/
xyzLoc = (double ***) create3DArray (nx+1, ny+1, 4, sizeof(double));
histoire = (STORY **) create2DArray (nx+1, ny+1, sizeof(STORY));
if (!xyzLoc || !histoire)
{
destroy3DArray ((char ***) xyzLoc, nx+1, ny+1, 4);
destroy2DArray ((char **) histoire, nx+1, ny+1);
if (batchExecution)
fprintf (stderr, "Error, Not enough memory to calculate block Layer");
else
//xvt_dm_post_error ("Error, Not enough memory to calculate block Layer");
return (FALSE);
}
/* *********************************** */
/* Allocate Topography if it is needed */
if (useTopo && geologyOptions.useTopography)
{
topoOverlay = (double **) create2DArray (nx+1, ny+1, sizeof(double));
overlayTopoOnArray (topographyMap, TopoCol, TopoRow,
TopomapYW, TopomapYE, TopomapXW, TopomapXE,
topoOverlay, nx, ny,
yLoc-blockSize/2.0, (yLoc-blockSize/2.0) + (ny)*blockSize, /* give full extents, not 1/2 blocksize in */
xLoc-blockSize/2.0, (xLoc-blockSize/2.0) + (nx)*blockSize);
/*
yLoc-blockSize, yLoc + (ny-1)*blockSize,
xLoc-blockSize, xLoc + (nx-1)*blockSize);
*/
}
/* **************** */
/* Initialise Layer */
for (x = 0; x < nx; x++)
{
for (y = 0; y < ny; y++)
{
xyzLoc[x+1][y+1][1] = (x*blockSize) + xLoc;
xyzLoc[x+1][y+1][2] = ((ny-y-1)*blockSize) + yLoc;
xyzLoc[x+1][y+1][3] = zLoc;
histoire[x+1][y+1].again = TRUE;
izero(histoire[x+1][y+1].sequence);
}
}
if (abortLongJob ())
return (FALSE);
/* ************************************ */
/* Do the forward modeling of the layer */
reverseEvents (xyzLoc, histoire, nx, ny);
/* ***************************** */
/* Assign the block layer values */
for (y = 0; y < ny; y++)
{
for (x = 0; x < nx; x++)
{
/* Clear block if any of it is above topo */
if (topoOverlay && (zLocBase > topoOverlay[x+1][y+1]))
blockLayer[x][y] = (LAYER_PROPERTIES *) NULL;
else
{
taste(numEvents, histoire[x+1][y+1].sequence,
&rockType, &eventIndex);
blockLayer[x][y] = whichLayer (eventIndex, xyzLoc[x+1][y+1][1],
xyzLoc[x+1][y+1][2], xyzLoc[x+1][y+1][3]);
}
}
}
/* ************************************* */
/* Assign Deformable Remenance if needed */
if (deformRemanence && remSusDecData && remSusAziData)
calcDeformRemanence(blockLayer, xyzLoc, histoire, nx, ny,
remSusDecData[zIndex], remSusAziData[zIndex]);
/* ************************************* */
/* Assign Deformable Remenance if needed */
if (deformAnisotropy && aniSusDipData && aniSusDDirData && aniSusPitchData)
calcDeformAnisotropy(blockLayer, xyzLoc, histoire, nx, ny,
aniSusDipData[zIndex], aniSusDDirData[zIndex], aniSusPitchData[zIndex]);
/* ******************************************** */
/* Assign The storing arrays the correct values */
assignLayerInBlockModels (blockLayer,
zIndex, nx, ny, numProps, rockProps,
deformRemanence, deformAnisotropy,
indexData, densityData, magSusData, remSusDecData,
remSusAziData, remSusStrData, aniSusDipData,
aniSusDDirData, aniSusPitchData, aniSusAxis1Data,
aniSusAxis2Data, aniSusAxis3Data);
/* ********************************* */
/* Assign Alteration Zones if needed */
if (alterationZones)
calcAlterationZone(blockLayer, xyzLoc, histoire,
zIndex, nx, ny, numProps, rockProps,
densityData, magSusData, remSusDecData,
remSusAziData, remSusStrData, aniSusDipData,
aniSusDDirData, aniSusPitchData, aniSusAxis1Data,
aniSusAxis2Data, aniSusAxis3Data);
/* ************************ */
/* Free any memory Alocated */
if (xyzLoc)
destroy3DArray ((char ***) xyzLoc, nx+1, ny+1, 4);
if (histoire)
destroy2DArray ((char **) histoire, nx+1, ny+1);
if (topoOverlay)
destroy2DArray ((char **) topoOverlay, nx, ny);
#ifdef _MPL
printf(" Done."); fflush (stdout);
#endif
return (TRUE);
}
/* ======================================================================
FUNCTION calcBlockDiagram
DESCRIPTION
Calc the block between two 3d locations
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
COLOR ***
#if XVT_CC_PROTO
calcBlockDiagramColors(double minX, double minY, double minZ,
int nx, int ny, int nz, double blockSize,
int numLayersToDraw, LAYER_PROPERTIES **drawLayers)
#else
calcBlockDiagramColors(minX, minY, minZ, nx, ny, nz, blockSize,
numLayersToDraw, drawLayers)
double minX, minY, minZ;
int nx, ny, nz;
double blockSize;
int numLayersToDraw;
LAYER_PROPERTIES **drawLayers;
#endif
{
COLOR ***blockData = NULL;
double ***xyzLoc = NULL;
STORY **histoire = NULL;
int numEvents = countObjects(NULL_WIN);
LAYER_PROPERTIES *layerProp;
unsigned int rockType;
int eventIndex;
register int x, y, z, layer;
double zLoc, halfCube;
/* NOTE all the +1's on array dimensions and
** Index's is because the original reverseEvents
** call that is still used requires the xyzLoc
** and historie arrays to start at 1 (a hang over
** from when this code was in "Fortran" no less.
** Anyway the xyz Locations are also from index 1
** that is why xyzLoc has a third dim of 4 and not 3
*/
blockData = (COLOR ***) create3DArray (nz, nx, ny, sizeof(COLOR));
xyzLoc = (double ***) create3DArray (nx+1, ny+1, 4, sizeof(double));
histoire = (STORY **) create2DArray (nx+1, ny+1, sizeof(STORY));
if (!blockData || !xyzLoc || !histoire)
{
destroy3DArray ((char ***) blockData, nz, nx, ny);
destroy3DArray ((char ***) xyzLoc, nx+1, ny+1, 4);
destroy2DArray ((char **) histoire, nx+1, ny+1);
if (batchExecution)
fprintf (stderr, "Error, Not enough memory to calculate block Diagram");
else
//xvt_dm_post_error ("Error, Not enough memory to calculate block Diagram");
return ((COLOR ***) NULL);
}
halfCube = ((double) blockSize)/2.0;
for (z = 0, zLoc = minZ + halfCube; z < nz; z++, zLoc += blockSize)
{
incrementLongJob (INCREMENT_JOB);
/* **************** */
/* Initialise Layer */
for (x = 0; x < nx; x++)
{
for (y = 0; y < ny; y++)
{
xyzLoc[x+1][y+1][1] = (x*blockSize) + minX + halfCube;
xyzLoc[x+1][y+1][2] = (y*blockSize) + minY + halfCube;
xyzLoc[x+1][y+1][3] = zLoc;
histoire[x+1][y+1].again = TRUE;
izero(histoire[x+1][y+1].sequence);
}
}
if (abortLongJob ())
return (FALSE);
/* ************************************ */
/* Do the forward modeling of the layer */
reverseEvents (xyzLoc, histoire, nx, ny);
/* ***************************** */
/* Assign the block layer values */
for (y = 0; y < ny; y++)
{
for (x = 0; x < nx; x++)
{
taste(numEvents, histoire[x+1][y+1].sequence,
&rockType, &eventIndex);
if (layerProp = whichLayer (eventIndex, xyzLoc[x+1][y+1][1],
xyzLoc[x+1][y+1][2],
xyzLoc[x+1][y+1][3]))
{
blockData[z][x][y] = COLOR_INVALID;
for (layer = 0; layer < numLayersToDraw; layer++)
{
if (drawLayers[layer] == layerProp)
{
blockData[z][x][y] = XVT_MAKE_COLOR(layerProp->color.red,
layerProp->color.green,
layerProp->color.blue);
break;
}
}
}
}
}
}
/* ************************ */
/* Free any memory Alocated */
if (xyzLoc)
destroy3DArray ((char ***) xyzLoc, nx+1, ny+1, 4);
if (histoire)
destroy2DArray ((char **) histoire, nx+1, ny+1);
return (blockData);
}
/* ======================================================================
FUNCTION calcBlockSection
DESCRIPTION
Calc the block a Position, dip direction, and pitch
NOTE this only does a 2d slice between the start and end
locations, not a 3d block.
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
int
#if XVT_CC_PROTO
calcReverseSection(double xLocStart, double yLocStart, double zLocStart,
double xLocEnd, double yLocEnd, double zLocEnd,
double cubeSize, double ****pXyzLoc, STORY ***pHistoire,
int *pDim1, int *pDim2)
#else
calcReverseSection(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, pXyzLoc, pHistoire, pDim1, pDim2)
double xLocStart, yLocStart, zLocStart;
double xLocEnd, yLocEnd, zLocEnd;
double cubeSize;
double ****pXyzLoc;
STORY ***pHistoire;
int *pDim1, *pDim2;
#endif
{
double xInc, yInc, zInc;
double diffX, diffY, diffZ;
double halfCube;
int dim1, dim2;
int i, j;
double ***xyzLoc = NULL;
STORY **histoire = NULL;
halfCube = cubeSize/2.0;
diffX = xLocEnd - xLocStart;
diffY = yLocEnd - yLocStart;
diffZ = zLocEnd - zLocStart;
if (fabs(diffZ) < TOLERANCE) /* No Z height */
{ /* first dim is line joining corners */
dim1 = (int) floor (diffX/cubeSize);
dim2 = (int) floor (diffY/cubeSize); /* second dimension is the height */
xInc = diffX/dim1; yInc = diffY/dim2; zInc = 0.0;
}
else
{ /* first dim is line joining corners */
dim1 = (int) floor (sqrt(diffX*diffX + diffY*diffY)/cubeSize);
dim2 = (int) floor (diffZ/cubeSize); /* second dimension is the height */
xInc = diffX/dim1; yInc = diffY/dim1; zInc = diffZ/dim2;
}
xLocStart += xInc/2.0;
yLocStart += yInc/2.0;
zLocStart += zInc/2.0;
/* NOTE all the +1's on array dimensions and
** Index's is because the original reverseEvents
** call that is still used requires the xyzLoc
** and historie arrays to start at 1 (a hang over
** from when this code was in "Fortran" no less.
** Anyway the xyz Locations are also from index 1
** that is why xyzLoc has a third dim of 4 and not 3
*/
xyzLoc = (double ***) create3DArray (dim1+1, dim2+1, 4, sizeof(double));
histoire = (STORY **) create2DArray (dim1+1, dim2+1, sizeof(STORY));
if (!xyzLoc || !histoire)
{
destroy3DArray ((char ***) xyzLoc, dim1+1, dim2+1, 4);
destroy2DArray ((char **) histoire, dim1+1, dim2+1);
if (batchExecution)
fprintf (stderr, "Error, Not enough memory to calculate block Layer");
else
//xvt_dm_post_error ("Error, Not enough memory to calculate block Layer");
return (FALSE);
}
/* **************** */
/* Initialise Layer */
if (fabs(diffZ) < TOLERANCE) /* No Z height */
{
for (i = 0; i < dim1; i++)
{
for (j = 0; j < dim2; j++)
{
xyzLoc[i+1][j+1][1] = (i*xInc) + xLocStart;
xyzLoc[i+1][j+1][2] = (j*yInc) + yLocStart;
xyzLoc[i+1][j+1][3] = zLocStart;
histoire[i+1][j+1].again = TRUE;
izero(histoire[i+1][j+1].sequence);
}
}
}
else
{
for (i = 0; i < dim1; i++)
{
for (j = 0; j < dim2; j++)
{
xyzLoc[i+1][j+1][1] = (i*xInc) + xLocStart;
xyzLoc[i+1][j+1][2] = (i*yInc) + yLocStart;
xyzLoc[i+1][j+1][3] = (j*zInc) + zLocStart;
histoire[i+1][j+1].again = TRUE;
izero(histoire[i+1][j+1].sequence);
}
}
}
if (abortLongJob ())
return (FALSE);
/* ************************************ */
/* Do the forward modeling of the layer */
reverseEvents (xyzLoc, histoire, dim1, dim2);
*pDim1 = dim1;
*pDim2 = dim2;
*pXyzLoc = xyzLoc;
*pHistoire = histoire;
return (TRUE);
}
/* ======================================================================
FUNCTION calcBlockSection
DESCRIPTION
Calc the block a Position, dip direction, and pitch
NOTE this only does a 2d slice between the start and end
locations, not a 3d block.
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
COLOR **
#if XVT_CC_PROTO
calcBlockSectionColors(double xLocStart, double yLocStart, double zLocStart,
double xLocEnd, double yLocEnd, double zLocEnd,
double cubeSize, int *pDim1, int *pDim2)
#else
calcBlockSectionColors(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, pDim1, pDim2)
double xLocStart, yLocStart, zLocStart;
double xLocEnd, yLocEnd, zLocEnd;
double cubeSize;
int *pDim1, *pDim2;
#endif
{
COLOR **blockLayer;
LAYER_PROPERTIES *layerProp;
int numEvents = countObjects(NULL_WIN);
unsigned int rockType;
int eventIndex, dim1, dim2;
int i, j;
double ***xyzLoc = NULL;
STORY **histoire = NULL;
if (batchExecution)
{
fprintf(stdout,"\nCalculating Block Section."); fflush (stdout);
}
if (!calcReverseSection(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, &xyzLoc, &histoire, &dim1, &dim2))
return (NULL);
blockLayer = (COLOR **) create2DArray (dim1, dim2, sizeof(COLOR));
if (!blockLayer || !xyzLoc || !histoire)
{
destroy2DArray ((char **) blockLayer, dim1, dim2);
destroy3DArray ((char ***) xyzLoc, dim1+1, dim2+1, 4);
destroy2DArray ((char **) histoire, dim1+1, dim2+1);
if (batchExecution)
fprintf (stderr, "Error, Not enough memory to calculate block Layer");
else
//xvt_dm_post_error ("Error, Not enough memory to calculate block Layer");
return (NULL);
}
/* ***************************** */
/* Assign the block layer values */
for (j = 0; j < dim2; j++)
{
for (i = 0; i < dim1; i++)
{
taste(numEvents, histoire[i+1][j+1].sequence,
&rockType, &eventIndex);
if (layerProp = whichLayer (eventIndex, xyzLoc[i+1][j+1][1],
xyzLoc[i+1][j+1][2], xyzLoc[i+1][j+1][3]))
blockLayer[i][j] = XVT_MAKE_COLOR(layerProp->color.red,
layerProp->color.green,
layerProp->color.blue);
else
blockLayer[i][j] = COLOR_INVALID;
}
}
/* ************************ */
/* Free any memory Alocated */
if (xyzLoc)
destroy3DArray ((char ***) xyzLoc, dim1+1, dim2+1, 4);
if (histoire)
destroy2DArray ((char **) histoire, dim1+1, dim2+1);
*pDim1 = dim1;
*pDim2 = dim2;
if (batchExecution)
{
fprintf(stdout," Done."); fflush (stdout);
}
return (blockLayer);
}
/* ======================================================================
FUNCTION calcBlockSectionIndexs
DESCRIPTION
Calc the block a Position, dip direction, and pitch
NOTE this only does a 2d slice between the start and end
locations, not a 3d block.
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
int **
#if XVT_CC_PROTO
calcBlockSectionIndexs(double xLocStart, double yLocStart, double zLocStart,
double xLocEnd, double yLocEnd, double zLocEnd,
double cubeSize, int *pDim1, int *pDim2)
#else
calcBlockSectionIndexs(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, pDim1, pDim2)
double xLocStart, yLocStart, zLocStart;
double xLocEnd, yLocEnd, zLocEnd;
double cubeSize;
int *pDim1, *pDim2;
#endif
{
int **blockLayer;
LAYER_PROPERTIES *layerProp, *properties[50];
int numEvents = countObjects(NULL_WIN);
unsigned int rockType;
int eventIndex, dim1, dim2;
int i, j, numProps, prop;
double ***xyzLoc = NULL;
STORY **histoire = NULL;
if (batchExecution)
{
fprintf(stdout,"\nCalculating Block Section."); fflush (stdout);
}
if (!calcReverseSection(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, &xyzLoc, &histoire, &dim1, &dim2))
return (NULL);
blockLayer = (int **) create2DArray (dim1, dim2, sizeof(int));
if (!blockLayer || !xyzLoc || !histoire)
{
destroy2DArray ((char **) blockLayer, dim1, dim2);
destroy3DArray ((char ***) xyzLoc, dim1+1, dim2+1, 4);
destroy2DArray ((char **) histoire, dim1+1, dim2+1);
if (batchExecution)
fprintf (stderr, "Error, Not enough memory to calculate block Layer");
else
//xvt_dm_post_error ("Error, Not enough memory to calculate block Layer");
return (NULL);
}
/* ***************************** */
/* Assign the block layer values */
numProps = assignPropertiesForStratLayers (properties, 50);
for (j = 0; j < dim2; j++)
{
for (i = 0; i < dim1; i++)
{
taste(numEvents, histoire[i+1][j+1].sequence,
&rockType, &eventIndex);
layerProp = whichLayer (eventIndex, xyzLoc[i+1][j+1][1],
xyzLoc[i+1][j+1][2], xyzLoc[i+1][j+1][3]);
blockLayer[i][j] = -1; /* No layer */
for (prop = 0; prop < numProps; prop++)
{
if (properties[prop] == layerProp)
{
blockLayer[i][j] = prop;
break;
}
}
}
}
/* ************************ */
/* Free any memory Alocated */
if (xyzLoc)
destroy3DArray ((char ***) xyzLoc, dim1+1, dim2+1, 4);
if (histoire)
destroy2DArray ((char **) histoire, dim1+1, dim2+1);
*pDim1 = dim1;
*pDim2 = dim2;
if (batchExecution)
{
fprintf(stdout," Done."); fflush (stdout);
}
return (blockLayer);
}
/* ======================================================================
FUNCTION calcBlockSection
DESCRIPTION
Calc the block a Position, dip direction, and pitch
NOTE this only does a 2d slice between the start and end
locations, not a 3d block.
RETURNED
TRUE - sucess, FALSE - error
====================================================================== */
LAYER_PROPERTIES ***
#if XVT_CC_PROTO
calcBlockSection(double xLocStart, double yLocStart, double zLocStart,
double xLocEnd, double yLocEnd, double zLocEnd,
double cubeSize, int *pDim1, int *pDim2)
#else
calcBlockSection(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, pDim1, pDim2)
double xLocStart, yLocStart, zLocStart;
double xLocEnd, yLocEnd, zLocEnd;
double cubeSize;
int *pDim1, *pDim2;
#endif
{
LAYER_PROPERTIES ***blockLayer;
int numEvents = countObjects(NULL_WIN);
unsigned int rockType;
int eventIndex, dim1, dim2;
int i, j;
double ***xyzLoc = NULL;
STORY **histoire = NULL;
if (batchExecution)
{
fprintf(stdout,"\nCalculating Block Section."); fflush (stdout);
}
if (!calcReverseSection(xLocStart, yLocStart, zLocStart,
xLocEnd, yLocEnd, zLocEnd,
cubeSize, &xyzLoc, &histoire, &dim1, &dim2))
return (NULL);