home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Between Heaven & Hell 2
/
BetweenHeavenHell.cdr
/
500
/
474
/
ems.arc
/
PC-EMS.FOR
< prev
next >
Wrap
Text File
|
1985-09-05
|
9KB
|
294 lines
C
C PC-EMS
C A Program for Sample Size Determinations
C Version 1.0
C September 2, 1985
C
C Gerard E. Dallal
C
C USDA Human Nutrition Research Center on Aging
C at Tufts University
C 711 Washington Street
C Boston, MA 02111
C
C and
C
C Tufts University School of Nutrition
C 132 Curtis Street
C Medford, MA 02155
C
C
C
C NOTICE
C
C Program and documentation copyright 1985 by Gerard E. Dallal.
C Reproduction of material for non-commercial purposes is
C permitted, without charge, provided that suitable reference
C is made to PC-EMS and its author.
C
C Neither PC-EMS nor its documentation should be modified in
C any way without permission from the author, except for those
C changes that are essential to move PC-EMS to another
C computer.
C
C Please acknowledge PC-EMS in any manuscript that uses its
C calculations.
C
C
C
C A PROGRAM TO CONSTRUCT EMS TABLES FOR BALANCED DESIGNS
C
C MATRICES ARE IN THE USUAL FORMAT--ROWS CORRESPOND TO
C EFFECTS; COLUMNS CORRESPOND TO SUBSCRIPTS
C
C ISUB(I,J) -- INDICATES WHETHER EFFECT I CONTAINS
C SUBSCRIPT J:
C 1 = PRESENT, NOT CONTAINED IN PARENTHESES
C 0 = ABSENT
C -1 = PRESENT, CONTAINED IN PARENTHESES
C
C COEF(I,J) -- THE COEFFICIENT OF EFFECT i CORRESPONDING TO
C SUBSCRIPT J
C
C SUB(J) -- THE SUBSCRIPTS
C
C TYPE(J) = 'F' ('R'), MAIN EFFECT CORRESPONDING TO SUBSCRIPT J IS
C FIXED (RANDOM)
C
C LEVELS(J) -- NUMBER OF LEVELS OF FACTOR CORRESPONDING TO
C SUBSCRIPT J
C
C LCHAR -- MAXIMUM NUMBER OF CHARACTERS IN A SINGLE TERM
C
C NCHAR(I) -- NUMBER OF CHARACTERS IN TERM I
C
IMPLICIT INTEGER (A-Z)
CHARACTER*1 TYPE(50), QUERY, SUB(10), TCHAR
CHARACTER*50 FNAME
CHARACTER*79 MODEL
CHARACTER*10 TERM(50), TOUT(50), TDUM
CHARACTER*11 TERMO
LOGICAL QFILE
DIMENSION COEF(50,10), ISUB(50,10), NCHAR(50), COUT(50),
* LEVELS(10)
C
DATA IIN /0/, IOUT /0/, IWOUT /11/
DATA LMODEL /79/, LCHAR /10/, MAXSUB /10/
C
WRITE(IOUT,1)
1 FORMAT (//36X,'PC-EMS'/
* 23X,'A Program to Construct EMS Tables'/
* 34X,'Version 1.0'/31X,'September 2, 1985'//
* 32X,'Gerard E. Dallal'/
* 17X,'USDA Human Nutrition Research Center on Aging'/
* 30X,'at Tufts University'/29X,'711 Washington Street'/
* 31X,'Boston, MA 02111'///37X,'NOTICE'//9X,'Please '
* 'acknowledge PC-EMS in any manuscript that uses its',/
* 9X,'calculations.')
WRITE(IOUT,2)
2 FORMAT(//' Do you wish to save the results of this session? ',
* '[N]: '$)
READ (IIN,3) QUERY
3 FORMAT (A1)
IF (QUERY.EQ.'Y' .OR. QUERY.EQ.'y') QFILE = .TRUE.
IF (.NOT. QFILE) GOTO 10
WRITE (IOUT,4)
4 FORMAT (' Enter output filename: '$)
READ (IIN,'(A)') FNAME
OPEN (IWOUT, FILE = FNAME, STATUS = 'NEW')
WRITE (IWOUT,1)
10 WRITE(IOUT,20)
IF (QFILE) WRITE (IWOUT,20)
20 FORMAT(///' Models are entered in the form:'//
* ' A + B(A) + C + AC + B(A)C'//
* ' Terms must be separated by ''+'' or '','' ;',
* ' blanks are optional.'/
* ' Grand mean and error term are NOT stated explicitly.'//
* ' Enter the model:'/)
30 READ (IIN,'(A)') MODEL
IF (QFILE) WRITE (IWOUT,40) MODEL
40 FORMAT (1X,A79)
C
C STRIP BLANKS
C
NTERM = 1
LEN = 0
DO 60 K = 1, LMODEL
IF (MODEL(K:K).EQ.' ') GOTO 60
IF (MODEL(K:K).EQ.',') MODEL(K:K) = '+'
IF (MODEL(K:K).EQ.'+') NTERM = NTERM + 1
LEN = LEN + 1
MODEL(LEN:LEN) = MODEL(K:K)
60 CONTINUE
KK = 0
DO 100 I = 1, NTERM
NCHAR0 = 0
TERM(I) = ' '
DO 80 K = 1, LCHAR
KK = KK + 1
IF (KK.GT.LEN .OR. MODEL(KK:KK).EQ.'+') GOTO 90
NCHAR0 = NCHAR0 + 1
TERM(I)(K:K) = MODEL(KK:KK)
80 CONTINUE
90 NCHAR(I) = NCHAR0
100 CONTINUE
C
C A MAIN EFFECT HAS ONLY ONE LETTER, OR ONE LETTER OUTSIDE THE
C FIRST LEVEL OF PARENTHESES
C
110 NSUB = 0
IF (QFILE) WRITE(IWOUT,120)
WRITE(IOUT,120)
120 FORMAT(' ')
DO 200 I = 1, NTERM
NCHAR0 = NCHAR(I)
IF (NCHAR0.NE.1 .AND. (TERM(I)(2:2).NE.'(' .OR.
* TERM(I)(NCHAR0:NCHAR0).NE.')')) GOTO 200
C
NSUB = NSUB + 1
IF (NSUB.LE.MAXSUB)GOTO 140
WRITE (IOUT,130) MAXSUB
IF (QFILE) WRITE (IWOUT,130) MAXSUB
130 FORMAT (/' ONLY ',I2,' FACTORS ARE ALLOWED IN THE MODEL.'/)
GOTO 10
140 SUB(NSUB) = TERM(I)(1:1)
C
C GET NUMBER OF LEVELS OF EACH FACTOR
C
IF (QFILE) WRITE (IWOUT,160) SUB(NSUB)
150 WRITE (IOUT,160) SUB(NSUB)
160 FORMAT (' Enter the number of levels of ',A1,' : '$)
READ (IIN,170,ERR=150) LEVELS(NSUB)
170 FORMAT (BN,I10)
IF (QFILE) WRITE (IWOUT,180) LEVELS(NSUB)
180 FORMAT(1X,I4)
200 CONTINUE
C
IF (QFILE) WRITE(IWOUT,120)
WRITE(IOUT,120)
DO 300 J = 1, NSUB
IF (QFILE) WRITE (IWOUT,220) SUB(J)
210 WRITE (IOUT,220) SUB(J)
220 FORMAT(' Is the factor ',A1,' fixed (F) or random (R)? '$)
READ(IIN,3) QUERY
IF (QUERY.NE.'f' .AND. QUERY.NE.'F' .AND. QUERY.NE.'r' .AND.
* QUERY.NE.'R') GOTO 210
C
IF (QUERY.EQ.'f') QUERY = 'F'
IF (QUERY.EQ.'r') QUERY = 'R'
IF (QFILE) WRITE (IWOUT,230) QUERY
230 FORMAT (3X,A1)
TYPE(J) = QUERY
300 CONTINUE
NTERM = NTERM + 1
C
C ? -- SYMBOL FOR ERROR TERM
C
TERM(NTERM)(1:2) = '?('
DO 310 J = 1, NSUB
310 TERM(NTERM)(J+2:J+2) = SUB(J)
NSUB = NSUB + 1
SUB(NSUB) = '?'
TYPE(NSUB) = 'R'
NCHAR(NTERM) = NSUB + 2
NCHAR0 = NCHAR(NTERM)
TERM(NTERM)(NCHAR0:NCHAR0) = ')'
IF (QFILE) WRITE (IWOUT,330)
320 WRITE (IOUT,330)
330 FORMAT (/' Enter the number of observations per cell: '$)
READ(IIN,170,END=320) LEVELS(NSUB)
IF (QFILE) WRITE (IWOUT,180) LEVELS(NSUB)
DO 500 I = 1, NTERM
NCHAR0 = NCHAR(I)
DO 400 J = 1, NSUB
NEST = 0
DO 350 K = 1, NCHAR0
TCHAR = TERM(I)(K:K)
IF (TCHAR.EQ.'(') NEST = NEST + 1
IF (TCHAR.EQ.')') NEST = NEST - 1
IF (TCHAR.NE.SUB(J)) GOTO 350
IF (NEST.EQ.0) ISUB(I,J) = 1
IF (NEST.GT.0) ISUB(I,J) = -1
GOTO 400
350 CONTINUE
ISUB(I,J) = 0
400 CONTINUE
500 CONTINUE
DO 2050 J = 1, NSUB
DO 2040 I = 1, NTERM
IF (ISUB(I,J).EQ.-1) COEF(I,J) = 1
IF (ISUB(I,J).EQ.0) COEF(I,J) = LEVELS(J)
IF (ISUB(I,J).EQ.1 .AND. TYPE(J).EQ.'F') COEF(I,J) = 0
IF (ISUB(I,J).EQ.1 .AND. TYPE(J).EQ.'R') COEF(I,J) = 1
2040 CONTINUE
2050 CONTINUE
C
C IE -- TERM BEING EVALUATED
C
DO 5000 IE = 1, NTERM
DO 3050 I = 1, NTERM
C = 1
DO 3010 J = 1, NSUB
IF (ISUB(IE,J).NE.0 .AND. ISUB(I,J).EQ.0) C = 0
IF (C.EQ.0) GOTO 3020
IF (ISUB(IE,J).NE.0) GOTO 3010
C = C * COEF(I,J)
3010 CONTINUE
3020 COUT(I) = C
3050 CONTINUE
C
NOUT = 0
DO 3100 I = 1, NTERM
IF (COUT(I).EQ.0) GOTO 3100
NOUT = NOUT + 1
COUT(NOUT) = COUT(I)
TOUT(NOUT) = TERM(I)
3100 CONTINUE
NOUT2 = (NOUT + 1) / 2
DO 3110 I = 1, NOUT2
K = NOUT - I + 1
CDUM = COUT(I)
TDUM = TOUT(I)
COUT(I) = COUT(K)
TOUT(I) = TOUT(K)
COUT(K) = CDUM
TOUT(K) = TDUM
3110 CONTINUE
TOUT(1) = 'error '
NCHAR0 = NCHAR(IE) + 1
TERMO = TERM(IE)
IF (IE.LT.NTERM) GOTO 3190
NCHAR0 = 6
TERMO = 'error '
3190 TERMO(NCHAR0:NCHAR0) = ')'
WRITE(IOUT,3200) TERMO, (COUT(I), TOUT(I), I = 1, NOUT)
IF (QFILE)
* WRITE(IWOUT,3200) TERMO, (COUT(I), TOUT(I), I = 1, NOUT)
3200 FORMAT(/1X,'EMS(',A11,' =',I4,' * ',A10:' +',I4,' * ',
* A10:' +',I4,' * ',A10:' +',
* (/18X,I4,' * ',A10:' +',I4,' * ',A10:' +',
* I4,' * ',A10:' +'))
5000 CONTINUE
WRITE (IOUT,5020)
5020 FORMAT (/' Do you wish to continue? [N]: '$)
READ (IIN,3) QUERY
IF (QUERY.EQ.'y' .OR. QUERY.EQ.'Y') GOTO 10
STOP ' '
END