function do_browse_image, image, raw_browseimage, label, img_size, logname

;+
; NAME:
;   DO_BROWSE_IMAGE
;
; PURPOSE:
;   Creates a browse image from an image.
;
; CALLING SEQUENCE:
;   Result= do_browse_image (image_array, browse_image_size)
;
; INPUTS:
;     image: The image that shall be reduced to a browse image
;     img_size: The new size of the browse image in pixels (must be square)
;     log_name: Name of a log file
;
; OUTPUTS:
;   Browse image with desired size
;
; MODIFICATION HISTORY:
;   2003 May, MA: First version
;   2008 Feb, SM: Modified to create a browse image
;-

create_log_entry, logname, '[Browse Image creator module] Entering browse image creator module'

; Scale the calibrated image (0-255)
scaleImage = bytscl(image)

; Get the position of the image depending on the filter type
filterXY = amie_getfilter(label)
filter = strtrim(pdspar(label, 'FILTER_NAME'),2)


; Use the raw browse image to create the calibrated browse image
browse = raw_browseimage

aiImageSize = size(image)
y = uint(filterXY[2]/8)
for j=0, aiImageSize[2]-1, 8 do begin

    if ( (y eq uint(filterXY[2]/8)) and $
         ((strpos(filter,'VIS_Y') ne -1) or (strpos(filter,'FeL_Y') ne -1) or (strpos(filter,'NONE') ne -1) ) ) then begin
         y++
         continue
    endif

    if ( (y eq uint(filterXY[3]/8)) and (strpos(filter,'LASER') ne -1) ) then begin
         y++
         continue
    endif

    x = uint(filterXY[0]/8)
    for i=0, aiImageSize[1]-1, 8 do begin
       
        if ( (x eq uint(filterXY[0]/8)) and $
         ((strpos(filter,'NONE') ne -1) or (strpos(filter,'FeL_X') ne -1) or (strpos(filter,'VIS_X') ne -1) ) ) then begin
            x++
            continue
         endif

        if ( (x eq uint(filterXY[1]/8)) and (strpos(filter,'LASER') ne -1) ) then begin
            x++
            continue
        endif

       
       browse(x,y) = scaleImage(i,j)
       x++
    endfor

    y++
endfor

create_log_entry, logname, '[Browse Image creator module] browse image created'

return, browse

end