subroutine ra_poly_head(linit,uv,y,nx,ny,nv,xbad,ixmin,ixmax) c c read_array subroutine to get poly head format (new format) data. c dimension uv(1),y(1),indy(20),ivar(20),zd(20),xflg(20) dimension kdate(5),zz(20) character fnam*40,form*40 COMMON /INFORM/ FORM,IDATE(5),LDATE(5) COMMON/matrix/ ImatDAT(5),LmatDAT(5),XDEL c c initialize, unless appending to array c 600 if(linit.eq.0)then call init_array(uv,nx,ny,nv,xbad) nz=0 ixmin=nx+1 ixmax=0 endif c read(5,*)nfiles c do ifile=1,nfiles c c read the input file parameters; open the input file c read(5,*)fnam,form,iftype,nflds,ydep, - (xflg(ifld),ifld=1,nflds) if(iftype.lt.0)read(5,*)(ivar(ifld),ifld=1,nflds) call cmpopn(fnam,form,nflds,zd,xflg) c if(iftype.eq.-2)then c c conventional time series; all variables from the same depth c do ifld=1,nflds zd(ifld)=ydep enddo c else if (iftype.eq.0) then c c multi variables and optionally muti-depths in each file. c Each depth must have fields for each of the nv variables. c ndepths = nflds/nv if(ndepths.eq.1)then do ifld=1,nflds zd(ifld)=ydep enddo endif do idepth = 1,ndepths do iv = 1,nv ifld = (idepth-1)*nv + iv ivar(ifld)=iv enddo enddo c else if (iftype.gt.0)then c c new composite with all fields holding the same variable c do ifld=1,nflds ivar(ifld)=iftype enddo endif c figure out the depth indices for the data in this file c if(linit.eq.0.and.ifile.eq.1)then call initz(zd,nflds,indy,nz,y) else call addz(zd,nflds,indy,nz,y,uv,nx,ny,nv) endif c c get all the data in the date range. c nread=0 610 read(1,form,end=690)kdate,(zz(k),k=1,nflds) dd=delday(imatdat,kdate) if(dd.lt.0.0)go to 610 ix=dd/xdel+1.1 if(ix.lt.1)go to 610 if(ix.gt.nx)go to 700 nread=nread+1 call add_cmprec(zz,nflds,xflg,ix,indy,ivar,uv,nx,ny,nv) if(ix.gt.ixmax)then call sub_date(kdate,ldate) ixmax=ix endif if(ix.lt.ixmin)then call sub_date(kdate,idate) ixmin=ix endif go to 610 690 print *,nread 700 close(1) enddo return end subroutine initz(zd,nfld,indy,nz,ascend) c c subroutine to start figuring out the sorted list of depths c for variables read from a new format composite file. c makes a sorted list of depths in zd. drops duplicate c depths. Output list is in ascend. For each depth in zd c indy will give the index for the same depth in ascend. c dimension zd(*),indy(*),ascend(*) logical loop c nz=1 ascend(1)=zd(1) c do ifld=2,nfld loop=.true. ia=1 do while(loop.and.ia.le.nz) if(zd(ifld).lt.ascend(ia))then loop=.false. do ja=nz,ia,-1 ascend(ja+1)=ascend(ja) enddo ascend(ia)=zd(ifld) nz=nz+1 else if (zd(ifld).eq.ascend(ia))then loop=.false. else ia=ia+1 endif enddo if(ia.gt.nz)then nz=nz+1 ascend(nz)=zd(ifld) endif enddo c c get the depth index for each field c do ifld=1,nfld loop=.true. ia=1 do while(loop.and.ia.le.nz) if(zd(ifld).eq.ascend(ia))then loop=.false. indy(ifld)=ia else ia=ia+1 endif enddo if(loop)then write(6,100) 100 format(' Error in INITZ!') stop endif enddo return end subroutine addz(zd,nfld,indy,nz,ascend,uv,nx,ny,nv) c c subroutine to add depths for one file to the sorted list of depths. c if it's neccessary to add a depth in the middle of ascend, c data in uv will be shifted around as appropriate. c dimension uv(nx,ny,nv),ascend(*),indy(*),zd(*) logical loop c c find spot for each depth in zd c do ifld=1,nfld loop=.true. ia=1 do while(loop.and.ia.le.nz) if(zd(ifld).lt.ascend(ia))then call shifty(zd(ifld),ia,nz,ascend,uv,nx,ny,nv) loop=.false. indy(ifld)=ia else if (zd(ifld).eq.ascend(ia))then loop=.false. indy(ifld)=ia else ia=ia+1 endif enddo if(loop)then nz=nz+1 ascend(nz)=zd(ifld) indy(ifld)=nz endif enddo return end subroutine shifty(z,ia,nz,ascend,uv,nx,ny,nv) c c subroutine to make room for a new depth in ascend and uv c dimension ascend(*),uv(nx,ny,nv) common /check/nchk,xbad c c make room c nz=nz+1 do iz=nz,ia+1,-1 ascend(iz)=ascend(iz-1) do ix=1,nx do iv=1,nv uv(ix,iz,iv)=uv(ix,iz-1,iv) enddo enddo enddo c c add new z to ascend; blank corresponding record in uv c ascend(ia)=z do ix=1,nx do iv=1,nv uv(ix,ia,iv)=xbad enddo enddo c return end subroutine add_cmprec(zz,nfld,xflg,ix,indy,ivar,uv,nx,ny,nv) c c add a record read from a new format composite file to uv c dimension uv(nx,ny,nv),zz(*),xflg(*),indy(*),ivar(*) c do i=1,nfld iy=indy(i) iv=ivar(i) if(zz(i).ne.xflg(i))uv(ix,iy,iv)=zz(i) enddo return end