rewrote allocate_memory
Return the error back to Modelcia so that Modelcia can stop
Added trace substances
Corrected the function for z direction
deleted unused variables, edited error return