forked from markjessell/functionNoddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacmag3.c
1752 lines (1602 loc) · 55.2 KB
/
Macmag3.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
====================================================================== */
#include "xvt.h"
#include "noddy.h"
#include <math.h>
#define DEBUG(X)
#ifdef OBSOLETE
enum { GRAVITY = 1, MAGNETICS };
/* ********************************** */
/* External Globals used in this file */
extern GEOLOGY_OPTIONS geologyOptions;
extern GEOPHYSICS_OPTIONS geophysicsOptions;
extern double iscale; /* scaling factor for geology */
extern double *** qdtrimat();
#if XVT_CC_PROTO
void tasteRemanent(int, int, int, int, int, double, double , double, long, long,
double *, double *, int, LAYER_PROPERTIES *, unsigned int);
#else
void tasteRemanent();
#endif
/* ************************* */
/* Globals used in this file */
void ReadData ();
void AddFields ();
void AddFields2d ();
void MakeZero ();
#ifdef _MPL
void p_MakeZero ();
extern void mapOverProcessors ();
#endif
void WriteMap ();
void WriteProfile ();
void MagGrav ();
void NameFile ();
void PutNum ();
void gm_main(blockData,
filename, intblock, nlitho, xmax, ymax, zmax,
rho, sus, ken, ang, plu, num, iRem, iAni)
#ifdef _MPL
plural int ***blockData;
#else
int ***blockData;
#endif
char *filename;
int intblock;
int nlitho;
int xmax, ymax, zmax;
float rho[121],sus[121][4];
double ken[121][4],ang[121],plu[121];
int num[121];
int iRem, iAni;
{
int xmax2, ymax2;
register int z,i,j;
char newgrav[255], newmag[255], *ptr;
int vrpol;
char filename1[255];
float airgap = (float) geophysicsOptions.altitude;
int msize = geophysicsOptions.calculationRange;
float grid = (float) geophysicsOptions.cubeSize;
float posn[7], dat[5];
int masterSizeX, masterSizeY;
double ***slave = NULL;
#ifdef _MPL
plural double ***master = NULL;
int promag, prograv, smag, sgrav;
#else
double ***master = NULL;
FILE *promag, *prograv, *smag, *sgrav;
#endif
/* initialise the arrays the code seems build around */
if (ymax == 1)
{
posn[1] = (float) geophysicsOptions.upperNorthEast_X;
posn[2] = (float) geophysicsOptions.upperNorthEast_Y;
posn[3] = (float) geophysicsOptions.lowerSouthWest_Z;
posn[4] = (float) geophysicsOptions.length;
posn[5] = (float) geophysicsOptions.orientation;
posn[6] = (float) geophysicsOptions.upperNorthEast_Z;
dat[2] = (float) -(geophysicsOptions.orientation + 90.0
+ geophysicsOptions.declination);
}
else
{
posn[1] = (float) geophysicsOptions.lowerSouthWest_X;
posn[2] = (float) geophysicsOptions.lowerSouthWest_Y;
posn[3] = (float) geophysicsOptions.lowerSouthWest_Z;
posn[4] = (float) geophysicsOptions.upperNorthEast_X;
posn[5] = (float) geophysicsOptions.upperNorthEast_Y;
posn[6] = (float) geophysicsOptions.upperNorthEast_Z;
dat[2] = (float) geophysicsOptions.declination;
}
dat[1] = (float) geophysicsOptions.inclination;
dat[3] = (float) geophysicsOptions.intensity;
DEBUG(printf("\nOUTPUT FILE = %s, msize = %d",filename,msize);)
if (ymax==1)
NameFile(filename, newgrav, newmag, 1);
else
NameFile(filename, newgrav, newmag, 2);
DEBUG(printf("\nMAG FILE = %s",newmag);)
DEBUG(printf("\nGRAV FILE = %s",newgrav);)
DEBUG(printf("\nxmax = %d, ymax = %d, msize = %d", xmax, ymax, msize);)
xmax2 = (int) (xmax+2*msize);
ymax2 = (int) (ymax+2*msize);
DEBUG(printf("\nxmax2 = %d, ymax2 = %d", xmax2, ymax2);)
slave = (double ***) qdtrimat(0,(int)(msize*2+1),0,(int)(msize*2+1),0,4);
#ifdef _MPL
mapOverProcessors (xmax2, ymax2, &masterSizeX, &masterSizeY);
#endif
if (ymax == 1) /* Realy a profile as its only 1 thick */
{
#ifdef _MPL
master = (plural double ***) p_qdtrimat(0,masterSizeX,0,1,0,2);
p_MakeZero(master,masterSizeX,1);
#else
master = (double ***) qdtrimat(0,xmax2,0,1,0,2);
MakeZero(master,xmax2,1);
#endif
#ifdef _MPL
printf("\nCalculating Anomalies."); fflush (stdout);
#endif
for (z = 0; z < zmax; z++)
{
MagGrav(msize*2+1,msize*2+1,grid,(z+0.5)*grid+airgap,slave,dat);
AddFields2d(master, slave, xmax ,sus, rho, msize,
ken, ang, plu, iRem, iAni, dat, blockData[z]);
}
#ifdef _MPL
printf(" Done."); fflush (stdout);
#endif
#ifdef _MPL
promag = open(newmag, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRWXG);
prograv = open(newgrav, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRWXG);
#else
promag = (FILE *) MacNewOpen(newmag);
prograv= (FILE *) MacNewOpen(newgrav);
#endif
WriteProfile(xmax,master,GRAVITY,prograv,msize,
ymax,zmax,dat,posn,grid,airgap);
DEBUG(printf("\nGM_MAIN: done WriteProfile");)
WriteProfile(xmax,master,MAGNETICS,promag,msize,
ymax,zmax,dat,posn,grid,airgap);
DEBUG(printf("\nGM_MAIN: done WriteProfile");)
#ifdef _MPL
close(promag);
close(prograv);
#else
fflush(promag); fclose(promag);
fflush(prograv); fclose(prograv);
#endif
freeqdtrimat(slave,0,(msize*2+1),0,(msize*2+1),0,4);
#ifdef _MPL
p_freeqdtrimat(master,0,masterSizeX,0,1,0,2);
#else
freeqdtrimat(master,0,xmax2,0,1,0,2);
#endif
}
else if (ymax >= 2) /* this is a full map */
{
#ifdef _MPL
master = (plural double ***) p_qdtrimat(0,masterSizeX,0,masterSizeY,0,2);
p_MakeZero(master,masterSizeX,masterSizeY);
#else
master = (double ***) qdtrimat(0,xmax2,0,ymax2,0,2);
MakeZero(master,xmax2,ymax2);
#endif
#ifdef _MPL
printf("\nCalculating Anomalies."); fflush (stdout);
#endif
for (z = 0; z < zmax; z++)
{
DEBUG(printf("\nGM_MAIN: dong MagGrav z = %d of %d\n",z, zmax);)
MagGrav(msize*2+1,msize*2+1,grid,(z+0.5)*grid+airgap,slave,dat);
DEBUG(printf("\nGM_MAIN: dong AdFields\n");)
AddFields(master, slave, xmax, ymax, sus, rho, msize,
ken, ang, plu, iRem, iAni, dat, blockData[z], z+1);
} /* end for Z */
#ifdef _MPL
printf(" Done."); fflush (stdout);
#endif
#ifdef _MPL
smag = open(newmag, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRWXG);
sgrav = open(newgrav, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRWXG);
#else
smag = (FILE *) MacNewOpen(newmag);
sgrav= (FILE *) MacNewOpen(newgrav);
#endif
WriteMap(xmax, ymax, master, MAGNETICS,
smag, msize, zmax, dat, posn, grid, airgap);
DEBUG(printf("\nGM_MAIN: done WriteMap\n");)
WriteMap(xmax, ymax, master, GRAVITY,
sgrav, msize, zmax, dat, posn, grid, airgap);
#ifdef _MPL
close(smag);
close(sgrav);
#else
fflush(smag); fclose(smag);
fflush(sgrav); fclose(sgrav);
#endif
freeqdtrimat(slave,0,msize*2+1,0,msize*2+1,0,4);
#ifdef _MPL
p_freeqdtrimat(master,0,masterSizeX,0,masterSizeY,0,2);
#else
freeqdtrimat(master,0,xmax2,0,ymax2,0,2);
#endif
}
#if (XVTWS == MACWS) /* set MAC file attributes for anom files */
{
FILE_SPEC fileSpec;
xvt_fsys_get_dir (&(fileSpec.dir));
strcpy (fileSpec.name, newmag);
xvt_fsys_set_file_attr(&fileSpec,XVT_FILE_ATTR_TYPESTR, (long) "TEXT");
xvt_fsys_set_file_attr(&fileSpec,XVT_FILE_ATTR_CREATORSTR, (long) "Nody");
strcpy (fileSpec.name, newgrav);
xvt_fsys_set_file_attr(&fileSpec,XVT_FILE_ATTR_TYPESTR, (long) "TEXT");
xvt_fsys_set_file_attr(&fileSpec,XVT_FILE_ATTR_CREATORSTR, (long) "Nody");
}
#endif
DEBUG(printf("\nGM_MAIN: finished");)
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
void ReadData(in, xmax,ymax,zmax,num,rho,sus,sp,nlitho,dat,msize,
airgap,posn,ken,ang,plu,piRem,piAni)
FILE *in;
float *sp,rho[121],sus[121][4],dat[5],*airgap,posn[7];
int *xmax,*ymax,*zmax,num[121],*nlitho;
int *msize;
double ken[121][4],ang[121],plu[121];
int *piRem,*piAni;
{
float refdens,refsus,drho,dsus,dummy,dken,dplu,dang;
float dsus2,dsus3,dsus0,dken2,dken3;
BOOLEAN iopen;
int ref,layers,test, iinum;
register int i;
fscanf(in,"%d",&test);
if (test==7777)
{
iopen=0;
fclose(in);
xvt_dm_post_error("Sorry, This is an old Block Model File");
return;
}
else if(test!=7771)
{
iopen=0;
fclose(in);
xvt_dm_post_error("This is not a Block Model File");
return;
}
else
{
*piRem=0;
*piAni=0;
fscanf(in,"%f %f %f %f",&dat[1],&dat[2],&dat[3],airgap);
fscanf(in,"%d %d %d %d",xmax,ymax,zmax,&layers);
fscanf(in,"%f",&dummy);
fscanf(in,"%d",msize);
fscanf(in,"%f %f %f",&posn[1],&posn[2],&posn[3]);
fscanf(in,"%f %f %f",&posn[4],&posn[5],&posn[6]);
*sp = dummy;
*nlitho = layers;
for (i = 0; i <= layers; i++)
{
fscanf(in,"%d %f %f %f %f %f %f %f %f %f %f",
&iinum,&drho,&dsus,&dsus2,&dsus3,&dsus0,
&dken,&dken2,&dken3,&dplu,&dang);
num[i]=iinum;
rho[iinum] = 1000*drho;
sus[iinum][1] = dsus;
sus[iinum][2] = dsus2;
sus[iinum][3] = dsus3;
sus[iinum][0] = dsus0;
ken[iinum][1] = dken;
ken[iinum][2] = dken2;
ken[iinum][3] = dken3;
plu[iinum] = dplu;
ang[iinum] = dang;
if (dken != 0.0)
*piRem = 1;
if (dsus0 != 0.0)
*piAni = 1;
}
}
}
/*----------------------------------------------------------------------*/
void AddFields(master, slave, xmax, ymax, sus, rho, msize,
ken, ang, plu, iRem, iAni, dat, blockData, z)
double ***slave;
int xmax,ymax;
float sus[121][4],rho[121];
int msize;
double ken[121][4],ang[121],plu[121];
int iRem,iAni;
float dat[5];
int z;
#ifdef _MPL
plural double ***master;
plural int **blockData;
#else
double ***master;
int **blockData;
#endif
{
double finc,angl,totl;
double sf,cf,sa,ca,cacf,sacf;
double totlsacf,totlcacf,totlsf;
register int j, i, dx, dy, nbytes;
double RemIncl, RemAngle;
double gx1 = geophysicsOptions.lowerSouthWest_X;
double gy1 = geophysicsOptions.lowerSouthWest_Y;
double gz1 = geophysicsOptions.lowerSouthWest_Z;
double gx2 = geophysicsOptions.upperNorthEast_X;
double gy2 = geophysicsOptions.upperNorthEast_Y;
double gz2 = geophysicsOptions.upperNorthEast_Z;
long gblock = geophysicsOptions.cubeSize;
LAYER_PROPERTIES *layerProps[30];
int layerEventNum[30];
unsigned int layerFlavor[30];
#ifdef _MPL
plural double result;
plural double * plural store;
plural register int p;
plural register int u, v;
plural register int xIndex, yIndex, xxIndex, yyIndex;
plural double kentotl1,sustotl1,kentotl2,sustotl2,kentotl3,sustotl3;
plural double JR1, JR2, JR3, cRf, sRf;
#else
register int p;
register int u, v;
register int xIndex, yIndex, xxIndex, yyIndex;
double kentotl1,sustotl1,kentotl2,sustotl2,kentotl3,sustotl3;
double JR1, JR2, JR3, cRf, sRf;
#endif
finc = dat[1];
angl = dat[2];
totl = dat[3];
sf = sin(finc*0.01745329);
cf = cos(finc*0.01745329);
sa = sin(angl*0.01745329);
ca = cos(angl*0.01745329);
cacf =ca*cf;
sacf=sa*cf;
#ifdef _MPL
nbytes = sizeof(plural double);
#endif
if (iRem==1 && iAni==1)
{
assignPropertiesForStratLayers (layerProps, 30);
assignEventNumForStratLayers (layerEventNum, 30);
assignFlavorForStratLayers (layerFlavor, 30);
#ifdef _MPL
for (v = iyproc, yIndex = 0; v < ymax; v += nyproc, yIndex++)
#else
for (yIndex = 1; yIndex <= ymax; yIndex++)
#endif
{
incrementLongJob (INCREMENT_JOB);
#ifdef _MPL
for (u = ixproc, xIndex = 0; u < xmax; u += nxproc, xIndex++)
#else
for (xIndex = 1; xIndex <= xmax; xIndex++)
#endif
{
p = blockData[xIndex][yIndex];
#ifndef _MPL
RemAngle = ang[p]; /* layerProps[p-1]->angleWithNorth */
RemIncl = plu[p]; /* layerProps[p-1]->inclination */
if (geophysicsOptions.deformableRemanence && ken[p][1])
tasteRemanent(xIndex, yIndex, z, p, ymax, gx1, gy1, gz2, gblock,
(long) msize, &RemIncl, &RemAngle, layerEventNum[p-1],
layerProps[p-1], layerFlavor[p-1]);
#endif
#ifdef _MPL
cRf=p_cos( plu[p] * 0.01745329 );
sRf=p_sin( plu[p] * 0.01745329 );
#else
cRf=cos( RemIncl * 0.01745329 );
sRf=sin( RemIncl * 0.01745329 );
#endif
kentotl1=ken[p][1];
kentotl2=ken[p][2];
kentotl3=ken[p][3];
sustotl1=sus[p][1]*totl;
sustotl2=sus[p][2]*totl;
sustotl3=sus[p][3]*totl;
#ifdef _MPL
JR1=sustotl1*(sacf+kentotl1*cRf*p_sin((angl-ang[p])*0.01745329));
JR2=sustotl2*(cacf+kentotl2*cRf*p_cos((angl-ang[p])*0.01745329));
#else
JR1=sustotl1*(sacf+kentotl1*cRf*sin((angl-RemAngle)*0.01745329));
JR2=sustotl2*(cacf+kentotl2*cRf*cos((angl-RemAngle)*0.01745329));
#endif
JR3=sustotl3*(sf+kentotl3*sRf);
for(i = 1; i <= msize*2 + 1; i++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of */
dx = i-1; /* the PE's */
xxIndex = (u+dx) / nxproc;
#endif
for(j = 1; j <= msize*2 + 1; j++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of
** the PE's */
dy = -(j-1);
/* (v-dy) uses "-" as dy is -ve to go south */
yyIndex = (v-dy) / nyproc;
if ((dx == 0) && (dy == 0))
{
master[xxIndex][yyIndex][MAGNETICS]
+= -JR1*slave[i][j][0]
-JR2*slave[i][j][1]
-JR3*slave[i][j][2];
master[xxIndex][yyIndex][GRAVITY]
+= rho[p]*slave[i][j][3];
}
else
{
store = &(master[xxIndex][yyIndex][MAGNETICS]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += -JR1*slave[i][j][0] -JR2*slave[i][j][1]
-JR3*slave[i][j][2];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
store = &(master[xxIndex][yyIndex][GRAVITY]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += rho[p]*slave[i][j][3];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
}
#else
master[xIndex+i-1][yIndex+j-1][MAGNETICS]
+= -JR1*slave[i][j][0]
-JR2*slave[i][j][1]
-JR3*slave[i][j][2];
master[xIndex+i-1][yIndex+j-1][GRAVITY]
+= rho[p]*slave[i][j][3];
#endif
}
}
}
}
} /* if(iRem) */
else if(iAni==0 && iRem==1)
{
assignPropertiesForStratLayers (layerProps, 30);
assignEventNumForStratLayers (layerEventNum, 30);
assignFlavorForStratLayers (layerFlavor, 30);
#ifdef _MPL
for (v = iyproc, yIndex = 0; v < ymax; v += nyproc, yIndex++)
#else
for (yIndex = 1; yIndex <= ymax; yIndex++)
#endif
{
incrementLongJob (INCREMENT_JOB);
#ifdef _MPL
for (u = ixproc, xIndex = 0; u < xmax; u += nxproc, xIndex++)
#else
for (xIndex = 1; xIndex <= xmax; xIndex++)
#endif
{
p = blockData[xIndex][yIndex];
#ifndef _MPL
RemAngle = ang[p]; /* layerProps[p-1]->angleWithNorth */
RemIncl = plu[p]; /* layerProps[p-1]->inclination */
if (geophysicsOptions.deformableRemanence && ken[p][1])
tasteRemanent(xIndex, yIndex, z, p, ymax, gx1, gy1, gz2, gblock,
(long) msize, &RemIncl, &RemAngle, layerEventNum[p-1],
layerProps[p-1], layerFlavor[p-1]);
#endif
#ifdef _MPL
cRf=p_cos( plu[p] * 0.01745329 );
sRf=p_sin( plu[p] * 0.01745329 );
#else
cRf=cos( RemIncl * 0.01745329 );
sRf=sin( RemIncl * 0.01745329 );
#endif
kentotl1=ken[p][1];
sustotl1=sus[p][1]*totl;
#ifdef _MPL
JR1=sustotl1*(sacf+kentotl1*cRf*p_sin((angl-ang[p])*0.01745329));
JR2=sustotl1*(cacf+kentotl1*cRf*p_cos((angl-ang[p])*0.01745329));
#else
JR1=sustotl1*(sacf+kentotl1*cRf*sin((angl-RemAngle)*0.01745329));
JR2=sustotl1*(cacf+kentotl1*cRf*cos((angl-RemAngle)*0.01745329));
#endif
JR3=sustotl1*(sf+kentotl1*sRf);
for(i = 1; i <= msize*2 + 1; i++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of */
dx = i-1; /* the PE's */
xxIndex = (u+dx) / nxproc;
#endif
for(j = 1; j <= msize*2 + 1; j++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of
** the PE's */
dy = -(j-1);
/* (v-dy) uses "-" as dy is -ve to go south */
yyIndex = (v-dy) / nyproc;
if ((dx == 0) && (dy == 0))
{
master[xxIndex][yyIndex][MAGNETICS]
+= -JR1*slave[i][j][0]
-JR2*slave[i][j][1]
-JR3*slave[i][j][2];
master[xxIndex][yyIndex][GRAVITY]
+= rho[p]*slave[i][j][3];
}
else
{
store = &(master[xxIndex][yyIndex][MAGNETICS]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += -JR1*slave[i][j][0] -JR2*slave[i][j][1]
-JR3*slave[i][j][2];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
store = &(master[xxIndex][yyIndex][GRAVITY]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += rho[p]*slave[i][j][3];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
}
#else
master[xIndex+i-1][yIndex+j-1][MAGNETICS]
+= -JR1*slave[i][j][0]
-JR2*slave[i][j][1]
-JR3*slave[i][j][2];
master[xIndex+i-1][yIndex+j-1][GRAVITY]
+= rho[p]*slave[i][j][3];
#endif
}
}
}
}
} /* end else if(Iani==0 && iRem==1) */
else if(iAni==1 && iRem==0)
{
totlsacf=totl*sacf;
totlcacf=totl*cacf;
totlsf =totl*sf;
#ifdef _MPL
for (v = iyproc, yIndex = 0; v < ymax; v += nyproc, yIndex++)
#else
for (yIndex = 1; yIndex <= ymax; yIndex++)
#endif
{
incrementLongJob (INCREMENT_JOB);
#ifdef _MPL
for (u = ixproc, xIndex = 0; u < xmax; u += nxproc, xIndex++)
#else
for (xIndex = 1; xIndex <= xmax; xIndex++)
#endif
{
p = blockData[xIndex][yIndex];
JR1=sus[p][1]*totlsacf;
JR2=sus[p][2]*totlcacf;
JR3=sus[p][3]*totlsf;
for(i = 1; i <= msize*2 + 1; i++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of */
dx = i-1; /* the PE's */
xxIndex = (u+dx) / nxproc;
#endif
for(j = 1; j <= msize*2 + 1; j++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of
** the PE's */
dy = -(j-1);
/* (v-dy) uses "-" as dy is -ve to go south */
yyIndex = (v-dy) / nyproc;
if ((dx == 0) && (dy == 0))
{
master[xxIndex][yyIndex][MAGNETICS]
+= -JR1*slave[i][j][0]
-JR2*slave[i][j][1]
-JR3*slave[i][j][2];
master[xxIndex][yyIndex][GRAVITY]
+= rho[p]*slave[i][j][3];
}
else
{
store = &(master[xxIndex][yyIndex][MAGNETICS]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += -JR1*slave[i][j][0] -JR2*slave[i][j][1]
-JR3*slave[i][j][2];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
store = &(master[xxIndex][yyIndex][GRAVITY]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += rho[p]*slave[i][j][3];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
}
#else
master[xIndex+i-1][yIndex+j-1][MAGNETICS]
+= -JR1*slave[i][j][0]
-JR2*slave[i][j][1]
-JR3*slave[i][j][2];
master[xIndex+i-1][yIndex+j-1][GRAVITY]
+= rho[p]*slave[i][j][3];
#endif
}
}
}
}
}
else /* no Remenance Mag and no anizotropy*/
{
#ifdef _MPL
for (v = iyproc, yIndex = 0; v < ymax; v += nyproc, yIndex++)
#else
for (yIndex = 1; yIndex <= ymax; yIndex++)
#endif
{
incrementLongJob (INCREMENT_JOB);
#ifdef _MPL
for (u = ixproc, xIndex = 0; u < xmax; u += nxproc, xIndex++)
#else
for (xIndex = 1; xIndex <= xmax; xIndex++)
#endif
{
p = blockData[xIndex][yIndex];
for (i = 1; i <= msize*2 + 1; i++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of */
dx = i-1; /* the PE's */
xxIndex = (u+dx) / nxproc;
#endif
for(j = 1; j <= msize*2 + 1; j++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of
** the PE's */
dy = -(j-1);
/* (v-dy) uses "-" as dy is -ve to go south */
yyIndex = (v-dy) / nyproc;
if ((dx == 0) && (dy == 0))
{
master[xxIndex][yyIndex][MAGNETICS]
+= -sus[p][1]*slave[i][j][4];
master[xxIndex][yyIndex][GRAVITY]
+= rho[p]*slave[i][j][3];
}
else
{
store = &(master[xxIndex][yyIndex][MAGNETICS]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += -sus[p][1]*slave[i][j][4];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
store = &(master[xxIndex][yyIndex][GRAVITY]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += rho[p]*slave[i][j][3];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
}
DEBUG(if ((u+dx == 13) && (v-dy == 65)))
DEBUG( printf("\nM--GRAV proc[0][12] => %lf %d+%d=13 %d-%d=65 (%d,%d)",\
proc[0][12].master[0][1][GRAVITY],globalor(u),dx,globalor(v),dy, \
globalor(xxIndex),globalor(yyIndex));)
DEBUG(if ((u+dx == 13) && (v-dy == 64)))
DEBUG( printf("\nM GRAV proc[63][12] => %lf %d+%d=13 %d-%d=64 (%d,%d)",\
proc[63][12].master[0][0][GRAVITY],globalor(u),dx,globalor(v),dy, \
globalor(xxIndex),globalor(yyIndex));)
#else
master[xIndex+i-1][yIndex+j-1][MAGNETICS]
+= -sus[p][1]*slave[i][j][4];
master[xIndex+i-1][yIndex+j-1][GRAVITY]
+= rho[p]*slave[i][j][3];
#endif
}
}
}
}
} /* end of else */
DEBUG(if ((ixproc == 12) && (iyproc == 0)))
DEBUG( printf("\nM---GRAV proc[0][12] => %lf", \
globalor(master[0][1][GRAVITY]));)
DEBUG(if ((ixproc == 12) && (iyproc == 63)))
DEBUG( printf("\nM GRAV proc[63][12] => %lf", \
globalor(master[0][0][GRAVITY]));)
}
/*--------------------------------------------------------------------*/
void AddFields2d(master, slave, xmax, sus, rho, msize,
ken, ang, plu, iRem, iAni, dat, blockData)
double ***slave;
float sus[121][4],rho[121];
int msize, xmax;
double ken[121][4],ang[121],plu[121];
int iRem,iAni;
float dat[5];
#ifdef _MPL
plural double ***master;
plural int **blockData;
#else
double ***master;
int **blockData;
#endif
{
double finc,angl,totl;
double sf,cf,sa,ca,cacf,sacf;
double totlsacf,totlcacf,totlsf;
register int j, i, dx, dy = 0, nbytes;
LAYER_PROPERTIES *layerProps[50];
#ifdef _MPL
plural double result;
plural double * plural store;
plural register int p;
plural register int u, v;
plural register int xIndex, yIndex = 0, xxIndex, yyIndex;
plural double kentotl1,sustotl1,kentotl2,sustotl2,kentotl3,sustotl3;
plural double JR1, JR2, JR3, cRf, sRf;
#else
register int p;
register int u, v;
register int xIndex, yIndex = 1, xxIndex, yyIndex;
double kentotl1,sustotl1,kentotl2,sustotl2,kentotl3,sustotl3;
double JR1, JR2, JR3, cRf, sRf;
#endif
finc = dat[1];
angl = dat[2];
totl = dat[3];
sf = sin(finc*0.01745329);
cf = cos(finc*0.01745329);
sa = sin(angl*0.01745329);
ca = cos(angl*0.01745329);
cacf =ca*cf;
sacf=sa*cf;
#ifdef _MPL
nbytes = sizeof(plural double);
#endif
if (iRem==1 && iAni==1)
{
assignPropertiesForStratLayers (layerProps, 50);
#ifdef _MPL
for (u = ixproc, xIndex = 0; u < xmax; u += nxproc, xIndex++)
#else
for (xIndex = 1; xIndex <= xmax; xIndex++)
#endif
{
p = blockData[xIndex][yIndex];
/*if(iUnDeformRemanent)
tasteRemanent();*/
#ifdef _MPL
cRf=p_cos( plu[p] * 0.01745329 );
sRf=p_sin( plu[p] * 0.01745329 );
#else
cRf=cos( plu[p] * 0.01745329 );
sRf=sin( plu[p] * 0.01745329 );
#endif
kentotl1=ken[p][1];
kentotl2=ken[p][2];
kentotl3=ken[p][3];
sustotl1=sus[p][1]*totl;
sustotl2=sus[p][2]*totl;
sustotl3=sus[p][3]*totl;
#ifdef _MPL
JR1=sustotl1*(sacf+kentotl1*cRf*p_sin((angl-ang[p])*0.01745329));
JR2=sustotl2*(cacf+kentotl2*cRf*p_cos((angl-ang[p])*0.01745329));
#else
JR1=sustotl1*(sacf+kentotl1*cRf*sin((angl-ang[p])*0.01745329));
JR2=sustotl2*(cacf+kentotl2*cRf*cos((angl-ang[p])*0.01745329));
#endif
JR3=sustotl3*(sf+kentotl3*sRf);
for(i = 1; i <= msize*2 + 1; i++)
{
for(j = 1; j <= msize*2 + 1; j++)
{
#ifdef _MPL
/* allow the array to wrap over the edge of
** the PE's */
dx = (j-1);
xxIndex = (u+dx) / nxproc;
if (dx == 0)
{
master[xxIndex][yyIndex][MAGNETICS] += -JR1*slave[j][i][0]
-JR2*slave[j][i][1]
-JR3*slave[j][i][2];
master[xxIndex][yyIndex][GRAVITY] += rho[p]*slave[j][i][3];
}
else
{
store = &(master[xxIndex][yyIndex][MAGNETICS]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += -JR1*slave[j][i][0] -JR2*slave[j][i][1]
-JR3*slave[j][i][2];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
store = &(master[xxIndex][yyIndex][GRAVITY]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += rho[p]*slave[j][i][3];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
}
#else
master[xIndex+j-1][1][MAGNETICS] += -JR1*slave[j][i][0]
-JR2*slave[j][i][1]
-JR3*slave[j][i][2];
master[xIndex+j-1][1][GRAVITY] += rho[p]*slave[j][i][3];
#endif
}
}
}
} /* end if(iRem) */
else if (iAni==0 && iRem==1)
{
#ifdef _MPL
for (u = ixproc, xIndex = 0; u < xmax; u += nxproc, xIndex++)
#else
for (xIndex = 1; xIndex <= xmax; xIndex++)
#endif
{
p = blockData[xIndex][yIndex];
/*if(iUnDeformRemanent)
tasteRemanent();*/
#ifdef _MPL
cRf=p_cos( plu[p] * 0.01745329 );
sRf=p_sin( plu[p] * 0.01745329 );
#else
cRf=cos( plu[p] * 0.01745329 );
sRf=sin( plu[p] * 0.01745329 );
#endif
kentotl1=ken[p][1];
sustotl1=sus[p][1]*totl;
#ifdef _MPL
JR1=sustotl1*(sacf+kentotl1*cRf*p_sin((angl-ang[p])*0.01745329));
JR2=sustotl1*(cacf+kentotl1*cRf*p_cos((angl-ang[p])*0.01745329));
#else
JR1=sustotl1*(sacf+kentotl1*cRf*sin((angl-ang[p])*0.01745329));
JR2=sustotl1*(cacf+kentotl1*cRf*cos((angl-ang[p])*0.01745329));
#endif
JR3=sustotl1*(sf+kentotl1*sRf);
for(i = 1; i <= msize*2 + 1; i++)
{
for(j = 1; j <= msize*2 + 1; j++)
{
/*master[j+u-1][1][MAGNETICS] += -sus[p]*slave[j][k][4];*/
#ifdef _MPL
/* allow the array to wrap over the edge of
** the PE's */
dx = (j-1);
xxIndex = (u+dx) / nxproc;
if (dx == 0)
{
master[xxIndex][yyIndex][MAGNETICS] += -JR1*slave[j][i][0]
-JR2*slave[j][i][1]
-JR3*slave[j][i][2];
master[xxIndex][yyIndex][GRAVITY] += rho[p]*slave[j][i][3];
}
else
{
store = &(master[xxIndex][yyIndex][MAGNETICS]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += -JR1*slave[j][i][0] -JR2*slave[j][i][1]
-JR3*slave[j][i][2];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
store = &(master[xxIndex][yyIndex][GRAVITY]);
ps_xfetch (dy, dx, (plural char * plural) store,
(plural char *) &result, nbytes);
result += rho[p]*slave[j][i][3];
sp_xsend (dy, dx, (plural char *) &result,
(plural char * plural) store, nbytes);
}
#else
master[xIndex+j-1][1][MAGNETICS] += -JR1*slave[j][i][0]
-JR2*slave[j][i][1]
-JR3*slave[j][i][2];
master[xIndex+j-1][1][GRAVITY] += rho[p]*slave[j][i][3];
#endif
}
}
}
} /* end else if(Iani==0 && iRem==1) */
else if(iAni==1 && iRem==0)
{
totlsacf=totl*sacf;
totlcacf=totl*cacf;
totlsf =totl*sf;