pro getdetname, fitsHeader, detname

      ; NAME:
      ;      pro getdetname.pro
      ;
      ; PURPOSE:
      ;      This program searches IDTL FITS headers for the
      ;      DETNAME keyword and returns its value in the string
      ;      detname.
      ;
      ; CALLING SEQUENCE:
      ;      IDL> detname = '' ; Declare an empty string to hold the result
      ;      IDL> getdetname, fitsHeader, detname
      ;
      ; INPUTS:
      ;      fitsHeader - A valid fits header.
      ;
      ; KEYWORD PARAMETERS:
      ;      none
      ;
      ;
      ; EXAMPLE
      ;
      ;     getdetname, fitsHeader, detname
      ;
      ;
      ; REFERENCE:
      ;
      ;
      ; MODIFICATION HISTORY:
      ;      Written by:
      ;      Modified:    B.J. Rauscher, IDTL, October 9, 2002
      ;                   Initial release
      ;-


      ;; Search the header for the keyword DETNAME
      a = strpos(fitsHeader, 'DETNAME')

      ;; Search for the line in which the match occurs at the first
      ;; char, index=0.
      for i=0, n_elements(a)-1 do begin
          if (a[i] eq 0) then begin

              ;; This command extracts the full substring starting
              ;; with the '=' character that ends the FITS keyword
              ;; field. The strtrim command trims off the leading and
              ;; trailing blanks.
              strlen = strpos(fitsHeader[i], '/') - strpos(fitsHeader[i], '=') - 2
              detname = strtrim(strmid(fitsHeader[i], strpos(fitsHeader[i], '=') + 1, strlen), 2)

              goto, done

          endif
      endfor

      done:

end
