;+
; Project     : SOHO - CDS     
;                   
; Name        : TP_WRT_FRAST()
;               
; Purpose     : Store the fundamental raster definition into the database.
;               
; Explanation : Checks whether the current fundamental raster definition
;               already exists in the database, if not then create a new
;               entry and report new ID.
;               
; Use         : id = tp_wrt_frast(tp_obs, msg_widg)
;    
; Inputs      : tp_obs   - the standard TPLAN structure.
;               msg_widg - widget ID for messages.
;               
; Opt. Inputs : None
;               
; Outputs     : Function returns ID of fundamental raster (<0 if a problem)
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : ADD_F_RASTER()
;               CHK_F_RASTER()
;
; Common      : None
;               
; Restrictions: Only for internal TPLAN use.
;               
; Side effects: Fundamental raster database could be updated.
;               
; Category    : Planning, technical
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 13-Oct-94
;               
; Modified    : Fix bad status return.  CDP, 2-Mar-95
;
; Version     : Version 2, 2-Mar-95
;-            

function tp_wrt_frast, tp_obs, msg_widg

;
;  check whether definition already exists.  
;
status = chk_f_raster(tp_obs.raster_p)

if status ge 0 then begin

   widget_control, msg_widg,/append,$
        set_val=string('Fundamental raster definition already exists. ID = ',$
                        status,form='(a,i3)')
   tp_obs.raster_p.ras_id = status
   tp_obs.raster_v.ras_id = status
   

endif else begin

   errmsg = ''
   tp_obs.raster_p.ras_id = 0
   temp = tp_obs.raster_p
   status = add_f_raster(temp, errmsg=errmsg)
   if errmsg ne '' then begin
      widget_control, msg_widg, /append, set_val=errmsg
      status = -1
   endif else begin
      widget_control, msg_widg, /append, $
                      set_v=string('Fundamental raster stored with ID = ',$
                                    temp.ras_id)
      tp_obs.raster_p.ras_id = temp.ras_id
      tp_obs.raster_v.ras_id = temp.ras_id
   endelse

endelse


return, status


end   
