1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
subroutine clunit( lunit, name, mode)
c ====================================================================
c
c system dependent routine to allocate files
c
c ====================================================================
c
c lunit logical unit number
c name file name
c mode attach mode
c recl = mode(2) ( direct file )
c mode(1) definit le mode d'ouverture
c le chiffre des centaines definit le format
c 0 -> formatted
c le chiffre des dizaines definit l' acces
c 0 -> sequential
c le chiffre des unites definit le status
c 0 -> new
c 1 -> old
c 2 -> scratch
c 3 -> unknown
c si mode est negatif, on ouvre en read seulement (vax/vms)
c
c
c sur apollo, pour les fichiers binaires sequentiels, on met un recl a
c 250000 si celui-ci n'est pas donne par l'utilisateur. Pour ce faire,
c il suffit de remplacer la chaine 'cap' par trois blancs.
c
c
c reference externe : cluni0
c fortran : len
c
c ====================================================================
c
c Copyright INRIA
include '../stack.h'
integer lunit,mode(*)
character*(*) name
c
c integer nunit,unit(50)
c common /units/ nunit,unit
c
integer iacc,ifor,ista,k,rec
character*11 for,sta,acc
character*800 nomfic
double precision res
c
if ( lunit.eq.rte) then
c attach units rte to terminal in
call addfile (lunit,1,0,1,001,char(0),ierr)
if(ierr.ne.0) then
call error(112)
return
endif
goto 100
elseif(lunit.eq.wte ) then
c attach units wte to terminal out
call addfile (lunit,1,0,1,000,char(0),ierr)
if(ierr.ne.0) then
call error(112)
return
endif
goto 100
endif
c
c ----------
c close file
c ----------
c
if ( lunit.lt.0 ) then
c . preserve permanent files
if (lunit.eq.-rte.or.lunit.eq.-wte) goto 100
c . close file and put it out of the table
call getfiletype(-lunit,ltype,info)
if(info.eq.0) then
if(ltype.eq.1) then
close( -lunit )
call delfile(-lunit)
else
call mclose(-lunit,res)
endif
endif
else
c
c ---------
c open file
c ---------
c
k = abs(mode(1))
c
c ------------------------
c definition des attributs
c ------------------------
c
rec = mode(2)
ifor = k / 100
k = k - 100 *ifor
iacc = k / 10
ista = k - 10 *iacc
c
if ( ifor.eq.0 ) then
for='formatted'
else
for='unformatted'
endif
c
if ( ista.eq.0 ) then
sta='new'
elseif ( ista.eq.1 ) then
sta='old'
elseif ( ista.eq.2 ) then
sta='scratch'
elseif ( ista.eq.3 ) then
sta='unknown'
else
err = 67
goto 100
endif
if ( iacc.ne.0 ) then
acc='direct'
else
acc='sequential'
endif
c
if ( lunit.ne.0 ) then
c . file is defined directly by its logical unit
call getfileinfo(lunit,ifa,iswap,ltype,mode,buf,lb,info)
if(info.eq.2) then
c . unit is free
call addfile(lunit,1,0,1,mode(1),char(0),ierr)
if(ierr.ne.0) then
call error(112)
return
endif
elseif(info.eq.1) then
c . unit is out of bounds
call error(66)
return
else
c . unit is not free
goto 40
endif
if ( iacc.ne.0 ) then
open(lunit,form=for,status=sta,access=acc,recl=rec,
$ err=30)
else
open(lunit,form=for,status=sta,access=acc,err=30)
endif
else
c . file is defined by its name
call getfiledesc(lunit)
if(lunit.lt.0) then
err = 66
return
endif
c . get full file name
call cluni0(name, nomfic, k)
if ( iacc.ne.0 ) then
open( lunit, file=nomfic(1:k), form=for,
1 access=acc , status=sta,recl=rec, err=30)
else
open( lunit, file=nomfic(1:k), form=for,
1 access=acc ,status=sta, err=30)
endif
endif
call addfile(lunit,1,0,1,mode(1),nomfic(1:k)//char(0),ierr)
if(ierr.ne.0) then
call error(112)
return
endif
if(ista.ne.0.and.iacc.eq.0) rewind(lunit)
endif
c
goto 100
c
c ----------
c error open
c ----------
c
30 continue
if(mode(1).ge.0) then
err = 240
else
err = 241
endif
goto 100
c
40 continue
err = 65
goto 100
c
c --------------
c end of program
c --------------
c
100 continue
end
|