@@ -615,20 +615,19 @@ bool read_spectra(const options_t& opts, input_state_t& state) {
615615 vec1u sid;
616616 vec1u col_flux, col_eflux;
617617 for (uint_t b : range (spec_header)) {
618- vec2s ext = regex_extract (spec_header[b], " F([0-9]+)" );
619- if (ext.empty ()) continue ;
620- std::string id = ext[0 ];
618+ if (spec_header[b][0 ] != ' F' ) continue ;
621619
622- uint_t cid = where_first (state.id == id);
620+ std::string id = erase_begin (spec_header[b], " F" );
621+ uint_t cid = where_first (toupper (state.id ) == id);
623622 if (cid == npos) {
624623 warning (" spectrum for source " , id, " has no corresponding photometry "
625624 " and will be ignored" );
626625 continue ;
627626 }
628627
629- uint_t ce = where_first (spec_header == " E" +ext[ 0 ] );
628+ uint_t ce = where_first (spec_header == " E" +id );
630629 if (ce == npos) {
631- warning (" spectral flux column " , spec_header[b], " has no uncertainty (E" +ext[ 0 ] +" ) "
630+ warning (" spectral flux column " , spec_header[b], " has no uncertainty (E" +id +" ) "
632631 " and will be ignored" );
633632 continue ;
634633 }
@@ -653,6 +652,11 @@ bool read_spectra(const options_t& opts, input_state_t& state) {
653652
654653 vec1s spl = split_any_of (line, " \t\n\r " );
655654
655+ if (spl.size () != spec_header.size ()) {
656+ error (" line " , l, " has " , spl.size (), " columns while header has " , spec_header.size ());
657+ return false ;
658+ }
659+
656660 if (col_tr != npos) {
657661 bool tr;
658662 if (!from_string (spl[col_tr], tr)) {
@@ -767,6 +771,10 @@ bool read_spectra(const options_t& opts, input_state_t& state) {
767771 slam1 = slam0 + dlam_whole;
768772 }
769773
774+ // Flag bad values
775+ vec1u idb = where (serr < 0 || !is_finite (sflx) || !is_finite (serr));
776+ serr[idb] = finf; sflx[idb] = 0 ;
777+
770778 // Apply binning if required
771779 if (!bin.empty ()) {
772780 // First sort by bin ID
@@ -808,7 +816,6 @@ bool read_spectra(const options_t& opts, input_state_t& state) {
808816
809817 // Accumulate the flux with weighting
810818 vec1f w = 1 /sqr (oerr (_,b));
811- w[where (!is_finite (w))] = 0 ;
812819 tf += oflx (_,b)*w;
813820 tw += w;
814821 ++nb;
@@ -847,7 +854,7 @@ bool read_spectra(const options_t& opts, input_state_t& state) {
847854 }
848855
849856 // Create synthetic filters
850- for (uint_t b : range (sflx)) {
857+ for (uint_t b : range (sflx. dims [ 1 ] )) {
851858 fast_filter_t f;
852859 f.spectral = true ;
853860 f.id = max (state.no_filt )+1 + b;
@@ -874,8 +881,8 @@ bool read_spectra(const options_t& opts, input_state_t& state) {
874881 uint_t nslam = sflx.dims [1 ];
875882 uint_t ngal = pflx.dims [0 ];
876883
877- state.flux = replicate (fnan , ngal, nplam+nslam);
878- state.eflux = replicate (fnan , ngal, nplam+nslam);
884+ state.flux = replicate (0 . 0f , ngal, nplam+nslam);
885+ state.eflux = replicate (finf , ngal, nplam+nslam);
879886
880887 for (uint_t i : range (ngal)) {
881888 state.flux (i,_-(nplam-1 )) = pflx (i,_);
0 commit comments