Error

fatal:The result of the conditional expression yields a missing value. NCL can not determine branch, see ismissing function

Solution

There are missing values in the loop statement. Try wrapping the ismissing() function.