func open_tri_file(fname)
 ;another way to open an hourly file, search all the paths and keep the last
 ;success
 ;first try with the last successful directory
 if defined($t3d_file_name) then {
 path = getfilepath($t3d_file_name)
 f_sans_path = removepath(fname)
 $t3d_file_name = path + f_sans_path
 if t3d_open_file() eq 1 then return, 1
 ;if that failed, a thorough search
 ;7/16/99 - make this less thorough since it is now taking a long time with
 ;years of data online. Check if we seem to be using weekly directories and
 ;try the appropiate one if we are
 iq = strpos(path, 'week')
 if iq ge 0 then {
  ;guess we are, proceed
  if iq gt 0 then path2 = path(0:(iq-1)) else path2 = ''
  ;now isolate the month/day part of the hourly
  s = strskp(f_sans_path,'tri')
  ty,'s =', s
  ;dump the hour part
  iq = strpos(s,'.')
  if iq eq 8 then {
   ;fussy here, it must be an 8 character field
   year = fix(s(0:3))
   ty,'year =', year
   dayofyear = doy(year, fix(s(4:5)), fix(s(6:7)))
   ;the weekly name should start with the previous Sunday (or the first
   ;day of the year) but we'll be slightly more general here and check for
   ;up to 7 potential weekly names. We still assume that there is a weekly at
   ;the start of the year however so this generality is mostly laziness.
   wq = 'week'+s(0:3)	;first part of weekly name
   ;try up to 7
   for jj = 0, 6 do {
    dq = dayofyear - jj
    if dq ge 1 then {
     doytodom, year, dq, im, idm
     save = $t3d_file_name
     $t3d_file_name = path2 + wq + sprintf('%02d%02d/', im, idm) + f_sans_path
     ;avoid mucking up $t3d_file_name if this is a bad name
     if t3d_open_file() eq 1 then return, 1 else $t3d_file_name = save
     }
    }
   ;OK, if we got here we didn't find it and we want to avoid the more
   ;thorough (time consuming) search - so give up!
   ty,'problem finding file: ', $t3d_file_name
   return, 0
   }
  
  }
 }
 ;if all that failed or $t3d_file_name was not defined, a thorough search
 base_path = t3d_get_base_path()
 fn = findfile(base_path, fname)
 if isscalar(fn) then {
 ty,'problem finding file in thorough search: '+fname
 return, 0 }

 ;found it
 $t3d_file_name = fn
 ty,'file name in open_tri_file:', fn
 if t3d_open_file() ne 1 then {
 	ty,'problem opening file: '+fname
	return, 0 }
 return, 1
 endfunc
 ;=======================================================