      SUBROUTINE ALG12
C
      REAL LOSS,LAMI,LAMIP1,LAMIM1
C
      DIMENSION PSTAT(32),XX(32)
C
      COMMON /UD300C/ NSTNS,NSTRMS,NMAX,NFORCE,NBL,NCASE,NSPLIT,NREAD,
     1NPUNCH,NPAGE,NSET1,NSET2,ISTAG,ICASE,IFAILO,IPASS,I,IVFAIL,IFFAIL,
     2NMIX,NTRANS,NPLOT,ILOSS,LNCT,ITUB,IMID,IFAIL,ITER,LOG1,LOG2,LOG3,
     3LOG4,LOG5,LOG6,IPRINT,NMANY,NSTPLT,NEQN,NSPEC(30),NWORK(30),
     4NLOSS(30),NDATA(30),NTERP(30),NMACH(30),NL1(30),NL2(30),NDIMEN(30)
     5,IS1(30),IS2(30),IS3(30),NEVAL(30),NDIFF(4),NDEL(30),NLITER(30),
     6NM(2),NRAD(2),NCURVE(30),NWHICH(30),NOUT1(30),NOUT2(30),NOUT3(30),
     7NBLADE(30),DM(11,5,2),WFRAC(11,5,2),R(21,30),XL(21,30),X(21,30),
     8H(21,30),S(21,30),VM(21,30),VW(21,30),TBETA(21,30),DIFF(15,4),
     9FDHUB(15,4),FDMID(15,4),FDTIP(15,4),TERAD(5,2),DATAC(100),
     1DATA1(100),DATA2(100),DATA3(100),DATA4(100),DATA5(100),DATA6(100),
     2DATA7(100),DATA8(100),DATA9(100),FLOW(10),SPEED(30),SPDFAC(10),
     3BBLOCK(30),BDIST(30),WBLOCK(30),WWBL(30),XSTN(150),RSTN(150),
     4DELF(30),DELC(100),DELTA(100),TITLE(18),DRDM2(30),RIM1(30),
     5XIM1(30),WORK(21),LOSS(21),TANEPS(21),XI(21),VV(21),DELW(21),
     6LAMI(21),LAMIM1(21),LAMIP1(21),PHI(21),CR(21),GAMA(21),SPPG(21),
     7CPPG(21),HKEEP(21),SKEEP(21),VWKEEP(21),DELH(30),DELT(30),VISK,
     8SHAPE,SCLFAC,EJ,G,TOLNCE,XSCALE,PSCALE,PLOW,RLOW,XMMAX,RCONST,
     9FM2,HMIN,C1,PI,CONTR,CONMX
C
      XMAX=X(1,NSTNS)
      XMIN=X(1,1)
      DO 100 J=2,NSTRMS
      IF(X(J,1).LT.XMIN)XMIN=X(J,1)
      IF(X(J,NSTNS).GT.XMAX)XMAX=X(J,NSTNS)
100   CONTINUE
      IF(XMIN.LT.0.0)XMIN=XMIN-1.0
      L1=XMIN-1.0
      XMIN=FLOAT(L1)
      L1=XMAX+1.0
      XMAX=FLOAT(L1)
      DELX=(XMAX-XMIN)/XSCALE+0.01
      XX(NSTNS+1)=XMIN
      XX(NSTNS+2)=XSCALE
      IF(NPLOT.EQ.2)GO TO 134
      PSTAT(NSTNS+1)=PLOW
      PSTAT(NSTNS+2)=PSCALE
      J=1
      K=1
110   DO 120 I=1,NSTNS
      HS=H(J,I)-(VW(J,I)**2+VM(J,I)**2)/(2.0*G*EJ)
      IF(HS.LT.HMIN)HS=HMIN
      PSTAT(I)=ALG4(HS,S(J,I))/SCLFAC**2
120   XX(I)=X(J,I)
      IF(J.EQ.NSTRMS)GO TO 130
      K=K+1
      IF(J.EQ.IMID)J=NSTRMS
      IF(J.EQ.1)J=IMID
      GO TO 110
130   CONTINUE
      IF(NPLOT.EQ.1)GO TO 180
134   CONTINUE
      PSTAT(NSTNS+1)=RLOW
      PSTAT(NSTNS+2)=XSCALE
      DO 150 J=1,NSTRMS
      DO 140 I=1,NSTNS
      XX(I)=X(J,I)
140   PSTAT(I)=R(J,I)
150   CONTINUE
      PSTAT(NSTRMS+1)=RLOW
      PSTAT(NSTRMS+2)=XSCALE
      XX(NSTRMS+1)=XMIN
      XX(NSTRMS+2)=XSCALE
      DO 170 I=1,NSTNS
      DO 160 J=1,NSTRMS
      PSTAT(J)=R(J,I)
160   XX(J)=X(J,I)
170   CONTINUE
180   RETURN
      END
