subroutine creep(mn,mx,mul) use creep_module implicit none integer:: mn,mx,mul !min,max delt, delt multiplier integer:: i,j,k,im,id,ix,iter,sdat(2) integer:: nss,opk,ipk,ocmd,noch,span real:: d0,d1,val,s0 logical did_wait !flag that bunches may be turned off d0=0.0 do i=1,3 call fxgetn(sred,sr1,sr2,sdat) ; d0=d0+max(sdat(1),sdat(2)) call csr_sleep(300) enddo d0=d0/3. ; d1=d0 ; s0=secnds(0.0) if(d0.lt.10) then call say_advise('cre', 'too low ') stop endif call vmgcmd(mnem,el,el,ocmd) !starting command ns=0 ; d=0 ; wei=0 ;noch=0 !clear sampl count,data,weighting im=-1 ; ix=1 !init scan range ; will expand once get heading opk=0 !init old peak to no change span=nsam ! how much history to use (only latest sample) do iter=1,3 call wait_fill(did_wait) !test that time enough remains if(did_wait) call bunon do id=im,ix call dxputn('search ',mnem,el,el,ocmd+id*mul) !new command call csr_sleep(wait) !device settling do j=1,nsam call csr_sleep(300) !long enough for new data nss=31.and.(ns(id)+1) ; ns(id)=nss !circular buffer sample loc call fxgetn(sred,sr1,sr2,sdat) d(id,nss)=max(sdat(1),sdat(2)) wei(id,nss)=min(1.5,float(j)*.6) !wei= count from last cmd change write(40,4040) mnem,el,ocmd+id,id,d(id,nss),secnds(s0) 4040 format(a,4(i6,','),f7.2,',') if(d(id,nss).lt.(d1/1.3)) goto 606 !curtail if drops too fast enddo 606 continue enddo call decide(span,im-1,ix+1,ipk,val) !data +/-1 from scan, return ipk+val d1=max(d1,val) !allow criterion for quit to creep up if(ipk.eq.opk) then noch=noch+1 im=ipk-1 ; ix=ipk+1 call dxputn(' no change ',mnem,el,el,ocmd+ipk*mul) !reset to old pk goto 777 !no gain , stop trying else if(ipk.gt.opk) then if(ipk.lt.ix) then im=ipk-1 ; ix=ipk+1 !stay close else im=ipk+1 ; ix=ipk+3 !press on endif else if(ipk.gt.im) then im=ipk-1 ; ix=ipk+1 !stay close else im=ipk-3 ; ix=ipk-1 !next range endif endif noch=0 ; opk=ipk call dxputn(' improved ',mnem,el,el,ocmd+ipk*mul) !load to new pk endif if((im.lt.mn).or.(ix.gt.mx)) return enddo 777 continue return end subroutine fxgetn(mmm,e1,e2,dat) use creep_module implicit none character*12 mmm integer:: e1,e2,dat(2),var(10),i,j,k integer:: tar(10)=[1630,70,220,280,(100,i=1,6)] real f,e if(fake_on) then call vmgcmd('PFN HI VOLTS',2,2,var(1)) call vmgcmd('LRF KLY PHS ',1,1,var(2)) call vmgcmd('INJ PRB PHAS',1,2,var(3)) f=5000. do i=1,4 e=abs(var(i)-tar(i)) f=f*(100.-2.*e)/100. enddo dat(1)=0 ; dat(2)=f else call vxgetn(mmm,e1,e2,dat) endif return end subroutine dxputn(str,mnem,e1,e2,vals) implicit none character*12:: mnem character*(*):: str integer:: e1,e2,vals(*) integer:: e real t t=secnds(0.0) call vxputn(mnem,e1,e2,vals) write(40,4040) str,mnem,e1,vals(1),t if(str(1:6).ne.'search') print 4040, str,mnem,e1,vals(1),t 4040 format(a,1x,a,i4,i7,f9.2) return end