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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
subroutine intwrite
c Copyright INRIA/ENPC
INCLUDE '../stack.h'
integer lch
parameter (lch=1024)
character chaine*(lch)
c
integer top2,id(nlgh),h(nsiz)
integer ftyp,fmttyp,mode(2)
integer top0
logical opened,eptover
integer iadr,sadr
character bu1*(bsiz),bu2*(bsiz)
c
iadr(l)=l+l-1
sadr(l)=(l/2)+1
c
top0=top-rhs+1
c
ftyp=0
if(rhs.gt.4.or.rhs.lt.2) then
call error(42)
return
endif
if(lhs.gt.1) then
call error(41)
return
endif
c opening file
top2 = top
top = top-rhs+1
il=iadr(lstk(top))
mode(1)=0
mode(2)=0
call v2unit(top,mode,lunit,opened,ierr)
if(ierr.gt.0) return
c
nc=0
iacces=0
if(rhs.eq.2) goto 61
il=iadr(lstk(top2))
if(rhs.eq.4) then
iacces=top2-1
else
if(istk(il).ne.10) then
call error(61)
goto 996
endif
endif
c analyse du format
if(istk(il).ne.10) then
err=top2-top+1
call error(55)
goto 996
endif
nc=istk(il+5)-1
l=il+5+istk(il+1)*istk(il+2)
ftyp=fmttyp(istk(l),nc)
if(ftyp.eq.0) then
call error(49)
goto 996
endif
call cvstr(nc,istk(l),buf,1)
top2=top2-1
fin=-fin
61 if(iacces.ne.0) then
c analyse des numero d'enregistrement
ilb=iadr(lstk(iacces))
if(istk(ilb+3).ne.0) then
err=top2-top
call error(52)
return
endif
nb=istk(ilb+1)*istk(ilb+2)
lb=sadr(ilb+4)
do 62 i=1,nb
istk(ilb-1+i)=int(stk(lb-1+i))
62 continue
top2=iacces-1
endif
il=iadr(lstk(top2))
if(istk(il).ne.1) goto 70
if(istk(il+3).ne.0) then
err=top2-top+1
call error(52)
goto 996
endif
if(fin.lt.0.and.ftyp.ne.1.and.ftyp.ne.2) then
call error(49)
goto 996
endif
m=istk(il+1)
n=istk(il+2)
l=sadr(il+4)
if(ftyp.eq.2) then
call entier(m*n,stk(l),istk(iadr(l)))
l=iadr(l)
endif
c---- ecriture de flottants
if(iacces.eq.0) then
c acces sequentiel
if(lunit.ne.wte) then
do 63 i=1,m
li=l+i-1
if(fin.gt.0) then
write(lunit,*,err=139)
1 (stk(li+(j-1)*m),j=1,n)
else
if(ftyp.eq.1) then
write(lunit,buf(1:nc),err=139)
1 (stk(li+(j-1)*m),j=1,n)
else
write(lunit,buf(1:nc),err=139)
1 (istk(li+(j-1)*m),j=1,n)
endif
endif
63 continue
else
do 68 i=1,m
li=l+i-1
if(fin.gt.0) then
buf=' '
nv=lct(5)/18
write(chaine,'(''('',i2,''(1x,1pd17.10))'')') nv
do 64 k1=1,n,nv
k2=min(n,k1+nv-1)
write(buf,chaine,err=139)
& (stk(li+(j-1)*m),j=k1,k2)
lc=18*(k2-k1+1)
call basout(io,wte,buf(1:lc))
64 continue
else
ib=nc+1
if(ftyp.eq.1) then
write(buf(ib:),buf(1:nc),err=139)
& (stk(li+j*m),j=0,n-1)
else
write(buf(ib:),buf(1:nc),err=139)
& (istk(li+j*m),j=0,n-1)
endif
lb1=bsiz+1
66 lb1=lb1-1
if(lb1.ge.ib+1.and.buf(lb1:lb1).eq.' ') goto 66
call basout(io,wte,buf(ib:lb1))
endif
68 continue
endif
c
else
c acces direct
if(nb.ne.m) then
call error(42)
goto 996
endif
do 69 i=1,m
li=l+i-1
if(ftyp.eq.1) then
write(lunit,buf(1:nc),rec=istk(ilb+i-1),
1 err=139) (stk(li+(j-1)*m),j=1,n)
else
write(lunit,buf(1:nc),rec=istk(ilb+i-1),
1 err=139) (istk(li+(j-1)*m),j=1,n)
endif
69 continue
endif
goto 78
c
c ecriture des chaines de caracteres
70 if(istk(il).ne.10) then
err=top2-top+1
call error(55)
goto 996
endif
if(fin.lt.0.and.ftyp.ne.4) then
call error(49)
goto 996
endif
n=istk(il+2)*istk(il+1)
m=istk(il+1)
il=il+4
l=il+n+1
if(iacces.ne.0) then
if(nb.ne.m) then
call error(42)
goto 996
endif
endif
do 77 i=1,n
m=istk(il+i)-istk(il+i-1)
if(iacces.eq.0) then
lm=l
if(lunit.ne.wte) then
c fichier format libre
if(fin.gt.0) then
if(m.eq.0) then
write(lunit,*,err=139)
else
do 73 i1=1,m,lch
i2=min(m,i1+lch-1)
m1=i2-i1+1
call cvstr(m1,istk(lm),chaine(1:m1),1)
write(lunit,*,err=139) chaine(1:m1)
lm=lm+m1
73 continue
endif
else
c fichier format donne
if(m.eq.0) then
write(lunit,buf(1:nc),err=139)
else
do 74 i1=1,m,lch
i2=min(m,i1+lch-1)
m1=i2-i1+1
call cvstr(m1,istk(lm),chaine(1:m1),1)
write(lunit,buf(1:nc),err=139) chaine(1:m1)
lm=lm+m1
74 continue
endif
endif
else
if(fin.gt.0) then
c ecran format libre
if(m.eq.0) then
call basout(io,lunit,' ')
else
do 75 i1=1,m,bsiz
i2=min(m,i1+bsiz-1)
m1=i2-i1+1
call cvstr(m1,istk(lm),buf(1:m1),1)
call basout(io,lunit, buf(1:m1))
lm=lm+m1
75 continue
endif
else
c ecran format donne
if(m.eq.0) then
call basout(io,wte,' ')
else
m1=min(bsiz,m)
call cvstr(m1,istk(l),bu1,1)
write(bu2,buf(1:nc),err=139) bu1(1:m1)
lb=bsiz+1
71 lb=lb-1
if(lb.ge.2.and.bu2(lb:lb).eq.' ') goto 71
call basout(io,wte,bu2(1:lb))
endif
endif
endif
else
c acces direct
m1=min(bsiz,m)
call cvstr(m1,istk(l),bu1,1)
write(lunit,buf(1:nc),rec=istk(ilb+i-1),err=139)
+ bu1(1:m1)
endif
l=l+m
77 continue
c
c fin generale de write
78 il=iadr(lstk(top))
istk(il)=0
if(.not.opened) then
mode(1)=0
mode(2)=0
call clunit(-lunit,buf,mode)
endif
goto 999
139 call error(49)
if(.not.opened) call clunit(-lunit,buf,mode)
return
996 if(.not.opened) call clunit(-lunit,buf,mode)
return
c
999 return
end
|