anchor.diff:                        Gave, Gvar, bnumMLMCsamps, numcellsLevel0, ncellwidth
   
     if(.not.allocated(numMLMCcells)) allocate(numMLMCcells(0:0))
  -  if(.not.allocated(M_optsamps)) allocate(M_optsamps(2,0:0))
  +  if(.not.allocated(M_optsamps)) allocate(M_optsamps(3,0:0))
   
     if(.not.allocated(Q_ufunctional)) allocate(Q_ufunctional(bnumMLMCsamps,0:0))
     if(.not.allocated(G_ufunctional)) allocate(G_ufunctional(bnumMLMCsamps,0:0))
  
positive.code: 
  print *,"new samps M_optsamps(1,:):",M_optsamps(1,:)
  print *,"new samps M_optsamps(2,:):",M_optsamps(2,:)
    do ilevel = 0,Level                                          !search each level
  print *,"ilevel:",ilevel
      if( M_optsamps(1,ilevel)>M_optsamps(2,ilevel) ) then       !if new samps to compute
  
negative.code:   do ilevel=0,Level
      !accumlate next part of accumulating term
      accterm = accterm + sqrt(Gvar(ilevel)*ncellwidth(ilevel)**(-linsolveEff*numDimensions))
  print *,"ilevel:",ilevel,"  accterm:",accterm
  print *,"term1:",(MLMC_TOLsplit*MLMC_TOL/C_alpha)**(-2.0d0)
  print *,"term2:",sqrt(abs(Gvar(ilevel)/Gave(ilevel)))
      !calculate new optimal samples estimate
      M_optsamps(3,ilevel) = ceiling(  (MLMC_TOLsplit*MLMC_TOL/C_alpha)**(-2.0d0) * &
                                       sqrt(abs(Gvar(ilevel)/Gave(ilevel))) * &
                                       accterm                             )                         
  
  print *,"M_optsamps(3,ilevel):",M_optsamps(3,ilevel)
      !use larger of new value and old value
      M_optsamps(1,ilevel) = max(M_optsamps(2,ilevel),M_optsamps(3,ilevel))
      !if new level's estimate higher, make backwards compatible
      if(ilevel/=0) then
        if(M_optsamps(1,ilevel) > M_optsamps(1,ilevel-1)) &
           M_optsamps(1,0:ilevel-1) = M_optsamps(1,ilevel)
      endif
  
  print *,"theoretical optimal M for level",ilevel,":",M_optsamps(3,ilevel)
  print *,"practical   optimal M for level",ilevel,":",M_optsamps(1,ilevel)
    enddo
  
    end subroutine MLMCcomputeOptSamps
  