pro SPEtoFITS, fileinpat, fits_extension, fileoutbase ; read a Princeton Instruments WinView file and write out the data and ; some of the header information to a FITS file ; EXAMPLE: SPEtoFITS, '*.spe', '.fit', 'spica_calib' ; FILEINPAT is the name of a file to open, or a filename patern for ; findfile() ; FITS_EXTENSION is the extension to append to the output filenames ; FILEOUTBASE (optional) is the base name for the output file(s). If more than one ; file is writen, a number will be appended to this name. If no name ; is given, the name of the input file will be used files = findfile( fileinpat, count = n ) if (n eq 0) then message, 'No files found matching: ' + fileinpat print, 'Converting:' print, files for i = 0, n-1 do begin filein = files[i] read_princeton, filein, data, exposure = exp, comments = com, date = date, time = time ; read in the .spe file datenums = stregex(date, '([0-9]{2})([A-Za-z]{3})([0-9]{4})', /extract, /subexpr) months = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] datenums[2] = where(months eq datenums[2]) ; datenums should now be integer ; representations of ;[2 digit day of month, 2 digit ; month, 4 digit year] ; make a standard date string YYYY-MM-DD datestr = strjoin( [string(datenums[3], format = '(i4)'), $ string(datenums[2], format = '(i2.2)'), $ string(datenums[1], format = '(i2.2)')]$ , '-') ; make a standard time string, ; HH:MM:SS, e.g. 15:21:33 timestr = strjoin( string(time, format = '(i2.2)'), ':' ) mkhdr, header, data ; make a FITS primary header, with the right parameters for the data sxaddpar, header, 'DATE-OBS', datestr sxaddpar, header, 'TIME-OBS', timestr sxaddpar, header, 'EXPTIME', exp.exp_sec sxaddpar, header, 'NOTES', 'Created from ' + filein if ( n eq 1 ) then begin fileout = (n_params() gt 2) ? $ fileoutbase + fits_extension :$ filein + fits_extension endif if (n gt 1) then begin fileout = (n_params() gt 2) ? $ fileoutbase + strtrim(string(i), 2) + fits_extension :$ filein + fits_extension endif FITS_write, fileout, data, header endfor end