# Version of doc.do.txt with user-defined code environments

TITLE: Demo document with computer code
AUTHOR: HPL
DATE: today

======= Data file =======

Suppose we have some data in a file typeset with `!bc dat`:

!bu-code file=mydat.txt label=cod:mydat Text file with data
@@@CODE mydat.txt envir=dat
!eu-code

======= Complete program and terminal output =======

The following program
# #if FORMAT in ('latex', 'pdflatex')
(which breaks a page)
# #endif
reads the data in the file and performs analysis (typeset with `!bc pypro`):

!bu-code file=fileread.py label=cod:fileread Read data and perform analysis
@@@CODE fileread.py
!eu-code
The output becomes (typeset with `!bc sys`):

!bu-code
!bc sys
Terminal> python fileread.py

mean=-0.006005
st.dev=0.583542
correlation matrix:
[[ 1.          0.0509676   0.52406366  0.20964645  0.1574504 ]
 [ 0.0509676   1.         -0.30920845 -0.12129049  0.7611538 ]
 [ 0.52406366 -0.30920845  1.          0.49355806 -0.42263817]
 [ 0.20964645 -0.12129049  0.49355806  1.         -0.38286589]
 [ 0.1574504   0.7611538  -0.42263817 -0.38286589  1.        ]]
!ec
!eu-code

======= Code snippet =======

Fortran 77 is also sometimes handy (typeset with `!bc fcod`):

!bu-code file=process.f Return `a` multiplied by `c`
!bc fcod
       subroutine process(a, n, c, r)
C      Return array r = c*a
       integer n
       real*8 a(n), c, r(n)
       integer i
       do i = 1,n
          r(i) = c*a(i)
       end do
       return
       end
!ec
!eu-code