static void get_reference (void)
{
    int n, narrays, na, dim;
    cgsize_t vec[12];
    CGNS_ENUMT(DataType_t) datatype;
    CGNS_ENUMT(AngleUnits_t) angle;
    int aloc = 0, units[5];
    char name[33];
    static char *refnames[4] = {
        "Mach",
        "AngleofAttack",
        "Reynolds",
        "TimeLatest"
    };

    reference[0] = 0.5;   /* Mach Number */
    reference[1] = 0.0;   /* angle of attack */
    reference[2] = 1.0e6; /* Reynolds Number */
    reference[3] = 0.0;   /* time */

    if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "end") ||
        cg_narrays (&narrays) || narrays < 1)
        return;
    for (na = 1; na <= narrays; na++) {
        if (cg_array_info (na, name, &datatype, &dim, vec))
            FATAL ("get_reference", NULL);
        if (dim != 1 || vec[0] != 1) continue;
        for (n = 0; n < 4; n++) {
            if (!strcmp (refnames[n], name)) {
                if (cg_array_read_as (na, CGNS_ENUMV(RealDouble), &reference[n]))
                    FATAL ("get_reference", NULL);
                if (n == 1) aloc = na;
                break;
            }
        }
    }

    /* angle of attack units */

    if (aloc) {
        if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1,
            "DataArray_t", aloc, "end"))
            FATAL ("get_reference", NULL);
        if (read_units (units))
            angle = (CGNS_ENUMT(AngleUnits_t))units[4];
        else
            angle = (CGNS_ENUMT(AngleUnits_t))baseunits[4];
        if (angle == CGNS_ENUMV(Radian))
            reference[1] *= 57.29578;
    }
}
static void write_q_formatted (char *qfile)
{
    int nz, i, j, n, k, nk, np;
    FILE *fp;

    printf ("\nwriting formatted Q file to %s\n", qfile);

    if (NULL == (fp = fopen (qfile, "w+"))) {
        fprintf (stderr, "couldn't open <%s> for writing\n", qfile);
        exit (1);
    }
    if (mblock || nblocks > 1)
        fprintf (fp, "%d\n", nblocks);
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured))
            fprintf (fp, "%d %d %d\n", (int)Zones[nz].dim[0],
                (int)Zones[nz].dim[1], (int)Zones[nz].dim[2]);
    }
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d ... ", nz+1);
            fflush (stdout);
            fprintf (fp, "%#g %#g %#g %#g\n", reference[0], reference[1],
                reference[2], reference[3]);
            compute_solution (nz);
            if (whole) {
                np = (int)Zones[nz].nverts;
                nk = 1;
            }
            else {
                np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
                nk = (int)Zones[nz].dim[2];
            }
            for (k = 0; k < nk; k++) {
                i = k * np;
                for (j = 0; j < 5; j++) {
                    for (n = 0; n < np; n++) {
                        if (n) putc ((n % 5) == 0 ? '\n' : ' ', fp);
                        fprintf (fp, "%#g", q[j][i+n]);
                    }
                    putc ('\n', fp);
                }
            }
            puts ("done");
        }
    }
    fclose (fp);
}
static int check_solution (int nz)
{
    int nf, flags = 0;
    SOLUTION *sol;

    if (!read_zone_solution (nz+1) ||
        usesol > Zones[nz].nsols) return 0;
    sol = &Zones[nz].sols[usesol-1];
    if (sol->nflds < 5 || (sol->location != CGNS_ENUMV(Vertex) &&
        sol->location != CGNS_ENUMV(CellCenter))) return 0;
    for (nf = 0; nf < sol->nflds; nf++) {
        if (!strcmp (sol->flds[nf].name, "Density")) {
            flags |= 0x01;
            continue;
        }
        if (!strcmp (sol->flds[nf].name, "VelocityX") ||
            !strcmp (sol->flds[nf].name, "MomentumX")) {
            flags |= 0x02;
            continue;
        }
        if (!strcmp (sol->flds[nf].name, "VelocityY") ||
            !strcmp (sol->flds[nf].name, "MomentumY")) {
            flags |= 0x04;
            continue;
        }
        if (!strcmp (sol->flds[nf].name, "VelocityZ") ||
            !strcmp (sol->flds[nf].name, "MomentumZ")) {
            flags |= 0x08;
            continue;
        }
        if (!strcmp (sol->flds[nf].name, "Pressure") ||
            !strcmp (sol->flds[nf].name, "EnergyStagnationDensity")) {
            flags |= 0x10;
            continue;
        }
    }
    return (flags & 0x1f) == 0x1f ? 1 : 0;
}
static void count_elements (int nz, cgsize_t *nelems, int *elemtype)
{
    int ns, et;
    cgsize_t n, nn, ne, nb = 0, nt = 0;
    ZONE *z = &Zones[nz];

    if (z->esets == NULL)
        read_zone_element (nz+1);
    for (ns = 0; ns < z->nesets; ns++) {
        ne = z->esets[ns].end - z->esets[ns].start + 1;
        et = z->esets[ns].type;
        if (et == CGNS_ENUMV(MIXED)) {
            for (n = 0, nn = 0; nn < ne; nn++) {
                et = (int)z->esets[ns].conn[n++];
                if (et < CGNS_ENUMV(NODE) || et > CGNS_ENUMV(HEXA_27))
                    FATAL (NULL, "unrecognized element type");
                if (et >= CGNS_ENUMV(TETRA_4)) {
                    if (et > CGNS_ENUMV(TETRA_10))
                        nb++;
                    else
                        nt++;
                }
                n += element_node_counts[et];
            }
            continue;
        }
        if (et >= CGNS_ENUMV(TETRA_4) && et <= CGNS_ENUMV(HEXA_27)) {
            if (et > CGNS_ENUMV(TETRA_10))
                nb += ne;
            else
                nt += ne;
        }
    }

    if (nt + nb == 0)
        FATAL (NULL, "no volume elements in the zone");
    *nelems = nt + nb;
    *elemtype = nb ? 3 : 2;
}
Beispiel #5
0
int main(int argc, char* argv[]) {
	/* Initialize varaibles */
	initialize(&argc,&argv);

	/* Time the creation of a file */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_open\n",comm_rank))
	if (cgp_open("benchmark.cgns", CG_MODE_WRITE, &fn))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("File Open", t1-t0);

	/* Time the creation of a base */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cg_base_write\n",comm_rank))
	if (cg_base_write(fn, "Base 1", 3, 3, &B))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("Base Write", t1-t0);

	/* Time the creation of a zone */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cg_zone_write\n",comm_rank))
	if (cg_zone_write(fn, B, "Zone 1", nijk, CGNS_ENUMV(Structured), &Z))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("Zone Write", t1-t0);

	/* Time the creation of coordinates X */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_coord_write X\n",comm_rank))
	if (cgp_coord_write(fn,B,Z,CGNS_ENUMV(RealDouble),"CoordinateX",&C))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("Coord X Write", t1-t0);

	/* Time the write speed of coordinates X */
	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_coord_write_data X\n",comm_rank))
	if (cgp_coord_write_data(fn,B,Z,C,min,max,x))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	MPI_Barrier(MPI_COMM_WORLD);
	ta = MPI_Wtime();

	doTimer("Coord X Write Data", t1-t0);
	doBandwidth("Coord X Write Data", t1-t0);
	doBandwidthAgg("Coord X Write Data", ta-t0);

	/* Time the creation of coordinates Y */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_coord_write Y\n",comm_rank))
	if (cgp_coord_write(fn,B,Z,CGNS_ENUMV(RealDouble),"CoordinateY",&C))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("Coord Y Write", t1-t0);

	/* Time the write speed of coordinates Y */
	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_coord_write_data Y\n",comm_rank))
	if (cgp_coord_write_data(fn,B,Z,C,min,max,y))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	MPI_Barrier(MPI_COMM_WORLD);
	ta = MPI_Wtime();

	doTimer("Coord Y Write Data", t1-t0);
	doBandwidth("Coord Y Write Data", t1-t0);
	doBandwidthAgg("Coord Y Write Data", ta-t0);

	/* Time the creation of coordinates Z */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_coord_write Z\n",comm_rank))
	if (cgp_coord_write(fn,B,Z,CGNS_ENUMV(RealDouble),"CoordinateZ",&C))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("Coord Z Write", t1-t0);

	/* Time the write speed of coordinates Z */
	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_coord_write_data Z\n",comm_rank))
	if (cgp_coord_write_data(fn,B,Z,C,min,max,z))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	MPI_Barrier(MPI_COMM_WORLD);
	ta = MPI_Wtime();

	doTimer("Coord Z Write Data", t1-t0);
	doBandwidth("Coord Z Write Data", t1-t0);
	doBandwidthAgg("Coord Z Write Data", ta-t0);

	/* Time closing of the file */
	t0 = MPI_Wtime();
	DEBUG_PRINT(("[%d]cgp_close\n",comm_rank))
	if (cgp_close(fn))
	    cgp_error_exit();
	t1 = MPI_Wtime();
	doTimer("File Close", t1-t0);

	finalize();

	return 0;
	}
Beispiel #6
0
/* override compute function */
int writeToCgns::compute(const char *) {
  //declarations
  //----------------------------------------------------------------------------
  char port[256];
  int nElem;
  int nConn;
  int nCoords;
  int index_file;
  int ier;
  //input ports and casts
  const coDistributedObject* obj;
  const coDoUnstructuredGrid* inGrid;
  const coDoIntArr* inInletElementNodes;
  const coDoIntArr* inOutletElementNodes;
  const coDoIntArr* inShroudElementNodes;
  const coDoIntArr* inShroudExtElementNodes;
  const coDoIntArr* inFrictlessElementNodes;
  const coDoIntArr* inPsbladeElementNodes;
  const coDoIntArr* inSsbladeElementNodes;
  const coDoIntArr* inWallElementNodes;
  const coDoIntArr* inSsleperiodicElementNodes;
  const coDoIntArr* inPsleperiodicElementNodes;
  const coDoIntArr* inSsteperiodicElementNodes;
  const coDoIntArr* inPsteperiodicElementNodes;
  const coDoIntArr* inRrinletElementNodes;
  const coDoIntArr* inRroutletElementNodes;
  const coDoIntArr* inHubAllElementNodes;
  const coDoIntArr* inShroudAllElementNodes;
  const coDoSet* inBoundaryElementFaces;
  //grid attributes
  int* tList;
  int* elem;
  int* conn;
  cgsize_t* intHelper;
  float* xCoord;
  float* yCoord;
  float* zCoord;
  int nPoly;
  int nCorn;
  int* corn;
  int* poly;
  int ii;
  int base_i;
  int baseCFX_i;
  int zone_i;
  int zoneCFX_i;
  int coord_i;
  int section_i;
  int tmpCounter;
  int gElemCounter;
  int boco_i;
  cgsize_t* ptrToCgsize;
  cgsize_t cgsize[3][3];
  int nNodesFace;
  int nElemInlet;
  int nElemOutlet;
  int nElemWall;
  int nElemFrictless;
  int nElemShroud;
  int nElemShroudExt;
  int nElemPsblade;
  int nElemSsblade;
  int nElemSsleperiodic;
  int nElemPsleperiodic;
  int nElemSsteperiodic;
  int nElemPsteperiodic;
  int nElemRrinlet;
  int nElemRroutlet;
  int nElemHubAll;
  int nElemShroudAll;
  int nNodesInlet;
  int nNodesOutlet;
  int nNodesWall;
  int nNodesFrictless;
  int nNodesShroud;
  int nNodesShroudExt;
  int nNodesPsblade;
  int nNodesSsblade;
  int nNodesSsleperiodic;
  int nNodesPsleperiodic;
  int nNodesSsteperiodic;
  int nNodesPsteperiodic;
  int nNodesRrinlet;
  int nNodesRroutlet;
  int nNodesHubAll;
  int nNodesShroudAll;
  int nNodesFaceInlet;
  int nNodesFaceOutlet;
  int nNodesFaceWall;
  int nNodesFaceFrictless;
  int nNodesFaceShroud;
  int nNodesFaceShroudExt;
  int nNodesFacePsblade;
  int nNodesFaceSsblade;
  int nNodesFaceSsleperiodic;
  int nNodesFacePsleperiodic;
  int nNodesFaceSsteperiodic;
  int nNodesFacePsteperiodic;
  int nNodesFaceRrinlet;
  int nNodesFaceRroutlet;
  int nNodesFaceHubAll;
  int nNodesFaceShroudAll;
  int nObjects;
  const coDistributedObject *const *objSet;
  //----------------------------------------------------------------------------
  
  // initialize
  //----------------------------------------------------------------------------
  gElemCounter = 0;
  //----------------------------------------------------------------------------
  
  //get input port and do some type checks
  //----------------------------------------------------------------------------
  //check ports and cast to expected types
  //grid
  obj = p_inputPort_grid->getCurrentObject();
  if (!obj) {
    sendError("did not receive object at port %s", p_inputPort_grid->getName());
    return FAILURE;
  }
  else {
    inGrid = dynamic_cast<const coDoUnstructuredGrid *>(obj);
    //check that cast was successful
    if (!inGrid){
      sendError("received wrong object type at port %s", p_inputPort_grid->getName());
      return FAILURE;
    }
  }
  
  //boundary element faces
  obj = p_inputPort_boundaryElementFaces->getCurrentObject();
  if (!obj) {
    sendInfo("did not receive object at port %s", p_inputPort_boundaryElementFaces->getName());
  }
  else {
    inBoundaryElementFaces = dynamic_cast<const coDoSet *>(obj);
    objSet = inBoundaryElementFaces->getAllElements(&nObjects);
    
    inInletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[0]);
    inOutletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[1]);
    inShroudElementNodes = dynamic_cast<const coDoIntArr *>(objSet[2]);
    inShroudExtElementNodes = dynamic_cast<const coDoIntArr *>(objSet[3]);
    inFrictlessElementNodes = dynamic_cast<const coDoIntArr *>(objSet[4]);
    inPsbladeElementNodes = dynamic_cast<const coDoIntArr *>(objSet[5]);
    inSsbladeElementNodes = dynamic_cast<const coDoIntArr *>(objSet[6]);
    inWallElementNodes = dynamic_cast<const coDoIntArr *>(objSet[7]);
    inSsleperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[8]);
    inPsleperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[9]);
    inSsteperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[10]);
    inPsteperiodicElementNodes = dynamic_cast<const coDoIntArr *>(objSet[11]);
    inRrinletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[12]);
    inRroutletElementNodes = dynamic_cast<const coDoIntArr *>(objSet[13]);
    inHubAllElementNodes = dynamic_cast<const coDoIntArr *>(objSet[14]);
    inShroudAllElementNodes = dynamic_cast<const coDoIntArr *>(objSet[15]);
    
    nNodesInlet = inInletElementNodes->getDimension(1);
    nNodesOutlet = inOutletElementNodes->getDimension(1);
    nNodesWall = inWallElementNodes->getDimension(1);
    nNodesFrictless = inFrictlessElementNodes->getDimension(1);
    nNodesShroud = inShroudElementNodes->getDimension(1);
    nNodesShroudExt = inShroudExtElementNodes->getDimension(1);
    nNodesPsblade = inPsbladeElementNodes->getDimension(1);
    nNodesSsblade = inSsbladeElementNodes->getDimension(1);
    nNodesSsleperiodic = inSsleperiodicElementNodes->getDimension(1);
    nNodesPsleperiodic = inPsleperiodicElementNodes->getDimension(1);
    nNodesSsteperiodic = inSsteperiodicElementNodes->getDimension(1);
    nNodesPsteperiodic = inPsteperiodicElementNodes->getDimension(1);
    nNodesRrinlet = inRrinletElementNodes->getDimension(1);
    nNodesRroutlet = inRroutletElementNodes->getDimension(1);
    nNodesHubAll = inHubAllElementNodes->getDimension(1);
    nNodesShroudAll = inShroudAllElementNodes->getDimension(1);
    
    elem = inInletElementNodes->getAddress();
    nNodesFaceInlet = *elem;
    elem = inOutletElementNodes->getAddress();
    nNodesFaceOutlet = *elem;
    elem = inWallElementNodes->getAddress();
    nNodesFaceWall = *elem;
    elem = inFrictlessElementNodes->getAddress();
    nNodesFaceFrictless = *elem;
    elem = inShroudElementNodes->getAddress();
    nNodesFaceShroud = *elem;
    elem = inShroudExtElementNodes->getAddress();
    nNodesFaceShroudExt = *elem;
    elem = inPsbladeElementNodes->getAddress();
    nNodesFacePsblade = *elem;
    elem = inSsbladeElementNodes->getAddress();
    nNodesFaceSsblade = *elem;
    elem = inSsleperiodicElementNodes->getAddress();
    nNodesFaceSsleperiodic = *elem;
    elem = inPsleperiodicElementNodes->getAddress();
    nNodesFacePsleperiodic = *elem;
    elem = inSsteperiodicElementNodes->getAddress();
    nNodesFaceSsteperiodic = *elem;    
    elem = inPsteperiodicElementNodes->getAddress();
    nNodesFacePsteperiodic = *elem;    
    elem = inRrinletElementNodes->getAddress();
    nNodesFaceRrinlet = *elem;    
    elem = inRroutletElementNodes->getAddress();
    nNodesFaceRroutlet = *elem;    
    elem = inHubAllElementNodes->getAddress();
    nNodesFaceHubAll = *elem;  
    elem = inShroudAllElementNodes->getAddress();
    nNodesFaceShroudAll = *elem;  
    
    nElemInlet = nNodesInlet/nNodesFaceInlet;
    nElemOutlet = nNodesOutlet/nNodesFaceOutlet;
    nElemShroud = nNodesShroud/nNodesFaceShroud;
    nElemShroudExt = nNodesShroudExt/nNodesFaceShroudExt;
    nElemFrictless = nNodesFrictless/nNodesFaceFrictless;
    nElemPsblade = nNodesPsblade/nNodesFacePsblade;
    nElemSsblade = nNodesSsblade/nNodesFaceSsblade;
    nElemWall = nNodesWall/nNodesFaceWall;
    nElemSsleperiodic = nNodesSsleperiodic/nNodesFaceSsleperiodic;
    nElemPsleperiodic = nNodesPsleperiodic/nNodesFacePsleperiodic;
    nElemSsteperiodic = nNodesSsteperiodic/nNodesFaceSsteperiodic;
    nElemPsteperiodic = nNodesPsteperiodic/nNodesFacePsteperiodic;
    nElemRrinlet = nNodesRrinlet/nNodesFaceRrinlet;
    nElemRroutlet = nNodesRroutlet/nNodesFaceRroutlet;
    nElemHubAll = nNodesHubAll/nNodesFaceHubAll;
    nElemShroudAll = nNodesShroudAll/nNodesFaceShroudAll;

    //check that cast was successful
    if (!inBoundaryElementFaces){
      sendError("received wrong object type at port %s", p_inputPort_boundaryElementFaces->getName());
      return FAILURE;
    }
  }
  
  /* -------------------------------------------------------------------------*/
  /* inGrid --> unstructured grid                                             */
  /*                                                                          */
  /* start to write inGrid into cgns file                                     */ 
  /* -------------------------------------------------------------------------*/
  
  
  //write out short info about mesh
  inGrid->getGridSize(&nElem, &nConn, &nCoords);
  sendInfo("nElements = %i", nElem);
  sendInfo("nConnectivities = %i", nConn);
  sendInfo("nCoordinates = %i", nCoords);
  
  //get addresses and type list
  inGrid->getAddresses(&elem, &conn, &xCoord, &yCoord, &zCoord);
  if (inGrid->hasTypeList()) {
    inGrid->getTypeList(&tList);
  }

/* debug output ///////////////////////////////////////////////////////////// */  
//  //write out type list
//  if (inGrid->hasTypeList()){
//    inGrid->getTypeList(&tList);
//    for (ii=0;ii<nElem;ii++){
//      cout << "tList[" << ii << "]" << "=(" << *(tList+ii) << endl;
//    }
//  }
//  //write out elements
//  for (ii=0;ii<nElem;ii++){
//    cout << "elem[" << ii << "]" << "=(" << *(elem+ii) << endl;
//  }
  //write out coordinates
//  for (ii=0;ii<nCoords;ii++){
//    cout << "coord[" << ii << "]" << "=(" << *(xCoord+ii) << "," << *(yCoord+ii) << "," << *(zCoord+ii) << ")" << endl;
//  }
//  //write out conectivities
//  for (ii=0;ii<nConn;ii++){
//    cout << "conn[" << ii << "]" << "=(" << *(conn+ii) << endl;
//  }
/* ////////////////////////////////////////////////////////////////////////// */  
  
  //write cgns file
  //----------------------------------------------------------------------------
  //open cgns file**************************************************************
  ier = cg_open(cgns_filebrowser->getValue(), CG_MODE_WRITE, &index_file);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "cgns file opened ..." << endl;
  //
  // base
  //
  //write base******************************************************************
  ier = cg_base_write(index_file, "base", 3, 3, &base_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "base written ..." << endl;
  // write zones****************************************************************
  cgsize[0][0] = nCoords;
  cgsize[0][1] = nElem;
  cgsize[0][2] = 0;
  ptrToCgsize = &cgsize[0][0];        
  ier = cg_zone_write(index_file, base_i, "runner", ptrToCgsize, CGNS_ENUMV(Unstructured), &zone_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "runner written ..." << endl;
  
  // write grid coordinates*****************************************************
  ier = cg_coord_write(index_file, base_i, zone_i, CGNS_ENUMV(RealSingle), "CoordinateX", xCoord, &coord_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "coordinate x written ..." << endl;
  ier = cg_coord_write(index_file, base_i, zone_i, CGNS_ENUMV(RealSingle), "CoordinateY", yCoord, &coord_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "coordinate y written ..." << endl;
  ier = cg_coord_write(index_file, base_i, zone_i, CGNS_ENUMV(RealSingle), "CoordinateZ", zCoord, &coord_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "coordinate z written ..." << endl;
  
  //write connectivities for 8-node-hexa grid***********************************
  intHelper = new cgsize_t[nConn];
  for (ii=0;ii<nConn;ii++){
    *(intHelper+ii) = *(conn+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }
  ier = cg_section_write(index_file, base_i, zone_i, "Elem", CGNS_ENUMV(HEXA_8), \
                         gElemCounter+1, nElem, 0, intHelper, &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  gElemCounter = gElemCounter + nElem;
  delete intHelper;
  cout << "Elem written ..." << endl;   
  
  //write inlet*****************************************************************
  elem = inInletElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesInlet];
  for (ii=0;ii<nNodesInlet;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }
  ier = cg_section_write(index_file, base_i, zone_i, "inlet", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemInlet, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemInlet;
  cout << "inlet written ... " << endl;
  
  //write outlet****************************************************************
  elem = inOutletElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesOutlet];
  for (ii=0;ii<nNodesOutlet;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "outlet", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemOutlet, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemOutlet;
  cout << "outlet written ... " << endl;   
  
  //write wall******************************************************************
  elem = inWallElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesWall];
  for (ii=0;ii<nNodesWall;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "wall", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemWall, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemWall;
  cout << "wall written ... " << endl;
  
  //write frictless*************************************************************
  elem = inFrictlessElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesFrictless];
  for (ii=0;ii<nNodesFrictless;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "frictless", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemFrictless, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemFrictless;
  cout << "frictless written ... " << endl;
  
  //write shroud****************************************************************
  elem = inShroudElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesShroud];
  for (ii=0;ii<nNodesShroud;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "shroud", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemShroud, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemShroud;
  cout << "shroud written ... " << endl;
  
  //write shroudExt*************************************************************
  elem = inShroudExtElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesShroudExt];
  for (ii=0;ii<nNodesShroudExt;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "shroudExt", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemShroudExt, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemShroudExt;
  cout << "shroudExt written ... " << endl; 
  
  //write psblade***************************************************************
  elem = inPsbladeElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesPsblade];
  for (ii=0;ii<nNodesPsblade;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "psblade", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemPsblade, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemPsblade;
  cout << "psblade written ... " << endl;   
  
  //write ssblade***************************************************************
  elem = inSsbladeElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesSsblade];
  for (ii=0;ii<nNodesSsblade;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "ssblade", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemSsblade, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemSsblade;
  cout << "ssblade written ... " << endl;  
  
  //write ssleperiodic**********************************************************
  elem = inSsleperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesSsleperiodic];
  for (ii=0;ii<nNodesSsleperiodic;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "ssleperiodic", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemSsleperiodic, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemSsleperiodic;
  cout << "ssleperiodic written ... " << endl; 
  
  //write psleperiodic**********************************************************
  elem = inPsleperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesPsleperiodic];
  for (ii=0;ii<nNodesPsleperiodic;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "psleperiodic", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemPsleperiodic, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemPsleperiodic;
  cout << "psleperiodic written ... " << endl;
  
  //write ssteperiodic**********************************************************
  elem = inSsteperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesSsteperiodic];
  for (ii=0;ii<nNodesSsteperiodic;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "ssteperiodic", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemSsteperiodic, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemSsteperiodic;
  cout << "ssteperiodic written ... " << endl;
  
  //write psteperiodic**********************************************************
  elem = inPsteperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesPsteperiodic];
  for (ii=0;ii<nNodesPsteperiodic;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "psteperiodic", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemPsteperiodic, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemPsteperiodic;
  cout << "psteperiodic written ... " << endl;
  
  //write rrinlet***************************************************************
  elem = inRrinletElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesRrinlet];
  for (ii=0;ii<nNodesRrinlet;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "rrinlet", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemRrinlet, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemRrinlet;
  cout << "rrinlet written ... " << endl;
  
  //write rroutlet**************************************************************
  elem = inRroutletElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesRroutlet];
  for (ii=0;ii<nNodesRroutlet;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "rroutlet", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemRroutlet, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemRroutlet;
  cout << "rroutlet written ... " << endl; 
  
  //write hubAll****************************************************************
  elem = inHubAllElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesHubAll];
  for (ii=0;ii<nNodesHubAll;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "hubAll", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemHubAll, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemHubAll;
  cout << "hubAll written ... " << endl; 
  
  //write shroudAll*************************************************************
  elem = inShroudAllElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesShroudAll];
  for (ii=0;ii<nNodesShroudAll;ii++){
    *(intHelper+ii) = *(elem+ii);
    *(intHelper+ii) = *(intHelper+ii)+1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "shroudAll", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemShroudAll, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemShroudAll;
  cout << "shroudAll written ... " << endl; 
  
  //write periodic suction******************************************************
  elem = inSsleperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesSsleperiodic+nNodesSsteperiodic];
  tmpCounter = 0;
  for (ii=0;ii<nNodesSsleperiodic;ii++){
    *(intHelper+tmpCounter) = *(elem+ii);
    *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1;
    tmpCounter = tmpCounter + 1;
  }    
  elem = inSsteperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  for (ii=0;ii<nNodesSsteperiodic;ii++){
    *(intHelper+tmpCounter) = *(elem+ii);
    *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1;
    tmpCounter = tmpCounter + 1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "periodic_suction", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemSsleperiodic+nElemSsteperiodic, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemSsleperiodic + nElemSsteperiodic;
  cout << "peridic_suction written ... " << endl;
  
  //write periodic pressure*****************************************************
  elem = inPsleperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  intHelper = new cgsize_t[nNodesPsleperiodic+nNodesPsteperiodic];
  tmpCounter = 0;
  for (ii=0;ii<nNodesPsleperiodic;ii++){
    *(intHelper+tmpCounter) = *(elem+ii);
    *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1;
    tmpCounter = tmpCounter + 1;
  }    
  elem = inPsteperiodicElementNodes->getAddress();
  //increment nodes
  elem = elem+1;
  for (ii=0;ii<nNodesPsteperiodic;ii++){
    *(intHelper+tmpCounter) = *(elem+ii);
    *(intHelper+tmpCounter) = *(intHelper+tmpCounter)+1;
    tmpCounter = tmpCounter + 1;
  }    
  ier = cg_section_write(index_file, base_i, zone_i, "periodic_pressure", CGNS_ENUMV(QUAD_4), \
                         gElemCounter+1, gElemCounter+nElemPsleperiodic+nElemPsteperiodic, 0, intHelper, \
                         &section_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  delete intHelper;
  gElemCounter = gElemCounter + nElemPsleperiodic + nElemPsteperiodic;
  cout << "peridic pressure written ... " << endl;
  
  //
  // baseCFX
  //
  //write base******************************************************************
  ier = cg_base_write(index_file, "baseCFX", 3, 3, &baseCFX_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "baseCFX written ..." << endl;
  // write zones****************************************************************
  cgsize[0][0] = nCoords;
  cgsize[0][1] = nElem;
  cgsize[0][2] = 0;
  ptrToCgsize = &cgsize[0][0];        
  ier = cg_zone_write(index_file, baseCFX_i, "runner", ptrToCgsize, CGNS_ENUMV(Unstructured), &zone_i);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "runner written ..." << endl;  
  
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("GridCoordinates", "", "/base/runner/GridCoordinates");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "coordinates linked ..." << endl;
  
  //connectivities
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("Elem", "", "/base/runner/Elem");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "Elem linked ..." << endl;   
  
  //write inlet*****************************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("inlet", "", "/base/runner/inlet");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "inlet linked ..." << endl;   
  
  //write outlet****************************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("outlet", "", "/base/runner/outlet");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "outlet linked ..." << endl;    
  
  //write psblade***************************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("blade_pressure", "", "/base/runner/psblade");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "psblade linked ..." << endl;    
  
  //write ssblade***************************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("blade_suction", "", "/base/runner/ssblade");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "ssblade linked ..." << endl;    
  
  //write hubAll****************************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("hub", "", "/base/runner/hubAll");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "hubAll linked ..." << endl;  
  
  //write shroudAll*************************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("shroud", "", "/base/runner/shroudAll");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "shroudAll linked ..." << endl;  
  
  //write periodic suction******************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("periodic_suction", "", "/base/runner/periodic_suction");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "periodic_suction linked ..." << endl;  
  
  //write periodic pressure*****************************************************
  ier = cg_goto(index_file, baseCFX_i, "runner", 0, "end"); 
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  ier = cg_link_write("periodic_pressure", "", "/base/runner/periodic_pressure");
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  cout << "periodic_pressure linked ..." << endl;
  
  //close cgns file*************************************************************
  ier = cg_close(index_file);
  if(ier) {
    sendError("%s", cg_get_error());
    return FAILURE;
  }
  //----------------------------------------------------------------------------
  
  sendInfo("grid successfully converted to cgns");
  return SUCCESS;
}
int main (int argc, char *argv[])
{
    int n, ib, nb, is, nz, celldim, phydim;
    cgsize_t imax;
    char basename[33];

    if (argc < 2)
        print_usage (usgmsg, NULL);

    ib = 0;
    basename[0] = 0;
    while ((n = getargs (argc, argv, options)) > 0) {
        switch (n) {
            case 's':
                mblock = 0;
                break;
            case 'p':
                whole = 0;
                break;
            case 'n':
                use_iblank = 0;
                break;
            case 'f':
            case 'u':
                format = n;
                break;
            case 'd':
                use_double = 1;
                break;
            case 'b':
                ib = atoi (argarg);
                break;
            case 'B':
                strncpy (basename, argarg, 32);
                basename[32] = 0;
                break;
            case 'g':
                gamma = atof (argarg);
                if (gamma <= 1.0)
                    FATAL (NULL, "invalid value for gamma");
                break;
            case 'w':
                weighting = 1;
                break;
            case 'S':
                usesol = atoi (argarg);
                break;
        }
    }

    if (argind > argc - 2)
        print_usage (usgmsg, "CGNSfile and/or XYZfile not given");
    if (!file_exists (argv[argind]))
        FATAL (NULL, "CGNSfile does not exist or is not a file");

    /* open CGNS file */

    printf ("reading CGNS file from %s\n", argv[argind]);
    nb = open_cgns (argv[argind], 1);
    if (!nb)
        FATAL (NULL, "no bases found in CGNS file");
    if (*basename && 0 == (ib = find_base (basename)))
        FATAL (NULL, "specified base not found");
    if (ib > nb) FATAL (NULL, "base index out of range");
    cgnsbase = ib ? ib : 1;
    if (cg_base_read (cgnsfn, cgnsbase, basename, &celldim, &phydim))
        FATAL (NULL, NULL);
    if (celldim != 3 || phydim != 3)
        FATAL (NULL, "cell and/or physical dimension must be 3");
    printf ("  using base %d - %s\n", cgnsbase, basename);

    read_zones ();
    for (nz = 0; nz < nZones; nz++) {
	if (Zones[nz].type == CGNS_ENUMV(Structured)) {
	    /* verify we can write out using ints */
	    for (n = 0; n < 3; n++) {
		if (Zones[nz].dim[n] > CG_MAX_INT32)
		    FATAL(NULL, "zone dimensions too large for integer");
	    }
	    if (whole) {
		if (Zones[nz].nverts > CG_MAX_INT32)
		    FATAL(NULL, "zone too large to write as whole using an integer");
	    }
	    else {
	        if (Zones[nz].dim[0]*Zones[nz].dim[1] > CG_MAX_INT32)
		    FATAL(NULL, "zone too large to write using an integer");
	    }
	    nblocks++;
	}
    }
    if (!nblocks) FATAL (NULL, "no structured zones found");

    /* read the nodes */

    printf ("reading %d zones\n", nblocks);
    ib = is = 0;
    imax = 0;
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d - %s ... ", nz+1, Zones[nz].name);
            fflush (stdout);
            read_zone_grid (nz+1);
            ib += read_zone_interface (nz+1);
            is += check_solution (nz);
            if (imax < Zones[nz].nverts) imax = Zones[nz].nverts;
            puts ("done");
        }
    }

    if (!ib) use_iblank = 0;
    if (use_iblank) {
        iblank = (int *) malloc ((size_t)imax * sizeof(int));
        if (NULL == iblank)
            FATAL (NULL, "malloc failed for iblank array");
    }

    /* write Plot3d XYZ file */

    if (format == 'f')
        write_xyz_formatted (argv[++argind]);
    else if (format == 'u')
        write_xyz_unformatted (argv[++argind]);
    else
        write_xyz_binary (argv[++argind]);

    if (use_iblank) free (iblank);

    /* write solution file */

    if (++argind < argc) {
        if (is != nblocks) {
            fprintf (stderr, "solution file is not being written since not\n");
            fprintf (stderr, "all the blocks contain a complete solution\n");
            cg_close (cgnsfn);
            exit (1);
        }
        for (n = 0; n < 5; n++) {
            q[n] = (double *) malloc ((size_t)imax * sizeof(double));
            if (NULL == q[n])
                FATAL (NULL, "malloc failed for solution working array");
        }
        get_reference ();
        if (format == 'f')
            write_q_formatted (argv[argind]);
        else if (format == 'u')
            write_q_unformatted (argv[argind]);
        else
            write_q_binary (argv[argind]);
    }

    cg_close (cgnsfn);
    return 0;
}
static void read_q (BINARYIO *bf)
{
    int i, k, n, nk, nz, np, nv, nmax;
    int *indices;
    void *data;
    SOLUTION *sol;
    FIELD *flds;
    double qq, rho;
    static char *fldnames[] = {
        "Density",
        "MomentumX",
        "MomentumY",
        "MomentumZ",
        "EnergyStagnationDensity",
        "VelocityX",
        "VelocityY",
        "VelocityZ",
        "Pressure"
    };

    /* get number of grid blocks */

    if (mblock) {
        bf_getints (bf, 1, &nz);
        if (nz != nZones)
            FATAL ("read_q", "number of blocks not the same as the XYZ file");
    }

    /* read indices for grids */

    indices = (int *) malloc (3 * nZones * sizeof(int));
    if (NULL == indices)
        FATAL ("read_q", "malloc failed for grid indices");
    bf_getints (bf, 3 * nZones, indices);
    for (nz = 0; nz < nZones; nz++) {
        for (n = 0; n < 3; n++) {
            if (indices[3*nz+n] != Zones[nz].dim[n])
                FATAL ("read_q", "mismatch in block sizes");
        }
    }
    free (indices);

    /* create solution data arrays */

    for (nmax = 0, nz = 0; nz < nZones; nz++) {
        np = whole ? (int)Zones[nz].nverts : (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
        if (nmax < np) nmax = np;
        sol = new_solution (1);
        strcpy (sol->name, "FlowSolution");
        sol->location = CGNS_ENUMV(Vertex);
        sol->size = Zones[nz].nverts;
        sol->nflds = 5;
        sol->flds = new_field (5, sol->size);
        for (nv = 0; nv < 5; nv++) {
            strcpy (sol->flds[nv].name, fldnames[nv]);
            sol->flds[nv].datatype = is_double ? CGNS_ENUMV(RealDouble) : CGNS_ENUMV(RealSingle);
        }
        Zones[nz].nsols = 1;
        Zones[nz].sols = sol;
    }

    if (nmax < 4) nmax = 4;
    if (is_double)
        data = (void *) malloc (nmax * sizeof(double));
    else
        data = (void *) malloc (nmax * sizeof(float));
    if (NULL == data)
        FATAL ("read_q", "malloc failed for solution working array");

    /* read the solution data */

    for (nz = 0; nz < nZones; nz++) {
        printf ("reading block %d solution ...", nz+1);
        fflush (stdout);
        if (is_double) {
            bf_getdoubles (bf, 4, data);
            if (0 == nz) {
                for (n = 0; n < 4; n++)
                    reference[n] = ((double *)data)[n];
            }
        }
        else {
            bf_getfloats (bf, 4, data);
            if (0 == nz) {
                for (n = 0; n < 4; n++)
                    reference[n] = ((float *)data)[n];
            }
        }

        if (whole) {
            np = (int)Zones[nz].nverts;
            nk = 1;
        }
        else {
            np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
            nk = (int)Zones[nz].dim[2];
        }
        flds = Zones[nz].sols->flds;
        for (k = 0; k < nk; k++) {
            i = k * np;
            for (nv = 0; nv < 5; nv++) {
                if (is_double) {
                    bf_getdoubles (bf, np, data);
                    for (n = 0; n < np; n++)
                        flds[nv].data[n+i] = ((double *)data)[n];
                }
                else {
                    bf_getfloats (bf, np, data);
                    for (n = 0; n < np; n++)
                        flds[nv].data[n+i] = ((float *)data)[n];
                }
            }
        }

        if (convert) {
            for (nv = 1; nv < 5; nv++)
                strcpy (flds[nv].name, fldnames[4+nv]);
            for (n = 0; n < Zones[nz].nverts; n++) {
                rho = flds[0].data[n];
                for (qq = 0.0, nv = 1; nv < 4; nv++) {
                    flds[nv].data[n] /= rho;
                    qq += flds[nv].data[n] * flds[nv].data[n];
                }
                flds[4].data[n] = (gamma - 1.0) *
                    (flds[4].data[n] - 0.5 * rho * qq);
            }
        }
        puts (" done");
    }

    free (data);
}
static int *volume_elements (int nz, cgsize_t *nelems, int *elemtype)
{
    int i, np, ns, nt, et;
    int *elems;
    cgsize_t n, nn, ne;
    ZONE *z = &Zones[nz];

    count_elements (nz, &ne, &nt);
    *nelems = ne;
    *elemtype = nt;

    elems = (int *) malloc ((size_t)ne * (1 << nt) * sizeof(int));
    if (NULL == elems)
        FATAL (NULL, "malloc failed for elements");

    for (np = 0, ns = 0; ns < z->nesets; ns++) {
        ne = z->esets[ns].end - z->esets[ns].start + 1;
        et = z->esets[ns].type;
        if (et < CGNS_ENUMV(TETRA_4) || et > CGNS_ENUMV(MIXED)) continue;
        for (n = 0, nn = 0; nn < ne; nn++) {
            if (z->esets[ns].type == CGNS_ENUMV(MIXED))
                et = (int)z->esets[ns].conn[n++];
            switch (et) {
                case CGNS_ENUMV(TETRA_4):
                case CGNS_ENUMV(TETRA_10):
                    if (nt == 2) {
                        for (i = 0; i < 4; i++)
                            elems[np++] = (int)z->esets[ns].conn[n+i];
                    }
                    else {
                        for (i = 0; i < 3; i++)
                            elems[np++] = (int)z->esets[ns].conn[n+i];
                        elems[np++] = (int)z->esets[ns].conn[n+2];
                        for (i = 0; i < 4; i++)
                            elems[np++] = (int)z->esets[ns].conn[n+3];
                    }
                    break;
                case CGNS_ENUMV(PYRA_5):
                case CGNS_ENUMV(PYRA_14):
                    for (i = 0; i < 4; i++)
                        elems[np++] = (int)z->esets[ns].conn[n+i];
                    for (i = 0; i < 4; i++)
                        elems[np++] = (int)z->esets[ns].conn[n+4];
                    break;
                case CGNS_ENUMV(PENTA_6):
                case CGNS_ENUMV(PENTA_15):
                case CGNS_ENUMV(PENTA_18):
                    for (i = 0; i < 3; i++)
                        elems[np++] = (int)z->esets[ns].conn[n+i];
                    elems[np++] = (int)z->esets[ns].conn[n+2];
                    for (i = 3; i < 6; i++)
                        elems[np++] = (int)z->esets[ns].conn[n+i];
                    elems[np++] = (int)z->esets[ns].conn[n+5];
                    break;
                case CGNS_ENUMV(HEXA_8):
                case CGNS_ENUMV(HEXA_20):
                case CGNS_ENUMV(HEXA_27):
                    for (i = 0; i < 8; i++)
                        elems[np++] = (int)z->esets[ns].conn[n+i];
                    break;
            }
            n += element_node_counts[et];
        }
    }

    return elems;
}
Beispiel #10
0
int main (int argc, char *argv[])
{
    int j, n;
    cgsize_t ne;
    int fnum, bnum, znum, snum, cnum;
    cgsize_t size[3];
    float exp[5];
    char *outfile = "elemtest.cgns";

    unlink (outfile);

    if (cg_open (outfile, CG_MODE_WRITE, &fnum) ||
        cg_base_write (fnum, "Base", 3, 3, &bnum) ||
        cg_goto(fnum, bnum, NULL) ||
        cg_dataclass_write(CGNS_ENUMV(NormalizedByDimensional)))
        cg_error_exit ();

    for (n = 0; n < 5; n++)
        exp[n] = (float)0.0;
    exp[1] = (float)1.0;

    /* zone with linear elements */

    size[0] = 11;
    size[1] = 12;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "1:Linear", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", xc, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", yc, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* NGON_n first so polyhedra face references are correct */

    if (cg_section_write (fnum, bnum, znum, "NGON_n", CGNS_ENUMV(NGON_n),
            ne+1, ne+npoly, 0, poly, &snum))
        cg_error_exit();
    ne += npoly;

    /* NODE */

    if (cg_section_write (fnum, bnum, znum, "NODE", CGNS_ENUMV(NODE),
            ne+1, ne+1, 0, node, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(NODE);
    elems[j++] = node[0];

    /* BAR_2 */

    if (cg_section_write (fnum, bnum, znum, "BAR_2", CGNS_ENUMV(BAR_2),
            ne+1, ne+1, 0, bar, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(BAR_2);
    for (n = 0; n < 2; n++)
        elems[j++] = bar[n];

    /* TRI_3 */

    if (cg_section_write (fnum, bnum, znum, "TRI_3", CGNS_ENUMV(TRI_3),
            ne+1, ne+1, 0, tri, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TRI_3);
    for (n = 0; n < 3; n++)
        elems[j++] = tri[n];

    /* QUAD_4 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_4", CGNS_ENUMV(QUAD_4),
            ne+1, ne+1, 0, quad9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_4);
    for (n = 0; n < 4; n++)
        elems[j++] = quad9[n];

    /* TETRA_4 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_4", CGNS_ENUMV(TETRA_4),
            ne+1, ne+1, 0, tetra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_4);
    for (n = 0; n < 4; n++)
        elems[j++] = tetra[n];

    /* PYRA_5 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_5", CGNS_ENUMV(PYRA_5),
            ne+1, ne+1, 0, pyra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_5);
    for (n = 0; n < 5; n++)
        elems[j++] = pyra[n];

    /* PENTA_6 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_6", CGNS_ENUMV(PENTA_6),
            ne+1, ne+1, 0, penta, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_6);
    for (n = 0; n < 6; n++)
        elems[j++] = penta[n];

    /* HEXA_8 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_8", CGNS_ENUMV(HEXA_8),
            ne+1, ne+1, 0, hexa, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_8);
    for (n = 0; n < 8; n++)
        elems[j++] = hexa[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+8, 0, elems, &snum))
        cg_error_exit ();
    ne += 8;

    /* NFACE_n */

    if (cg_section_write (fnum, bnum, znum, "NFACE_n", CGNS_ENUMV(NFACE_n),
            ne+1, ne+nface, 0, face, &snum))
        cg_error_exit ();

    /* zone with quadratic elements */

    size[0] = 42;
    size[1] = 8;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "2:Quadratic", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", xc, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", yc, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* BAR_3 */

    if (cg_section_write (fnum, bnum, znum, "BAR_3", CGNS_ENUMV(BAR_3),
            ne+1, ne+1, 0, bar, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(BAR_3);
    for (n = 0; n < 3; n++)
        elems[j++] = bar[n];

    /* TRI_6 */

    if (cg_section_write (fnum, bnum, znum, "TRI_6", CGNS_ENUMV(TRI_6),
            ne+1, ne+1, 0, tri, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TRI_6);
    for (n = 0; n < 6; n++)
        elems[j++] = tri[n];

    /* QUAD_8 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_8", CGNS_ENUMV(QUAD_8),
            ne+1, ne+1, 0, quad9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_8);
    for (n = 0; n < 8; n++)
        elems[j++] = quad9[n];

    /* TETRA_10 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_10", CGNS_ENUMV(TETRA_10),
            ne+1, ne+1, 0, tetra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_10);
    for (n = 0; n < 10; n++)
        elems[j++] = tetra[n];

    /* PYRA_13 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_13", CGNS_ENUMV(PYRA_13),
            ne+1, ne+1, 0, pyra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_13);
    for (n = 0; n < 13; n++)
        elems[j++] = pyra[n];

    /* PENTA_15 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_15", CGNS_ENUMV(PENTA_15),
            ne+1, ne+1, 0, penta, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_15);
    for (n = 0; n < 15; n++)
        elems[j++] = penta[n];

    /* HEXA_20 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_20", CGNS_ENUMV(HEXA_20),
            ne+1, ne+1, 0, hexa, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_20);
    for (n = 0; n < 20; n++)
        elems[j++] = hexa[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+7, 0, elems, &snum))
        cg_error_exit ();
    ne += 7;

    /* zone with quadratic elements with mid-nodes */

    size[0] = 42;
    size[1] = 8;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "3:Quadratic with mid-nodes", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", xc, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", yc, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* QUAD_9 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_9", CGNS_ENUMV(QUAD_9),
            ne+1, ne+1, 0, quad9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_9);
    for (n = 0; n < 9; n++)
        elems[j++] = quad9[n];

    /* TETRA_10 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_10", CGNS_ENUMV(TETRA_10),
            ne+1, ne+1, 0, tetra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_10);
    for (n = 0; n < 10; n++)
        elems[j++] = tetra[n];

    /* PYRA_14 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_14", CGNS_ENUMV(PYRA_14),
            ne+1, ne+1, 0, pyra, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_14);
    for (n = 0; n < 14; n++)
        elems[j++] = pyra[n];

    /* PENTA_18 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_18", CGNS_ENUMV(PENTA_18),
            ne+1, ne+1, 0, penta, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_18);
    for (n = 0; n < 18; n++)
        elems[j++] = penta[n];

    /* HEXA_27 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_27", CGNS_ENUMV(HEXA_27),
            ne+1, ne+1, 0, hexa, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_27);
    for (n = 0; n < 27; n++)
        elems[j++] = hexa[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+5, 0, elems, &snum))
        cg_error_exit ();
    ne += 5;

    /* zone with cubic elements */

    size[0] = 55;
    size[1] = 8;
    size[2] = 0;
    if (cg_zone_write (fnum, bnum, "4:Cubic", size,
            CGNS_ENUMV(Unstructured), &znum) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateX", x3, &cnum) ||
        cg_goto(fnum, bnum, "Zone_t", znum, "GridCoordinates", 0,
            "CoordinateX", 0, NULL) ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateY", y3, &cnum) ||
        cg_gopath(fnum, "../CoordinateY") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp) ||
        cg_coord_write (fnum, bnum, znum, CGNS_ENUMV(RealDouble),
            "CoordinateZ", zc, &cnum) ||
        cg_gopath(fnum, "../CoordinateZ") ||
        cg_exponents_write(CGNS_ENUMV(RealSingle), exp))
        cg_error_exit ();
    ne = j = 0;

    /* BAR_4 */

    if (cg_section_write (fnum, bnum, znum, "BAR_4", CGNS_ENUMV(BAR_4),
            ne+1, ne+1, 0, bar4, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(BAR_4);
    for (n = 0; n < 4; n++)
        elems[j++] = bar4[n];

    /* TRI_9 */

    if (cg_section_write (fnum, bnum, znum, "TRI_9", CGNS_ENUMV(TRI_9),
            ne+1, ne+1, 0, tri9, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TRI_9);
    for (n = 0; n < 9; n++)
        elems[j++] = tri9[n];

    /* QUAD_12 */

    if (cg_section_write (fnum, bnum, znum, "QUAD_12", CGNS_ENUMV(QUAD_12),
            ne+1, ne+1, 0, quad12, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(QUAD_12);
    for (n = 0; n < 12; n++)
        elems[j++] = quad12[n];

    /* TETRA_16 */

    if (cg_section_write (fnum, bnum, znum, "TETRA_16", CGNS_ENUMV(TETRA_16),
            ne+1, ne+1, 0, tetra16, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(TETRA_16);
    for (n = 0; n < 16; n++)
        elems[j++] = tetra16[n];

    /* PYRA_21 */

    if (cg_section_write (fnum, bnum, znum, "PYRA_21", CGNS_ENUMV(PYRA_21),
            ne+1, ne+1, 0, pyra21, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PYRA_21);
    for (n = 0; n < 21; n++)
        elems[j++] = pyra21[n];

    /* PENTA_24 */

    if (cg_section_write (fnum, bnum, znum, "PENTA_24", CGNS_ENUMV(PENTA_24),
            ne+1, ne+1, 0, penta24, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(PENTA_24);
    for (n = 0; n < 24; n++)
        elems[j++] = penta24[n];

    /* HEXA_32 */

    if (cg_section_write (fnum, bnum, znum, "HEXA_32", CGNS_ENUMV(HEXA_32),
            ne+1, ne+1, 0, hexa32, &snum))
        cg_error_exit ();
    ne++;

    elems[j++] = (int)CGNS_ENUMV(HEXA_32);
    for (n = 0; n < 32; n++)
        elems[j++] = hexa32[n];

    /* MIXED */

    if (cg_section_write (fnum, bnum, znum, "MIXED", CGNS_ENUMV(MIXED),
            ne+1, ne+7, 0, elems, &snum))
        cg_error_exit ();
    ne += 7;

    if (cg_close (fnum)) cg_error_exit ();
    return 0;
}
static void write_xyz_formatted (char *xyzfile)
{
    int n, k, nk, nz, np, *ib;
    VERTEX *verts;
    FILE *fp;

    printf ("\nwriting formatted XYZ file to %s\n", xyzfile);
    if (use_iblank) printf ("  with iblank array\n");

    if (NULL == (fp = fopen (xyzfile, "w+"))) {
        fprintf (stderr, "couldn't open <%s> for writing\n", xyzfile);
        exit (1);
    }
    if (mblock || nblocks > 1)
        fprintf (fp, "%d\n", nblocks);
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured))
            fprintf (fp, "%d %d %d\n", (int)Zones[nz].dim[0],
                (int)Zones[nz].dim[1], (int)Zones[nz].dim[2]);
    }
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d - %d x %d x %d ... ", nz+1,
                (int)Zones[nz].dim[0], (int)Zones[nz].dim[1],
		(int)Zones[nz].dim[2]);
            fflush (stdout);
            if (use_iblank) compute_iblank (nz);
            if (whole) {
                np = (int)Zones[nz].nverts;
                nk = 1;
            }
            else {
                np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
                nk = (int)Zones[nz].dim[2];
            }
            for (k = 0; k < nk; k++) {
                verts = &Zones[nz].verts[k*np];
                for (n = 0; n < np; n++) {
                    if (n) putc ((n % 5) == 0 ? '\n' : ' ', fp);
                    fprintf (fp, "%#g", verts[n].x);
                }
                putc ('\n', fp);
                for (n = 0; n < np; n++) {
                    if (n) putc ((n % 5) == 0 ? '\n' : ' ', fp);
                    fprintf (fp, "%#g", verts[n].y);
                }
                putc ('\n', fp);
                for (n = 0; n < np; n++) {
                    if (n) putc ((n % 5) == 0 ? '\n' : ' ', fp);
                    fprintf (fp, "%#g", verts[n].z);
                }
                putc ('\n', fp);
                if (use_iblank) {
                    ib = &iblank[k*np];
                    for (n = 0; n < np; n++, ib++) {
                        if (n && (n % 10) == 0)
                            putc ('\n', fp);
                        fprintf (fp, "%5d", *ib);
                    }
                    putc ('\n', fp);
                }
            }
            puts ("done");
        }
    }
    fclose (fp);
}
static void write_xyz_unformatted (char *xyzfile)
{
    int n, i, ierr, *indices;
    int nz, k, nk, np;
    char buff[129];
    VERTEX *verts;
    void *xyz;
    float *xyzf;
    double *xyzd;

    printf ("\nwriting unformatted XYZ file to %s\n", xyzfile);
    printf ("  in %s-precision", use_double ? "double" : "single");
    if (use_iblank) printf (" with iblank array");
    putchar ('\n');

    for (np = 0, nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            nk = whole ? (int)Zones[nz].nverts :
                (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
            if (np < nk) np = nk;
        }
    }
    indices = (int *) malloc (3 * nblocks * sizeof(int));
    if (use_double) {
        xyz = (void *) malloc (3 * np * sizeof(double));
        xyzd = (double *)xyz;
    }
    else {
        xyz = (void *) malloc (3 * np * sizeof(float));
        xyzf = (float *)xyz;
    }
    if (NULL == indices || NULL == xyz)
        FATAL ("write_xyx_unformatted", "malloc failed for working arrays");

    unlink (xyzfile);
    strcpy (buff, xyzfile);
    for (n = (int)strlen(buff); n < 128; n++)
        buff[n] = ' ';
    buff[128] = 0;
    n = 0;
    OPENF (&n, buff, 128);

    if (mblock || nblocks > 1) {
        n = 1;
        WRITEIF (&n, &nblocks, &ierr);
    }
    for (n = 0, nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            for (i = 0; i < 3; i++)
                indices[n++] = (int)Zones[nz].dim[i];
        }
    }
    WRITEIF (&n, indices, &ierr);

    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d - %d x %d x %d ... ", nz+1,
                (int)Zones[nz].dim[0], (int)Zones[nz].dim[1],
		(int)Zones[nz].dim[2]);
            fflush (stdout);
            if (use_iblank) compute_iblank (nz);
            if (whole) {
                np = (int)Zones[nz].nverts;
                nk = 1;
            }
            else {
                np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
                nk = (int)Zones[nz].dim[2];
            }
            for (k = 0; k < nk; k++) {
                verts = &Zones[nz].verts[k*np];
                if (use_double) {
                    for (i = 0, n = 0; n < np; n++)
                        xyzd[i++] = verts[n].x;
                    for (n = 0; n < np; n++)
                        xyzd[i++] = verts[n].y;
                    for (n = 0; n < np; n++)
                        xyzd[i++] = verts[n].z;
                    if (use_iblank)
                        WRITEGDF (&np, xyzd, &iblank[k*np], &ierr);
                    else
                        WRITEDF (&i, xyzd, &ierr);
                }
                else {
                    for (i = 0, n = 0; n < np; n++)
                        xyzf[i++] = (float)verts[n].x;
                    for (n = 0; n < np; n++)
                        xyzf[i++] = (float)verts[n].y;
                    for (n = 0; n < np; n++)
                        xyzf[i++] = (float)verts[n].z;
                    if (use_iblank)
                        WRITEGFF (&np, xyzf, &iblank[k*np], &ierr);
                    else
                        WRITEFF (&i, xyzf, &ierr);
                }
            }
            puts ("done");
        }
    }
    CLOSEF ();
    free (indices);
    free (xyz);
}
static void write_xyz_binary (char *xyzfile)
{
    int nz, i, dims[3];
    int n, k, nk, np;
    VERTEX *verts;
    void *xyz;
    float *xyzf;
    double *xyzd;
    FILE *fp;

    printf ("\nwriting binary XYZ file to %s\n", xyzfile);
    printf ("  in %s-precision", use_double ? "double" : "single");
    if (use_iblank) printf (" with iblank array");
    putchar ('\n');

    for (np = 0, nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            nk = whole ? (int)Zones[nz].nverts :
                (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
            if (np < nk) np = nk;
        }
    }
    if (use_double) {
        xyz = (void *) malloc (np * sizeof(double));
        xyzd = (double *)xyz;
    }
    else {
        xyz = (void *) malloc (np * sizeof(float));
        xyzf = (float *)xyz;
    }
    if (NULL == xyz)
        FATAL ("write_xyx_binary", "malloc failed for working arrays");

    if (NULL == (fp = fopen (xyzfile, "w+b"))) {
        fprintf (stderr, "couldn't open <%s> for writing\n", xyzfile);
        exit (1);
    }
    if (mblock || nblocks > 1)
        fwrite (&nblocks, sizeof(int), 1, fp);
    for (nz = 0; nz < nZones; nz++) {
	if (Zones[nz].type == CGNS_ENUMV(Structured)) {
	    for (i = 0; i < 3; i++)
		dims[i] = (int)Zones[nz].dim[i];
            fwrite (dims, sizeof(int), 3, fp);
	}
    }
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d - %d x %d x %d ... ", nz+1,
                (int)Zones[nz].dim[0], (int)Zones[nz].dim[1],
		(int)Zones[nz].dim[2]);
            fflush (stdout);
            if (use_iblank) compute_iblank (nz);
            if (whole) {
                np = (int)Zones[nz].nverts;
                nk = 1;
            }
            else {
                np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
                nk = (int)Zones[nz].dim[2];
            }
            for (k = 0; k < nk; k++) {
                verts = &Zones[nz].verts[k*np];
                if (use_double) {
                    for (n = 0; n < np; n++)
                        xyzd[n] = verts[n].x;
                    fwrite (xyzd, sizeof(double), np, fp);
                    for (n = 0; n < np; n++)
                        xyzd[n] = verts[n].y;
                    fwrite (xyzd, sizeof(double), np, fp);
                    for (n = 0; n < np; n++)
                        xyzd[n] = verts[n].z;
                    fwrite (xyzd, sizeof(double), np, fp);
                }
                else {
                    for (n = 0; n < np; n++)
                        xyzf[n] = (float)verts[n].x;
                    fwrite (xyzf, sizeof(float), np, fp);
                    for (n = 0; n < np; n++)
                        xyzf[n] = (float)verts[n].y;
                    fwrite (xyzf, sizeof(float), np, fp);
                    for (n = 0; n < np; n++)
                        xyzf[n] = (float)verts[n].z;
                    fwrite (xyzf, sizeof(float), np, fp);
                }
                if (use_iblank)
                    fwrite (&iblank[k*np], sizeof(int), np, fp);
            }
            puts ("done");
        }
    }
    fclose (fp);
    free (xyz);
}
int main (int argc, char *argv[])
{
    int n, ib = 0, nb, flags = 0, has_q = 0;
    BINARYIO *bf;
    static char basename[33] = "Base";

    if (argc < 3)
        print_usage (usgmsg, NULL);

    /* get options */

    while ((n = getargs (argc, argv, options)) > 0) {
        switch (n) {
            case 'f':
                flags &= ~OPEN_FORTRAN;
                flags |= OPEN_ASCII;
                break;
            case 'u':
                flags &= ~OPEN_ASCII;
                flags |= OPEN_FORTRAN;
                break;
            case 's':
                mblock = 0;
                break;
            case 'p':
                whole = 0;
                break;
            case 'i':
                use_iblank = 1;
                /* fall through */
            case 'n':
                has_iblank = 1;
                break;
            case 'd':
                is_double = 1;
                break;
            case 'M':
                flags &= ~MACH_UNKNOWN;
                flags |= get_machine (argarg);
                break;
            case 'b':
                ib = atoi (argarg);
                break;
            case 'B':
                strncpy (basename, argarg, 32);
                basename[32] = 0;
                break;
            case 'g':
                gamma = atof (argarg);
                if (gamma <= 1.0)
                    FATAL (NULL, "invalid value for gamma");
                break;
            case 'c':
                convert = 1;
                break;
        }
    }

    if (argind > argc - 2)
        print_usage (usgmsg, "XYZfile and/or CGNSfile not given");

    /* read Plot3d file */

    printf ("reading PLOT3D grid file %s\n", argv[argind]);
    printf ("  as %s-block %s", mblock ? "multi" : "single",
        flags == OPEN_ASCII ? "ASCII" :
        (flags == OPEN_FORTRAN ? "FORTRAN unformatted" : "binary"));
    if (has_iblank) printf (" with iblank array");
    putchar ('\n');
    if (!file_exists (argv[argind]))
        FATAL (NULL, "XYZ file does not exist or is not a file");
    if (NULL == (bf = bf_open (argv[argind], flags | OPEN_READ))) {
        fprintf (stderr, "can't open <%s> for reading", argv[argind]);
        exit (1);
    }
    read_xyz (bf);
    bf_close (bf);

    if (use_iblank) build_interfaces ();

    /* read solution file if given */

    if (++argind < argc-1) {
        printf ("\nreading PLOT3D solution file %s\n", argv[argind]);
        if (!file_exists (argv[argind]))
            FATAL (NULL, "Solution file does not exist or is not a file");

        if (NULL == (bf = bf_open (argv[argind], flags | OPEN_READ))) {
            fprintf (stderr, "can't open <%s> for reading", argv[argind]);
            exit (1);
        }
        read_q (bf);
        bf_close (bf);
        argind++;
        has_q = 1;
    }

    /* open CGNS file */

    printf ("\nwriting CGNS file to %s\n", argv[argind]);
    nb = open_cgns (argv[argind], 0);
    if (ib) {
        if (ib > nb)
            FATAL (NULL, "specified base index out of range");
        if (cg_base_read (cgnsfn, ib, basename, &n, &n))
            FATAL (NULL, NULL);
    }
    if (cg_base_write (cgnsfn, basename, 3, 3, &cgnsbase) ||
        cg_goto (cgnsfn, cgnsbase, "end") ||
        cg_dataclass_write (CGNS_ENUMV(NormalizedByUnknownDimensional)))
        FATAL (NULL, NULL);
    printf ("  output to base %d - %s\n", cgnsbase, basename);

    write_zones ();
    for (n = 1; n <= nZones; n++) {
        printf ("writing zone %d ... grid", n);
        fflush (stdout);
        write_zone_grid (n);
        write_zone_interface (n);
        if (has_q) {
            printf (", solution");
            fflush (stdout);
            write_zone_solution (n, 1);
            write_solution_field (n, 1, 0);
        }
        puts (" done");
    }
    if (has_q) write_reference ();

    cg_close (cgnsfn);

    return 0;
}
static void write_reference (void)
{
    int n;
    cgsize_t cnt = 1;
    CGNS_ENUMT(DataType_t) datasize;
    float ref[4];
    void *mach, *alpha, *rey, *time;

    printf ("writing reference state...");
    fflush (stdout);
    if (cg_goto (cgnsfn, cgnsbase, "end") ||
        cg_state_write ("PLOT3D reference state"))
        FATAL ("write_reference", NULL);

    if (is_double) {
        datasize = CGNS_ENUMV(RealDouble);
        mach  = (void *)&reference[0];
        alpha = (void *)&reference[1];
        rey   = (void *)&reference[2];
        time  = (void *)&reference[3];
    }
    else {
        for (n = 0; n < 4; n++)
            ref[n] = (float)reference[n];
        datasize = CGNS_ENUMV(RealSingle);
        mach  = (void *)&ref[0];
        alpha = (void *)&ref[1];
        rey   = (void *)&ref[2];
        time  = (void *)&ref[3];
    }

    if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "end") ||
        cg_array_write ("Mach", datasize, 1, &cnt, mach) ||
        cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1,
            "DataArray_t", 1, "end") ||
        cg_dataclass_write (CGNS_ENUMV(NondimensionalParameter)))
        FATAL ("write_reference", NULL);

    if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "end") ||
        cg_array_write ("AngleofAttack", datasize, 1, &cnt, alpha) ||
        cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1,
            "DataArray_t", 2, "end") ||
        cg_dataclass_write (CGNS_ENUMV(Dimensional)) ||
        cg_units_write (CGNS_ENUMV(MassUnitsNull), CGNS_ENUMV(LengthUnitsNull), CGNS_ENUMV(TimeUnitsNull),
            CGNS_ENUMV(TemperatureUnitsNull), CGNS_ENUMV(Degree)))
        FATAL ("write_reference", NULL);

    if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "end") ||
        cg_array_write ("Reynolds", datasize, 1, &cnt, rey) ||
        cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1,
            "DataArray_t", 3, "end") ||
        cg_dataclass_write (CGNS_ENUMV(NondimensionalParameter)))
        FATAL ("write_reference", NULL);

    if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "end") ||
        cg_array_write ("TimeLatest", datasize, 1, &cnt, time) ||
        cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1,
            "DataArray_t", 4, "end") ||
        cg_dataclass_write (CGNS_ENUMV(Dimensional)) ||
        cg_units_write (CGNS_ENUMV(MassUnitsNull), CGNS_ENUMV(LengthUnitsNull),
            CGNS_ENUMV(Second), CGNS_ENUMV(TemperatureUnitsNull), CGNS_ENUMV(AngleUnitsNull)))
        FATAL ("write_reference", NULL);

    puts (" done");
}
int main(int argc, char* argv[]) {
	int k;
	int F;
	int B;

	int *Z, *E, *S, *A;
	int *Cx, *Cy, *Cz;
	int *Fu, *Fv, *Fw;

	cgsize_t nijk[3];
	cgsize_t min, max;

	double T0,T1;
	double Tw0,Tw1;
	double Tr0,Tr1;
	double t0,t1;

	initialize(&argc,&argv);

	Z = (int *)malloc(10*zc*sizeof(int));
	E = Z + zc;
	S = E + zc;
	A = S + zc;
	Cx = A + zc;
	Cy = Cx + zc;
	Cz = Cy + zc;
	Fu = Cz + zc;
	Fv = Fu + zc;
	Fw = Fv + zc;

	if (cgp_open("thesis_benchmark.cgns", CG_MODE_WRITE, &F) ||
	    cg_base_write(F,"Base",3,3,&B))
	    cgp_error_exit();

	nijk[0] = Nl*ppz;
	nijk[1] = Nl*ppz;
	nijk[2] = 0;

	for(k=0;k<zc;k++) {
		char zonename[100+1];
		sprintf(zonename,"%s %d","Zone",k);
		if (cg_zone_write(F,B,zonename,nijk,CGNS_ENUMV(Unstructured),&(Z[k])) ||
		    cgp_coord_write(F,B,Z[k],CGNS_ENUMV(RealDouble),"CoordinateX",&(Cx[k])) ||
		    cgp_coord_write(F,B,Z[k],CGNS_ENUMV(RealDouble),"CoordinateY",&(Cy[k])) ||
		    cgp_coord_write(F,B,Z[k],CGNS_ENUMV(RealDouble),"CoordinateZ",&(Cz[k])) ||
		    cgp_section_write(F,B,Z[k],"Elements",CGNS_ENUMV(NODE),1,Nl*ppz,0,&(E[k])) ||
		    cg_sol_write(F,B,Z[k],"Solution",CGNS_ENUMV(Vertex),&S[k]) ||
		    cgp_field_write(F,B,Z[k],S[k],CGNS_ENUMV(RealDouble),"MomentumX",&(Fu[k])) ||
		    cgp_field_write(F,B,Z[k],S[k],CGNS_ENUMV(RealDouble),"MomentumY",&(Fv[k])) ||
		    cgp_field_write(F,B,Z[k],S[k],CGNS_ENUMV(RealDouble),"MomentumZ",&(Fw[k])))
		    cgp_error_exit();
		if (cg_goto(F,B,zonename,0,NULL) ||
		    cg_user_data_write("User Data") ||
		    cg_gorel(F, "User Data", 0, NULL) ||
		    cgp_array_write("phi",CGNS_ENUMV(RealDouble),1,nijk,&A[k]))
		    cgp_error_exit();
		}

	MPI_Barrier(MPI_COMM_WORLD);
	T0 = MPI_Wtime();
	Tw0 = MPI_Wtime();

	/* Writes */
	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cgp_coord_write_data(F,B,Z[zones[k]],Cx[zones[k]],&min,&max,x) ||
		    cgp_coord_write_data(F,B,Z[zones[k]],Cy[zones[k]],&min,&max,y) ||
		    cgp_coord_write_data(F,B,Z[zones[k]],Cz[zones[k]],&min,&max,z))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Coords Write\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cgp_field_write_data(F,B,Z[zones[k]],S[zones[k]],Fu[zones[k]],&min,&max,u) ||
		    cgp_field_write_data(F,B,Z[zones[k]],S[zones[k]],Fv[zones[k]],&min,&max,v) ||
		    cgp_field_write_data(F,B,Z[zones[k]],S[zones[k]],Fw[zones[k]],&min,&max,w))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Solutions Write\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cg_goto(F,B,"Zone_t",Z[zones[k]],
		        "UserDefinedData_t",1,NULL) ||
		    cgp_array_write_data(A[zones[k]],&min,&max,h))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Arrays Write\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cgp_elements_write_data(F,B,Z[zones[k]],E[zones[k]],min,max,e))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Elements Write\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",((double) sizeof(int))/((double) sizeof(double))*data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	Tw1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Total Write Time=%lf\n",Tw1-Tw0);
		printf("Total Write Bandwidth=%lf\n",(6.0+((double) sizeof(int))/((double) sizeof(double)))*data_size/(Tw1-Tw0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	cgp_close(F);
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) printf("Close_Time=%lf\n",t1-t0);

	/*=======
	 *=Reads=
	 *=======*/

	if (cgp_open("thesis_benchmark.cgns", CG_MODE_READ, &F))
	    cgp_error_exit();

	MPI_Barrier(MPI_COMM_WORLD);
	Tr0 = MPI_Wtime();

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cgp_coord_read_data(F,B,Z[zones[k]],Cx[zones[k]],&min,&max,x) ||
		    cgp_coord_read_data(F,B,Z[zones[k]],Cy[zones[k]],&min,&max,y) ||
		    cgp_coord_read_data(F,B,Z[zones[k]],Cz[zones[k]],&min,&max,z))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Coords Read\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cgp_field_read_data(F,B,Z[zones[k]],S[zones[k]],Fu[zones[k]],&min,&max,u) ||
		    cgp_field_read_data(F,B,Z[zones[k]],S[zones[k]],Fv[zones[k]],&min,&max,v) ||
		    cgp_field_read_data(F,B,Z[zones[k]],S[zones[k]],Fw[zones[k]],&min,&max,w))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Solutions Read\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",3.0*data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cg_goto(F,B,"Zone_t",Z[zones[k]],
		        "UserDefinedData_t",1,NULL) ||
		    cgp_array_read_data(A[zones[k]],&min,&max,h))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Arrays Read\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	for(k=0;k<zpp;k++) {
		min = subzones[k]*Nl+1;
		max = (subzones[k]+1)*Nl;

		if (cgp_elements_read_data(F,B,Z[zones[k]],E[zones[k]],min,max,e))
		    cgp_error_exit();
		}
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Elements Read\n");
		printf("\tTime=%lf\n",t1-t0);
		printf("\tBandwidth=%lf\n",((double) sizeof(int))/((double) sizeof(double))*data_size/(t1-t0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	Tr1 = MPI_Wtime();
	if(comm_rank==0) {
		printf("Total Read Time=%lf\n",Tr1-Tr0);
		printf("Total Read Bandwidth=%lf\n",(6.0+((double) sizeof(int))/((double) sizeof(double)))*data_size/(Tr1-Tr0));
		}

	MPI_Barrier(MPI_COMM_WORLD);
	t0 = MPI_Wtime();
	cgp_close(F);
	MPI_Barrier(MPI_COMM_WORLD);
	t1 = MPI_Wtime();
	if(comm_rank==0) printf("Close_Time=%lf\n",t1-t0);

	MPI_Barrier(MPI_COMM_WORLD);
	T1 = MPI_Wtime();

	if(comm_rank==0) {
		printf("Total Time=%lf\n",T1-T0);
		}

	finalize();

	return 0;
	}
Beispiel #17
0
Shared::Shared()
{
  m_supported_element_types.reserve(9);
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Line1D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Line2D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Line3D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Triag2D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Triag3D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Quad2D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Quad3D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Tetra3D");
  m_supported_element_types.push_back("cf3.mesh.LagrangeP1.Hexa3D");

  m_elemtype_CGNS_to_CF[CGNS_ENUMV( BAR_2 ) ] = "cf3.mesh.LagrangeP1.Line";
  m_elemtype_CGNS_to_CF[CGNS_ENUMV( TRI_3 ) ] = "cf3.mesh.LagrangeP1.Triag";
  m_elemtype_CGNS_to_CF[CGNS_ENUMV( QUAD_4) ] = "cf3.mesh.LagrangeP1.Quad";
  m_elemtype_CGNS_to_CF[CGNS_ENUMV( TETRA_4)] = "cf3.mesh.LagrangeP1.Tetra";
  m_elemtype_CGNS_to_CF[CGNS_ENUMV( HEXA_8 )] = "cf3.mesh.LagrangeP1.Hexa";

  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Line1D" ] = CGNS_ENUMV( BAR_2 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Line2D" ] = CGNS_ENUMV( BAR_2 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Line3D" ] = CGNS_ENUMV( BAR_2 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Triag2D"] = CGNS_ENUMV( TRI_3 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Triag3D"] = CGNS_ENUMV( TRI_3 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Quad2D" ] = CGNS_ENUMV( QUAD_4 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Quad3D" ] = CGNS_ENUMV( QUAD_4 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Tetra3D"] = CGNS_ENUMV( TETRA_4 );
  m_elemtype_CF3_to_CGNS["cf3.mesh.LagrangeP1.Hexa3D" ] = CGNS_ENUMV( HEXA_8 );
}
static void compute_solution (int nz)
{
    int n, nf, loc[5], con[5];
    double vel2;
    SOLUTION *sol = &Zones[nz].sols[usesol-1];

    for (n = 0; n < 5; n++)
        loc[n] = -1;
    for (nf = 0; nf < sol->nflds; nf++) {
        if (!strcmp (sol->flds[nf].name, "Density")) {
            loc[0] = nf;
            con[0] = 0;
        }
        else if (!strcmp (sol->flds[nf].name, "VelocityX")) {
            if (loc[1] >= 0) continue;
            loc[1] = nf;
            con[1] = 1;
        }
        else if (!strcmp (sol->flds[nf].name, "MomentumX")) {
            loc[1] = nf;
            con[1] = 0;
        }
        else if (!strcmp (sol->flds[nf].name, "VelocityY")) {
            if (loc[2] >= 0) continue;
            loc[2] = nf;
            con[2] = 1;
        }
        else if (!strcmp (sol->flds[nf].name, "MomentumY")) {
            loc[2] = nf;
            con[2] = 0;
        }
        else if (!strcmp (sol->flds[nf].name, "VelocityZ")) {
            if (loc[3] >= 0) continue;
            loc[3] = nf;
            con[3] = 1;
        }
        else if (!strcmp (sol->flds[nf].name, "MomentumZ")) {
            loc[3] = nf;
            con[3] = 0;
        }
        else if (!strcmp (sol->flds[nf].name, "Pressure")) {
            if (loc[4] >= 0) continue;
            loc[4] = nf;
            con[4] = 1;
        }
        else if (!strcmp (sol->flds[nf].name, "EnergyStagnationDensity")) {
            loc[4] = nf;
            con[4] = 0;
        }
        else
            continue;
        read_solution_field (nz+1, usesol, nf+1);
    }
    if (sol->location != CGNS_ENUMV(Vertex))
        cell_vertex_solution (nz+1, usesol, weighting);

    for (nf = 0; nf < 5; nf++) {
        for (n = 0; n < sol->size; n++)
            q[nf][n] = sol->flds[loc[nf]].data[n];
    }
    for (nf = 1; nf <= 3; nf++) {
        if (con[nf]) {
            for (n = 0; n < sol->size; n++)
                q[nf][n] *= q[0][n];
        }
    }
    if (con[4]) {
        for (n = 0; n < sol->size; n++) {
            vel2 = 0.0;
            for (nf = 1; nf <= 3; nf++)
                vel2 += (q[nf][n] * q[nf][n]);
            q[4][n] = q[4][n] / (gamma - 1.0) + 0.5 * vel2 / q[0][n];
        }
    }
}
static void write_q_binary (char *qfile)
{
    int i, j, n, k, nk, nz, np, dim[3];
    float qf[4];
    FILE *fp;

    printf ("\nwriting binary Q file to %s\n", qfile);
    printf ("  in %s-precision\n", use_double ? "double" : "single");

    if (NULL == (fp = fopen (qfile, "w+b"))) {
        fprintf (stderr, "couldn't open <%s> for writing\n", qfile);
        exit (1);
    }
    if (mblock || nblocks > 1)
        fwrite (&nblocks, sizeof(int), 1, fp);
    for (nz = 0; nz < nZones; nz++) {
	if (Zones[nz].type == CGNS_ENUMV(Structured)) {
	    for (i = 0; i < 3; i++)
		dim[i] = (int)Zones[nz].dim[i];
            fwrite (dim, sizeof(int), 3, fp);
	}
    }
    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d ... ", nz+1);
            fflush (stdout);
            compute_solution (nz);
            if (whole) {
                np = (int)Zones[nz].nverts;
                nk = 1;
            }
            else {
                np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
                nk = (int)Zones[nz].dim[2];
            }
            if (use_double) {
                fwrite (reference, sizeof(double), 4, fp);
                for (k = 0; k < nk; k++) {
                    for (i = 0; i < 5; i++)
                        fwrite (&q[i][k*np], sizeof(double), np, fp);
                }
            }
            else {
                 for (n = 0; n < 4; n++)
                     qf[n] = (float)reference[n];
                fwrite (qf, sizeof(float), 4, fp);
                for (k = 0; k < nk; k++) {
                    for (i = 0; i < 5; i++) {
                        j = k * np;
                        for (n = 0; n < np; n++, j++) {
                            qf[0] = (float)q[i][j];
                            fwrite (qf, sizeof(float), 1, fp);
                        }
                    }
                }
            }
            puts ("done");
        }
    }
    fclose (fp);
}
static void write_q_unformatted (char *qfile)
{
    int np, nk, nz, nq, ierr;
    int i, j, k, n, *indices;
    char buff[129];
    void *qdata;
    float *qf = 0;
    double *qd = 0;

    printf ("\nwriting unformatted Q file to %s\n", qfile);
    printf ("  in %s-precision\n", use_double ? "double" : "single");

    for (np = 0, nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            nk = whole ? (int)Zones[nz].nverts :
                (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
            if (np < nk) np = nk;
        }
    }
    indices = (int *) malloc (3 * nblocks * sizeof(int));
    if (use_double) {
        qdata = (void *) malloc (5 * np * sizeof(double));
        qd = (double *)qdata;
    }
    else {
        qdata = (void *) malloc (5 * np * sizeof(float));
        qf = (float *)qdata;
    }
    if (NULL == indices || NULL == qdata)
        FATAL ("write_q_unformatted", "malloc failed for working arrays");

    unlink (qfile);
    strcpy (buff, qfile);
    for (n = (int)strlen(buff); n < 128; n++)
        buff[n] = ' ';
    buff[128] = 0;
    n = 0;
    OPENF (&n, buff, 128);

    if (mblock || nblocks > 1) {
        n = 1;
        WRITEIF (&n, &nblocks, &ierr);
    }
    for (np = 0, nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            for (n = 0; n < 3; n++)
                indices[np++] = (int)Zones[nz].dim[n];
        }
    }
    WRITEIF (&np, indices, &ierr);

    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].type == CGNS_ENUMV(Structured)) {
            printf ("  zone %d ... ", nz+1);
            fflush (stdout);
            compute_solution (nz);
            if (whole) {
                np = (int)Zones[nz].nverts;
                nk = 1;
            }
            else {
                np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
                nk = (int)Zones[nz].dim[2];
            }
            if (use_double) {
                n = 4;
                WRITEDF (&n, reference, &ierr);
                for (k = 0; k < nk; k++) {
                    for (nq = 0, j = 0; j < 5; j++) {
                        i = k * np;
                        for (n = 0; n < np; n++, i++)
                            qd[nq++] = q[j][i];
                    }
                    WRITEDF (&nq, qd, &ierr);
                }
            }
            else {
                for (n = 0; n < 4; n++)
                    qf[n] = (float)reference[n];
                WRITEFF (&n, qf, &ierr);
                for (k = 0; k < nk; k++) {
                    for (nq = 0, j = 0; j < 5; j++) {
                        i = k * np;
                        for (n = 0; n < np; n++, i++)
                            qf[nq++] = (float)q[j][i];
                    }
                    WRITEFF (&nq, qf, &ierr);
                }
            }
            puts ("done");
        }
    }
    CLOSEF ();
    free (indices);
    free (qdata);
}
int main (int argc, char *argv[])
{
    int i, n, ib, nb, nz, nv, celldim, phydim;
    int nn, type, *elems = 0, idata[5];
    cgsize_t ne;
    char *p, basename[33], title[65];
    float value, *var;
    SOLUTION *sol;
    FILE *fp;

    if (argc < 2)
        print_usage (usgmsg, NULL);

    ib = 0;
    basename[0] = 0;
    while ((n = getargs (argc, argv, options)) > 0) {
        switch (n) {
            case 'a':
                ascii = 1;
                break;
            case 'b':
                ib = atoi (argarg);
                break;
            case 'B':
                strncpy (basename, argarg, 32);
                basename[32] = 0;
                break;
            case 'w':
                weighting = 1;
                break;
            case 'S':
                usesol = atoi (argarg);
                break;
        }
    }

    if (argind > argc - 2)
        print_usage (usgmsg, "CGNSfile and/or Tecplotfile not given");
    if (!file_exists (argv[argind]))
        FATAL (NULL, "CGNSfile does not exist or is not a file");

    /* open CGNS file */

    printf ("reading CGNS file from %s\n", argv[argind]);
    nb = open_cgns (argv[argind], 1);
    if (!nb)
        FATAL (NULL, "no bases found in CGNS file");
    if (*basename && 0 == (ib = find_base (basename)))
        FATAL (NULL, "specified base not found");
    if (ib > nb) FATAL (NULL, "base index out of range");
    cgnsbase = ib ? ib : 1;
    if (cg_base_read (cgnsfn, cgnsbase, basename, &celldim, &phydim))
        FATAL (NULL, NULL);
    if (celldim != 3 || phydim != 3)
        FATAL (NULL, "cell and physical dimension must be 3");
    printf ("  using base %d - %s\n", cgnsbase, basename);

    if (NULL == (p = strrchr (argv[argind], '/')) &&
        NULL == (p = strrchr (argv[argind], '\\')))
        strncpy (title, argv[argind], sizeof(title));
    else
        strncpy (title, ++p, sizeof(title));
    title[sizeof(title)-1] = 0;
    if ((p = strrchr (title, '.')) != NULL)
        *p = 0;

    read_zones ();
    if (!nZones)
        FATAL (NULL, "no zones in the CGNS file");
    
    /* verify dimensions fit in an integer */

    for (nz = 0; nz < nZones; nz++) {
        if (Zones[nz].nverts > CG_MAX_INT32)
	    FATAL(NULL, "zone size too large to write with integers");
	if (Zones[nz].type == CGNS_ENUMV(Unstructured)) {
            count_elements (nz, &ne, &type);
            if (ne > CG_MAX_INT32)
	        FATAL(NULL, "too many elements to write with integers");
        }
     }

    nv = 3 + check_solution ();

    /* open Tecplot file */

    printf ("writing %s Tecplot data to <%s>\n",
        ascii ? "ASCII" : "binary", argv[++argind]);
    if (NULL == (fp = fopen (argv[argind], ascii ? "w+" : "w+b")))
        FATAL (NULL, "couldn't open Tecplot output file");

    /* write file header */

    if (ascii)
        fprintf (fp, "TITLE = \"%s\"\n", title);
    else {
        fwrite ("#!TDV75 ", 1, 8, fp);
        i = 1;
        write_ints (fp, 1, &i);
        write_string (fp, title);
    }

    /* write variables */

    if (ascii) {
        fprintf (fp, "VARIABLES = \"X\", \"Y\", \"Z\"");
        if (usesol) {
            sol = Zones->sols;
            for (n = 0; n < sol->nflds; n++)
                fprintf (fp, ",\n\"%s\"", sol->flds[n].name);
        }
    }
    else {
        write_ints (fp, 1, &nv);
        write_string (fp, "X");
        write_string (fp, "Y");
        write_string (fp, "Z");
        if (usesol) {
            sol = Zones->sols;
            for (n = 0; n < sol->nflds; n++)
                write_string (fp, sol->flds[n].name);
        }
    }

    /* write zones */

    if (!ascii) {
        for (nz = 0; nz < nZones; nz++) {
            if (Zones[nz].type == CGNS_ENUMV(Structured)) {
                idata[0] = 0;          /* BLOCK */
                idata[1] = -1;         /* color not specified */
                idata[2] = (int)Zones[nz].dim[0];
                idata[3] = (int)Zones[nz].dim[1];
                idata[4] = (int)Zones[nz].dim[2];
            }
            else {
                count_elements (nz, &ne, &type);
                idata[0] = 2;          /* FEBLOCK */
                idata[1] = -1;         /* color not specified */
                idata[2] = (int)Zones[nz].dim[0];
                idata[3] = (int)ne;
                idata[4] = type;
            }
            value = 299.0;
            write_floats (fp, 1, &value);
            write_string (fp, Zones[nz].name);
            write_ints (fp, 5, idata);
        }
        value = 357.0;
        write_floats (fp, 1, &value);
    }

    for (nz = 0; nz < nZones; nz++) {
        printf ("  zone %d...", nz+1);
        fflush (stdout);
        read_zone_grid (nz+1);
        ne = 0;
        type = 2;
        nn = (int)Zones[nz].nverts;
        var = (float *) malloc (nn * sizeof(float));
        if (NULL == var)
            FATAL (NULL, "malloc failed for temp float array");
        if (Zones[nz].type == CGNS_ENUMV(Unstructured))
            elems = volume_elements (nz, &ne, &type);

        if (ascii) {
            if (Zones[nz].type == CGNS_ENUMV(Structured))
                fprintf (fp, "\nZONE T=\"%s\", I=%d, J=%d, K=%d, F=BLOCK\n",
                    Zones[nz].name, (int)Zones[nz].dim[0],
                    (int)Zones[nz].dim[1], (int)Zones[nz].dim[2]);
            else
                fprintf (fp, "\nZONE T=\"%s\", N=%d, E=%d, F=FEBLOCK, ET=%s\n",
                    Zones[nz].name, nn, (int)ne, type == 2 ? "TETRAHEDRON" : "BRICK");
        }
        else {
            value = 299.0;
            write_floats (fp, 1, &value);
            i = 0;
            write_ints (fp, 1, &i);
            i = 1;
            for (n = 0; n < nv; n++)
                write_ints (fp, 1, &i);
        }

        for (n = 0; n < nn; n++)
            var[n] = (float)Zones[nz].verts[n].x;
        write_floats (fp, nn, var);
        for (n = 0; n < nn; n++)
            var[n] = (float)Zones[nz].verts[n].y;
        write_floats (fp, nn, var);
        for (n = 0; n < nn; n++)
            var[n] = (float)Zones[nz].verts[n].z;
        write_floats (fp, nn, var);

        if (usesol) {
            read_solution_field (nz+1, usesol, 0);
            sol = &Zones[nz].sols[usesol-1];
            if (sol->location != CGNS_ENUMV(Vertex))
                cell_vertex_solution (nz+1, usesol, weighting);
            for (nv = 0; nv < sol->nflds; nv++) {
                for (n = 0; n < nn; n++)
                    var[n] = (float)sol->flds[nv].data[n];
                write_floats (fp, nn, var);
            }
        }

        free (var);

        if (Zones[nz].type == CGNS_ENUMV(Unstructured)) {
            if (!ascii) {
                i = 0;
                write_ints (fp, 1, &i);
            }
            nn = 1 << type;
            for (i = 0, n = 0; n < ne; n++, i += nn)
                write_ints (fp, nn, &elems[i]);
            free (elems);
        }
        puts ("done");
    }

    fclose (fp);
    cg_close (cgnsfn);
    return 0;
}
static void read_xyz (BINARYIO *bf)
{
    int i, k, n, nk, nz, np, nmax;
    int *indices, *iblank;
    void *xyz;
    VERTEX *verts;

    /* get number of grid blocks */

    if (mblock) {
        bf_getints (bf, 1, &nZones);
        if (nZones < 1 || nZones > 100000) {
            fprintf (stderr, "found %d blocks\n", nZones);
            fprintf (stderr, "file type and/or format is probably incorrect\n");
            bf_close (bf);
            exit (1);
        }
    }
    else
        nZones = 1;
    printf ("reading %d grid blocks\n", nZones);

    /* read indices for grids */

    indices = (int *) malloc (3 * nZones * sizeof(int));
    if (NULL == indices)
        FATAL ("read_xyz", "malloc failed for grid indices");
    bf_getints (bf, 3 * nZones, indices);

    /* create zone structures */

    Zones = new_zone (nZones);
    for (nmax = 0, nz = 0; nz < nZones; nz++) {
        Zones[nz].type = CGNS_ENUMV(Structured);
        for (np = 1, n = 0; n < 3; n++) {
            nk = indices[3 * nz + n];
            Zones[nz].dim[n] = nk;
            np *= nk;
        }
        Zones[nz].vertflags = 7;
        Zones[nz].datatype = is_double ? CGNS_ENUMV(RealDouble) : CGNS_ENUMV(RealSingle);
        Zones[nz].nverts = np;
        Zones[nz].verts = new_vertex (np);
        nk = whole ? (int)Zones[nz].nverts : (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
        if (nmax < nk) nmax = nk;
    }

    free (indices);

    if (is_double)
        xyz = (void *) malloc (3 * nmax * sizeof(double));
    else
        xyz = (void *) malloc (3 * nmax * sizeof(float));
    if (NULL == xyz)
        FATAL ("read_xyz", "malloc failed for coordinate working array");
    if (has_iblank) {
        iblank = (int *) malloc (nmax * sizeof(int));
        if (NULL == iblank)
            FATAL ("read_xyz", "malloc failed for iblank array");
    }
    else
        use_iblank = 0;

    /* read the grid blocks */

    for (nz = 0; nz < nZones; nz++) {
        printf ("reading block %d grid %dx%dx%d ...", nz+1,
            (int)Zones[nz].dim[0], (int)Zones[nz].dim[1],
            (int)Zones[nz].dim[2]);
        fflush (stdout);
        if (whole) {
            np = (int)Zones[nz].nverts;
            nk = 1;
        }
        else {
            np = (int)(Zones[nz].dim[0] * Zones[nz].dim[1]);
            nk = (int)Zones[nz].dim[2];
        }
        verts = Zones[nz].verts;
        for (k = 0; k < nk; k++) {
            if (is_double)
                bf_getdoubles (bf, 3 * np, xyz);
            else
                bf_getfloats (bf, 3 * np, xyz);
            if (has_iblank)
                bf_getints (bf, np, iblank);
            if (is_double) {
                for (i = 0, n = 0; n < np; n++, i++)
                    verts[n].x = ((double *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].y = ((double *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].z = ((double *)xyz)[i];
            }
            else {
                for (i = 0, n = 0; n < np; n++, i++)
                    verts[n].x = ((float *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].y = ((float *)xyz)[i];
                for (n = 0; n < np; n++, i++)
                    verts[n].z = ((float *)xyz)[i];
            }
            for (n = 0; n < np; n++, verts++)
                verts->id = use_iblank ? iblank[n] : 1;
        }
        puts (" done");
    }

    free (xyz);
    if (has_iblank) free (iblank);
}