bridge/class-master/depend/pari/src/modules/mpqs.c
/* create and read an F2m from a relation file FREL.
 * Also record the position of each relation in the file for later use
 * rows = size_of_FB+1, cols = rel */
create and read an F2m from a relation file FREL.
Also record the position of each relation in the file for later use
rows = size_of_FB+1, cols = rel
create and read an F2m from a relation file FREL . Also record the position of each relation in the file for later use rows = size_of_FB + 1 cols = rel
static GEN
stream_read_F2m(pariFILE *pFREL, long rows, long cols, long *fpos)
{
  FILE *FREL = pFREL->file;
  long i, e, p;
  char buf[MPQS_STRING_LENGTH], *s;
  GEN m;
  long space = 2*((nbits2nlong(rows)+3)*cols+1);
  if ((long)((GEN)avma - (GEN)pari_mainstack->bot) < space)
  {
    pari_sp av = avma;
    m = gclone(zero_F2m(rows, cols));
    if (DEBUGLEVEL>=4)
      err_printf("MPQS: allocating %ld words for Gauss\n",space);
    avma = av;
  }
  else
    m = zero_F2m_copy(rows, cols);
  for (i = 0;; i++)
  {
    char *tok=NULL;
    if (i < cols && (fpos[i] = ftell(FREL)) < 0)
      pari_err_FILE("full relations file [ftell]", pFREL->name);
    if (!fgets(buf, MPQS_STRING_LENGTH, FREL)) break;
    s = strchr(buf, ':');
    if (!s) pari_err_FILE("full relations file [strchr]", pFREL->name);
    s = paristrtok_r(s+2, " \n", &tok);
    while (s != NULL)
    {
      e = atol(s); if (!e) break;
      s = paristrtok_r(NULL, " \n", &tok);
      p = atol(s);
      if (e & 1) F2m_set(m, p, i+1);
      s = paristrtok_r(NULL, " \n", &tok);
    }
  }
  if (i != cols)
  {
    err_printf("MPQS: full relations file %s than expected",
               i > cols ? "longer" : "shorter");
    pari_err(e_BUG, "MPQS [panicking]");
  }
  return m;
}
static GEN stream_read_F2m ( pariFILE * pFREL , long rows , long cols , long * fpos ) { FILE * FREL = pFREL -> file ; long i , e , p ; char buf [ MPQS_STRING_LENGTH ] , * s ; GEN m ; long space = 2 * ( ( nbits2nlong ( rows ) + 3 ) * cols + 1 ) ; if ( ( long ) ( ( GEN ) avma - ( GEN ) pari_mainstack -> bot ) < space ) { pari_sp av = avma ; m = gclone ( zero_F2m ( rows , cols ) ) ; if ( DEBUGLEVEL >= 4 ) err_printf ( " \n " , space ) ; avma = av ; } else m = zero_F2m_copy ( rows , cols ) ; for ( i = 0 ; ; i ++ ) { char * tok = NULL ; if ( i < cols && ( fpos [ i ] = ftell ( FREL ) ) < 0 ) pari_err_FILE ( " " , pFREL -> name ) ; if ( ! fgets ( buf , MPQS_STRING_LENGTH , FREL ) ) break ; s = strchr ( buf , ' ' ) ; if ( ! s ) pari_err_FILE ( " " , pFREL -> name ) ; s = paristrtok_r ( s + 2 , " \n " , & tok ) ; while ( s != NULL ) { e = atol ( s ) ; if ( ! e ) break ; s = paristrtok_r ( NULL , " \n " , & tok ) ; p = atol ( s ) ; if ( e & 1 ) F2m_set ( m , p , i + 1 ) ; s = paristrtok_r ( NULL , " \n " , & tok ) ; } } if ( i != cols ) { err_printf ( " " , i > cols ? " " : " " ) ; pari_err ( e_BUG , " " ) ; } return m ; }
create and read an F2m from a relation file FREL.
create and read an F2m from a relation file FREL .