# I want to create FORTRAN User-Defined Model, but I couldn't understand FORTRAN examples

I am a PSS / E 34.2.0 user.

The FORTRAN example below is called BESS with droop control applied.

- I want to create a user-defined model of the secondary controller of CBEST (BESS).
- I want to put Low Voltage Ride Through function in CBEST auxiliary controller.

So I am learning Fortran 77.

However, the subroutine fortran example (which I have) is hard to understand.

First, I do not know how the variables of the CBEST model and the User-Defined Subroutine model are connected.

Second, where is the main program Fortran file in the top of Subroutine?

Third, what are the MODE1, MODE2, MODE3, MODE4 that most examples have?

Fourth, I could not found meaning of GENCHK at CALL GENCHK( ). What's the GENCHK?

Is there an easy user-defined modeling example?

================================================

```
SUBROUTINE WACS(M, J, K, L)
INCLUDE 'COMON4.INS'
INTEGER IVAL, IERR
INTEGER M302
INTEGER COUNT_DROOP, I_ITER
REAL P302
REAL FREQ, FREQ_LAG, BEFORE_P, P_BATMAX
REAL P_INPUT, FREQ_DROOP, C_DROOP
REAL DBMAX, DBMIN
CALL GENCHK (302, '1', M302, 'IN CONEC')
P302=PELEC(M302)
BEFORE_P = 100*P302
FREQ = BSFREQ(M302)
DBMAX = 0.017/60
DBMIN = -0.017/60
COUNT_DROOP = 0
P_BATMAX = 30
C_DROOP = P_BATMAX/(0.005-DBMIN)
IF (MODE.GT.4) RETURN
IVAL = K+1
IF (MODE.EQ.4) THEN
IF (IVAL.GT.NINTEG) NINTEG=IVAL
RETURN
ENDIF
IF (MODE.EQ.1) THEN
P_INPUT = 0.0
COUNT_DROOP = VAR(L+7)
FREQ_LAG = NWLAG_MODE1(1.0, 0.1, 0.0042, -0.0042, FREQ, K, IERR)
FREQ_DROOP = 0.0
IF (TIME.GT.20) THEN
IF (FREQ.GT.DBMAX) THEN
COUNT_DROOP = -1*C_DROOP*(FREQ-DBMAX)
ENDIF
ELSE IF (FREQ.LT.DBMIN) THEN
COUNT_DROOP = COUNT_DROOP + 1
IF (COUNT_DROOP.GT.6) THEN
FREQ_DROOP = -1*C_DROOP*(FREQ-DBMIN)
ENDIF
ELSE
COUNT_DROOP = 0
FREQ_DROOP = 0.0
ENDIF
VAR(L+7) = COUNT_DROOP
ENDIF
VAR(1) = FREQ_DROOP
VAR(2) = 0.0
VAR(L+8) = 60+(60*FREQ)
ENTRY TACS(M, J, K, L)
RETURN
END
```