/* -------------------------------------------------------- purpose -- to read a BPG object from a formatted file return value -- 1 if success, 0 if failure created -- 95oct06, cca -------------------------------------------------------- */ int BPG_readFromFormattedFile ( BPG *bpg, FILE *fp ) { Graph *graph ; int nX, nY, rc ; int itemp[2] ; /* --------------- check the input --------------- */ if ( bpg == NULL || fp == NULL ) { fprintf(stderr, "\n error in BPG_readFromFormattedFile(%p,%p)" "\n bad input\n", bpg, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ BPG_clearData(bpg) ; /* ----------------- read in nX and nY ----------------- */ if ( (rc = IVfscanf(fp, 2, itemp)) != 2 ) { fprintf(stderr, "\n error in BPG_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", bpg, fp, rc, 2) ; return(0) ; } nX = itemp[0] ; nY = itemp[1] ; /* -------------------------------------------------- create the Graph IVL object, then read in its data -------------------------------------------------- */ graph = Graph_new() ; Graph_setDefaultFields(graph) ; rc = Graph_readFromFormattedFile(graph, fp) ; if ( rc != 1 ) { fprintf(stderr, "\n error in BPG_readFromFormattedFile(%p,%p)" "\n trying to read in Graph" "\n return code %d from Graph_readFormattedFile(%p,%p)", bpg, fp, rc, graph, fp) ; return(0) ; } /* --------------------- initialize the object --------------------- */ BPG_init(bpg, nX, nY, graph) ; return(1) ; }
/* ----------------------------------------------------- purpose -- to read an IV object from a formatted file return value -- 1 if success, 0 if failure created -- 95oct06, cca ----------------------------------------------------- */ int IV_readFromFormattedFile ( IV *iv, FILE *fp ) { int rc, size ; /* --------------- check the input --------------- */ if ( iv == NULL || fp == NULL ) { fprintf(stderr, "\n error in IV_readFromFormattedFile(%p,%p)" "\n bad input\n", iv, fp) ; return(0) ; } IV_clearData(iv) ; /* ------------------------------ read in the size of the vector ------------------------------ */ if ( (rc = fscanf(fp, "%d", &size)) != 1 ) { fprintf(stderr, "\n error in IV_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", iv, fp, rc, 1) ; return(0) ; } /* --------------------- initialize the object --------------------- */ IV_init(iv, size, NULL) ; iv->size = size ; /* ------------------------ read in the vec[] vector ------------------------ */ if ( (rc = IVfscanf(fp, size, iv->vec)) != size ) { fprintf(stderr, "\n error in IV_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", iv, fp, rc, size) ; return(0) ; } return(1) ; }
/* -------------------------------------------------------- purpose -- to read a Graph object from a formatted file return value -- 1 if success, 0 if failure created -- 95sep29, cca -------------------------------------------------------- */ int Graph_readFromFormattedFile ( Graph *graph, FILE *fp ) { int nedges, nvbnd, nvtx, rc, totewght, totvwght, type ; int itemp[6] ; int *vwghts ; IVL *adjIVL, *ewghtIVL ; /* --------------- check the input --------------- */ if ( graph == NULL || fp == NULL ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n bad input\n", graph, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ Graph_clearData(graph) ; /* --------------------------------------------- read in the six scalar parameters type, nvtx, nvbnd, nedges, totvwght, totewght --------------------------------------------- */ if ( (rc = IVfscanf(fp, 6, itemp)) != 6 ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", graph, fp, rc, 6) ; return(0) ; } type = itemp[0] ; nvtx = itemp[1] ; nvbnd = itemp[2] ; nedges = itemp[3] ; totvwght = itemp[4] ; totewght = itemp[5] ; /* -------------------------------------------------- create the adjIVL IVL object, set its type to IVL_CHUNKED, then read in its data -------------------------------------------------- */ adjIVL = IVL_new() ; IVL_setDefaultFields(adjIVL) ; adjIVL->type = IVL_CHUNKED ; rc = IVL_readFromFormattedFile(adjIVL, fp) ; if ( rc != 1 ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n trying to read in adjIVL" "\n return code %d from IVL_readFormattedFile(%p,%p)", graph, fp, rc, adjIVL, fp) ; return(0) ; } if ( type % 2 == 1 ) { int nvtot, wght ; /* -------------------------- vertex weights are present -------------------------- */ nvtot = nvtx + nvbnd ; vwghts = IVinit2(nvtot) ; if ( (rc = IVfscanf(fp, nvtot, vwghts)) != nvtot ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", graph, fp, rc, nvtot) ; return(0) ; } wght = IVsum(nvtot, vwghts) ; if ( wght != totvwght ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n totvwght = %d, IVsum(vwghts) = %d\n", graph, fp, totvwght, wght) ; return(0) ; } } else { vwghts = NULL ; } if ( type >= 2 ) { int wght ; /* ----------------------------------------------------- edge weights are present, create the ewghtIVL object, set its type to IVL_CHUNKED, then read in its data ----------------------------------------------------- */ ewghtIVL = IVL_new() ; IVL_setDefaultFields(ewghtIVL) ; ewghtIVL->type = IVL_CHUNKED ; rc = IVL_readFromFormattedFile(ewghtIVL, fp) ; if ( rc != 1 ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n trying to read in ewghtIVL" "\n return code %d from IVL_readFormattedFile(%p,%p)", graph, fp, rc, ewghtIVL, fp) ; return(0) ; } wght = IVL_sum(ewghtIVL) ; if ( wght != totewght ) { fprintf(stderr, "\n error in Graph_readFromFormattedFile(%p,%p)" "\n totewght = %d, IVL_sum(ewghtIVL) = %d\n", graph, fp, totewght, wght) ; return(0) ; } } else { ewghtIVL = NULL ; } /* --------------------- initialize the object --------------------- */ Graph_init2(graph, type, nvtx, nvbnd, nedges, totvwght, totewght, adjIVL, vwghts, ewghtIVL) ; return(1) ; }
/* ------------------------------------------------------ purpose -- to read an IVL object from a formatted file return value -- 1 if success, 0 if failure created -- 95sep29, cca ------------------------------------------------------ */ int IVL_readFromFormattedFile ( IVL *ivl, FILE *fp ) { int nlist, rc, type ; int itemp[3] ; int *sizes ; /* --------------- check the input --------------- */ if ( ivl == NULL || fp == NULL ) { fprintf(stderr, "\n error in IVL_readFromFormattedFile(%p,%p)" "\n bad input\n", ivl, fp) ; return(0) ; } switch ( ivl->type ) { case IVL_CHUNKED : case IVL_SOLO : break ; default : fprintf(stderr, "\n error in IVL_readFormattedFile(%p,%p)" "\n bad type = %d", ivl, fp, ivl->type) ; return(0) ; } /* ------------------------------------------- save the ivl type and clear the data fields ------------------------------------------- */ type = ivl->type ; IVL_clearData(ivl) ; /* ----------------------------------- read in the three scalar parameters type, # of lists, # of indices ----------------------------------- */ if ( (rc = IVfscanf(fp, 3, itemp)) != 3 ) { fprintf(stderr, "\n error in IVL_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", ivl, fp, rc, 3) ; return(0) ; } nlist = itemp[1] ; /* fprintf(stdout, "\n itemp = { %d %d %d } ", itemp[0], itemp[1], itemp[2]) ; */ /* -------------------------- read in the sizes[] vector -------------------------- */ sizes = IVinit(nlist, 0) ; if ( (rc = IVfscanf(fp, nlist, sizes)) != nlist ) { fprintf(stderr, "\n error in IVL_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", ivl, fp, rc, nlist) ; return(0) ; } /* --------------------- initialize the object --------------------- */ IVL_init3(ivl, type, nlist, sizes) ; IVfree(sizes) ; /* ----------------------- now read in the indices ----------------------- */ switch ( type ) { case IVL_SOLO : { int ilist, size ; int *ind ; for ( ilist = 0 ; ilist < nlist ; ilist++ ) { IVL_listAndSize(ivl, ilist, &size, &ind) ; if ( size > 0 ) { if ( (rc = IVfscanf(fp, size, ind)) != size ) { fprintf(stderr, "\n error in IVL_readFromFormattedFile(%p,%p)" "\n list %d, %d items of %d read\n", ivl, fp, ilist, rc, size) ; return(0) ; } } } } break ; case IVL_CHUNKED : { /* -------------------------------------------------------- read in the indices into the contiguous block of storage -------------------------------------------------------- */ if ( (rc = IVfscanf(fp, ivl->tsize, ivl->chunk->base)) != ivl->tsize ) { fprintf(stderr, "\n error in IVL_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", ivl, fp, rc, ivl->tsize) ; return(0) ; } } break ; } return(1) ; }
/* ------------------------------------------------------ purpose -- to read an Perm object from a formatted file return value -- 1 if success, 0 if failure created -- 96jan05, cca ------------------------------------------------------ */ int Perm_readFromFormattedFile ( Perm *perm, FILE *fp ) { int i, isPresent, j, rc, size ; int itemp[2] ; /* --------------- check the input --------------- */ if ( perm == NULL || fp == NULL ) { fprintf(stderr, "\n error in Perm_readFromFormattedFile(%p,%p)" "\n bad input\n", perm, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ Perm_clearData(perm) ; /* ----------------------------------------------------- read in the two scalar parameters: isPresent and size ----------------------------------------------------- */ if ( (rc = IVfscanf(fp, 2, itemp)) != 2 ) { fprintf(stderr, "\n error in Perm_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", perm, fp, rc, 2) ; return(0) ; } isPresent = itemp[0] ; size = itemp[1] ; if ( isPresent < 1 || isPresent > 3 || size <= 0 ) { fprintf(stderr, "\n error in Perm_readFromFormattedFile(%p,%p)" "\n isPresent = %d, size = %d", perm, fp, isPresent, size) ; return(0) ; } /* --------------------- initialize the object --------------------- */ Perm_initWithTypeAndSize(perm, isPresent, size) ; if ( isPresent == 2 || isPresent == 3 ) { /* ----------------------------------------- read in the old-to-new permutation vector ----------------------------------------- */ int *oldToNew = perm->oldToNew ; if ( (rc = IVfscanf(fp, size, oldToNew)) != size ) { fprintf(stderr, "\n error in Perm_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", perm, fp, rc, size) ; exit(-1) ; } for ( i = 0 ; i < size ; i++ ) { if ( oldToNew[i] == size ) { for ( j = 0 ; j < size ; j++ ) { oldToNew[j]-- ; } break ; } } } if ( isPresent == 1 || isPresent == 3 ) { /* ----------------------------------------- read in the new-to-old permutation vector ----------------------------------------- */ int *newToOld = perm->newToOld ; if ( (rc = IVfscanf(fp, size, newToOld)) != size ) { fprintf(stderr, "\n error in Perm_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", perm, fp, rc, size) ; exit(-1) ; } for ( i = 0 ; i < size ; i++ ) { if ( newToOld[i] == size ) { for ( j = 0 ; j < size ; j++ ) { newToOld[j]-- ; } break ; } } } /* ---------------------------- check the permutation object ---------------------------- */ if ( Perm_checkPerm(perm) != 1 ) { fprintf(stderr, "\n fatal error in Perm_readFromFormattedFile(%p,%p)" "\n permutation is not valid\n", perm, fp) ; exit(-1) ; } return(1) ; }
/* -------------------------------------------------------- purpose -- to read an ETree object from a formatted file return value -- 1 if success, 0 if failure created -- 95nov15, cca -------------------------------------------------------- */ int ETree_readFromFormattedFile ( ETree *etree, FILE *fp ) { int rc ; int itemp[2] ; /* --------------- check the input --------------- */ if ( etree == NULL || fp == NULL ) { fprintf(stderr, "\n error in ETree_readFromFormattedFile(%p,%p)" "\n bad input\n", etree, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ ETree_clearData(etree) ; /* --------------------------- initialize the ETree object --------------------------- */ ETree_init1(etree, 0, 0) ; /* ----------------------------- read in the two scalar fields ----------------------------- */ if ( (rc = IVfscanf(fp, 2, itemp)) != 2 ) { fprintf(stderr, "\n error in ETree_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", etree, fp, rc, 2) ; return(0) ; } etree->nfront = itemp[0] ; etree->nvtx = itemp[1] ; /* ----------------------- read in the Tree object ----------------------- */ Tree_readFromFormattedFile(etree->tree, fp) ; /* ------------------------------ read in the nodwghts IV object ------------------------------ */ IV_readFromFormattedFile(etree->nodwghtsIV, fp) ; /* ------------------------------ read in the bndwghts IV object ------------------------------ */ IV_readFromFormattedFile(etree->bndwghtsIV, fp) ; /* -------------------------------- read in the vtxToFront IV object -------------------------------- */ IV_readFromFormattedFile(etree->vtxToFrontIV, fp) ; return(1) ; }
/* ----------------------------------------------------------- purpose -- to read an SolveMap object from a formatted file return value -- 1 if success, 0 if failure created -- 98apr09, cca ----------------------------------------------------------- */ int SolveMap_readFromFormattedFile ( SolveMap *solvemap, FILE *fp ) { int nblockLower, nblockUpper, nfront, nproc, rc, symmetryflag ; int itemp[5] ; /* --------------- check the input --------------- */ if ( solvemap == NULL || fp == NULL ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n bad input\n", solvemap, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ SolveMap_clearData(solvemap) ; /* ----------------------------------------------------- read in the five scalar parameters symmetryflag, nfront, nproc, nblockUpper, nblockLower ----------------------------------------------------- */ if ( (rc = IVfscanf(fp, 5, itemp)) != 5 ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, 5) ; return(0) ; } symmetryflag = itemp[0] ; nfront = itemp[1] ; nproc = itemp[2] ; nblockUpper = itemp[3] ; nblockLower = itemp[4] ; /* --------------------- initialize the object --------------------- */ SolveMap_init(solvemap, symmetryflag, nfront, nproc, nblockUpper, nblockLower) ; /* --------------------------- read in the owners[] vector --------------------------- */ if ( (rc = IVfscanf(fp, nfront, solvemap->owners)) != nfront ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nfront) ; return(0) ; } if ( nblockUpper > 0 ) { /* -------------------------------- read in the rowidsUpper[] vector -------------------------------- */ if ( (rc = IVfscanf(fp, nblockUpper, solvemap->rowidsUpper)) != nblockUpper ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nblockUpper) ; return(0) ; } /* -------------------------------- read in the colidsUpper[] vector -------------------------------- */ if ( (rc = IVfscanf(fp, nblockUpper, solvemap->colidsUpper)) != nblockUpper ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nblockUpper) ; return(0) ; } /* ----------------------------- read in the mapUpper[] vector ----------------------------- */ if ( (rc = IVfscanf(fp, nblockUpper, solvemap->mapUpper)) != nblockUpper ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nblockUpper) ; return(0) ; } } if ( symmetryflag == 2 && nblockLower > 0 ) { /* -------------------------------- read in the rowidsLower[] vector -------------------------------- */ if ( (rc = IVfscanf(fp, nblockLower, solvemap->rowidsLower)) != nblockLower ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nblockLower) ; return(0) ; } /* -------------------------------- read in the colidsLower[] vector -------------------------------- */ if ( (rc = IVfscanf(fp, nblockLower, solvemap->colidsLower)) != nblockLower ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nblockLower) ; return(0) ; } /* ----------------------------- read in the mapLower[] vector ----------------------------- */ if ( (rc = IVfscanf(fp, nblockLower, solvemap->mapLower)) != nblockLower ) { fprintf(stderr, "\n error in SolveMap_readFromFormattedFile(%p,%p)" "\n %d items of %d read\n", solvemap, fp, rc, nblockLower) ; return(0) ; } } return(1) ; }
/* -------------------------------------------------- purpose -- to read an object from a formatted file return value -- 1 if success, 0 if failure created -- 98may01, cca -------------------------------------------------- */ int A2_readFromFormattedFile ( A2 *mtx, FILE *fp ) { int rc, size ; int itemp[5] ; /* --------------- check the input --------------- */ if ( mtx == NULL || fp == NULL ) { fprintf(stderr, "\n error in A2_readFromFormattedFile(%p,%p)" "\n bad input", mtx, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ A2_clearData(mtx) ; /* ----------------------------------------------------------- read in the five scalar parameters: type n1, n2, inc1, inc2 ----------------------------------------------------------- */ if ( (rc = IVfscanf(fp, 5, itemp)) != 5 ) { fprintf(stderr, "\n error in A2_readFromFormattedFile()" "\n %d items of %d read\n", rc, 5) ; return(0) ; } /* --------------------- initialize the object --------------------- */ A2_init(mtx, itemp[0], itemp[1], itemp[2], itemp[3], itemp[4], NULL) ; /* ---------------------------- read in the entries[] vector ---------------------------- */ if ( (size = 1 + (mtx->n1-1)*mtx->inc1 + (mtx->n2-1)*mtx->inc2) > 0 ) { if ( A2_IS_REAL(mtx) ) { if ( (rc = DVfscanf(fp, size, mtx->entries)) != size ) { fprintf(stderr, "\n error in A2_readFromFormattedFile" "\n %d items of %d read\n", rc, size) ; return(0) ; } } else if ( A2_IS_COMPLEX(mtx) ) { if ( (rc = DVfscanf(fp, 2*size, mtx->entries)) != 2*size ) { fprintf(stderr, "\n error in A2_readFromFormattedFile" "\n %d items of %d read\n", rc, 2*size) ; return(0) ; } } } return(1) ; }
/* -------------------------------------------------- purpose -- to read an object from a formatted file return value -- 1 if success, 0 if failure created -- 98aug13 -------------------------------------------------- */ int DenseMtx_readFromFormattedFile ( DenseMtx *mtx, FILE *fp ) { int rc, size ; int itemp[7] ; /* --------------- check the input --------------- */ if ( mtx == NULL || fp == NULL ) { fprintf(stderr, "\n error in DenseMtx_readFromFormattedFile(%p,%p)" "\n bad input", mtx, fp) ; return(0) ; } /* --------------------- clear the data fields --------------------- */ DenseMtx_clearData(mtx) ; /* -------------------------------------------- read in the seven scalar parameters: type, rowid, colid, nrow, ncol, inc1, inc2 -------------------------------------------- */ if ( (rc = IVfscanf(fp, 7, itemp)) != 7 ) { fprintf(stderr, "\n error in DenseMtx_readFromFormattedFile()" "\n %d items of %d read\n", rc, 7) ; return(0) ; } /* --------------------- initialize the object --------------------- */ DenseMtx_init(mtx, itemp[0], itemp[1], itemp[2], itemp[3], itemp[4], itemp[5], itemp[6]) ; /* --------------------------- read in the rowind[] vector --------------------------- */ if ( (size = mtx->nrow) > 0 ) { if ( (rc = IVfscanf(fp, size, mtx->rowind)) != size ) { fprintf(stderr, "\n error in DenseMtx_readFromFormattedFile()" "\n %d items of %d read for rowind\n", rc, size) ; return(0) ; } } /* --------------------------- read in the colind[] vector --------------------------- */ if ( (size = mtx->ncol) > 0 ) { if ( (rc = IVfscanf(fp, size, mtx->colind)) != size ) { fprintf(stderr, "\n error in DenseMtx_readFromFormattedFile()" "\n %d items of %d read for colind\n", rc, size) ; return(0) ; } } /* ---------------------------- read in the entries[] vector ---------------------------- */ if ( (size = mtx->nrow*mtx->ncol) > 0 ) { if ( DENSEMTX_IS_REAL(mtx) ) { if ( (rc = DVfscanf(fp, size, mtx->entries)) != size ) { fprintf(stderr, "\n error in DenseMtx_readFromFormattedFile()" "\n %d items of %d read for entries\n", rc, size) ; return(0) ; } } else if ( DENSEMTX_IS_COMPLEX(mtx) ) { if ( (rc = DVfscanf(fp, 2*size, mtx->entries)) != 2*size ) { fprintf(stderr, "\n error in DenseMtx_readFromFormattedFile()" "\n %d items of %d read for entries\n", rc, 2*size) ; return(0) ; } } } return(1) ; }