      subroutine funkmin_cica(ndim,beta,fvalue)
      implicit none
  
      include '../testarea/cica.h'
      
      integer ndim
      double precision beta(1:ndim),fvalue
!(in)  ndim: the dimension of the parameter vector
!(in)  beta: the parameters       
!(out) fvalue: the value of the cost function at beta
!
      integer i
      double precision cica,der_cica,term,der_beta(ndim)
      
!----------- End of variables declaration ---------------------------------
!
! check to see if parameters are out of bounds
      
      do i=1,ndim
        if(beta(i).lt.bmin(i).or.beta(i).gt.bmax(i))then
! parameter out of bound          
          fvalue=1.0d+100
          return
        endif
      enddo
      fvalue=0.0d0
      do i=1,nobs
        term=pco2ambient(i)
        call cica_ca5(imodel,ndim,beta,term,cica,der_cica,der_beta)
        fvalue=fvalue+(cicameas(i)-cica)**2
      enddo
      return
      end subroutine funkmin_cica

!$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$      
      double precision function f1dim_cica(x)
      INTEGER NMAX
      double precision x
      PARAMETER (NMAX=1000)
CU    USES funkmin_stom
      INTEGER j,ncom
      double precision pcom(NMAX),xicom(NMAX),xt(NMAX)
      COMMON /f1com/ pcom,xicom,ncom

      do 11 j=1,ncom
        xt(j)=pcom(j)+x*xicom(j)
11    continue
      call funkmin_cica(ncom,xt,f1dim_cica)
      return
      END
