       subroutine mexFunction(nlhs,plhs,nrhs,prhs)

       integer plhs(*),prhs(*)
       integer mxCreateFull,mxGetPr
       integer mxGetM,mxGetN,m,n,nsize,nsum
       integer valstore_pr,vidxstore_pr,prox_pr
       integer nlhs,nrhs
       real*8 valstore(2**25),prox(25*25),vidxstore(2**25)
      
       m = mxGetM(prhs(1))
       n = mxGetN(prhs(1))
       nsize = m*n
       nsum = (2**n) - 1
       
       plhs(2) = 0
       plhs(1) = mxCreateFull(nsum,1,0)
       IF (plhs(1) /= 0) plhs(2) = mxCreateFull(nsum,1,0)
       
       IF (plhs(2) /= 0) THEN
              prox_pr = mxGetPr(prhs(1))
              valstore_pr = mxGetPr(plhs(1))
              vidxstore_pr = mxGetPr(plhs(2))
              call uscalfor(%val(valstore_pr),%val(vidxstore_pr),
     &                      %val(prox_pr),n,nsum)
       
       ELSE   
C           ! cleanup any (partially) successfull allocations)
                  IF (plhs(1) .eq. 0) CALL mxFreeMatrix(plhs(1))
           IF (plhs(2) .eq. 0) CALL mxFreeMatrix(plhs(2))
C           ! print error and return
       call mexErrMsgTxt('insufficient memory to solve problem')
       END IF           

       return
       end
   