# open - open function for ratfor. include ratdef integer function open (name, mode) character name(ARB) integer mode include channel integer string(40), ch # build a proper filename in string for (i = 1; name(i) == BLANK; i = i+1) ; # get rid of leading blanks for (j = 1; name(i) ^= EOS; i = i+1) { # copy to packed string byte(string,j) = name(i); j = j+1 } byte(string,j) = NULL # terminate with null # find a free channel number for (ch = 0; ch <= MAXCHNL; ch = ch+1) if (channel(ch) == ERR) break if (ch > MAXCHNL) ier = ERR # open the file in the proper mode else if (mode == READ) call OPEN (ch, string, 1, ier) else if (mode == WRITE | mode == READWRITE) { call CFILW (string, 2, ier) call OPEN (ch, string, 3, ier) } if (ier ^= 1) { write (STDERR, 1) ier, ch, mode, string(1) 1 format(" open error=",i5,", ch=",i2, ", mode=",i2,", file=",s20) ch = ERR } else channel(ch) = mode return(ch) end