forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cost_gencost_sshv4.F
1377 lines (1217 loc) · 47.8 KB
/
cost_gencost_sshv4.F
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
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_gencost_sshv4.F,v 1.34 2015/11/12 12:11:20 atn Exp $
C $Name: $
#include "ECCO_OPTIONS.h"
subroutine cost_gencost_sshv4(
I mythid
& )
c ==================================================================
c SUBROUTINE cost_gencost_sshv4
c ==================================================================
c
c o Evaluate cost function contributions of sea surface height.
c
c started: Gael Forget, Oct-2009
c
c working assumption for the time mean dynamic topography (MDT) constraint:
c the various SLA data sets (tp, ers, gfo) have been consistenty cross-referenced,
c as done in the RADS data sets. We do not need to know the reference dynamic
c topography (or SSH/Geoid). Simply it is assumed that the biases
c between instruments have been taken care of. This is only a matter
c for the MDT constraint, not for SLA constraints (see below).
c
cgf 1) there are a few hardcoded numbers that will eventually be put in common
cgf blocks/namelists
cgf 2) there are a several refinements that should be considered, such as
cgf modulating weights with respect to numbers of samples
c
c ==================================================================
c SUBROUTINE cost_gencost_sshv4
c ==================================================================
implicit none
c == global variables ==
#include "EEPARAMS.h"
#include "SIZE.h"
#include "PARAMS.h"
#include "GRID.h"
#ifdef ALLOW_CAL
# include "cal.h"
#endif
#ifdef ALLOW_ECCO
# include "ecco.h"
#endif
#ifdef ALLOW_SMOOTH
# include "SMOOTH.h"
#endif
c == routine arguments ==
integer mythid
#ifdef ALLOW_GENCOST_CONTRIBUTION
c == functions ==
LOGICAL MASTER_CPU_THREAD
EXTERNAL MASTER_CPU_THREAD
c == local variables ==
integer bi,bj
integer i,j,k
integer itlo,ithi
integer jtlo,jthi
integer jmin,jmax
integer imin,imax
integer irec,jrec,krec
integer ilps
logical doglobalread
logical ladinit
c mapping to gencost
integer igen_mdt, igen_lsc, igen_gmsl
integer igen_tp, igen_ers, igen_gfo
integer igen_etaday
_RL spval, factor
_RL offset
_RL offset_sum
_RL slaoffset
_RL slaoffset_sum
_RL slaoffset_weight
c local arrays
_RL num0array ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy )
_RL num0total
integer tempinteger
_RL diagnosfld ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy )
_RL mdtob(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL tpob(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL ersob(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL gfoob(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mdtma(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL tpma(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL ersma(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL gfoma(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL etaday(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
character*(MAX_LEN_FNAM) mdtfi, tpfi, ersfi, gfofi
integer tpsta(4), erssta(4), gfosta(4)
integer mdtsta(4), mdtend(4)
_RL tpper, ersper, gfoper
c for PART 1: re-reference MDT (mdt) to the inferred SLA reference field
_RL psmean ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy )
_RL mean_slaobs_mdt(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_slaobs_NUM(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
c for PART 2: compute time mean differences over the model period
_RL mean_slaobs_model(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMssh_all(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMssh_all_NUM(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMssh_all_MSK(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMslaobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMslaobs_MSK(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMtpobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMtpobs_NUM(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMersobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMersobs_NUM(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMgfoobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL mean_psMgfoobs_NUM(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
c for PART 4/5: compute smooth/raw anomalies
_RL anom_psMslaobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_psMslaobs_NUM (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_psMslaobs_MSK (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_psMslaobs_SUB (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_slaobs (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_slaobs_SUB (1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_psMtpobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_tpobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_psMersobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_ersobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_psMgfoobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
_RL anom_gfoobs(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
integer mdt_y0,mdt_y1,year,day
integer num0
_RL junk,junkweight
integer ndaysave
_RL ndaysaveRL
character*(80) fname
character*(80) fname4test
character*(MAX_LEN_MBUF) msgbuf
LOGICAL doReference
LOGICAL useEtaMean
c == external functions ==
integer ilnblnk
external ilnblnk
c == end of interface ==
jtlo = mybylo(mythid)
jthi = mybyhi(mythid)
itlo = mybxlo(mythid)
ithi = mybxhi(mythid)
jmin = 1
jmax = sny
imin = 1
imax = snx
c-- detect the relevant gencost indices
igen_mdt=0
igen_tp =0
igen_ers=0
igen_gfo=0
igen_lsc=0
igen_gmsl=0
igen_etaday=0
do k=1,NGENCOST
if (gencost_name(k).EQ.'sshv4-mdt') igen_mdt=k
if (gencost_name(k).EQ.'sshv4-tp') igen_tp=k
if (gencost_name(k).EQ.'sshv4-ers') igen_ers=k
if (gencost_name(k).EQ.'sshv4-gfo') igen_gfo=k
if (gencost_name(k).EQ.'sshv4-lsc') igen_lsc=k
if (gencost_name(k).EQ.'sshv4-gmsl') igen_gmsl=k
enddo
call ecco_zero(gencost_weight(:,:,1,1,igen_mdt),1,zeroRL,myThid)
call ecco_zero(gencost_weight(:,:,1,1,igen_lsc),1,zeroRL,myThid)
call ecco_zero(gencost_weight(:,:,1,1,igen_tp),1,zeroRL,myThid)
call ecco_zero(gencost_weight(:,:,1,1,igen_ers),1,zeroRL,myThid)
call ecco_zero(gencost_weight(:,:,1,1,igen_gfo),1,zeroRL,myThid)
if ( gencost_errfile(igen_mdt) .NE. ' ' )
& call ecco_readwei(gencost_errfile(igen_mdt),
& gencost_weight(:,:,1,1,igen_mdt),1,1,mythid)
if ( gencost_errfile(igen_lsc) .NE. ' ' )
& call ecco_readwei(gencost_errfile(igen_lsc),
& gencost_weight(:,:,1,1,igen_lsc),1,1,mythid)
if ( gencost_errfile(igen_tp) .NE. ' ' )
& call ecco_readwei(gencost_errfile(igen_tp),
& gencost_weight(:,:,1,1,igen_tp),1,1,mythid)
if ( gencost_errfile(igen_ers) .NE. ' ' )
& call ecco_readwei(gencost_errfile(igen_ers),
& gencost_weight(:,:,1,1,igen_ers),1,1,mythid)
if ( gencost_errfile(igen_gfo) .NE. ' ' )
& call ecco_readwei(gencost_errfile(igen_gfo),
& gencost_weight(:,:,1,1,igen_gfo),1,1,mythid)
c switch for excluding global mean
useEtaMean=.TRUE.
write(msgbuf,'(a,l)')
& ' sshv4: use global mean of eta useEtaMean=',useEtaMean
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
c minimum number of observations to consider re-referenced MDT
num0=100
c determine whether or not to re-reference
c-- not only model period has to fall within the mdt period
c-- but that there has to be at least 365 days of model run
c-- so for short model run, this will always get set to FALSE
doReference=.FALSE.
if ((modelstartdate(1).GT.1992*10000).AND.
& (modelstartdate(1).LT.2011*10000).AND.
& (ndaysrec.GE.365)) doReference=.TRUE.
write(msgbuf,'(a,l)') ' sshv4:re-reference MDT=',doReference
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
c-- initialize local arrays
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
mdtma(i,j,bi,bj) = 0. _d 0
mdtob(i,j,bi,bj) = 0. _d 0
tpma(i,j,bi,bj) = 0. _d 0
tpob(i,j,bi,bj) = 0. _d 0
ersma(i,j,bi,bj) = 0. _d 0
ersob(i,j,bi,bj) = 0. _d 0
gfoma(i,j,bi,bj) = 0. _d 0
gfoob(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
c mdtfi, mdtsta, mdtend
if (igen_mdt.GT.0) then
ilps=ilnblnk( gencost_datafile(igen_mdt) )
mdtfi=gencost_datafile(igen_mdt)(1:ilps)
call cal_CopyDate(gencost_startdate(1,igen_mdt),mdtsta,mythid)
call cal_CopyDate(gencost_enddate(1,igen_mdt), mdtend, mythid)
endif
c tpfi, tpsta, tpper
if (igen_tp.GT.0) then
ilps=ilnblnk( gencost_datafile(igen_tp) )
tpfi=gencost_datafile(igen_tp)(1:ilps)
call cal_CopyDate(gencost_startdate(1,igen_tp),tpsta,mythid)
tpper=gencost_period(igen_tp)
if (gencost_barfile(igen_tp)(1:5).EQ.'m_eta')
& igen_etaday=igen_tp
endif
c ersfi, erssta, ersper
if (igen_ers.GT.0) then
ilps=ilnblnk( gencost_datafile(igen_ers) )
ersfi=gencost_datafile(igen_ers)(1:ilps)
call cal_CopyDate(gencost_startdate(1,igen_ers),erssta,mythid)
ersper=gencost_period(igen_ers)
if (gencost_barfile(igen_ers)(1:5).EQ.'m_eta')
& igen_etaday=igen_ers
endif
c gfofi, gfosta, gfoper
if (igen_gfo.GT.0) then
ilps=ilnblnk( gencost_datafile(igen_gfo) )
gfofi=gencost_datafile(igen_gfo)(1:ilps)
call cal_CopyDate(gencost_startdate(1,igen_gfo),gfosta,mythid)
gfoper=gencost_period(igen_gfo)
if (gencost_barfile(igen_gfo)(1:5).EQ.'m_eta')
& igen_etaday=igen_gfo
endif
c mdt_y0, mdt_y1
mdt_y0=mdtsta(1)/10000
mdt_y1=mdtend(1)/10000
write(msgbuf,'(a,i8,a,i8)')
& 'mdt[start,end]date(1): ', mdtsta(1), ',', mdtend(1)
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(a,i4,a,i4)')
& ' TP MDT yrrange: ', mdt_y0, ',', mdt_y1
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
c-- First, read tiled data.
doglobalread = .false.
ladinit = .false.
write(fname(1:80),'(80a)') ' '
ilps=ilnblnk( gencost_barfile(igen_etaday) )
write(fname(1:80),'(2a,i10.10)')
& gencost_barfile(igen_etaday)(1:ilps),'.',eccoiter
cgf =======================================================
cgf PART 1:
cgf x Get the MDT (mdt) ... compute the sample mean
cgf (mean_slaobs_mdt) of the SLA data (i.e. RADS for tp, ers, and gfo
cgf together) over the time interval of the MDT ... subtract
cgf mean_slaobs_mdt from mdt.
cgf x At this point, mdt is the inferred SLA reference field.
cgf x From there on, mdt+sla will be directly comparable to
cgf the model SSH (etaday).
cgf =======================================================
c-- Read mean field and mask
if (using_mdt)
&call mdsreadfield( mdtfi, cost_iprec, cost_yftype, 1,
& mdtob, 1, mythid )
factor = 0.01 _d 0
spval = -9990. _d 0
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( (maskC(i,j,1,bi,bj) .eq. 0.).OR.
#ifndef ALLOW_SHALLOW_ALTIMETRY
& (R_low(i,j,bi,bj).GT.-200.).OR.
#endif
& (mdtob(i,j,bi,bj) .lt. spval ).OR.
& (mdtob(i,j,bi,bj) .eq. 0. _d 0) ) then
mdtma(i,j,bi,bj) = 0. _d 0
mdtob(i,j,bi,bj) = 0. _d 0
else
mdtma(i,j,bi,bj) = 1. _d 0
mdtob(i,j,bi,bj) = mdtob(i,j,bi,bj)*factor
endif
enddo
enddo
enddo
enddo
c-- Compute mean_slaobs_mdt: sample mean SLA over the time period of mdt.
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
mean_slaobs_mdt(i,j,bi,bj) = 0. _d 0
mean_slaobs_NUM(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
do year=mdt_y0,mdt_y1
do day=1,366
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
tpma(i,j,bi,bj) = 0. _d 0
tpob(i,j,bi,bj) = 0. _d 0
ersma(i,j,bi,bj) = 0. _d 0
ersob(i,j,bi,bj) = 0. _d 0
gfoma(i,j,bi,bj) = 0. _d 0
gfoob(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
if (using_tpj)
& call cost_sla_read_yd( tpfi, tpsta,
& tpob, tpma,
& year, day, mythid )
if (using_ers)
& call cost_sla_read_yd( ersfi, erssta,
& ersob, ersma,
& year, day, mythid )
if (using_gfo)
& call cost_sla_read_yd( gfofi, gfosta,
& gfoob, gfoma,
& year, day, mythid )
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( tpma(i,j,bi,bj)*mdtma(i,j,bi,bj)*
& gencost_weight(i,j,bi,bj,igen_tp) .NE. 0. ) then
mean_slaobs_mdt(i,j,bi,bj)= mean_slaobs_mdt(i,j,bi,bj)+
& tpob(i,j,bi,bj)
mean_slaobs_NUM(i,j,bi,bj)= mean_slaobs_NUM(i,j,bi,bj)+1. _d 0
endif
if ( ersma(i,j,bi,bj)*mdtma(i,j,bi,bj)*
& gencost_weight(i,j,bi,bj,igen_ers) .NE. 0. ) then
mean_slaobs_mdt(i,j,bi,bj)= mean_slaobs_mdt(i,j,bi,bj)+
& ersob(i,j,bi,bj)
mean_slaobs_NUM(i,j,bi,bj)= mean_slaobs_NUM(i,j,bi,bj)+1. _d 0
endif
if ( gfoma(i,j,bi,bj)*mdtma(i,j,bi,bj)*
& gencost_weight(i,j,bi,bj,igen_gfo) .NE. 0. ) then
mean_slaobs_mdt(i,j,bi,bj)= mean_slaobs_mdt(i,j,bi,bj)+
& gfoob(i,j,bi,bj)
mean_slaobs_NUM(i,j,bi,bj)= mean_slaobs_NUM(i,j,bi,bj)+1. _d 0
endif
enddo
enddo
enddo
enddo
enddo !do day=1,366
enddo !do year=mdt_y0,mdt_y1
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( ( mean_slaobs_NUM(i,j,bi,bj) .NE. 0. ).AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. ).AND.
& ( mdtma(i,j,bi,bj) .NE. 0. ) ) then
mean_slaobs_mdt(i,j,bi,bj) =
& mean_slaobs_mdt(i,j,bi,bj) /
& mean_slaobs_NUM(i,j,bi,bj)
else
mean_slaobs_mdt(i,j,bi,bj) = 0. _d 0
endif
enddo
enddo
enddo
enddo
c-- smooth mean_slaobs_mdt:
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'sla2mdt_raw'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,mean_slaobs_mdt,1,1,mythid)
endif
#ifdef ALLOW_SMOOTH
if ( useSMOOTH )
& call smooth_hetero2d(mean_slaobs_mdt,maskc,
& gencost_scalefile(igen_mdt),
& gencost_smooth2Ddiffnbt(igen_mdt),mythid)
#endif
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'sla2mdt_smooth'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,mean_slaobs_mdt,1,1,mythid)
endif
c-- re-reference mdt:
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( ( mdtma(i,j,bi,bj) .NE. 0. ).AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. ).AND.
& ( doReference ) ) then
mdtob(i,j,bi,bj) = mdtob(i,j,bi,bj)
& -mean_slaobs_mdt(i,j,bi,bj)
endif
enddo
enddo
enddo
enddo
cgf =======================================================
cgf PART 2: compute sample means of etaday-slaobs over the
cgf period that is covered by the model (i.e. etaday).
cgf x for all SLA data sets together: mean_psMssh_all, mean_psMssh_all_MSK,
cgf and offset will be used in PART 3 (MDT cost term).
cgf x for each SLA data individually. mean_psMtpobs, mean_psMtpobs_MS, etc.
cgf will be used in PART 4&5 (SLA cost terms).
cgf =======================================================
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
psmean(i,j,bi,bj) = 0. _d 0
mean_psMslaobs(i,j,bi,bj) = 0. _d 0
mean_psMtpobs(i,j,bi,bj) = 0. _d 0
mean_psMersobs(i,j,bi,bj) = 0. _d 0
mean_psMgfoobs(i,j,bi,bj) = 0. _d 0
mean_psMssh_all(i,j,bi,bj) = 0. _d 0
mean_slaobs_model(i,j,bi,bj) = 0. _d 0
mean_psMtpobs_NUM(i,j,bi,bj) = 0. _d 0
mean_psMersobs_NUM(i,j,bi,bj) = 0. _d 0
mean_psMgfoobs_NUM(i,j,bi,bj) = 0. _d 0
mean_psMssh_all_NUM(i,j,bi,bj) = 0. _d 0
mean_psMslaobs_MSK(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
offset = 0. _d 0
offset_sum = 0. _d 0
do irec = 1, ndaysrec
#ifdef ALLOW_AUTODIFF
call active_read_xy( fname, etaday, irec, doglobalread,
& ladinit, eccoiter, mythid,
& gencost_dummy(igen_etaday) )
#else
CALL READ_REC_XY_RL( fname, etaday, iRec, 1, myThid )
#endif
if (.NOT.useEtaMean)
& CALL REMOVE_MEAN_RL( 1, etaday, maskInC, maskInC, rA, drF,
& 'etaday', 0. _d 0, myThid )
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
tpma(i,j,bi,bj) = 0. _d 0
tpob(i,j,bi,bj) = 0. _d 0
ersma(i,j,bi,bj) = 0. _d 0
ersob(i,j,bi,bj) = 0. _d 0
gfoma(i,j,bi,bj) = 0. _d 0
gfoob(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
if (using_tpj)
& call cost_sla_read( tpfi, tpsta, tpper,
& zeroRL, zeroRL,
& tpob, tpma,
& irec, mythid )
if (using_ers)
& call cost_sla_read( ersfi, erssta, ersper,
& zeroRL, zeroRL,
& ersob, ersma,
& irec, mythid )
if (using_gfo)
& call cost_sla_read( gfofi, gfosta, gfoper,
& zeroRL, zeroRL,
& gfoob, gfoma,
& irec, mythid )
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
psmean(i,j,bi,bj) = psmean(i,j,bi,bj) +
& etaday(i,j,bi,bj) / float(ndaysrec)
if ( tpma(i,j,bi,bj)*
& gencost_weight(i,j,bi,bj,igen_tp) .NE. 0. ) then
mean_slaobs_model(i,j,bi,bj)=
& mean_slaobs_model(i,j,bi,bj)+tpob(i,j,bi,bj)
mean_psMtpobs(i,j,bi,bj) =
& mean_psMtpobs(i,j,bi,bj) +
& etaday(i,j,bi,bj)-tpob(i,j,bi,bj)
mean_psMtpobs_NUM(i,j,bi,bj) =
& mean_psMtpobs_NUM(i,j,bi,bj) + 1. _d 0
endif
if ( ersma(i,j,bi,bj)*
& gencost_weight(i,j,bi,bj,igen_ers) .NE. 0. ) then
mean_slaobs_model(i,j,bi,bj)=
& mean_slaobs_model(i,j,bi,bj)+ersob(i,j,bi,bj)
mean_psMersobs(i,j,bi,bj) =
& mean_psMersobs(i,j,bi,bj) +
& etaday(i,j,bi,bj)-ersob(i,j,bi,bj)
mean_psMersobs_NUM(i,j,bi,bj) =
& mean_psMersobs_NUM(i,j,bi,bj) + 1. _d 0
endif
if ( gfoma(i,j,bi,bj)*
& gencost_weight(i,j,bi,bj,igen_gfo) .NE. 0. ) then
mean_slaobs_model(i,j,bi,bj)=
& mean_slaobs_model(i,j,bi,bj)+gfoob(i,j,bi,bj)
mean_psMgfoobs(i,j,bi,bj) =
& mean_psMgfoobs(i,j,bi,bj) +
& etaday(i,j,bi,bj)-gfoob(i,j,bi,bj)
mean_psMgfoobs_NUM(i,j,bi,bj) =
& mean_psMgfoobs_NUM(i,j,bi,bj) + 1. _d 0
endif
enddo
enddo
enddo
enddo
c-- END loop over records for the first time.
enddo
call ecco_zero(num0array,1,oneRL,mythid)
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( ( mean_psMtpobs_NUM(i,j,bi,bj) .NE. 0. )
& ) then
mean_psMssh_all(i,j,bi,bj) =
& mean_psMssh_all(i,j,bi,bj) +
& mean_psMtpobs(i,j,bi,bj)
mean_psMssh_all_NUM(i,j,bi,bj) =
& mean_psMssh_all_NUM(i,j,bi,bj) +
& mean_psMtpobs_NUM(i,j,bi,bj)
mean_psMtpobs(i,j,bi,bj) =
& mean_psMtpobs(i,j,bi,bj) /
& mean_psMtpobs_NUM(i,j,bi,bj)
endif
if ( ( mean_psMersobs_NUM(i,j,bi,bj) .NE. 0. )
& ) then
mean_psMssh_all(i,j,bi,bj) =
& mean_psMssh_all(i,j,bi,bj) +
& mean_psMersobs(i,j,bi,bj)
mean_psMssh_all_NUM(i,j,bi,bj) =
& mean_psMssh_all_NUM(i,j,bi,bj) +
& mean_psMersobs_NUM(i,j,bi,bj)
mean_psMersobs(i,j,bi,bj) =
& mean_psMersobs(i,j,bi,bj) /
& mean_psMersobs_NUM(i,j,bi,bj)
endif
if ( ( mean_psMgfoobs_NUM(i,j,bi,bj) .NE. 0. )
& ) then
mean_psMssh_all(i,j,bi,bj) =
& mean_psMssh_all(i,j,bi,bj) +
& mean_psMgfoobs(i,j,bi,bj)
mean_psMssh_all_NUM(i,j,bi,bj) =
& mean_psMssh_all_NUM(i,j,bi,bj) +
& mean_psMgfoobs_NUM(i,j,bi,bj)
mean_psMgfoobs(i,j,bi,bj) =
& mean_psMgfoobs(i,j,bi,bj) /
& mean_psMgfoobs_NUM(i,j,bi,bj)
endif
if ( ( mean_psMssh_all_NUM(i,j,bi,bj) .GT. 0 ).AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. )
& ) then
mean_psMslaobs(i,j,bi,bj) =
& mean_psMssh_all(i,j,bi,bj) /
& mean_psMssh_all_NUM(i,j,bi,bj)
mean_psMslaobs_MSK(i,j,bi,bj) = 1. _d 0
else
mean_psMslaobs(i,j,bi,bj) = 0. _d 0
mean_psMslaobs_MSK(i,j,bi,bj) = 0. _d 0
endif
if ( ( mean_psMssh_all_NUM(i,j,bi,bj) .GT. num0 ).AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. ) .AND.
& ( mdtma(i,j,bi,bj) .NE. 0. ).AND.
& ( doReference ) ) then
mean_slaobs_model(i,j,bi,bj) =
& mean_slaobs_model(i,j,bi,bj) /
& mean_psMssh_all_NUM(i,j,bi,bj)
mean_psMssh_all(i,j,bi,bj) =
& mean_psMssh_all(i,j,bi,bj) /
& mean_psMssh_all_NUM(i,j,bi,bj)-mdtob(i,j,bi,bj)
mean_psMssh_all_MSK(i,j,bi,bj) = 1. _d 0
offset=offset+RA(i,j,bi,bj)*mean_psMssh_all(i,j,bi,bj)
offset_sum=offset_sum+RA(i,j,bi,bj)
elseif ( ( mdtma(i,j,bi,bj) .NE. 0. ) .AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. ).AND.
& ( .NOT.doReference ) ) then
mean_slaobs_model(i,j,bi,bj) = 0.d0
mean_psMssh_all(i,j,bi,bj) = 0. _d 0
mean_psMssh_all_MSK(i,j,bi,bj) = 1. _d 0
offset=offset+RA(i,j,bi,bj)
& *( psmean(i,j,bi,bj) -mdtob(i,j,bi,bj) )
offset_sum=offset_sum+RA(i,j,bi,bj)
num0array(i,j,bi,bj)=0. _d 0
else
mean_slaobs_model(i,j,bi,bj) = 0.d0
mean_psMssh_all(i,j,bi,bj) = 0. _d 0
mean_psMssh_all_MSK(i,j,bi,bj) = 0. _d 0
num0array(i,j,bi,bj)=0. _d 0
endif
enddo
enddo
enddo
enddo
c-- Do a global summation.
_GLOBAL_SUM_RL( offset , mythid )
_GLOBAL_SUM_RL( offset_sum , mythid )
catn--- add warning that written mean_slaobs_model is all zero
c due to having less data points that hardcoded num0
num0total=0. _d 0
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
num0total=num0total+num0array(i,j,bi,bj)
enddo
enddo
enddo
enddo
if(num0total.lt.1. _d 0) then
write(msgbuf,'(A,i5,A)')
& '** WARNING ** S/R COST_GENCOST_SSHV4: There are <',num0,' pts'
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(A)')
& ' at all grid points for combined tp+ers+gfo.'
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(A)')
& 'So, all model slaob minus model sla2model_raw are set to 0.'
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
endif
catn-------
if (offset_sum .eq. 0.0) then
if (gencost_outputlevel(igen_gmsl).GT.0) then
_BEGIN_MASTER( mythid )
write(msgbuf,'(a)') ' sshv4: offset_sum = zero!'
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
_END_MASTER( mythid )
endif
c stop ' ... stopped in cost_ssh.'
else
if (gencost_outputlevel(igen_gmsl).GT.0) then
_BEGIN_MASTER( mythid )
write(msgbuf,'(a,2d22.15)') ' sshv4:offset,sum=',
& offset,offset_sum
call print_message( msgbuf, standardmessageunit,
& SQUEEZE_RIGHT , mythid)
_END_MASTER( mythid )
endif
endif
c-- Compute (average) offset
offset = offset / offset_sum
c-- subtract offset from mean_psMssh_all and psmean
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( (mean_psMssh_all_NUM(i,j,bi,bj) .GT. num0) .AND.
& ( mdtma(i,j,bi,bj) .NE. 0. ) .AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. ) .AND.
& ( doReference ) ) then
c use the re-referencing approach
mean_psMssh_all(i,j,bi,bj) =
& mean_psMssh_all(i,j,bi,bj) - offset
mean_psMssh_all_MSK(i,j,bi,bj) = 1. _d 0
elseif ( ( mdtma(i,j,bi,bj) .NE. 0. ) .AND.
& ( maskc(i,j,1,bi,bj) .NE. 0. ) .AND.
& ( .NOT.doReference ) ) then
c use the simpler approach
mean_psMssh_all(i,j,bi,bj) =
& psmean(i,j,bi,bj) -mdtob(i,j,bi,bj) - offset
mean_psMssh_all_MSK(i,j,bi,bj) = 1. _d 0
else
mean_psMssh_all(i,j,bi,bj) = 0. _d 0
mean_psMssh_all_MSK(i,j,bi,bj) = 0. _d 0
endif
if ( maskc(i,j,1,bi,bj) .NE. 0. )
& psmean(i,j,bi,bj)=psmean(i,j,bi,bj)-offset
enddo
enddo
enddo
enddo
c-- smooth mean_psMssh_all
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'mdtdiff_raw'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,mean_psMssh_all,1,1,mythid)
endif
#ifdef ALLOW_SMOOTH
if ( useSMOOTH )
& call smooth_hetero2d(mean_psMssh_all,maskc,
& gencost_scalefile(igen_mdt),
& gencost_smooth2Ddiffnbt(igen_mdt),mythid)
#endif
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'mdtdiff_smooth'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,mean_psMssh_all,1,1,mythid)
endif
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'sla2model_raw'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,mean_slaobs_model,1,1,mythid)
endif
#ifdef ALLOW_SMOOTH
if ( useSMOOTH )
& call smooth_hetero2d(mean_slaobs_model,maskc,
& gencost_scalefile(igen_mdt),
& gencost_smooth2Ddiffnbt(igen_mdt),mythid)
#endif
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'sla2model_smooth'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,mean_slaobs_model,1,1,mythid)
endif
cgf at this point:
cgf 1) mean_psMssh_all is the sample mean <etaday-slaobs-mdt-offset>,
cgf to which a smoothing filter has been applied.
cgf 2) mean_psMtpobs is the (unsmoothed) sample mean <etaday-tpobs>.
cgf And similarly for ers and gfo, each treated separately.
cgf =======================================================
cgf PART 3: compute MDT cost term
cgf =======================================================
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if (mean_psMssh_all_MSK(i,j,bi,bj).NE.0. _d 0) then
junk = mean_psMssh_all(i,j,bi,bj)
junkweight = gencost_weight(i,j,bi,bj,igen_mdt)
& * mdtma(i,j,bi,bj)
else
junk = 0. _d 0
junkweight = 0. _d 0
endif
objf_gencost(bi,bj,igen_mdt) = objf_gencost(bi,bj,igen_mdt)
& + junk*junk*junkweight
if ( junkweight .ne. 0. ) num_gencost(bi,bj,igen_mdt) =
& num_gencost(bi,bj,igen_mdt) + 1. _d 0
diagnosfld(i,j,bi,bj) = junk*junk*junkweight
enddo
enddo
enddo
enddo
if (gencost_outputlevel(igen_mdt).GT.0) then
write(fname4test(1:80),'(1a)') 'misfits_mdt'
call mdswritefield(fname4test,32,.false.,'RL',
& 1,diagnosfld,1,1,mythid)
endif
cgf =======================================================
cgf PART 4: compute smooth SLA cost term
cgf =======================================================
ndaysave=35
ndaysaveRL=ndaysave
catn add a warning if have less nrecday than the hardcoded 35days
tempinteger=ndaysrec-ndaysave+1
if(tempinteger.lt.1) then
write(msgbuf,'(A,i5)')
& '** WARNING ** S/R COST_GENCOST_SSHV4: There are < ',ndaysave
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(A)')
& ' days required to calculate running mean tp+ers+gfo.'
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(A)')
& 'PART 4 in cost_gencost_sshv4 is skipped entirely, and there'
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
write(msgbuf,'(A)')
& 'will be NO report of [tp,ers,gfo,lsc,gmsl] in costfunction.'
call print_message( msgbuf, errormessageunit,
& SQUEEZE_RIGHT , mythid)
endif
catn -----------
do irec = 1, ndaysrec-ndaysave+1
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
anom_psMslaobs(i,j,bi,bj) = 0. _d 0
anom_psMslaobs_MSK(i,j,bi,bj) = 0. _d 0
anom_psMslaobs_SUB(i,j,bi,bj) = 0. _d 0
anom_slaobs(i,j,bi,bj) = 0. _d 0
anom_slaobs_SUB(i,j,bi,bj) = 0. _d 0
anom_psMslaobs_NUM(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
c PART 4.1: compute running sample average over ndaysave
c ------------------------------------------------------
do jrec=1,ndaysave
krec=irec+jrec-1
#ifdef ALLOW_AUTODIFF
call active_read_xy( fname, etaday, krec, doglobalread,
& ladinit, eccoiter, mythid,
& gencost_dummy(igen_etaday) )
#else
CALL READ_REC_XY_RL( fname, etaday, kRec, 1, myThid )
#endif
if (.NOT.useEtaMean)
& CALL REMOVE_MEAN_RL( 1, etaday, maskInC, maskInC, rA, drF,
& 'etaday', 0. _d 0, myThid )
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
tpma(i,j,bi,bj) = 0. _d 0
tpob(i,j,bi,bj) = 0. _d 0
ersma(i,j,bi,bj) = 0. _d 0
ersob(i,j,bi,bj) = 0. _d 0
gfoma(i,j,bi,bj) = 0. _d 0
gfoob(i,j,bi,bj) = 0. _d 0
enddo
enddo
enddo
enddo
if (using_tpj)
& call cost_sla_read( tpfi, tpsta, tpper,
& zeroRL, zeroRL,
& tpob, tpma,
& krec, mythid )
if (using_ers)
& call cost_sla_read( ersfi, erssta, ersper,
& zeroRL, zeroRL,
& ersob, ersma,
& krec, mythid )
if (using_gfo)
& call cost_sla_read( gfofi, gfosta, gfoper,
& zeroRL, zeroRL,
& gfoob, gfoma,
& krec, mythid )
do bj = jtlo,jthi
do bi = itlo,ithi
do j = jmin,jmax
do i = imin,imax
if ( tpma(i,j,bi,bj)*mean_psMslaobs_MSK(i,j,bi,bj)
& .NE.0. ) then
anom_psMslaobs(i,j,bi,bj)= anom_psMslaobs(i,j,bi,bj)+
& etaday(i,j,bi,bj)-tpob(i,j,bi,bj)
& -mean_psMslaobs(i,j,bi,bj)
anom_slaobs(i,j,bi,bj)= anom_slaobs(i,j,bi,bj)+
& tpob(i,j,bi,bj)
anom_psMslaobs_NUM(i,j,bi,bj)=
& anom_psMslaobs_NUM(i,j,bi,bj)+1. _d 0
if ( (2*jrec.EQ.ndaysave).OR.(2*jrec+1.EQ.ndaysave) )
& anom_psMslaobs_MSK(i,j,bi,bj) = 1. _d 0
endif
if ( ersma(i,j,bi,bj)*mean_psMslaobs_MSK(i,j,bi,bj)
& .NE.0. ) then
anom_psMslaobs(i,j,bi,bj)= anom_psMslaobs(i,j,bi,bj)+
& etaday(i,j,bi,bj)-ersob(i,j,bi,bj)
& -mean_psMslaobs(i,j,bi,bj)
anom_slaobs(i,j,bi,bj)= anom_slaobs(i,j,bi,bj)+
& ersob(i,j,bi,bj)
anom_psMslaobs_NUM(i,j,bi,bj)=
& anom_psMslaobs_NUM(i,j,bi,bj)+1. _d 0
if ( (2*jrec.EQ.ndaysave).OR.(2*jrec+1.EQ.ndaysave) )
& anom_psMslaobs_MSK(i,j,bi,bj) = 1. _d 0
endif