PRO derotw,date,wtime
;
;Derotation of WL images of 23,25 June 1997.
;Procedure LPANGLES + subroutines is used.
;INPUT:  date = 23 or 25
;	 wtime = array of time UT in seconds
;	 files XXjun/wnXX.seq, where XX is the date
;OUTPUT: files XXjun/wdXX.seq, where XX is the date
;
on_error,1

; IMAGE PARAMETERS ----------------------------------------------------

if (date ne 23) and (date ne 25) then  $
   message,'Sorry, I do not know how to handle this dataset'
dat=strtrim(date,2)
nami=dat+'jun/wn'+dat+'.'
namo=dat+'jun/wd'+dat+'.'
im=intarr(1528,1024)
siz=size(wtime)
n=siz(1)-1

if date eq 23 then begin
	ref=165		;reference frame no.
	x=731		;pivot point coords.
	y=375
endif else begin
	ref=182
	x=736
	y=370
endelse

; ANGLE CALCULATION --------------------------------------------------

angles=lpangles(97,6,date,wtime)*!radeg	;(year,month,day,time)
angles=angles-angles(ref)		;zero derotation of frame ref

; LOOP OVER FRAMES ---------------------------------------------------

for i=0,n do begin

  openr,1,nami+strtrim(i,2)
  readu,1,im
  close,1

  ima=rot(im,angles(i),1.,x,y,/cubic,/pivot,missing=mean(im))

  print,namo+strtrim(i,2)
  openw,1,namo+strtrim(i,2)
  writeu,1,ima
  close,1

endfor

END