1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_geoid.F,v 1.8 2014/10/18 18:15:44 gforget Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
|
6 |
subroutine cost_geoid( |
7 |
O sphcost, |
8 |
I shc, |
9 |
I mythid |
10 |
& ) |
11 |
|
12 |
c ================================================================== |
13 |
c SUBROUTINE cost_geoid |
14 |
c ================================================================== |
15 |
c |
16 |
c o Evaluate the cost function of the geoid contribution. |
17 |
c |
18 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
19 |
c |
20 |
c changed: Christian Eckert eckert@mit.edu 25-Feb-2000 |
21 |
c - Restructured the code in order to create a package |
22 |
c for the MITgcmUV. |
23 |
c |
24 |
c changed: Ralf Giering Ralf.Giering@FastOpt.de 12-Jun-2001 |
25 |
c - totally rewrite for parallel processing |
26 |
c |
27 |
c heimbach@mit.edu 05-May-2005 |
28 |
c - debugged and restructuted |
29 |
c |
30 |
c ================================================================== |
31 |
c SUBROUTINE cost_geoid |
32 |
c ================================================================== |
33 |
|
34 |
implicit none |
35 |
|
36 |
c == global variables == |
37 |
|
38 |
#ifdef ALLOW_EGM96_ERROR_COV |
39 |
#include "EEPARAMS.h" |
40 |
#include "SIZE.h" |
41 |
#include "PARAMS.h" |
42 |
|
43 |
#include "ecco_cost.h" |
44 |
#ifdef ALLOW_SPHERE |
45 |
# include "sphere.h" |
46 |
#else |
47 |
integer ncShc |
48 |
parameter (ncShc=1) |
49 |
#endif |
50 |
#else |
51 |
integer ncShc |
52 |
parameter (ncShc=1) |
53 |
#endif |
54 |
|
55 |
c == routine arguments == |
56 |
|
57 |
_RL sphcost |
58 |
_RL shc( ncShc ) |
59 |
integer mythid |
60 |
|
61 |
#ifdef ALLOW_EGM96_ERROR_COV |
62 |
|
63 |
c == local variables == |
64 |
|
65 |
Real*8 pinv( ncshc ) |
66 |
|
67 |
integer i,j |
68 |
integer ilo,ihi |
69 |
integer ireads |
70 |
integer egmsize |
71 |
parameter( egmsize = 8 ) |
72 |
|
73 |
integer jsize, joff, jbeg, jend |
74 |
integer reclength |
75 |
|
76 |
_RL factor |
77 |
_RL recip_rr |
78 |
|
79 |
c == end of interface == |
80 |
|
81 |
c-- Only the master thread is doing I/O |
82 |
_BEGIN_MASTER( mythid ) |
83 |
|
84 |
c-- initialise cost variable for all threads |
85 |
c-- to allow usage of global_sum_r8 |
86 |
sphcost = 0. _d 0 |
87 |
do i=1,ncShc |
88 |
pinv(i) = 0. _d 0 |
89 |
enddo |
90 |
|
91 |
c-- Initialise variables. |
92 |
recip_rr = recip_rsphere*recip_rsphere |
93 |
|
94 |
c-- round up the quotient to get jsize |
95 |
jsize = ncshc / numberOfProcs |
96 |
if (jsize*numberOfProcs .lt. ncshc ) then |
97 |
jsize = jsize + 1 |
98 |
end if |
99 |
|
100 |
c-- compute sub-intervall of 1..ncshc for this processor |
101 |
joff = myProcId*jsize |
102 |
jbeg = 1 + joff |
103 |
jend = min( ncshc, joff+jsize ) |
104 |
reclength = ncshc*egmsize |
105 |
|
106 |
c-- read part of geoid error covariance matrix |
107 |
c-- and compute corresponding part of cost contribution |
108 |
CADJ loop = parallel |
109 |
do j = jbeg,jend |
110 |
|
111 |
call cost_readgeoid( |
112 |
I geoid_covariancefile, reclength, j, |
113 |
O pinv, |
114 |
I mythid ) |
115 |
|
116 |
factor = 0. |
117 |
do i = 1,ncShc |
118 |
factor = factor + pinv(i)*shc(i)*recip_rr |
119 |
enddo |
120 |
sphcost = sphcost + factor*shc(j) |
121 |
enddo |
122 |
|
123 |
_END_MASTER( mythid ) |
124 |
|
125 |
_GLOBAL_SUM_RL( sphcost, mythid ) |
126 |
|
127 |
#endif /* ALLOW_EGM96_ERROR_COV */ |
128 |
|
129 |
end |