       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
       if(n.gt.25) then
          call mexErrMsgTxt('n must be <= 25')
       end if

       plhs(1) = mxCreateFull(nsum,1,0)
       plhs(2) = mxCreateFull(nsum,1,0)
       prox_pr = mxGetPr(prhs(1))
       valstore_pr = mxGetPr(plhs(1))
       vidxstore_pr = mxGetPr(plhs(2))
     
       call mxCopyPtrToReal8(prox_pr,prox,nsize)
       call uscalfor(valstore,vidxstore,prox,n,nsum)
       call mxCopyReal8ToPtr(valstore,valstore_pr,nsum)
       call mxCopyReal8ToPtr(vidxstore,vidxstore_pr,nsum)
    

       return

       end

   