# Calls Smolyak_Elem_Isotrop.jl and Smolyak_Grid.jl to produce a Smolyak GRID
# Scales the dimensions given an input vector.

function fScaleSmolyakGrid(fixed_grid,vSmolyakGridSpec,params_use)

    d      = vSmolyakGridSpec[1]
    mu     = vSmolyakGridSpec[2]
    sd     = vSmolyakGridSpec[3]
    wSmolyak = vSmolyakGridSpec[4]
    R_quantile = vSmolyakGridSpec[5]

    Smol_grid = zeros(size(fixed_grid))

    R_ss=params_use["R_ss"]
    R_min=log(1/R_ss)
    R_max=log(R_quantile/R_ss)

    rho_z  = params_use["rho_z"];
    rho_g  = params_use["rho_g"];
    rho_r  = params_use["rho_r"];
    rho_d  = params_use["rho_d"];

    sig_z  = params_use["sig_z"];
    sig_g  = params_use["sig_g"];
    sig_r  = params_use["sig_r"];
    sig_d  = params_use["sig_d"];

    z_min=-sd*sig_z/sqrt(1-rho_z^2)
    z_max=sd*sig_z/sqrt(1-rho_z^2)

    d_min=-sd*sig_d/sqrt(1-rho_d^2)
    d_max=sd*sig_d/sqrt(1-rho_d^2)

    g_min=-sd*sig_g/sqrt(1-rho_g^2)
    g_max=sd*sig_g/sqrt(1-rho_g^2)

    er_min=-sd*sig_r
    er_max=sd*sig_r

    y_max=z_max;
    y_min=z_min;

    max_min=[R_max R_min ;y_max y_min; er_max er_min; g_max g_min; z_max  z_min; d_max  d_min]

    for i=1:Int(d)
        max_t=max_min[i,1]
        min_t=max_min[i,2]
        Smol_grid[:,i]=(fixed_grid[:,i].+1)/2 .*(max_t-min_t) .+min_t
    end

    if wSmolyak==1
        wSmolyak=zeros(size(Smol_grid,1))
        for i=1:size(Smol_grid,1)
            vec_t=fixed_grid[i,:]
            prob=Distributions.pdf(MvNormal(6,1/sd),vec_t)
            wSmolyak[i]=prob
        end
        wSmolyak=wSmolyak./sum(wSmolyak).*size(Smol_grid,1)

    else
        wSmolyak=ones(size(Smol_grid,1))
    end


return Smol_grid,wSmolyak

end
