First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
Variable IVAL will contain the index of the first STATE for the wind generator model at bus 2, machine 1.
The third VAR should be VAR(L+2) = STATE(IVAL)
Variable IERR is zero when the call is succesful. It is wrong to assign VAR(L+3) = VAR(IERR)
, since VAR array doesn't have index 0. Remove the statement for VAR(L+3).