Recover from a rejected edit
A weight must be finite and positive. If an edit fails, inspect the diagnostic on the object, correct the input and reset the diagnostic before retrying. This program deliberately submits zero as the second weight of a line.
program retry_a_weight
use forcad, only: rk, nurbs_curve
implicit none
type(nurbs_curve) :: curve
real(rk) :: weights(2)
call curve%set(Xc=reshape([0._rk,1._rk,0._rk,0._rk],[2,2]))
if (.not. curve%err%ok) error stop "Could not build the line"
call curve%modify_Wc(W=0._rk, num=2)
if (.not. curve%err%ok) then
call curve%err%print()
call curve%err%reset()
call curve%modify_Wc(W=2._rk, num=2)
end if
if (.not. curve%err%ok) error stop "Weight edit failed"
weights = curve%get_Wc()
print '(2f6.2)', weights
end program
The diagnostic identifies modify_Wc and the positive-weight requirement. The rejected edit preserves the original controls and weights. The successful retry prints 1.00 2.00.
Check err%ok immediately after a call that can fail. For operations that return a new patch, such as range extraction, check the returned object’s diagnostic. In an integration loop, check the patch diagnostic after each quadrature call, as in Integrate a field over a surface.