-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsuccession4new.cc
More file actions
2119 lines (1734 loc) · 59.2 KB
/
Copy pathsuccession4new.cc
File metadata and controls
2119 lines (1734 loc) · 59.2 KB
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
//
//
// succession4new.cc
//
// 3P-2Z-N-S-D-LA-LF-DIC-Alk version
//
// Program to study four phytoplankton species succession
// in the Bering Sea with two zooplankton (micro, meso), three nutrients (nitrate,
// ammonium, silicate), detritus, attached and free coccoliths, DIC and total alkalinity.
// Carbonate concentration, Omega-calcite and Omega-aragonite cycles are also calculated.
//
// NOTE: In the pre-1995 run, Ehux and coccoliths are set to zero so to avoid
// the carbon system to be affected by the Ehux presence before 1995.
//
//
// Agostino Merico
//
// (Last modified Sep 2003)
//
//
// (Previous modification Mar 2003 to make a multi-year run
// before 1995 followed by a transient run from 1995 to 2002)
//
//
//
// to be compiled using g++ and together with:
//
// routines.cc
// nrutil.cc
//
// EXAMPLE:
// to compile type: g++ succession4new.cc routines.cc nrutil.cc -o a.out -Wno-deprecated
// to run type: ./a.out
//
//
// INPUT FILES: mldXX.in (or mldnew.dat for 'Fasham-modified' MLD)
// sstXX.in
// winXX.in
// sal.in
//
// HEADER FILES: param.h
// nrutil.h
//
//
// CRUCIAL PARAMETERS: Y (number of years to run the model)
// IGNY (number of initial years to ignore for steady-state)
// HOFY (hour of the year to consider for poincare' sections)
//
// trans (set TRUE to look at transient results)
// (set FALSE to look at steady-state results)
//
//
#include <iostream.h>
#include <fstream.h>
#include <math.h>
#include "param.h" // parameters and prototype functions
#include "nrutil.h" // required by function rk4
#define TRUE 1 // first year run
#define FALSE 0 // after first year run
#define NEQ 14 // number of ODEs
#define STEP 366 // number of steps in integration
#define Y 9 // number of years for which run the model (0 is one year cycle)
#define IGNY 0 // number of years required by the model to reach equilibrium (spin-up)
#define HOFY 4320 // hour of the year to consider for poincare' sections
#define DSTEP 365 // number of steps [number of days in one year]
#define HSTEP 8760 // number of steps [number of hours in one year]
#define HHSTEP 17520 // number of steps [number of half hours in one year]
#define HYSTEP 61320 // number of steps [number of hours in seven years 1995-2001]
#define TIME 8758 // normalisation factor for time unit (24 gives X-axis in julian day)
// (8760 gives X-axis in years)
#define TI 1 // initial time [day, huor]
#define TD 366 // final time [day]
#define TH 8761 // final time [hour]
#define THH 17521 // final time [1/2 hour]
// ======== FUNCTIONS ========
void rkdriver(double vstart[], int nvar, double t1, double t2, int nstep,
void (*derivs)(double, double [], double []));
void rk4(double y[], double dydt[], int n, double t, double h, double yout[],
void (*derivs)(double, double [], double []));
void derivs(double t, double y[], double dydt[]);
// ===== GLOBAL VARIABLES =====
static int trans = TRUE; // set to TRUE to look at transient results
// set to FALSE to look at steady-state
int yy;
//double MEH=0.0;
double ingEH=0.0; // variable ingestion rate for Ehuxleyi (depends on omega)
double ingDI=0.0; // variable ingesiton rate for diatoms (depends on silicate)
double pon=0.0; // particulate organic nitrogen
double photoeh=0.0; // photosinthetic rate of Ehux
double calcieh=0.0; // calcification rate of Ehuc
double newphypro=0.0; // new primary production
double regphypro=0.0; // regenerated primary production
double regdiapro=0.0; // regenerated diatoms primary production
double regdinpro=0.0; // regenerated dinofla primary production
double regflapro=0.0; // regenerated flagell primary production
double regehupro=0.0; // regenerated ehuxley primary production
double regtest=0.0;
double totphypro=0.0; // primary production as given by the phytoplankton growth term
double totzoopro=0.0; // total zooplankton biomass
double totphyloss=0.0; // total phytoplankton loss
double totzooloss=0.0; // total zooplankton loss
double totphymix=0.0; // total phytoplankton mixing
double dianutgro=0.0;
double dinnutgro=0.0;
double flanutgro=0.0;
double ehunutgro=0.0;
double dialightgro=0.0;
double dinlightgro=0.0;
double flalightgro=0.0;
double ehulightgro=0.0;
double diagra=0.0;
double dingra=0.0;
double flagra=0.0;
double ehugra=0.0;
double micgra=0.0;
double callightgro=0.0;
double caltemgro=0.0;
double grazd=0.0; // microzoo grazing on diatoms
double graze=0.0; // microzoo grazing on Ehu
double esurf=0.0;
double diff=0.0; // cross-termocline mixing rate
double nbo=0.0;
double sbo=0.0;
double **y, *tt; // required by rkdriver, for communicating back with main
double varTeh=0.0;
double varT=0.0;
double varM=0.0;
double varH=0.0; // h+(t) = maximum(h(t), 0) as in FASH93, h(t) is d(mixed)/dt
double mixed=0.0; // actual mixed layer depth as obtained from Levitus data
double mld[HSTEP]; // mixed layer depth
double mldo[HSTEP];
double *mldp95, *mldp95o, *sstp95, *win94; // forcing prior 1995
double *mld95o, *mld96o, *mld97o, *mld98o, *mld99o, *mld00o, *mld01o;
double *mld95, *mld96, *mld97, *mld98, *mld99, *mld00, *mld01;
double *sst95, *sst96, *sst97, *sst98, *sst99, *sst00, *sst01;
double *par95, *par96, *par97, *par98, *par99, *par00, *par01;
double *win95, *win96, *win97, *win98, *win99, *win00, *win01;
double chltoc=0.0; // adaptive Chl:C ratio
double tem[HSTEP]; // temperature
double sal[HSTEP]; // salinity
double sir[HSTEP]; // irradiance at surface
double wsp[HSTEP]; // wind speed
double gtv=0.0; // gas transfer velocity
double co2sol=0.0; // CO2 solubility in seawater
double pco2w=0.0; // pCO2 in seawater
double co32=0.0; // [CO3=]
double o_cal=0.0; // Omega calcite
double o_ara=0.0; // Omega aragonite
double ph=0.0; // pH
double bica=0.0; // [HCO3-]
double co2aq=0.0; // [CO2(aq)]
double psi=0.0; // light limiting all phytoplankton
double psieh=0.0; // light limiting Emiliania huxleyi
double psica=0.0; // light limiting calcification
double li,gli,nc,gnc,glidf,gncdf,sc,gsc;
double ber=0.0;
double los=0.0;
double yi1,yi2,yi3,yi4,yi5,yi6,yi7,yi8,yi9,yi10,yi11,yi12,yi13,yi14; // initial reservois' values
// open files for results
ofstream outinf("./results/info.dat");
// multi-year solution
ofstream out1("./results/diato.dat");
ofstream out2("./results/flage.dat");
ofstream out3("./results/nitra.dat");
ofstream out4("./results/silic.dat");
ofstream out5("./results/mesoz.dat");
ofstream out6("./results/detri.dat");
ofstream out7("./results/micro.dat");
ofstream out8("./results/dinof.dat");
ofstream out9("./results/ehuxl.dat");
ofstream out10("./results/ammon.dat");
ofstream out11("./results/acocc.dat");
ofstream out12("./results/fcocc.dat");
ofstream out13("./results/tdic.dat");
ofstream out14("./results/talk.dat");
ofstream out15("./results/pco2.dat");
ofstream out16("./results/co32.dat");
ofstream out17("./results/ocal.dat");
ofstream out18("./results/oara.dat");
ofstream out19("./results/tzoop.dat");
ofstream out20("./results/npratio.dat");
ofstream outa("./results/tempd.dat");
ofstream outb("./results/tempdf.dat");
ofstream outc("./results/airr.dat");
ofstream outd("./results/sirr.dat");
// one-year (last) solution
ofstream outl("./results/dia_d.dat");
ofstream outm("./results/fla_d.dat");
ofstream outn("./results/nit_d.dat");
ofstream outo("./results/mic_d.dat");
ofstream outp("./results/din_d.dat");
ofstream outq("./results/sil_d.dat");
ofstream outr("./results/mes_d.dat");
ofstream outs("./results/det_d.dat");
ofstream outw("./results/ehu_d.dat");
ofstream outx("./results/amm_d.dat");
ofstream outf("./results/aco_d.dat");
ofstream outg("./results/fco_d.dat");
ofstream outcp("./results/diagnoST-PROVA.dat");
ofstream outres("./results/resST-PROVA.dat");
ofstream outt("./results/phy_d.dat");
ofstream outu("./results/phyto.dat");
ofstream outy("./results/tzo_d.dat");
ofstream outv("./results/zp.dat");
ofstream outz("./results/ehc_d.dat");
ofstream outctochl("./results/cch_d.dat");
ofstream outluce("./results/ali_d.dat");
ofstream outdic("./results/dic_d.dat");
ofstream outalk("./results/alk_d.dat");
ofstream outpco("./results/pco_d.dat");
ofstream outco3("./results/co3_d.dat");
ofstream outoca("./results/oca_d.dat");
ofstream outora("./results/oar_d.dat");
ofstream outoph("./results/ph_d.dat");
ofstream outobi("./results/bic_d.dat");
ofstream outbe("./results/birth.dat");
ofstream outlo("./results/loss.dat");
ofstream outmi("./results/mixed.dat");
//=================================== MAIN ======================================
main()
{
static int first_time = TRUE; // for setting first year initial conditions
// === LOAD INPUT FILES (MLD, TEMP, SAL, AND WIND SPEED VALUES) ===
int h=0;
int hi=0;
int t=0;
mldp95=dvector(1,HSTEP);
mldp95o=dvector(1,HSTEP);
sstp95=dvector(1,HSTEP);
win94=dvector(1,HSTEP);
mld95=dvector(1,HSTEP);
sst95=dvector(1,HSTEP);
par95=dvector(1,HSTEP);
win95=dvector(1,HSTEP);
mld96=dvector(1,HSTEP);
sst96=dvector(1,HSTEP);
par96=dvector(1,HSTEP);
win96=dvector(1,HSTEP);
mld97=dvector(1,HSTEP);
sst97=dvector(1,HSTEP);
par97=dvector(1,HSTEP);
win97=dvector(1,HSTEP);
mld98=dvector(1,HSTEP);
sst98=dvector(1,HSTEP);
par98=dvector(1,HSTEP);
win98=dvector(1,HSTEP);
mld99=dvector(1,HSTEP);
sst99=dvector(1,HSTEP);
par99=dvector(1,HSTEP);
win99=dvector(1,HSTEP);
mld00=dvector(1,HSTEP);
sst00=dvector(1,HSTEP);
par00=dvector(1,HSTEP);
win00=dvector(1,HSTEP);
mld01=dvector(1,HSTEP);
sst01=dvector(1,HSTEP);
par01=dvector(1,HSTEP);
win01=dvector(1,HSTEP);
mld95o=dvector(1,HSTEP);
mld96o=dvector(1,HSTEP);
mld97o=dvector(1,HSTEP);
mld98o=dvector(1,HSTEP);
mld99o=dvector(1,HSTEP);
mld00o=dvector(1,HSTEP);
mld01o=dvector(1,HSTEP);
//char mldp95f[20]=".input/mldnew2i.in";
//char sstp95f[20]=".input/tem.in";
char mldp95f[20]="./input/mldnew2i.in";
char sstp95f[20]="./input/tem.in";
char win94f[20]="./input/win94.in";
char mld95f[20]="./input/mld95i2.in";
char sst95f[20]="./input/sst95i.in";
char par95f[20]="./input/par95n.in";
char win95f[20]="./input/win95.in";
char mld96f[20]="./input/mld96i.in";
char sst96f[20]="./input/sst96i.in";
char par96f[20]="./input/par96n.in";
char win96f[20]="./input/win96.in";
char mld97f[20]="./input/mld97i2.in";
char sst97f[20]="./input/sst97i.in";
char par97f[20]="./input/par97n.in";
char win97f[20]="./input/win97.in";
char mld98f[20]="./input/mld98i.in";
char sst98f[20]="./input/sst98i.in";
char par98f[20]="./input/par98n.in";
char win98f[20]="./input/win98.in";
char mld99f[20]="./input/mld99i.in";
char sst99f[20]="./input/sst99i.in";
char par99f[20]="./input/par99n.in";
char win99f[20]="./input/win99.in";
char mld00f[20]="./input/mld00i.in";
char sst00f[20]="./input/sst00i.in";
char par00f[20]="./input/par00n.in";
char win00f[20]="./input/win00.in";
char mld01f[20]="./input/mld01i2.in";
char sst01f[20]="./input/sst01bi2.in";
char par01f[20]="./input/par01n.in";
char win01f[20]="./input/win01.in";
//============== Forcing for post-1995 years =============
if(trans){
cout<<endl;
cout<<"looking at transient"<<endl;
cout<<endl;
// === open 1995 ===
ifstream inl1(mld95f);
if(!inl1){
cout<<" Impossible to open 1995 MLD file\n";
return 1;
}
ifstream inl2(sst95f);
if(!inl2){
cout<<" Impossible to open 1995 TEM file\n";
return 1;
}
ifstream inl3(par95f);
if(!inl3){
cout<<" Impossible to open 1995 PAR file\n";
return 1;
}
ifstream inlw1(win95f);
if(!inlw1){
cout<<" Impossible to open 1995 WIN file\n";
return 1;
}
// === open 1996 ===
ifstream inl4(mld96f);
if(!inl4){
cout<<" Impossible to open 1996 MLD file\n";
return 1;
}
ifstream inl5(sst96f);
if(!inl5){
cout<<" Impossible to open 1996 TEM file\n";
return 1;
}
ifstream inl6(par96f);
if(!inl6){
cout<<" Impossible to open 1996 PAR file\n";
return 1;
}
ifstream inlw2(win96f);
if(!inlw2){
cout<<" Impossible to open 1997 WIN file\n";
return 1;
}
// === open 1997 ===
ifstream inl7(mld97f);
if(!inl7){
cout<<" Impossible to open 1997 MLD file\n";
return 1;
}
ifstream inl8(sst97f);
if(!inl8){
cout<<" Impossible to open 1997 TEM file\n";
return 1;
}
ifstream inl9(par97f);
if(!inl9){
cout<<" Impossible to open 1997 PAR file\n";
return 1;
}
ifstream inlw3(win97f);
if(!inlw3){
cout<<" Impossible to open 1997 WIN file\n";
return 1;
}
// === open 1998 ===
ifstream inl10(mld98f);
if(!inl10){
cout<<" Impossible to open 1998 MLD file\n";
return 1;
}
ifstream inl11(sst98f);
if(!inl11){
cout<<" Impossible to open 1998 TEM file\n";
return 1;
}
ifstream inl12(par98f);
if(!inl12){
cout<<" Impossible to open 1998 PAR file\n";
return 1;
}
ifstream inlw4(win95f);
if(!inlw4){
cout<<" Impossible to open 1998 WIN file\n";
return 1;
}
// === open 1999 ===
ifstream inl13(mld99f);
if(!inl13){
cout<<" Impossible to open 1999 MLD file\n";
return 1;
}
ifstream inl14(sst99f);
if(!inl14){
cout<<" Impossible to open 1999 TEM file\n";
return 1;
}
ifstream inl15(par99f);
if(!inl15){
cout<<" Impossible to open 1999 PAR file\n";
return 1;
}
ifstream inlw5(win99f);
if(!inlw5){
cout<<" Impossible to open 1999 WIN file\n";
return 1;
}
// === open 2000 ===
ifstream inl16(mld00f);
if(!inl16){
cout<<" Impossible to open 2000 MLD file\n";
return 1;
}
ifstream inl17(sst00f);
if(!inl17){
cout<<" Impossible to open 2000 TEM file\n";
return 1;
}
ifstream inl18(par00f);
if(!inl18){
cout<<" Impossible to open 2000 PAR file\n";
return 1;
}
ifstream inlw6(win95f);
if(!inlw6){
cout<<" Impossible to open 2000 WIN file\n";
return 1;
}
// === open 2001 ===
ifstream inl19(mld01f);
if(!inl19){
cout<<" Impossible to open 2001 MLD file\n";
return 1;
}
ifstream inl20(sst01f);
if(!inl20){
cout<<" Impossible to open 2001 TEM file\n";
return 1;
}
ifstream inl21(par01f);
if(!inl21){
cout<<" Impossible to open 2001 PAR file\n";
return 1;
}
ifstream inlw7(win95f);
if(!inlw7){
cout<<" Impossible to open 2001 WIN file\n";
return 1;
}
// ==== load 1995 ====
t=0;
while(inl1){
inl1>>mld95[t];
//test
mld95[t]=mld95[t];// + 3.0;
mld95o[t]=mld95[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld95[h]=(mld95[h+1]-mld95[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl2){
inl2>>sst95[t];
t++;
}
t=0;
while(inl3){
inl3>>par95[t];
t++;
}
t=0;
while(inlw1){
inlw1>>win95[t];
t++;
}
// ==== load 1996 ====
t=0;
while(inl4){
inl4>>mld96[t];
//test
mld96[t]=mld96[t];// + 3.0;
mld96o[t]=mld96[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld96[h]=(mld96[h+1]-mld96[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl5){
inl5>>sst96[t];
t++;
}
t=0;
while(inl6){
inl6>>par96[t];
t++;
}
t=0;
while(inlw2){
inlw2>>win96[t];
t++;
}
// ==== load 1997 ====
t=0;
while(inl7){
inl7>>mld97[t];
//test
mld97[t]=mld97[t];// - 5.0;
mld97o[t]=mld97[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld97[h]=(mld97[h+1]-mld97[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl8){
inl8>>sst97[t];
t++;
}
t=0;
while(inl9){
inl9>>par97[t];
t++;
}
t=0;
while(inlw3){
inlw3>>win97[t];
t++;
}
// ==== load 1998 ====
t=0;
while(inl10){
inl10>>mld98[t];
//test
mld98[t]=mld98[t];// + 3.0;
mld98o[t]=mld98[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld98[h]=(mld98[h+1]-mld98[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl11){
inl11>>sst98[t];
t++;
}
t=0;
while(inl12){
inl12>>par98[t];
t++;
}
t=0;
while(inlw4){
inlw4>>win98[t];
t++;
}
// ==== load 1999 ====
t=0;
while(inl13){
inl13>>mld99[t];
//test
mld99[t]=mld99[t];// + 3.0;
mld99o[t]=mld99[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld99[h]=(mld99[h+1]-mld99[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl14){
inl14>>sst99[t];
t++;
}
t=0;
while(inl15){
inl15>>par99[t];
t++;
}
t=0;
while(inlw5){
inlw5>>win99[t];
t++;
}
// ==== load 2000 ====
t=0;
while(inl16){
inl16>>mld00[t];
//test
mld00[t]=mld00[t];// + 3.0;
mld00o[t]=mld00[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld00[h]=(mld00[h+1]-mld00[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl17){
inl17>>sst00[t];
t++;
}
t=0;
while(inl18){
inl18>>par00[t];
t++;
}
t=0;
while(inlw6){
inlw6>>win00[t];
t++;
}
// ==== load 2001 ====
t=0;
while(inl19){
inl19>>mld01[t];
//test
mld01[t]=mld01[t];// + 3.0;
mld01o[t]=mld01[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld01[h]=(mld01[h+1]-mld01[h])/1.0; // 1.0 is the time interval (1 hour)
}
t=0;
while(inl20){
inl20>>sst01[t];
t++;
}
t=0;
while(inl21){
inl21>>par01[t];
t++;
}
t=0;
while(inlw7){
inlw7>>win01[t];
t++;
}
// === close input files ===
inl1.close();
inl2.close();
inl3.close();
inl4.close();
inl5.close();
inl6.close();
inl7.close();
inl8.close();
inl9.close();
inl10.close();
inl11.close();
inl12.close();
inl13.close();
inl14.close();
inl15.close();
inl16.close();
inl17.close();
inl18.close();
inl19.close();
inl20.close();
inl21.close();
inlw1.close();
inlw2.close();
inlw3.close();
inlw4.close();
inlw5.close();
inlw6.close();
inlw7.close();
}
else{
cout<<endl;
cout<<"looking at steady-state"<<endl;
cout<<endl;
ifstream in1(mld96f); //in1("mldnew.dat");
if(!in1){
cout<<" Impossible to open MLD file\n";
return 1;
}
ifstream in2(sst96f); //in2("tem.dat");
if(!in2){
cout<<" Impossible to open TEM file\n";
return 1;
}
ifstream in5(par96f);
if(!in5){
cout<<" Impossible to open PAR file\n";
return 1;
}
ifstream inw(win96f);
if(!inw){
cout<<" Impossible to open WIN file\n";
return 1;
}
t=0;
while(in1){
in1>>mld96[t];
mld96o[t]=mld96[t];
t++;
}
t=0;
while(in2){
in2>>sst96[t];
//tem[t]+=5;
t++;
}
t=0;
while(in5){
in5>>par96[t];
t++;
}
t=0;
while(inw){
inw>>win96[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mld96[h]=(mld96[h+1]-mld96[h])/1.0; // 1.0 is the time interval (1 hour)
}
in1.close();
in2.close();
in5.close();
inw.close();
}
//==================================================
// ==== open pre-1995 ====
ifstream in6(mldp95f);
if(!in6){
cout<<" Impossible to open pre-1995 MLD file\n";
return 1;
}
ifstream in7(sstp95f);
if(!in7){
cout<<" Impossible to open pre-1995 SST file\n";
return 1;
}
ifstream in8(par95f);
if(!in8){
cout<<" Impossible to open pre-1995 PAR file\n";
return 1;
}
ifstream in9(win94f);
if(!in9){
cout<<" Impossible to open pre-1995 WIN file\n";
return 1;
}
// ==== load pre-1995 ====
t=0;
while(in6){
in6>>mldp95[t];
mldp95o[t]=mldp95[t];
t++;
}
t=0;
while(in7){
in7>>sstp95[t];
t++;
}
t=0;
while(in8){
in8>>par95[t];
t++;
}
t=0;
while(in9){
in9>>win94[t];
t++;
}
for(h=0;h<=HSTEP;h++){ // calculating dM/dt, as in FASH93 at pag.493
mldp95[h]=(mldp95[h+1]-mldp95[h])/1.0; // 1.0 is the time interval (1 hour)
}
// == THESE SAL AND WSP SHOULD BE DELETED NOW ==
// == open sal and WSP ==
ifstream in3("./input/sal.in");
if(!in3){
cout<<" Impossible to open SAL file\n";
return 1;
}
ifstream in4("./input/wsp.in");
if(!in4){
cout<<" Impossible to open WSP file\n";
return 1;
}
// == load sal and WSP ==
t=0;
while(in3){
in3>>sal[t];
t++;
}
t=0;
while(in4){
in4>>wsp[t];
t++;
}
in3.close();
in4.close();
// =============================================
in6.close();
in7.close();
in8.close();
in9.close();
// =================================================
int i=0;
double *vstart;
tt=dvector(1,HSTEP);
y=dmatrix(1,NEQ,1,HSTEP);
vstart=dvector(1,NEQ);
// ======== set initial conditions ===========
double i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14;
if(first_time){ // setting first year initial conditions
first_time = FALSE;
i1=0.01; // dia 0.01
i2=0.01; // fla 0.01
i3=20.0; // 15 nit
i4=35.0; // 30 sil
i5=0.01; // mes
i6=0.05; // det
i7=0.01; // mic
i8=0.01; // din 0.01
i9=0.01; //0.01; // ehu 0.01
i10=0.0001;// amm (WHIT99, in Dynamics of Bering Sea)
i11=0.3; //0.3; // aco 0.3 (about 30 times the concentration of Ehux)
i12=0.0001;//0.0001; // fco
i13=2100.0;// dic
i14=2250.0;// alk
outres<<"#jday "<<"month "<<"temp "<<"MLD "<<"sal "<<"Irr "<<"diato "<<"flage "<<"dino "
<<"ehux "<<"microz "<<"mesoz "<<"totphy "<<"nit "<<"ammo "<<"sil "<<"DIC "<<"Alk "
<<"pCO2 "<<"CO3 "<<"omegacal "<<"omegaara "<<"acocco "<<"fcocco "<<"CO2(aq) "<<"HCO3 "
<<"totzoo "<<endl;
outcp<<"#jday "<<"month "<<"Pho:Cal ratio "<<"f-ratio "<<"Tot phy biomass "
<<"Tot phy prod (phyto growth terms) "<<"PON "<<"Tot zoo biomass "
<<"C:Chl ratio "<<"TAlk "<<"Sal"<<endl;
}
vstart[1]=i1; // [1] - diatoms
vstart[2]=i2; // [2] - flagellates
vstart[3]=i3; // [3] - nitrogen
vstart[4]=i4; // [4] - silicate
vstart[5]=i5; // [5] - mesozooplankton
vstart[6]=i6; // [6] - detritus
vstart[7]=i7; // [7] - microzooplankton
vstart[8]=i8; // [8] - dinoflagellates
vstart[9]=i9; // [9] - ehux
vstart[10]=i10; // [10] - ammonia
vstart[11]=i11; // [11] - attached coccoliths
vstart[12]=i12; // [12] - free coccoliths
vstart[13]=i13; // [13] - total dissolved inorganic carbon
vstart[14]=i14; // [14] - total alkalinity
//vstart[10]=0.0; // [10] - silicate mass balance management
//vstart[11]=0.0; // [11] - nitrogen mass balance management
yi1=vstart[1];
yi2=vstart[2];
yi3=vstart[3];
yi4=vstart[4];
yi5=vstart[5];
yi6=vstart[6];
yi7=vstart[7];
yi8=vstart[8];
yi9=vstart[9];
yi10=vstart[10];
yi11=vstart[11];
yi12=vstart[12];
yi13=vstart[13];
yi14=vstart[14];