;+
; NAME:
;    wimagr_fits2map
; PURPOSE:
;    OVSA FITS to MAP conversion routine
; CATEGORY:
;     OVSA
; CALLING SEQUENCE:
;     wimagr_fits2map,filename,no_reformat=no_reformat
; INPUTS:
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;
; ROUTINES CALLED:
;
; OUTPUTS:
; COMMENTS:
; Intended to replace obsolete ovsa2map
; SIDE EFFECTS:
; RESTRICTIONS:
;  If FITS header indicates RHESSI as instrument instead of OVSA, hsi_fits2map is called. Fo all other cases, the general purpose fits2map is called
; MODIFICATION HISTORY:
;     Written 14-May-2014 Gelu M. Nita
;
function wimagr_fits2map,filename,header,no_reformat=no_reformat
 if n_elements(filename) eq 0 then filename=dialog_pickfile(filter='*.f*')
 if ~file_exist(filename) then return,0
 data=mrdfits(filename,0,header,/silent)
 instr=strcompress(fxpar(header,'INSTRUME'),/rem)
 case instr of 
 'OVSA':BEGIN
  catch, error_stat
   if error_stat ne 0 then begin
     catch, /cancel
     MESSAGE, /INFO, !ERROR_STATE.MSG
     err:
     info={npol:1,nfreq:1,ntim:1,offset:[0.0,0.]}
     index={header:header}
     goto, skip
   end
   info=mrdfits(filename,'info',/silent)
   if size(info,/tname) eq 'STRUCT' then begin
     index=mrdfits(filename,'index',/silent)
     skip:
     map_arr=wimagr_index2map(data,index,info)
     if ~keyword_set(no_reformat) then map_arr=reform(map_arr,info.npol,info.nfreq,info.ntim)
     header=index.header
   endif else goto,err
   END
   'RHESSI':hsi_fits2map,filename,map_arr ;,header=header
 else:fits2map,filename,map_arr,header=header
 endcase
 return,map_arr
end