function timstr2tim, instr, toint=toint, toex=toex, type=type
;+
;   Name: anystr2tim
;
;   Purpose: convert various time strings to Yohkoh internal or External Format
; 
;   History:
;      11-Mar-1994 (SLF) - vectorization of timstr2ex
;
;   Restrictions: proto for testing
;-
temp=instr				        ; dont clobber input
data=strtrim(strcompress(temp),2)	        ; simplify problem
time=strsplit(data,/tail,head=date)		; split time/date components
onecomp=where(date eq '',onecnt)		; single component

if onecnt gt 0 then begin
;  No time, then default to 00:00:00
   datess=where(strpos(date(onecomp),':') eq -1,dcnt)
   if dcnt gt 0 then date(datess) = '00:00:00'
;  No date, then default to today
   timess=where(strpos(date(onecomp),':') ne -1,tcnt)
   if tcnt gt 0 then date(timess) = gt_day(!stime,/str)
endif   
; ------------------------------------------------------------------
; place in date/time order
revchk=where(strpos(date,':') ne -1, revcnt)
if revcnt gt 0 then begin
   ttemp=date(revchk)
   date(revchk)=time(revchk)
   time(revchk)=ttemp
endif
; ------------------------------------------------------------------
; should be date/time order now - check to see if date is 1 digit
delim=reform(byte(strmid(data,1,1)))
chk=where(delim lt 48 or delim gt 57,dchk) 
if dchk gt 0 then data(chk) = '0' + data(chk)	; prepend '0'
; ------------------------------------------------------------------

ndata=n_elements(data)
outdata=intarr(7,ndata)
if keyword_set(type) then format=type else format=1
; ******** eventually, choose type from data checks if not passed ****
; poschar gets starting character and number of characters for each field
; ------------------------------------------------------------------
case format of
;     compressed formats (embeded blanks or date-time order changes ok)
;                0123456789012345678
;     format 1 = mm/dd/yy hh:mm:ss
;                0123456789012345678
;     format 2 = dd-mmm-yy hh:mm:ss
;                0123456789012345678
;     format 3 = mm/dd/yyyy hh:mm:ss
;                hrs     mins    secs    msec     day    mnth     yr
   1: poschar=[[ 9,2],  [12,2],  [15,2], [-1,-1], [3,2], [0,2],  [6,2]]
   2: poschar=[[ 10,2], [13,2],  [16,2], [-1,-1], [0,2], [3,-1], [7,2]]
   3: poschar=[[ 11,2], [14,2],  [17,2], [-1,-1], [3,2], [0,2],  [6,4]]
   else:
endcase
; ------------------------------------------------------------------
for i=0,6 do begin
   if poschar(1,i) ne -1 then $
       outdata(i,*)=fix(strmid(data,poschar(0,i),poschar(1,i)))
endfor
; ------------------------------------------------------------------

; ------------------------------------------------------------------
; three character month convention
if poschar(1,5) eq -1 then begin
   months=['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
   mnts=strlowcase(strmid(data,poschar(0,5),3))
   for i=0,11 do begin
      chkmnth=where(mnts eq months(i),cnt)
      if cnt gt 0 then outdata(5,chkmnth) = fix(i+1)
   endfor
endif
; ------------------------------------------------------------------

; ------------------------------------------------------------------
; correct for four digit years
century=outdata(6,*) / 100
cent_corr=where(century,cent_cnt)
if cent_cnt gt 0 then outdata(6,cent_corr) = outdata(6,cent_corr) $
   mod (century(cent_corr)*100)
; ------------------------------------------------------------------

; convert to internal format on request
if keyword_set(toint) then outdata=anytim2ints(outdata)

return, outdata

end
