      program int2_mc ! Bernd Berg Sep 04 2008.
c Homework: Integral estimate by MC.
      include '../../ForLib/implicit.sta'
      include '../../ForLib/constants.par'
      parameter(iuo=6,iud=9,miuo=-iuo,iseed1=0,iseed2=1,ndat=10**6)
c
      write(iuo,'(/," 2. Integral with MC:",/)')
      area=two
      write(iuo,'(" area =    =        ",1F10.1)') area
      call rmaset(miuo,iud,iseed1,iseed2,'ranmar.d')
      fsum=zero
      open(iud,file="data.d",form='formatted',status='unknown')
      do idat=1,ndat
        xr=two*rmafun()-one
        yr=rmafun()
        if(xr**2.lt.sin(yr).and.yr**2.lt.cos(xr)) then
          f=exp(sqrt(xr**2+yr**2))
          fsum=fsum+f
          write(iud,'(2G16.7,I10)') xr,yr,idat
        endif
      end do
      close(iud)
      write(iuo,'(" fsum =             ",1F10.1)') fsum
      estimate=area*fsum/ndat
      write(iuo,'(" integral estimate =",1F10.5)') estimate
c
      stop
      end

      include '../../ForLib/rmaset.f'
      include '../../ForLib/ranmar.f'
      include '../../ForLib/rmafun.f'
