- You overwrite "layer[i" ("drained", etc.) immediately with the angle and so you lose that information. Either use a different variable for the angle vector and augment the vectors when you return the result or create "layer" as a matrix with two columns, using a second index (O and O+1).
- Additionally you forgot to return the vector(s) you created and so the return value of your program is just the last result of the loop.
- When you create your input table you have to use text (strings) for "sand" and "clay", otherwise you get the error as of undefined variables. It was easier for me to define the two variables with string values but of course normally you would type the strings directly in the table.

This is what it would look like using a second vector for the angle and returning the augmented result

You could also do without the vector 'angle" as is it is the very same as the vector phi in your input table!
But it looks to me that you use a faulty logic as you never can arrive at the "not drained" branch.
You have four different branches in your program but there only are three different locations for 'bottom'!
It can be
1) larger than z (above -0.62,)
2) between d and z (between -2.4 m and -0.62 m)
or
3) lower than d (below -2,4 m).
I don't know which of the three sections you would call "drained", "partially drained" or "not drained".
But you sure don't need four branches in your program to distinct between the three different locations.
The logic in your program is that a value between d and z is called "drained" and everything else is called "partially drained".
I guess that's not as it should be,
Prime 10 sheet attached