C $Header: /home/ubuntu/mnt/e9_copy/MITgcm/pkg/ecco/Attic/cost_drift.F,v 1.1 2003/11/06 22:10:07 heimbach Exp $ #include "COST_CPPOPTIONS.h" subroutine cost_Drift( I myiter, I mytime, I mythid & ) c ================================================================== c SUBROUTINE cost_Drift c ================================================================== c c o Evaluate cost function contribution of the t and S difference c between the first and the last year. c c started: from the "old" code c c Elisabeth Remy eremy@ucsd.edu july 31 2001 c c heimbach@mit.edu 17-Jun-2003: SIO merge: c changed cosphi(i,j,bi,bj)*100.0 factor to c cosphi(i,j,bi,bj)*2.5 c c ================================================================== c SUBROUTINE cost_Drift c ================================================================== implicit none c == global variables == #include "EEPARAMS.h" #include "SIZE.h" #include "GRID.h" #include "DYNVARS.h" #include "cal.h" #include "ecco_cost.h" #include "ctrl.h" #include "ctrl_dummy.h" #include "optim.h" c == routine arguments == integer myiter _RL mytime integer mythid c == local variables == _RS one_rs parameter( one_rs = 1. ) integer bi,bj integer i,j,k integer itlo,ithi integer jtlo,jthi integer jmin,jmax integer imin,imax integer irec integer iltheta integer ilsalt integer nf, nl _RL fctilet _RL fctiles _RL fcthread_tdrift _RL fcthread_tdrifs character*(80) fnametheta character*(80) fnamesalt logical doglobalread logical ladinit character*(MAX_LEN_MBUF) msgbuf 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-- Read tiled data. doglobalread = .false. ladinit = .false. #ifdef ALLOW_DRIFT_COST_CONTRIBUTION #ifdef ECCO_VERBOSE _BEGIN_MASTER( mythid ) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,i8.8)') & ' cost_Theta: number of records to process = ',nmonsrec call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) _END_MASTER( mythid ) #endif if (optimcycle .ge. 0) then iltheta = ilnblnk( tbarfile ) write(fnametheta(1:80),'(2a,i10.10)') & tbarfile(1:iltheta),'.',optimcycle ilsalt = ilnblnk( sbarfile ) write(fnamesalt(1:80),'(2a,i10.10)') & sbarfile(1:ilsalt),'.',optimcycle endif if (nmonsrec.lt.12) then print* print*,' cost_Drift: assimilation period smaller' print*,' than 1 year, no drift computed.' print* stop ' ... stopped in cost_Drift.' endif fcthread_tdrift = 0. _d 0 fcthread_tdrifs = 0. _d 0 do bj = jtlo,jthi do bi = itlo,ithi do k = 1,nr do j = jmin,jmax do i = imin,imax Tfmean(i,j,k,bi,bj) = 0.0 Sfmean(i,j,k,bi,bj) = 0.0 Tlmean(i,j,k,bi,bj) = 0.0 Slmean(i,j,k,bi,bj) = 0.0 enddo enddo enddo enddo enddo nf = 0 nl = 0 c-- Loop over records. do irec = 1,12 c-- Read time averages and the monthly mean data. call active_read_xyz( fnametheta, tbar, irec, & doglobalread, ladinit, & optimcycle, mythid, & xx_tbar_mean_dummy ) call active_read_xyz( fnamesalt, sbar, irec, & doglobalread, ladinit, & optimcycle, mythid, & xx_sbar_mean_dummy ) nf = nf + 1 do bj = jtlo,jthi do bi = itlo,ithi do k = 1,nr do j = jmin,jmax do i = imin,imax Tfmean(i,j,k,bi,bj) = Tfmean(i,j,k,bi,bj) + & tbar(i,j,k,bi,bj) Sfmean(i,j,k,bi,bj) = Sfmean(i,j,k,bi,bj) + & sbar(i,j,k,bi,bj) enddo enddo enddo enddo enddo enddo do irec = nmonsrec-12+1, nmonsrec c-- Read time averages and the monthly mean data. call active_read_xyz( fnametheta, tbar, irec, & doglobalread, ladinit, & optimcycle, mythid, & xx_tbar_mean_dummy ) call active_read_xyz( fnamesalt, sbar, irec, & doglobalread, ladinit, & optimcycle, mythid, & xx_sbar_mean_dummy ) nl = nl + 1 do bj = jtlo,jthi do bi = itlo,ithi do k = 1,nr do j = jmin,jmax do i = imin,imax Tlmean(i,j,k,bi,bj) = Tlmean(i,j,k,bi,bj) + & tbar(i,j,k,bi,bj) Slmean(i,j,k,bi,bj) = Slmean(i,j,k,bi,bj) + & sbar(i,j,k,bi,bj) enddo enddo enddo enddo enddo enddo do bj = jtlo,jthi do bi = itlo,ithi c-- Loop over the model layers fctiles = 0. _d 0 fctilet = 0. _d 0 do k = 1,nr c-- Compute model misfit and cost function term for c the temperature field. do j = jmin,jmax do i = imin,imax if (_hFacC(i,j,k,bi,bj) .ne. 0.) then fctiles = fctiles + & (wsalt(k,bi,bj)*cosphi(i,j,bi,bj)*100.0* & (Slmean(i,j,k,bi,bj)/nl - Sfmean(i,j,k,bi,bj)/nf)* & (Slmean(i,j,k,bi,bj)/nl - Sfmean(i,j,k,bi,bj)/nf)) & fctilet = fctilet + & (wtheta(k,bi,bj)*cosphi(i,j,bi,bj)*100.0* & (Tlmean(i,j,k,bi,bj)/nl - Tfmean(i,j,k,bi,bj)/nf)* & (Tlmean(i,j,k,bi,bj)/nl - Tfmean(i,j,k,bi,bj)/nf)) endif enddo enddo enddo c-- End of loop over layers. fcthread_tdrift = fcthread_tdrift + fctilet fcthread_tdrifs = fcthread_tdrifs + fctiles objf_tdrift(bi,bj) = objf_tdrift(bi,bj) + fctilet objf_sdrift(bi,bj) = objf_sdrift(bi,bj) + fctiles #ifdef ECCO_VERBOSE c-- Print cost function for each tile in each thread. write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') & ' cost_Drift: irec,bi,bj = ',irec,bi,bj call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,d22.15)') & ' cost function (temperature) = ', & fctilet+fctiles call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) #endif enddo enddo #ifdef ECCO_VERBOSE c-- Print cost function for all tiles. c _GLOBAL_SUM_R8( fcthread_tdrift , myThid ) c _GLOBAL_SUM_R8( fcthread_tdrifs , myThid ) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,i8.8)') & ' cost_Drift: irec = ',irec call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,a,d22.15)') & ' global cost function value', & ' (temp + salt) = ',fcthread_tdrift+fcthread_tdrifs call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) #endif #else c-- Do not enter the calculation of the drift contribution to c-- the final cost function. _BEGIN_MASTER( mythid ) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,a)') & ' cost_Drift: no contribution of drift between the first ', & 'and the last year to cost function.' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a,a,i9.8)') & ' cost_Drift: number of records that would have', & ' been processed: ',nmonsrec call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) write(msgbuf,'(a)') ' ' call print_message( msgbuf, standardmessageunit, & SQUEEZE_RIGHT , mythid) _END_MASTER( mythid ) #endif return end