;+
; Project     : SOHO - CDS
;
; Name        : CDS_PLAN_POINT
;
; Purpose     : create map structures for planned CDS pointings
;
; Category    : planning
;
; Syntax      : IDL> cds_plan_point,cmap,tstart,tend
;
; Inputs      : TSTART = plot start time [def=current date]
;
; Opt. Inputs : TEND = plot end time [def = 24 hour window]
;
; Outputs     : CMAP = CDS plan pointings in MAP structures
;
; Keywords    : COUNT = # of pointings found
;
; History     : Version 1,  20-May-1998,  D.M. Zarro.  Written
;
; Contact     : DZARRO@SOLAR.STANFORD.EDU
;-

pro cds_plan_point,cmap,tstart,tend,count=count,err=err,_extra=extra

err=''
count=0
delvarx,cmap

;-- check time inputs

t1=get_def_times(tstart,tend,dend=t2,_extra=extra)

list_detail,t1,t2,plans,count

if count eq 0 then begin
 err='No CDS detailed plans during specified times'
 message,err,/cont
 return
endif

;-- make pointing structures

plans=list_to_detail(plans)
for i=0,count-1 do begin
 study=get_cds_study(plans(i).study_id,plans(i).studyvar)
 get_cds_xy,plans(i),x,y,fixed=fixed,/one
 get_cds_fov,plans(i),width,height,/one
 time=anytim2utc(plans(i).date_obs,/vms)
 tend=anytim2utc(plans(i).date_end,/vms)
 eng=study.n_raster_def eq 0
 npoints=n_elements(x)
 if npoints gt 1 then begin
  get_study_par,plans(i).study_id,plans(i).studyvar,rdur=rdur
  if n_elements(rdur) eq 1 then rdur=replicate(rdur,npoints)
  if n_elements(rdur) ne npoints then begin
   message,'# durations do not match pointings',/cont
  endif
  rdur=rdur[0:npoints-1]
  time=replicate(plans[i].date_obs,npoints)
  for j=1,npoints-1 do time[j]=time[j-1]+rdur[j-1]
  time=anytim2utc(time,/vms)
 endif

 for k=0,npoints-1 do begin
  temp=make_map(fltarr(2,2),xc=x(k),yc=y(k),dx=width(k)/2.,dy=height(k)/2.,$
                time=time[k],tend=tend,/soho,id=study.obs_prog,eng=eng,$
                fixed=fixed(k))
  cmap=merge_struct(cmap,temp)
 endfor
endfor

count=n_elements(cmap)

return & end

