it defines a flat surface at j=idepth, β1β is red and β3β is blue in your figure. But as its name suggests, idepth depends on i. Just before the if, you should write something like idepth = d + a*sin(b*i-c), with the good values for a, b, c, d.
And if you want also the flat segments, it would be something like idepth = min(d+a*sin(b*i-c), e) where e is the z position of those flat segments.
Note also that in modern Fortran you donβt need to define yourself the unit value (2012 in your code). You can write open(newunit=my_file, file=.... where my_file is an integer variable that will automatically receive an available unit number.