C $Header: /u/gcmpack/MITgcm/pkg/seaice/seaice_cost_init_fixed.F,v 1.7 2015/03/23 21:04:59 gforget Exp $
C $Name:  $

#include "SEAICE_OPTIONS.h"
#include "AD_CONFIG.h"

      subroutine SEAICE_COST_INIT_FIXED( mythid )

C     ==================================================================
C     SUBROUTINE seaice_cost_init_fixed
C     ==================================================================
C
C     o Set contributions to the cost function and the cost function
C       itself to zero. The cost function and the individual contribu-
C       tions are defined in the header file "SEAICE_COST.h".
C
C     ==================================================================
C     SUBROUTINE seaice_cost_init_fixed
C     ==================================================================

      implicit none

C     == global variables ==
#include "EEPARAMS.h"
#include "SIZE.h"
#include "GRID.h"
#include "PARAMS.h"
#ifdef ALLOW_COST
# include "SEAICE_COST.h"
#endif
#ifdef ALLOW_CAL
# include "cal.h"
#endif

C     == routine arguments ==
      integer mythid

#ifdef ALLOW_COST
#ifdef ALLOW_COST_ICE

C     == local variables ==
      integer tempDate1(4)
      integer tempDate2(4)
      logical exst

C     == external functions ==
c#ifdef ALLOW_CAL
c     integer  cal_IntMonths
c     external cal_IntMonths
c     integer  cal_IntDays
c     external cal_IntDays
c#endif

C     == end of interface ==

#ifdef ALLOW_CAL

      _BEGIN_MASTER( myThid )

C--   Sea-ice cost function start and stop times in model seconds.
        call CAL_FULLDATE  ( costIceStart1 , costIceStart2,
     &                       tempDate1     , mythid )
        call CAL_TIMEPASSED( modelStartDate, tempDate1    ,
     &                       tempDate2     , mythid )
        call CAL_TOSECONDS ( tempDate2 , costIceStart , mythid )
        costIceStart = costIceStart + startTime

        if ( costIceEnd1.EQ.0 ) then
C-      use "modelEndDate" as default value for costIceEnd
          costIceEnd1 = modelEndDate(1)
          costIceEnd2 = modelEndDate(2)
        endif
        call CAL_FULLDATE  ( costIceEnd1   , costIceEnd2  ,
     &                       tempDate1     , mythid )
        call CAL_TIMEPASSED( modelStartDate, tempDate1    ,
     &                       tempDate2     , mythid )
        call CAL_TOSECONDS ( tempDate2 , costIceEnd , mythid )
        costIceEnd = costIceEnd + startTime
C--
        if ( smrareadatfile .ne. ' ' )
     &   call CAL_FULLDATE( smrareastartdate1, smrareastartdate2,
     &                      smrareastartdate,  mythid )

      _END_MASTER( mythid )

#endif /* ALLOW_CAL */

C--   Get the weights that are to be used for the individual cost
C--   function contributions.
      call SEAICE_COST_WEIGHTS( mythid )

C--   Initialise adjoint of monthly mean files calculated
C--   in cost_averagesfields (and their ad...).
cph(
cph   The following init. shoud not be applied if in the middle
cph   of a divided adjoint run
cph)
#ifndef ALLOW_TANGENTLINEAR_RUN
cph!!! and I think it needs to be seen by TAF
cph!!! for repeated TLM runs
cph!!!
      inquire( file='costfinal', exist=exst )
      if ( .NOT. exst) then
cph         call seaice_cost_init_barfiles( mythid )
      endif
#endif

      _BARRIER

#endif /* ALLOW_COST_ICE */
#endif /* ALLOW_COST */

      RETURN
      END