       subroutine errfig (ipmax,iko,ih,ik,il,theta,devi,in,icont,       ERRF001
     &                    isys,wgt,itext)                               ERRF002
c -----------------------------------------------------------           ERRF003
c      draws the lineplots for deviations in a cell parameter           ERRF004
c      vs. theta  (XLAT module)                                         ERRF005
c -----------------------------------------------------------           ERRF006
c      version 3.0 last revised 23.2.89 ETH-LNS -                       ERRF007
c -----------------------------------------------------------           ERRF008
c      parameter ierr=outfile, nl= max number of reflections            ERRF009
c -----------------------------------------------------------           ERRF010
       parameter(nl=150,ierr=6)                                         ERRF011
       character*70 itext                                               ERRF012
       dimension devi(ipmax,*), ih(*), ik(*), il(*), theta(*)           ERRF013
       dimension mat(nl,55), icont(ipmax,*), wgt(*), axlabl(5)          ERRF014
                                                                        ERRF015
       write (*,'(/a)')'  Plotting of error figure '                    ERRF016
       write (ierr,'(a1)') char(12)                                     ERRF017
       write (ierr,'(/,a,i1)')'  Error figures - refinement cycle ',iko ERRF018
       write (ierr,8001) itext                                          ERRF019
                                                                        ERRF020
       jk=1                                                             ERRF021
       lk=1                                                             ERRF022
                                                                        ERRF023
 1000  continue                                                         ERRF024
c ---- find largest deviation in cell parameter ik                      ERRF025
       ymax=abs(devi(jk,1))                                             ERRF026
       do 0001 i=1,in                                                   ERRF027
          temp=abs(devi(jk,i))                                          ERRF028
          if(ymax.lt.temp) ymax=temp                                    ERRF029
 0001  continue                                                         ERRF030
                                                                        ERRF031
c ---- initialize                                                       ERRF032
       do 0003 j=1,in                                                   ERRF033
          do 0003 i=1, 55                                               ERRF034
             mat(j,i)=' '                                               ERRF035
 0003        mat(j,28)='.'                                              ERRF036
                                                                        ERRF037
c ---- normalize to -27,0,27 columns and plot array                     ERRF038
       ymax=ymax*1.0e4                                                  ERRF039
       do 0002 i=1,in                                                   ERRF040
          temp=devi(jk,i)*27.0E4/ymax+28.5                              ERRF041
          itemp=aint(temp)                                              ERRF042
          if (icont(lk,i).eq.0) then                                    ERRF043
             mat(i,itemp)='*'                                           ERRF044
          else if(icont(lk,i).eq.1) then                                ERRF045
             mat(i,itemp) = 'U'                                         ERRF046
          else                                                          ERRF047
             mat(i,itemp) = 'E'                                         ERRF048
          end if                                                        ERRF049
 0002  continue                                                         ERRF050
                                                                        ERRF051
                                                                        ERRF052
c ---- first row of plot                                                ERRF053
       write(ierr,                                                      ERRF054
     &  '(/''  h  k  l  theta'',59x,''wgt.'',/,2x,78(''-''))')          ERRF055
                                                                        ERRF056
c ---- implied do loop for middle rows                                  ERRF057
       write(ierr,'(1x,i2,2i3,1x,f6.2,1x,55a1,1x,f6.2)')                ERRF058
     & (ih(i),ik(i),il(i),theta(i),(mat(i,j),j=1,55),wgt(i),i=1,in)     ERRF059
                                                                        ERRF060
c ---- calculate values for axis labels last row                        ERRF061
       axlabl(1)= - ymax/10000.0                                        ERRF062
       axlabl(2)= axlabl(1)/2.0                                         ERRF063
       axlabl(3)= 0.0                                                   ERRF064
       axlabl(4)= - axlabl(2)                                           ERRF065
       axlabl(5)= - axlabl(1)                                           ERRF066
                                                                        ERRF067
c ---- plot last row                                                    ERRF068
       write(ierr,'(2x,78(''-''))')                                     ERRF069
       write(ierr,'(3x,5(13x,''I''))')                                  ERRF070
       write (ierr,'(5x,5(6x,f8.4))') (axlabl(i), i=1,5)                ERRF071
                                                                        ERRF072
c ---- new page as finished                                             ERRF073
c      write (ierr,'(a1)') char(12)                                     ERRF074
                                                                        ERRF075
c ---- reenter at 1000 if plot for another parameter required           ERRF076
       if (jk.eq.1) then                                                ERRF077
          if (isys.gt.3) then                                           ERRF078
             write (ierr,8002) ITEXT                                    ERRF079
c ---------- remember to swap array columns if ortho                    ERRF080
             jk=3                                                       ERRF081
             lk=2                                                       ERRF082
             goto 1000                                                  ERRF083
          end if                                                        ERRF084
       end if                                                           ERRF085
       if (isys.eq.4.and.jk.ne.2) then                                  ERRF086
          write (ierr,8003) ITEXT                                       ERRF087
          jk=2                                                          ERRF088
          lk=3                                                          ERRF089
          goto 1000                                                     ERRF090
       end if                                                           ERRF091
       if ((isys.eq.2.or.isys.eq.3).and.jk.ne.2) then                   ERRF092
          write (ierr,8003) ITEXT                                       ERRF093
          jk=2                                                          ERRF094
          lk=2                                                          ERRF095
          goto 1000                                                     ERRF096
       end if                                                           ERRF097
                                                                        ERRF098
       return                                                           ERRF099
                                                                        ERRF100
 8001  format(1H ///10x,'Error figure  A(obs) - A(calc)',3X, a35,/,     ERRF101
     1 10x,30('='),/)                                                   ERRF102
 8002  format(1H ///10X,'Error figure  B(obs) - B(calc)',3X, a35,/,     ERRF103
     1 10x,30('='),/)                                                   ERRF104
 8003  format(1H ///10X,'Error figure  C(obs) - C(calc)',3X, a35,/,     ERRF105
     1 10x,30('='),/)                                                   ERRF106
                                                                        ERRF107
       end                                                              ERRF108
                                                                        ERRF109
