PRO CheckNans ;spectra = file_search('m0*V',COUNT=nfiles) spectra = file_search('m0985V',COUNT=nfiles) nans = indgen(nfiles) badValue=0.001 for j=0,nfiles-1 do begin rows=file_lines(spectra[j]) data=fltarr(2,rows) OPENR, lun, spectra[j], /get_lun READF, lun, data FREE_LUN, lun CLOSE, lun ; Criterium below finds NaN values in the spectrum ; if (size(where(Finite(spec) eq 0),/dimen) ne 0) then nans[j] = 0 else nans[j] = 1 ; Check if there is more than one NaN in the interval [3780:9270]AA ;spec=fits.spectrum[where(fits.wavelength ge 3780) AND where(fits.wavelength le 9270)] ;spec=data[1,*] & lam = data[0,*] ;spec=spec[where(lam ge 3800)] & wave = wave[where(lam ge 3800)] data = data[*,where(data[0,*] gt 3800)] spec=data[1,*] & wave = data[0,*] dim=n_elements(spec) bad = (where(spec le badValue,count)) nans[j]=1 if (count gt 1) then begin if (count gt 2) then begin if ((where(spec le badValue))[1] eq 1) OR ((where(spec le badValue))[count-2] eq (dim-2)) then nans[j]=0 else nans[j]=1 endif else begin if ((where(spec le badValue))[1] eq 1) then nans[j]=0 else nans[j]=1 endelse endif ; Calculate the size of the largest gap in the spectrum maxGap=0 sum=1 index=where(spec le badValue) for i=0,n_elements(index)-2 do begin if (index[i+1]-index[i] eq 1) then begin sum=sum+1 ; print, index[i], index[i+1], sum endif else begin if (sum gt maxGap) then maxGap=sum sum=1 endelse endfor if (count ge 1 AND sum gt maxGap) then maxGap=sum ; nans=1 means that either gaps at the edges are larger then one pixels or the larges gap is larger than 100AA --> don't use this spectrum ; nans=0 means that there are no gaps larger then 100AA and at the edges more than one pixel --> use this spectrum print, File_Basename(spectra[j]), ' ',nans[j],' ',maxGap, 'pixels',2.5*maxGap,' angstroms ', wave[0], max(wave), FORMAT='(A32, A1, I1, A1, I6, A7, F6.1, A12, 2F13.6)' ;print,where(data[1,*] le badValue) ;print,File_Basename(spectra[j]),count ;print, File_Basename(spectra[j]), ' ',nans[j], FORMAT='(A32, A3, I1)' ;print, File_Basename(spectra[j]), ' ',maxGap, 'pixels',0.4*maxGap,'angstroms', FORMAT='(A32, A3, I56, A10, F6.1, A10)' if (count gt 0) then spec[bad] = replicate(!Values.F_NAN,count) if (nans[j] eq 1) then begin ; Spectrum will be further used OpenW, lun, spectra[j]+'.txt' for i=0,n_elements(spec)-1 do PrintF, lun, wave[i], ' ',spec[i], format='(f8.3,A4,f9.7)' Free_lun, lun Close, lun endif endfor END