for(edge = 0; edge < edgecnt; edge++) {
   const char *field1, *field2;
   double tmp;
   int fieldcnt, i, j, err;
   unsigned long idx, loc;

   if(tdf_getLine(tdf) < 0) {
      ERRLINE(tdf_getCurLine(tdf), "error reading line");
      freeTabDelimFile(tdf);
      freeLabelList(tlabels);
      free(tmat);
      return -4;
   }
   fieldcnt = tdf_getNumFields(tdf);
   if(fieldcnt != fcnt) {
      if(fcnt == 0) {
         if(fieldcnt != 2 && fieldcnt != 3) {
            ERRLINE(tdf_getCurLine(tdf), "improper edge line");
            freeTabDelimFile(tdf);
            freeLabelList(tlabels);
            free(tmat);
            return -4;
         }
         fcnt = fieldcnt;
      } else {
         ERRLINE(tdf_getCurLine(tdf), "(un)weightedness is inconsistent");
         freeTabDelimFile(tdf);
         freeLabelList(tlabels);
         free(tmat);
         return -4;
      }
   }

   field1 = tdf_getField(tdf, 0);
   field2 = tdf_getField(tdf, 1);
 
   if((j = ll_getIndex(tlabels, field2, &err)) == 0 && err != 0) {
      j = ll_getLength(tlabels);
      if(ll_appendLabel(tlabels, field2) < 0) {
         ERRLINE(-1, "");
         freeTabDelimFile(tdf);
         freeLabelList(tlabels);
         free(tmat);
         return -3;
      }
   }
   if((i = ll_getIndex(tlabels, field1, &err)) == 0 && err != 0) {
      i = ll_getLength(tlabels);
      if(ll_appendLabel(tlabels, field1) < 0) {
         ERRLINE(-1, "");
         freeTabDelimFile(tdf);
         freeLabelList(tlabels);
         free(tmat);
         return -3;
      }
   }
   if(i < j) {
      int tmp = i;
      i = j;
      j = tmp;
   } else if(i == j) {
      ERRLINE(tdf_getCurLine(tdf), "edge from a vertex to itself not allowed");
      freeTabDelimFile(tdf);
      freeLabelList(tlabels);
      free(tmat);
      return -4;
   }

   if(fieldcnt == 3) {
      tmp = tdf_getFieldAsFloat(tdf, 2, &err);

      if(tmp == 0 && err != 0) {
         ERRLINE(tdf_getCurLine(tdf), "invalid weight");
         freeTabDelimFile(tdf);
         freeLabelList(tlabels);
         free(tmat);
         return -4;
      }
      if(DOABS(tmp) >= (threshold-(1e-6))) {
         val = (MYTYPE)(((MYTYPE)(tmp*denom + ((tmp >= 0)?(.5):(-.5))))&mask);
         idx = ((i*(i-1))>>1) + j;
         loc = (numvals - (idx%numvals) - 1)*valbits;
         pos = &tmat[idx/numvals];
         *pos = (MYTYPE)(((*pos)^(flag<<loc))|(val<<loc));
      }
   } else {
      idx = ((i*(i-1))>>1) + j;
      loc = (numvals - (idx%numvals) - 1)*valbits;
      pos = &tmat[idx/numvals];
      *pos = (MYTYPE)(((*pos)^(flag<<loc))|(nflag<<loc));
   }
}
