-
Notifications
You must be signed in to change notification settings - Fork 6
/
loadjmart.c
executable file
·1617 lines (1595 loc) · 43 KB
/
loadjmart.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
/* Start save marker data */
/* added by Gregor, last modified: 18/10/2011) */
int markersave()
{
long int m3;
int mmm3;
double mmm4;
/**/
/* Write out marker data, however amir.t3c should be set to different output field than composition! */
/**/
if(fl1otp!=5) /* Set amir.t3c other than composition (c) */
{
/**/
/* Saves marker coordinates and silicate melt fraction */
fl = fopen("marker_melt.txt","wt");
for(m3=0;m3<=marknum;m3++)
{
fprintf(fl,"% 5.4e % 5.4e % 5.4e \n",markx[m3]/xsize,marky[m3]/ysize,melt_frac[m3]);
}
fclose(fl);
/**/
/* Saves marker coordinates and marker types */
fl = fopen("marker_comp.txt","wt");
for(m3=0;m3<=marknum;m3++)
{
mmm3=markt[m3];
fprintf(fl,"% 5.4e % 5.4e %d \n",markx[m3]/xsize,marky[m3]/ysize,mmm3);
}
fclose(fl);
/**/
/* Saves marker coordinates and marker magnetization */
fl = fopen("marker_magnet.txt","wt");
for(m3=0;m3<=marknum;m3++)
{
mmm3=markmg_old[m3];
fprintf(fl,"% 5.4e % 5.4e %d \n",markx[m3]/xsize,marky[m3]/ysize,mmm3);
}
fclose(fl);
/**/
/* Saves marker coordinates and marker magnetization */
fl = fopen("marker_magnet_time.txt","wt");
for(m3=0;m3<=marknum;m3++)
{
mmm4=markmg_time[m3];
fprintf(fl,"% 5.4e % 5.4e % 5.4e \n",markx[m3]/xsize,marky[m3]/ysize,mmm4);
}
fclose(fl);
}
/**/
return 0;
}
/* End marker saving */
/*====================================================================================================*/
/**/
/**/
/* Load information from configuration file amir.t3c ============== */
void loadconf()
{
/* Counter */
int n1,n2,n3;
/**/
/**/
/**/
/* Open File amir.t3c */
fl = fopen("amir.t3c","rt");
/**/
/* Load first Input File name */
ffscanf();
fl0num=0;
while(sa[0]!='~')
{
/* Check file Counter */
if(fl0num>=MAXFLN) {printf("Space out in fl0out[]"); exit(0);}
/* Save Input file name */
for (n1=0;n1<50;n1++) fl0in[fl0num][n1]=sa[n1];
/* Load TYPE of input - b=binary t=text */
ffscanf(); if(sa[0] == 'b') fl0itp[fl0num]=1;
/**/
/* Load, Save Output File name */
ffscanf();
for (n1=0;n1<50;n1++) fl0out[fl0num][n1]=sa[n1];
/* Load TYPE of output */
/* 1 - T,t = temperature */
/* 2 - V,v = Log viscosity */
/* 3 - */
/* 4 - H,h = Log shear heating */
/* 5 - C,c = chemical field (rock types) */
/* 6 - D,d = density */
/* 7 - K,k = heat conductivity */
/* 8 - G,g = Log total heat generation */
/* 9 - vp - vp-seismic velosity, km/s */
/* 10 - vs - vs-seismic velosity, km/s */
/* 11 - vp/vs - seismic velosity ratio */
/* 12 - R,r - vorticity/shear ratio */
/* 13 - O,o - topography */
/* 14 - L,l - overriding plate length */
/**/
ffscanf();
if(sa[0] == 'T' || sa[0] == 't') fl0otp[fl0num]=1;
if(sa[0] == 'V' || sa[0] == 'v') fl0otp[fl0num]=2;
if(sa[0] == 'H' || sa[0] == 'h') fl0otp[fl0num]=4;
if(sa[0] == 'C' || sa[0] == 'c') fl0otp[fl0num]=5;
if(sa[0] == 'D' || sa[0] == 'd') fl0otp[fl0num]=6;
if(sa[0] == 'K' || sa[0] == 'k') fl0otp[fl0num]=7;
if(sa[0] == 'G' || sa[0] == 'g') fl0otp[fl0num]=8;
if(sa[1] == 'P' || sa[1] == 'p') fl0otp[fl0num]=9;
if(sa[1] == 'S' || sa[1] == 's') fl0otp[fl0num]=10;
if(sa[1] == 'R' || sa[1] == 'r') fl0otp[fl0num]=11;
if(sa[0] == 'R' || sa[0] == 'r') fl0otp[fl0num]=12;
if(sa[0] == 'O' || sa[0] == 'o') fl0otp[fl0num]=13;
if(sa[0] == 'L' || sa[0] == 'l') fl0otp[fl0num]=14;
/**/
/* Resolution,position of the output */
ffscanf();fl0stp[fl0num][0]=atof(sa);
ffscanf();fl0stp[fl0num][1]=atof(sa);
ffscanf();fl0stp[fl0num][2]=atof(sa);
ffscanf();fl0stp[fl0num][3]=atof(sa);
ffscanf();fl0stp[fl0num][4]=atof(sa);
ffscanf();fl0stp[fl0num][5]=atof(sa);
/**/
/* Incr File Counters */
fl0num++;
/**/
/* Load Next Input File names */
ffscanf();
}
/**/
/* Service */
ffscanf();printmod=atoi(sa);
ffscanf();timedir=atof(sa);
ffscanf();movemod=atoi(sa);
ffscanf();tempmod=atoi(sa);
ffscanf();markmod=atoi(sa);
ffscanf();ratemod=atoi(sa);
ffscanf();gridmod=atoi(sa);
ffscanf();intermod=atoi(sa);
ffscanf();intermod1=atoi(sa);
ffscanf();outgrid=atoi(sa);
ffscanf();densimod=atoi(sa);
/**/
/* V */
ffscanf();DIVVMIN=atof(sa);
ffscanf();STOKSMIN=atof(sa);
ffscanf();stoksmod=atoi(sa);
ffscanf();presmod=atoi(sa);
ffscanf();stoksfd=atoi(sa);
ffscanf();nubeg=atof(sa);
ffscanf();nuend=atof(sa);
ffscanf();nucontr=atof(sa);
ffscanf();hidry=atof(sa);
ffscanf();hidrl=atof(sa);
ffscanf();strmin=atof(sa);
ffscanf();strmax=atof(sa);
/**/
/**/
/**/
/* T */
ffscanf();HEATMIN=atof(sa);
ffscanf();heatmod=atoi(sa);
ffscanf();heatfd=atoi(sa);
ffscanf();heatdif=atof(sa);
ffscanf();frictyn=atof(sa)*3.15576e+7;
ffscanf();adiabyn=atof(sa)*3.15576e+7;
ffscanf();core_form_time=atof(sa)*3.15576e+7;
ffscanf();si_melting=atoi(sa);
ffscanf();fe_melting=atoi(sa);
ffscanf();ice_melting=atoi(sa);
/**/
fclose(fl);
/* End Load information from configuration file amir.t3c */
/**/
/* stop.yn file creation */
fl = fopen("stop.yn","wt");
fprintf(fl,"n \n");
fclose(fl);
/**/
/**/
/**/
/* Load thermodynamic database */
/* Database P-T grid parameters */
tknum=350;
pbnum=350;
tkmin=500.005;
pbmin=1000.5;
tkstp=(5000.0-tkmin)/(double)(tknum-1);
pbstp=(500000.0-pbmin)/(double)(pbnum-1);
/*
printf("%d %d %e %e %e %e",tknum,pbnum,tkmin,pbmin,tkstp,pbstp);getchar();
*/
/**/
/* Mars Mantle */
/* RO - density */
fl = fopen("mars_mantle","rt");
/* Read heading line */
for (n1=0;n1<46;n1++)
{
fscanf(fl,"%s",sa);
/*
printf("A %d %s",n1,sa);getchar();
*/
}
/* Read Database %
/**/
for (n1=0;n1<pbnum;n1++)
for (n2=0;n2<tknum;n2++)
{
for (n3=0;n3<42;n3++)
{
fscanf(fl,"%s",sa);
wi[n3]=atof(sa);
/*
printf("%d %e ",n3,wi[n3]);getchar();
*/
}
/* Density, g/cm3 */
td[n2][n1][0][0]=wi[11]/1000.0;
/* Enthalpy, kCal/kg */
td[n2][n1][0][1]=wi[3]/wi[18]/4.1837;
/*
td[n2][n1][0][1]=wi[3]/wi[18]*1e+3;
if (n2>0)
{
printf("%d %d %e %e %e ",n1,n2,td[n2-1][n1][0][1],td[n2][n1][0][1],(td[n2][n1][0][1]-td[n2-1][n1][0][1])/tkstp);getchar();
}
printf("%d %d %e %e %e ",n1,n2,td[n2][n1][0][0],td[n2][n1][0][1],td[n2][n1][0][2]);getchar();
td[n2][n1][0][1]=wi[3]/wi[2]*1e+5/wi[11];
td[n2][n1][0][2]=wi[3]/wi[18]*1e+3;
*/
}
fclose(fl);
printf("mars_mantle OK \n");
/**/
/* Mars Crust */
/* RO - density */
fl = fopen("mars_crust","rt");
/* Read heading line */
for (n1=0;n1<48;n1++)
{
fscanf(fl,"%s",sa);
/*
printf("A %d %s",n1,sa);getchar();
*/
}
/* Read Database %
/**/
for (n1=0;n1<pbnum;n1++)
for (n2=0;n2<tknum;n2++)
{
for (n3=0;n3<44;n3++)
{
fscanf(fl,"%s",sa);
wi[n3]=atof(sa);
/*
printf("%d %e ",n3,wi[n3]);getchar();
*/
}
/* Density, g/cm3 */
td[n2][n1][1][0]=wi[11]/1000.0;
/* Enthalpy, kCal/kg */
td[n2][n1][1][1]=wi[3]/wi[18]/4.1837;
/*
td[n2][n1][0][1]=wi[3]/wi[18]*1e+3;
if (n2>0)
{
printf("%d %d %e %e %e ",n1,n2,td[n2-1][n1][0][1],td[n2][n1][0][1],(td[n2][n1][0][1]-td[n2-1][n1][0][1])/tkstp);getchar();
}
printf("%d %d %e %e %e ",n1,n2,td[n2][n1][0][0],td[n2][n1][0][1],td[n2][n1][0][2]);getchar();
td[n2][n1][0][1]=wi[3]/wi[2]*1e+5/wi[11];
td[n2][n1][0][2]=wi[3]/wi[18]*1e+3;
*/
}
fclose(fl);
printf("mars_crust OK \n");
}
/* Load information from configuration file mode.t3c ============== */
/* Load Information from data file ------------------------------- */
void loader()
/* bondv[] - boundary value */
/* bondm[] - boundary mode 0=Not, -1=Value, 1,2...=LinNum+1 */
/* m1,m2 - node X,Y number */
{
/* Counter */
int n1;
char nn1,nn2,nn3;
long int m1,m2,m3,nv[100];
long int mm1,mm2,erosmark=0;
char szint,szlong,szfloat,szdouble,szcur;
float ival0,iv[100];
double ival1;
/**/
/**/
/**/
/* Load Past Results from data file-------------------------------- */
if (printmod) printf("Load Past results from %s ...",fl1in);
/**/
/**/
/**/
/* Load in Text Format ---------------------------- */
if(fl1itp==0)
{
fl = fopen(fl1in,"rt");
/**/
/* Grid Parameters */
ffscanf();xnumx=atoi(sa);
ffscanf();ynumy=atoi(sa);
ffscanf();mnumx=atoi(sa);
ffscanf();mnumy=atoi(sa);
ffscanf();marknum=atoi(sa);
ffscanf();xsize=atof(sa);
ffscanf();ysize=atof(sa);
ffscanf();gamma_eff=atof(sa);
ffscanf();memory_fe=atof(sa);
ffscanf();memory_si=atof(sa);
ffscanf();por_init=atof(sa);
ffscanf();growth_model=atoi(sa);
ffscanf();gr_init=atof(sa);
ffscanf();znumz=atoi(sa);
ffscanf();corr2d3d=atoi(sa);
ffscanf();pinit=atof(sa);
ffscanf();pkf[0]=atof(sa);
ffscanf();pkf[1]=atof(sa);
ffscanf();pkf[2]=atof(sa);
ffscanf();pkf[3]=atof(sa);
ffscanf();GXKOEF=atof(sa);
ffscanf();GYKOEF=atof(sa);
ffscanf();tmp_ambient=atof(sa);
ffscanf();timeexit=atof(sa)*3.15576e+7;
ffscanf();al2627_init=atof(sa)*1.0e-5;
ffscanf();fe6056_init=atof(sa)*1.0e-8;
ffscanf();rocknum=atoi(sa);
ffscanf();bondnum=atoi(sa);
ffscanf();
ffscanf();timesum=atof(sa)*3.15576e+7;
/**/
/* Calc,Check Grid parameters */
gridcheck();
/**/
/* Rock Types information */
for (n1=0;n1<rocknum;n1++)
{
ffscanf();
ffscanf();markim[n1]=atoi(sa);;
ffscanf();markn0[n1]=atof(sa);;
ffscanf();markn1[n1]=atof(sa);;
ffscanf();marks0[n1]=atof(sa);;
ffscanf();marks1[n1]=atof(sa);;
ffscanf();marknu[n1]=atof(sa);;
ffscanf();markdh[n1]=atof(sa);;
ffscanf();markdv[n1]=atof(sa);;
ffscanf();markss[n1]=atof(sa);;
ffscanf();markmm[n1]=atof(sa);;
ffscanf();markll[n1]=atof(sa);;
ffscanf();marka0[n1]=atof(sa);;
ffscanf();marka1[n1]=atof(sa);;
ffscanf();markb0[n1]=atof(sa);;
ffscanf();markb1[n1]=atof(sa);;
ffscanf();marke0[n1]=atof(sa);;
ffscanf();marke1[n1]=atof(sa);;
ffscanf();markro[n1]=atof(sa);;
ffscanf();markbb[n1]=atof(sa);;
ffscanf();markaa[n1]=atof(sa);;
ffscanf();markcp[n1]=atof(sa);;
ffscanf();markkt[n1]=atof(sa);;
ffscanf();markkf[n1]=atof(sa);;
ffscanf();markkp[n1]=atof(sa);;
ffscanf();markht[n1]=atof(sa);;
}
/**/
/* Nodes information */
/* Vx,Vy,bondm[],ro[],nu[],ep[],et[],tk[],cp[],kt[],ht[] */
for (m1=0;m1<xnumx;m1++)
for (m2=0;m2<ynumy;m2++)
{
m3=m1*ynumy+m2;
ffscanf();
ffscanf();
ffscanf();pr[m3]=atof(sa);
ffscanf();vx[m3]=atof(sa);
ffscanf();vy[m3]=atof(sa);
ffscanf();bondm[m3*3+0]=atoi(sa);
ffscanf();bondm[m3*3+1]=atoi(sa);
ffscanf();bondm[m3*3+2]=atoi(sa);
ffscanf();exx[m3]=atof(sa);
ffscanf();eyy[m3]=atof(sa);
ffscanf();exy[m3]=atof(sa);
ffscanf();sxx[m3]=atof(sa);
ffscanf();syy[m3]=atof(sa);
ffscanf();sxy[m3]=atof(sa);
ffscanf();ro[m3]=atof(sa);
ffscanf();nu[m3]=atof(sa);
ffscanf();nd[m3]=atof(sa);
ffscanf();po[m3]=atof(sa);
ffscanf();mu[m3]=atof(sa);
ffscanf();ep[m3]=atof(sa);
ffscanf();et[m3]=atof(sa);
ffscanf();tk[m3]=atof(sa);
ffscanf();bondm[nodenum3+m3]=atoi(sa);
ffscanf();cp[m3]=atof(sa);
ffscanf();kt[m3]=atof(sa);
ffscanf();ht[m3]=atof(sa);
}
/**/
/* Gridlines positions */
for (m1=0;m1<xnumx;m1++)
{
ffscanf();
ffscanf();gx[m1]=atof(sa);
}
for (m2=0;m2<ynumy;m2++)
{
ffscanf();
ffscanf();gy[m2]=atof(sa);
}
/**/
/* Boundary Conditions Equations */
for (m1=1;m1<bondnum;m1++)
{
ffscanf();
ffscanf();bondv[m1][0]=atof(sa);
ffscanf();bondv[m1][1]=atof(sa);
ffscanf();bondv[m1][2]=atof(sa);
ffscanf();bondv[m1][3]=atof(sa);
ffscanf();bondn[m1][0]=atoi(sa);
ffscanf();bondn[m1][1]=atoi(sa);
ffscanf();bondn[m1][2]=atoi(sa);
}
/**/
/* Markers X,Y,types */
for (mm1=0;mm1<=marknum;mm1++)
{
ffscanf();markx[mm1]=atof(sa);
ffscanf();marky[mm1]=atof(sa);
ffscanf();markk[mm1]=atof(sa);
ffscanf();markv[mm1]=atof(sa);
ffscanf();markhi[mm1]=atof(sa); /* Greg: marker impact history variable */
ffscanf();markpor[mm1]=atof(sa); /* Greg: marker porosity */
ffscanf();markgr[mm1]=atof(sa); /* Greg: marker grain size */
ffscanf();marktmax[mm1]=atof(sa); /* Tim: marker maximum temperature */
ffscanf();markacc[mm1]=atof(sa); /* Tim: marker accretion time */
ffscanf();markmg_old[mm1]=atof(sa); /* Greg: marker magnetization variable */
ffscanf();markmg_time[mm1]=atof(sa); /* Greg: marker magnetization time */
ffscanf();markt[mm1]=atoi(sa);
}
}
/* Load in Text Format ---------------------------- */
/**/
/**/
/**/
/* Load in Binary Format ---------------------------- */
else
{
fl = fopen(fl1in,"rb");
/**/
/* Sizes of var definition */
szint=sizeof(n1);
szlong=sizeof(m1);
szfloat=sizeof(ival0);
szdouble=sizeof(ival1);
/* Check sizes of variables */
fread(&szcur,1,1,fl);
if (szcur!=szint) {printf("Current INT size <%d> is different from given in file <%d> \n",szint,szcur); exit(0);}
fread(&szcur,1,1,fl);
if (szcur!=szlong) {printf("Current LONG INT size <%d> is different from given in file <%d> \n",szlong,szcur); exit(0);}
fread(&szcur,1,1,fl);
if (szcur!=szfloat) {printf("Current FLOAT size <%d> is different from given in file <%d> \n",szfloat,szcur); exit(0);}
fread(&szcur,1,1,fl);
if (szcur!=szdouble) {printf("Current DOUBLE size <%d> is different from given in file <%d> \n",szdouble,szcur); exit(0);}
/**/
/* Grid Parameters */
fread(&xnumx,szlong,1,fl);
fread(&ynumy,szlong,1,fl);
fread(&mnumx,szlong,1,fl);
fread(&mnumy,szlong,1,fl);
fread(&marknum,szlong,1,fl);
fread(&xsize,szdouble,1,fl);
fread(&ysize,szdouble,1,fl);
fread(&gamma_eff,szdouble,1,fl);
fread(&memory_fe,szdouble,1,fl);
fread(&memory_si,szdouble,1,fl);
fread(&por_init,szdouble,1,fl);
fread(&growth_model,szlong,1,fl);
fread(&gr_init,szdouble,1,fl);
fread(&znumz,szlong,1,fl);
fread(&corr2d3d,szlong,1,fl);
fread(&pinit,szdouble,1,fl);
fread(pkf,szdouble,4,fl);
fread(&GXKOEF,szdouble,1,fl);
fread(&GYKOEF,szdouble,1,fl);
fread(&tmp_ambient,szdouble,1,fl);
fread(&timeexit,szdouble,1,fl);timeexit*=3.15576e+7;
fread(&al2627_init,szdouble,1,fl);al2627_init*=1.0e-5;
fread(&fe6056_init,szdouble,1,fl);fe6056_init*=1.0e-8;
fread(&rocknum,szint,1,fl);
fread(&bondnum,szlong,1,fl);
fread(&n1,szint,1,fl);
fread(×um,szdouble,1,fl);timesum*=3.15576e+7;
/**/
/* Calc,Check Grid parameters */
gridcheck();
/**/
/* Rock Types information */
fread(markim,szint,rocknum,fl);
fread(markn0,szdouble,rocknum,fl);
fread(markn1,szdouble,rocknum,fl);
fread(marks0,szdouble,rocknum,fl);
fread(marks1,szdouble,rocknum,fl);
fread(marknu,szdouble,rocknum,fl);
fread(markdh,szdouble,rocknum,fl);
fread(markdv,szdouble,rocknum,fl);
fread(markss,szdouble,rocknum,fl);
fread(markmm,szdouble,rocknum,fl);
fread(markll,szdouble,rocknum,fl);
fread(marka0,szdouble,rocknum,fl);
fread(marka1,szdouble,rocknum,fl);
fread(markb0,szdouble,rocknum,fl);
fread(markb1,szdouble,rocknum,fl);
fread(marke0,szdouble,rocknum,fl);
fread(marke1,szdouble,rocknum,fl);
fread(markro,szdouble,rocknum,fl);
fread(markbb,szdouble,rocknum,fl);
fread(markaa,szdouble,rocknum,fl);
fread(markcp,szdouble,rocknum,fl);
fread(markkt,szdouble,rocknum,fl);
fread(markkf,szdouble,rocknum,fl);
fread(markkp,szdouble,rocknum,fl);
fread(markht,szdouble,rocknum,fl);
/**/
/* Nodes information */
/* Vx,Vy,bondm[],ro[],nu[],ep[],et[],tk[],cp[],kt[],ht[] */
for (m1=0;m1<nodenum;m1++)
{
fread(iv,szfloat,3,fl);
pr[m1]=(double)(iv[0]);
vx[m1]=(double)(iv[1]);
vy[m1]=(double)(iv[2]);
fread(nv,szlong,3,fl);
bondm[m1*3+0]=nv[0];
bondm[m1*3+1]=nv[1];
bondm[m1*3+2]=nv[2];
fread(iv,szfloat,14,fl);
exx[m1]=(double)(iv[0]);
eyy[m1]=(double)(iv[1]);
exy[m1]=(double)(iv[2]);
sxx[m1]=(double)(iv[3]);
syy[m1]=(double)(iv[4]);
sxy[m1]=(double)(iv[5]);
ro[m1]=(double)(iv[6]);
nu[m1]=(double)(iv[7]);
nd[m1]=(double)(iv[8]);
po[m1]=(double)(iv[9]);
mu[m1]=(double)(iv[10]);
ep[m1]=(double)(iv[11]);
et[m1]=(double)(iv[12]);
tk[m1]=(double)(iv[13]);
fread(&m2,szlong,1,fl);bondm[nodenum3+m1]=m2;
fread(iv,szfloat,3,fl);
cp[m1]=(double)(iv[0]);
kt[m1]=(double)(iv[1]);
ht[m1]=(double)(iv[2]);
}
/**/
/* Gridlines positions */
for (m1=0;m1<xnumx;m1++)
{
fread(&ival0,szfloat,1,fl);gx[m1]=(double)(ival0);
}
for (m2=0;m2<ynumy;m2++)
{
fread(&ival0,szfloat,1,fl);gy[m2]=(double)(ival0);
}
/**/
/* Bondary Conditions Equations */
for (m1=1;m1<bondnum;m1++)
{
fread(iv,szfloat,4,fl);
bondv[m1][0]=(double)(iv[0]);
bondv[m1][1]=(double)(iv[1]);
bondv[m1][2]=(double)(iv[2]);
bondv[m1][3]=(double)(iv[3]);
fread(nv,szlong,3,fl);
bondn[m1][0]=nv[0];
bondn[m1][1]=nv[1];
bondn[m1][2]=nv[2];
}
/**/
/* Markers X,Y,types */
for (mm1=0;mm1<=marknum;mm1++)
{
fread(iv,szfloat,7,fl);
markx[mm1]=iv[0];
marky[mm1]=iv[1];
markk[mm1]=iv[2];
markv[mm1]=iv[3];
markhi[mm1]=iv[4]; /* Greg: marker history variable */
markpor[mm1]=iv[5]; /* Greg: marker porosity */
markgr[mm1]=iv[6]; /* Greg: marker grain size */
marktmax[mm1]=iv[7]; /* Tim: marker maximum temperature */
markacc[mm1]=iv[8]; /* Tim: marker accretion time */
fread(&nn3,1,1,fl);markmg_old[mm1]=nn3; /* Greg: marker magnetization variable */
fread(&nn2,1,1,fl);markmg_time[mm1]=nn2; /* Greg: marker magnetization time */
fread(&nn1,1,1,fl);markt[mm1]=nn1;
}
}
/* Load in Binary Format ---------------------------- */
/**/
/**/
/**/
fclose(fl);
if (printmod) printf("OK!\n");
}
/* Load Information from data file ------------------------------- */
/* Print Results to data file ----------------------------------- */
void saver(int n0)
/* n0 - file number */
{
/* Counters */
int n1,n2,mm2,mm3,ccur,cmin=0,cmax=0,yn;
char nn1,nn2,nn3;
long int m1,m2,m3,m4,m5,m6,m7;
long int mm1,erosmark=0;
/* Buffers for XY */
double x,y;
char szint,szlong,szfloat,szdouble;
float ival0;
double ival, ival1,xresx,yresy,xminx,xmaxx,yminy,ymaxy,ea,na,mpb,mtk,mro,mbb,mnu,mkt,mcp,mht,mvp,mvs,xcur,ycur,mwa;
long int xresol,yresol,nresol,markstp;
long int xresol0,xresolsum;
double xincr,xminx0,yminy0;
/* TD Database variables */
double n,e;
/**/
/**/
/**/
if (printmod) printf("Print data to %s...",fl1out);
/**/
/**/
/**/
/* Open file */
fl = fopen(fl1out,"wt");
/* Read check resolution */
xincr=xresol=xresol0=(long int)(fl0stp[n0][2]);
yresol=(long int)(fl0stp[n0][5]);
nresol=xresol0*yresol;
/* Check coordinates, calc step */
if (fl0stp[n0][0]<0) fl0stp[n0][0]=0;
if (fl0stp[n0][1]>1.0) fl0stp[n0][1]=1.0;
if (fl0stp[n0][3]<0) fl0stp[n0][3]=0;
if (fl0stp[n0][4]>1.0) fl0stp[n0][4]=1.0;
xminx0=xminx=fl0stp[n0][0]*xsize;
xmaxx=fl0stp[n0][1]*xsize;
xresx=(xmaxx-xminx)/(double)(xresol-1);
yminy0=yminy=fl0stp[n0][3]*ysize;
ymaxy=fl0stp[n0][4]*ysize;
yresy=(ymaxy-yminy)/(double)(yresol-1);
yminy-=yresy; if(yminy<0) yminy=0;
ymaxy+=yresy; if(ymaxy>ysize) ymaxy=ysize;
if((nresol*2)>MAXMAT)
{
printf("\n Limited space in val0[] lin0[], spleating ...\n");
xincr=(long int)((double)(MAXMAT)/(double)(yresol*2));
}
/* X, Y Resolution save */
/*
printf("%ld %ld %ld %e %e %e %e %e %e\n",xresol,yresol,nresol,xminx,xmaxx,xresx,yminy,ymaxy,yresy); getchar();
*/
fprintf(fl,"%e \n %ld %ld \n",timesum/3.15576e+7,xresol0,yresol);
/* Step for markers definition */
ival=0.1*(double)(marknum)/(double)(nresol);
markstp=(long int)(ival);
if (markstp<1) markstp=1;
/**/
/**/
/**/
/* Compute vorticity tensor */
for (m1=1;m1<xnumx-1;m1++)
for (m2=1;m2<ynumy-1;m2++)
{
/* Pos of in ol0[] */
m3=m1*ynumy+m2;
/**/
/* Min,Max Vx definition */
esp[m3]=spncalc(m1,m2);
/*
printf("%d %ld %ld %ld %e %e %e %e ",fl1otp,m1,m2,m3,exy[m3],eps[0],eps[1],esp[m3]); getchar();
*/
}
/* Compute vorticity tensor */
/**/
/**/
/**/
/* Save data in text format ---------------------------- */
xresolsum=0;
do
{
/* Set x resolution */
xresol=xincr;
if(xresolsum+xresol>xresol0) xresol=xresol0-xresolsum;
nresol=xresol*yresol;
xminx=xminx0=fl0stp[n0][0]*xsize+xresx*((double)(xresolsum));
xminx-=xresx; if(xminx<0) xminx=0;
xmaxx=fl0stp[n0][0]*xsize+xresx*((double)(xresolsum+xresol));
if(xmaxx>xsize) xmaxx=xsize;
/**/
/*
printf("%ld %ld %ld %ld %e %e %e %e %e %e\n",xresol,yresol,nresol,markstp,xminx,xmaxx,xresx,yminy,ymaxy,yresy); getchar();
*/
/* Clear visual arrays */
for (m1=0;m1<nresol;m1++)
{
val0[m1]=val0[nresol+m1]=0;
lin0[m1]=lin0[nresol+m1]=0;
}
/**/
/**/
/**/
/* CHEMICAL COMPONENT VISUALISATION ----------------------------*/
/* Variations in markers types for chemical component visualisation */
if(fl1otp==5)
{
cmin=1000,cmax=0;
/* Markers cycle */
for (m3=0;m3<=marknum;m3+=markstp)
/* Check markers out of visualisation area */
if ((double)(markx[m3])>xminx && (double)(markx[m3])<xmaxx && (double)(marky[m3])>yminy && (double)(marky[m3])<ymaxy && markt[m3]<50)
{
if (cmin>markt[m3]) cmin=markt[m3];
if (cmax<markt[m3]) cmax=markt[m3];
}
/**/
/* Marker type cycle for chemical component Visualisation */
for (ccur=cmin;ccur<=cmax;ccur++)
{
/* Markers cycle */
for (m3=0;m3<=marknum;m3+=markstp)
/* Check markers out of visualisation area */
if ((double)(markx[m3])>xminx && (double)(markx[m3])<xmaxx && (double)(marky[m3])>yminy && (double)(marky[m3])<ymaxy && markt[m3]==ccur)
{
/*
printf("%d %d %d %ld %d %e %e %e \n",cmin,cmax,ccur,m3,markt[m3],markx[m3],marky[m3],markk[m3]); getchar();
*/
/* Define relative position of the marker */
ea=((double)(markx[m3])-xminx0)/xresx+1.0;
m1=(long int)(ea);
if(m1<0) m1=0;
if(m1>xresol) m1=xresol;
ea-=(double)(m1);
na=((double)(marky[m3])-yminy0)/yresy+1.0;
m2=(long int)(na);
if(m2<0) m2=0;
if(m2>yresol) m2=yresol;
na-=(double)(m2);
/* Add weights for four nodes surrounding the marker */
m4=nresol+(m1-1)*yresol+(m2-1);
if(m1>0 && m2>0) val0[m4]+=(float)((1.0-ea)*(1.0-na));
if(m1>0 && m2<yresol) val0[m4+1]+=(float)((1.0-ea)*na);
if(m1<xresol && m2>0) val0[m4+yresol]+=(float)(ea*(1.0-na));
if(m1<xresol && m2<yresol) val0[m4+yresol+1]+=(float)(ea*na);
/*
if(xresolsum){printf("%ld %ld %ld %ld %e %e %e %e \n",m3,m1,m2,m4,markx[m3],marky[m3],ea,na); getchar();}
*/
}
/**/
/* Change types for nodes of visual arrays */
for (m1=0;m1<nresol;m1++)
{
if(val0[nresol+m1]>val0[m1])
{
val0[m1]=val0[nresol+m1];
lin0[m1]=ccur;
/* Clear value */
val0[nresol+m1]=0;
}
}
}
/**/
/* Marker type reload for chemical component Visualisation */
yn=0;
for (m1=0;m1<nresol;m1++)
{
if(!val0[m1])
{
lin0[m1]=-1;
yn=1;
}
}
/**/
/* Marker type reinterpolate for empty nodes */
if(gridmod && yn)
{
/* Node cycle */
for (m1=0;m1<xresol;m1++)
for (m2=0;m2<yresol;m2++)
{
m3=m1*yresol+m2;
/* Interpolate marker types from other nodes */
if(lin0[m3]==-1)
{
/* Serch for surrounding non empty nodes */
m4=1;
yn=0;
do
{
cmin=1000,cmax=0;
for (m5=m1-m4;m5<=m1+m4;m5++)
for (m6=m2-m4;m6<=m2+m4;m6++)
if (m5>=0 && m5<xresol && m6>=0 && m6<yresol)
{
m7=m5*yresol+m6;
if(lin0[m7]!=-1)
{
yn=1;
if (cmin>lin0[m7]) cmin=lin0[m7];
if (cmax<lin0[m7]) cmax=lin0[m7];
}
}
m4++;
}
while(!yn && m4<=gridmod);
/**/
/* Recalc using non empty nodes */
if(yn)
{
/* Marker type cycle for chemical component Visualisation */
for (ccur=cmin;ccur<=cmax;ccur++)
{
for (m5=m1-m4+1;m5<m1+m4;m5++)
for (m6=m2-m4+1;m6<m2+m4;m6++)
if (m5>=0 && m5<xresol && m6>=0 && m6<yresol)
{
m7=m5*yresol+m6;
/* Add weight */
if(lin0[m7]==ccur)
{
ea=ABSV(((double)(m5-m1))/(double)(m4));
na=ABSV(((double)(m6-m2))/(double)(m4));
val0[nresol+m3]+=(float)((1.0-ea)*(1.0-na))*val0[m7];
/*
val0[nresol+m3]+=(float)((1.0-ea)*(1.0-na));
{printf("%ld %ld %ld %ld %ld %ld %ld %d \n",m1,m2,m3,m4,m5,m6,m7,ccur); getchar();}
*/
}
}
/* Set new marker type */
if(val0[nresol+m3]>val0[m3])
{
val0[m3]=val0[nresol+m3];
lin0[nresol+m3]=ccur;
/* Clear value */
val0[nresol+m3]=0;
}
}
}
}
}
/**/
/* Marker type reload for chemical component Visualisation */
for (m1=0;m1<nresol;m1++)
{
if(lin0[m1]==-1 && val0[m1])
{
lin0[m1]=lin0[nresol+m1];
lin0[nresol+m1]=0;
yn=1;
}
}
}
}
/* End CHEMICAL COMPONENT VISUALISATION ----------------------------*/
/**/
/**/
/**/
/* TRANSPORT PROPERTIES VISUALISATION +++++++++++++++++++++++++++++ */
if(fl1otp!=5)
{
/**/
/**/
/* Markers cycle (not for shear heating) */
if(fl1otp!=4 && fl1otp!=12)
for (m3=0;m3<=marknum;m3+=markstp)
/* Check markers out of visualisation area */
if ((double)(markx[m3])>xminx && (double)(markx[m3])<xmaxx && (double)(marky[m3])>yminy && (double)(marky[m3])<ymaxy && markt[m3]<50)
{
/*
printf("%ld %d %e %e %e \n",m3,markt[m3],markx[m3],marky[m3],markk[m3]); getchar();
*/
/* P, T parameters calc */
allinter1((double)(markx[m3]),(double)(marky[m3]));
mpb=eps[10]*1e-5;
/* Reset marker temperature for newly coming markers */
if(markk[m3]<1.0) markk[m3]=(float)(eps[2]);
mtk=(double)(markk[m3]);
/* Set starting value for marker maximum temperature field (Tim, 28/12/2016) */
if(markt[m3]!=0)
{
if(marktmax[m3]<markk[m3]) marktmax[m3]=(float)(markk[m3]);
}
/**/
/* Marker type */
mm2=markt[m3];
/* Melt fraction */
meltpart1(mtk,mpb,mm2);
melt_frac[m3]=eps[21];
/**/
/* Marker Properties */
mnu=markv[m3];
/* Min,Max NU limitation */
if(mnu<nubeg) mnu=nubeg;
if(mnu>nuend) mnu=nuend;
mro=dencalc(mtk,mpb,(double)(markpor[m3]),(double)(markx[m3]),(double)(marky[m3]),mm2);
mbb=eps[20];
mcp=markcp[mm2];
mkt=(markkt[mm2]+markkf[mm2]/(mtk+77.0))*exp(markkp[mm2]*mpb);
/* Test Heat conductivity k=ko/(1+b*(T-To)/To) */
if (markkt[mm2]<0) mkt=-markkt[mm2]/(1.0+markkf[mm2]*(mtk-markkp[mm2])/markkp[mm2]);
mht=markht[mm2];
/**/
/**/
/**/
/* Thermodynamic database use for ro, Cp */
if (densimod==2)
if(mm2==5 || mm2==6 || mm2==11 || mm2==12)
{
/* Compute TD variables */
eps[47]=mkt;
tdbasecalc(mtk,mpb,mm2,mm1);
mro=eps[41];
mcp=eps[43];
mbb=eps[44];
mkt=eps[47];
/**/
}
/**/
/*
printf("num=%ld type=%d x=%e y=%e mpb=%e mtk=%e nu=%e ro=%e cp=%e kt=%e ht=%e",mm1,mm2,markx[mm1],marky[mm1],mpb,mtk,mnu,mro,mcp,mkt,mht);getchar();
*/
/**/
/* Define parameter for the visualisation */
/* 1 - T,t = temperature */
/* 2 - V,v = Log viscosity */
/* 3 - S,s = bulk strain */
/* 4 - H,h = Log shear heating */
/* 5 - C,c = chemical field (rock types) */
/* 6 - D,d = density */
/* 7 - K,k = heat conductivity */
/* 8 - G,g = Log total heat generation */
/* 9 - vp - vp-seismic velosity, km/s */
/* 10 - vs - vs-seismic velosity, km/s */
/* 11 - vr - vp/vs */
/* 12 - R,r vorticity/strainrate ratio */
switch(fl1otp)
{
/* 1 - T,t = temperature */
case 1: ival=mtk; break;
/**/
/* 2 - V,v = Log viscosity */
case 2: ival=log(mnu)/log(10.0); break;
/**/
/* 3 - */
case 3: break;
/**/
/* 4 - H,h = Log shear heating */
/* EPSxx*SIGxx EPSyy*SIGyy EPSxy*SIGxy interpolated values */
case 4: ival=2.0*eps[13]+eps[14]+eps[15];
if(ival<1e-30) ival=1e-30;
ival=log(ival)/log(10.0); break;
break;
/**/
/* 6 - D,d = density */
case 6: ival=mro; break;
/**/
/* 7 - K,k = heat conductivity */
case 7: ival=mkt; break;
/**/
/* 8 - G,g = Log total heat generation */
case 8: ival=mht+2.0*eps[13]+eps[14]+eps[15]; break;
if(ival<1e-30) ival=1e-30;
ival=log(ival)/log(10.0);
break;
/**/
/* 9 - vp - vp-seismic velosity, km/s */
case 9: ival=mvp; break;
/**/
/* 10 - vs - vs-seismic velosity, km/s */
case 10: ival=mvs; break;
/**/
/* 11 - vr - vp/vs */
case 11:
ival=0;
if(mvs>0) ival=mvp/mvs;
break;
/**/
/* 12 - R,r - vorticity/shear ratio */
case 12: ival=pow(eps[4]*eps[4]+0.5*(eps[6]*eps[6]+eps[8]*eps[8]),0.5);
/*