function readModelAndGenerateMeshMref(m,pad::Int64,newSize::Vector,domain::Vector)
########################## m,mref are in Velocity here. ###################################


mref = copy(m);
# mref[:,:,1:end-17] = getSimilarLinearModel(m[:,:,1:end-17],1.75,2.8);
mref = getSimilarLinearModel(m,1.75,2.9);

sea = abs.(m[:] .- minimum(m)) .< 5e-2;
mref[sea] = m[sea];
if newSize!=[]
	m    = expandModelNearest(m,   collect(size(m)),newSize);
	mref = expandModelNearest(mref,collect(size(mref)),newSize);
end

Minv = getRegularMesh(domain,collect(size(m))-1);

(mPadded,MinvPadded) = addAbsorbingLayer(m,Minv,pad);
(mrefPadded,MinvPadded) = addAbsorbingLayer(mref,Minv,pad);

N = prod(MinvPadded.n+1);
boundsLow  = minimum(mPadded);
boundsHigh = maximum(mPadded);

boundsLow  = ones(N)*boundsLow;
boundsLow = convert(Array{Float32},boundsLow);
boundsHigh = ones(N)*boundsHigh;
boundsHigh = convert(Array{Float32},boundsHigh);

return (mPadded,MinvPadded,mrefPadded,boundsHigh,boundsLow);
end