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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
|
subroutine iread(it)
c Copyright INRIA
c
INCLUDE '../stack.h'
c
integer top2,tops,id(nlgh),h(nsiz)
integer ftyp,fmttyp,mode(2)
logical opened,eptover
integer iadr,sadr
logical checkrhs,checklhs
c
save opened,lunit,job,icomp
c
iadr(l)=l+l-1
sadr(l)=(l/2)+1
c
if (ddt .eq. 4) then
write(buf(1:4),'(i4)') fin
call basout(io,wte,' matio '//buf(1:4))
endif
c
tops=top
c
120 continue
lw=lstk(top+1)
if(.not.checkrhs('iread',3,5)) return
if(.not.checklhs('iread',1,1)) return
c
c opening file
top2 = top
top = top-rhs+1
il=iadr(lstk(top))
mode(1)=-1
mode(2)=0
call v2unit(top,mode,lunit,opened,ierr)
if(ierr.gt.0) return
c
iacces=0
if(rhs.gt.3) then
il=iadr(lstk(top2))
if(rhs.eq.5) then
iacces=top2-1
else
if(istk(il).eq.1) then
call error(61)
goto 996
endif
endif
c analyse du format
if(istk(il).ne.10) then
err=rhs
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
endif
c
121 if(iacces.ne.0) then
c get record numbers
ilb=iadr(lstk(iacces))
if(istk(ilb+3).ne.0) then
err=top2-top+1
call error(52)
goto 996
endif
nb=istk(ilb+1)*istk(ilb+2)
lb=sadr(ilb+4)
ilb=iadr(lw)
err=sadr(ilb+nb)-lstk(bot)
if(err.gt.0) then
call error(17)
goto 996
endif
do 122 i=1,nb
istk(ilb+i-1)=int(stk(lb+i-1))
122 continue
top2=iacces-1
endif
123 continue
c number of rows
il=iadr(lstk(top2))
l=sadr(il+4)
n=int(stk(l))
top2=top2-1
c number of columns
il=iadr(lstk(top2))
l=sadr(il+4)
m=int(stk(l))
il=iadr(lstk(top))
l=sadr(il+4)
if(m.eq.0.or.n.le.0) then
c terminate if nothing to read
istk(il)=1
istk(il+1)=0
istk(il+2)=0
istk(il+3)=0
lstk(top+1)=sadr(il+4)
if(.not.opened) then
mode(1)=0
mode(2)=0
call clunit(-lunit,buf,mode)
endif
goto 999
endif
c create header of variable to return
istk(il)=8
istk(il+1)=m
istk(il+2)=n
istk(il+3)=it
l=il+4
lw=l+(m*n*it/4+1)
err=sadr(lw+n*it/4+1)-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
if(fin.lt.0.and.ftyp.ne.1) then
buf='incorrect format'
call error(9999)
return
endif
if(fin.gt.0) then
buf(1:1)='*'
nc=1
endif
c
if(iacces.eq.0) then
c sequential acces
if(m.gt.0) then
c . specified number of rows
if(it.eq.4) then
call mibasin(ierr,lunit,buf(1:nc),istk(l),m,n)
elseif(it.eq.2) then
call mi2basin(ierr,lunit,buf(1:nc),istk(l),m,n)
elseif(it.eq.1) then
call mi2basin(ierr,lunit,buf(1:nc),istk(l),m,n)
call i22i1(m*n,istk(l),1,istk(l),1)
endif
if(ierr.eq.1) then
goto 997
elseif(ierr.eq.2) then
goto 998
endif
else
c . unspecified number of rows
m=-(iadr(lstk(bot))-li)*it/4
if(it.eq.4) then
call mibasin(ierr,lunit,buf(1:nc),istk(l),n,m)
elseif(it.eq.2) then
call mi2basin(ierr,lunit,buf(1:nc),istk(l),n,m)
elseif(it.eq.1) then
call mi2basin(ierr,lunit,buf(1:nc),istk(l),n,m)
call i22i1(n*m,istk(l),1,istk(l),1)
endif
if(ierr.eq.0) goto 1241
if(ierr.eq.2) goto 998
if(m.ne.0) then
if(m.ge.1.and.n.ge.1) then
err=sadr(l+2*m*n*it/4)-lstk(bot)
if(err.gt.0) then
call error(17)
return
endif
l1=l+m*n
if(it.eq.4) then
call icopy(m*n,istk(l),1,istk(l1),1)
call imtran(istk(l1),n,istk(l),m,n,m)
elseif(it.eq.2) then
call i2copy(m*n,istk(l),1,istk(l1),1)
call i2mtran(istk(l1),n,istk(l),m,n,m)
elseif(it.eq.1) then
call i1copy(m*n,istk(l),1,istk(l1),1)
call i1mtran(istk(l1),n,istk(l),m,n,m)
endif
istk(il+1)=m
endif
else
istk(il+1)=0
istk(il+2)=0
endif
endif
else
c acces direct
if(nb.ne.m) then
call error(42)
goto 996
endif
if(fin.gt.0) then
call error(61)
goto 996
endif
if(m.lt.0) then
call error(43)
return
endif
if(it.eq.4) then
call irecread(lunit,buf(1:nc),istk(ilb),n,m,istk(l),ierr)
elseif(it.eq.2) then
call i2recread(lunit,buf(1:nc),istk(ilb),n,m,istk(l),ierr)
elseif(it.eq.1) then
call i2recread(lunit,buf(1:nc),istk(ilb),n,m,istk(l),ierr)
call i22i1(m*n, istk(l),1, istk(l),1)
endif
if(ierr.eq.1) goto 998
endif
lstk(top+1)=sadr(l+m*n*it/4+1)
if(.not.opened) then
mode(1)=0
mode(2)=0
call clunit(-lunit,buf,mode)
endif
goto 999
996 if(.not.opened) call clunit(-lunit,buf,mode)
return
997 err=i
call error(62)
if(.not.opened) call clunit(-lunit,buf,mode)
return
998 call error(49)
if(.not.opened) call clunit(-lunit,buf,mode)
return
c
999 return
end
subroutine irecread(lunit,fmt,records,n,m,a,ierr)
integer lunit,records(*),n,m,ia,a(m,*),ierr
character*(*) fmt
do 10 i=1,m
read(lunit,fmt,rec=records(i),err=20) (a(i,j),j=1,n)
10 continue
ierr=0
return
20 ierr=1
return
end
subroutine i2recread(lunit,fmt,records,n,m,a,ierr)
integer lunit,records(*),n,m,ia,ierr
integer*2 a(m,*)
character*(*) fmt
do 10 i=1,m
read(lunit,fmt,rec=records(i),err=20) (a(i,j),j=1,n)
10 continue
ierr=0
return
20 ierr=1
return
end
subroutine mibasin(ierr,lunit,fmt,v,m,n)
c Copyright INRIA
include '../stack.h'
character*(*) fmt
integer v(*)
integer ierr,lunit
character*512 string
c
ierr=0
if(lunit.eq.rte) then
string=' '
call xscion(iflag)
if(m.gt.0) then
do 01 l=1,m
call zzledt(string,len(string),lline,status,0,iflag)
if(status.ne.0) goto 10
if (lline.eq.0) then
string(1:1)=' '
lline=1
endif
if(fmt(1:1).ne.'*') then
read(string(1:lline),fmt,end=10,err=20) (v(l-1+i),
$ i=1,n*iv,iv)
else
call rldint(string(1:lline),v(l),iv,n1,n,ierr)
if(ierr.ne.0) goto 20
if(n1.lt.n) goto 10
endif
01 continue
else
if(fmt(1:1).ne.'*') then
read(lunit,fmt,end=10,err=20) (v(i),i=1,n*iv,iv)
else
read(lunit,*,end=10,err=20) (v(i),i=1,n*iv,iv)
endif
endif
c
return
c
10 ierr=1
return
20 ierr=2
return
end
subroutine i2basin(ierr,lunit,fmt,v,iv,n)
c Copyright INRIA
include '../stack.h'
character*(*) fmt
integer*2 v(*)
integer ierr,lunit
character*512 string
c
ierr=0
if(lunit.eq.rte) then
string=' '
call xscion(iflag)
call zzledt(string,len(string),lline,status,0,iflag)
if(status.ne.0) goto 10
if (lline.eq.0) then
string(1:1)=' '
lline=1
endif
if(fmt(1:1).ne.'*') then
read(string(1:lline),fmt,end=10,err=20) (v(i),i=1,n*iv,iv)
else
call rldi2(string(1:lline),v,iv,n1,n,ierr)
if(ierr.ne.0) goto 20
if(n1.lt.n) goto 10
endif
else
if(fmt(1:1).ne.'*') then
read(lunit,fmt,end=10,err=20) (v(i),i=1,n*iv,iv)
else
read(lunit,*,end=10,err=20) (v(i),i=1,n*iv,iv)
endif
endif
c
return
c
10 ierr=1
return
20 ierr=2
return
end
subroutine rldint(str,v,iv,n,maxv,ierr)
c!purpose
c internal "list-directed" read mode is not standard fortran.
c This routine emulates :read(str,*) (v(1,i),i=1,n)
c!
integer v(iv,maxv),vv
character*(*) str
character*1 si
logical del
c
ls=len(str)
del=.true.
c
ierr=0
n0=n
n=0
i=0
10 i=i+1
c loop on descriptors
if(i.gt.ls) goto 20
si=str(i:i)
if(si.eq.'/'.or.si.eq.',') then
if(del) then
if(n+1.gt.maxv) return
v(1,n+1)=0
n=n+1
goto 10
else
del=.true.
endif
endif
if(si.ne.' '.and.si.ne.'/'.and.si.ne.',') then
c conversion of a descriptor to a (repeated) value
call nextint(str(i:),vv,nv,ir,ierr)
if(ierr.ne.0) return
if(n+nv.gt.maxv) nv=maxv-n
if(nv.le.0) return
call iset(nv,vv,v(1,n+1),iv)
n=n+nv
i=i+ir-2
del=.false.
endif
goto 10
20 continue
if(del) then
if(n+1.gt.maxv) return
v(1,n+1)=0
n=n+1
endif
return
end
subroutine rldi2(str,v,iv,n,maxv,ierr)
c!purpose
c internal "list-directed" read mode is not standard fortran.
c This routine emulates :read(str,*) (v(1,i),i=1,n)
c!
integer*2 v(iv,maxv),vv2
integer vv
character*(*) str
character*1 si
logical del
c
ls=len(str)
del=.true.
c
ierr=0
n0=n
n=0
i=0
10 i=i+1
c loop on descriptors
if(i.gt.ls) goto 20
si=str(i:i)
if(si.eq.'/'.or.si.eq.',') then
if(del) then
if(n+1.gt.maxv) return
v(1,n+1)=0
n=n+1
goto 10
else
del=.true.
endif
endif
if(si.ne.' '.and.si.ne.'/'.and.si.ne.',') then
c conversion of a descriptor to a (repeated) value
call nextint(str(i:),vv,nv,ir,ierr)
if(ierr.ne.0) return
if(n+nv.gt.maxv) nv=maxv-n
if(nv.le.0) return
call i42i2(1,vv,1,vv2,1)
call i2set(nv,vv2,v(1,n+1),iv)
n=n+nv
i=i+ir-2
del=.false.
endif
goto 10
20 continue
if(del) then
if(n+1.gt.maxv) return
v(1,n+1)=0
n=n+1
endif
return
end
subroutine nextint(str,v,nv,ir,ierr)
c form integer number described by a string with format:
c [nn*][+|-][mmmmm]
character*(*) str
character*1 next
integer v
integer sgn
ls=len(str)
nv=1
i=1
ic=0
c
01 if(str(i:i).eq.'-') then
sgn=-1
i=i+1
elseif(str(i:i).eq.'+') then
sgn=1
i=i+1
else
sgn=1
endif
10 if(i.gt.ls) goto 20
call s2int(str(i:),nlz,iv,ir,ierr)
if(ierr.ne.0) iv=0
i=i-1+ir
if(i.le.ls) then
next=str(i:i)
else
next=' '
endif
if (next.eq.','.or.next.eq.'/') next=' '
c
if(next.eq.'*') then
if(ic.eq.0.and.iv.gt.0.and.sgn.gt.0) then
c number of values
nv=iv
i=i+1
goto 10
else
ierr=2
return
endif
elseif(next.eq.' ') then
c end of number definition
goto 20
else
ierr=2
return
endif
20 continue
ir=i
v=sgn*iv
return
end
|