;+ ; Project : COURSE COMPUTER PROJECT ; ; Name : RDGALSPEC ; ; Purpose : Procedure to read in the galaxy spectrum files. ; ; Explanation : This procedure reads in the galaxy spectral data for the files ; used in the Hubble constant project. ; ; Use : RDGALSPEC, FILE, GALNAME, WAVE, FLUX ; ; Inputs : FILE: The file name to be read. ; ; Opt. Inputs : None. ; ; Outputs : GALNAME: The name of the galaxy. ; ; WAVE: The wavelength array in Angstroms. ; ; FLUX: The flux array in erg/s/cm^2/s. ; ; Opt. Outputs: None. ; ; Keywords : DELIM: The directory delimiters in the full path file name. ; If not passed, it is determined from the windows name ; in !D.NAME. ; ; ERRMSG: If defined and passed, then any error messages will ; be returned to the user in this parameter rather than ; being printed internally by this procedure. If no ; errors are encountered, then a null string is ; returned. In order to use this feature, the string ; ERRMSG must be defined first, e.g., ; ; ERRMSG = '' ; RDGALSPEC, FILE, GALNAME, WAVE, FLUX, ERRMSG=ERRMSG ; IF ERRMSG(0) NE '' THEN ... ; ; Calls : None. ; ; Common : None. ; ; Restrictions: None. ; ; Side effects: The galaxy spectra are stored in ASCII text files with the ; file extension ".txt". NULL values are returned for output if ; errors are encountered. ; ; Category : Class project, cosmology, Hubble's law, galaxies, spectra. ; ; Prev. Hist. : None. ; ; Written : Donald G. Luttermoser, ETSU/Physics, 1 Sep 2002. ; ; Modified : Version 1, Donald G. Luttermoser, ETSU/Physics, 1 Sep 2002 ; Initial program. ; Version 2, Donald G. Luttermoser, ETSU/Physics, 31 Mar 2007 ; Replaced the MESSAGE utility with a simple print statement. ; Changed the internal EMESSAGE string variable with EMESS. ; ; Version : Version 1, 31 March 2007. ; ;- PRO RDGALSPEC, FILE, GALNAME, WAVE, FLUX, DELIM=DELIM, ERRMSG=ERRMSG ; ON_ERROR, 2 ; Return to caller if error is encountered. EMESS = '' ; Set to non-null string if error is encountered. GALNAME = '' & WAVE = 0.0D0 & FLUX = 0.0D0 ; In case of errors. ; ; Check input. ; IF N_PARAMS() NE 4 THEN BEGIN EMESS = 'Syntax: RDGALSPEC, FILE, GALNAME, WAVE, FLUX' GOTO, HANDLE_ERROR ENDIF ; ; Check keywords. ; IF NOT KEYWORD_SET(DELIM) THEN BEGIN ; ; Check the machine type. ; TERM = STRUPCASE(!D.NAME) CASE TERM OF 'X': DELIM = '/' 'WIN': DELIM = '\' ELSE: BEGIN EMESS = 'Unknown windows and machine type: ' + TERM GOTO, HANDLE_ERROR END ENDCASE ENDIF ; ; Read the data. ; RDLINE = '' OPENR, URD, FILE, /GET_LUN WHILE NOT EOF(URD) DO BEGIN READF, URD, RDLINE & RDLINE = STRTRIM(STRCOMPRESS(RDLINE), 2) ALEN = STRLEN(RDLINE) IF ALEN GT 1 THEN BEGIN BL1POS = STRPOS(RDLINE, ' ') CW = DOUBLE(STRMID(RDLINE, 0, BL1POS)) CF = DOUBLE(STRMID(RDLINE, BL1POS+1, ALEN-BL1POS-1)) WAVE = [WAVE, CW] & FLUX = [FLUX, CF] ENDIF ENDWHILE FREE_LUN, URD ; ; Ignore negative fluxes. ; IUSE = WHERE(FLUX NE 0.0, NUSE) IF NUSE GT 0 THEN BEGIN WAVE = WAVE(IUSE) & FLUX = FLUX(IUSE) ENDIF ; ; Clean up the data. ; IUSE = WHERE(WAVE GT 0., NUSE) IF NUSE GT 0 THEN BEGIN WAVE = WAVE(IUSE) & FLUX = FLUX(IUSE) ENDIF ; ; Retrieve the galaxy name from the file name. ; DPOS = RSTRPOS(FILE, DELIM) & TLEN = STRLEN(FILE) DOTPOS = STRPOS(FILE, '.', (DPOS>0)) & IF DOTPOS EQ -1 THEN DOTPOS = TLEN GALNAME = STRMID(FILE, DPOS+1, DOTPOS-DPOS-1) ; PRINT, 'Data read from ' + FILE ; IF EMESS NE '' THEN GOTO, HANDLE_ERROR IF N_ELEMENTS(ERRMSG) GT 0 THEN ERRMSG=EMESS RETURN ; ; Error handling portion of the procedure. ; HANDLE_ERROR: ; IF N_ELEMENTS(ERRMSG) EQ 0 THEN PRINT, EMESS ERRMSG = EMESS RETURN ; END