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; }
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; }
/*---------- PostProcesssing -------------------------------------- * Post-Analysis of CFD Data * Developed only for CFD-Tutor with single base - single zone 2D * -------------------------------------------------------------*/ int PostProcessing(const char *file) { int visual; int nbases, ncoords, celldim, phydim; char basename[33]; ZONE *z; int i, j, nz; SOLUTION *s; /* Checks for existance of file */ if (!file_exists(file)) FATAL(NULL, "File does not exist"); /* Read CGNS file */ printf("Reading CGNS file from %s\n", file); fflush(stdout); /* Open CGNS File */ nbases = open_cgns(file, 0); if (!nbases) FATAL(NULL, "No bases in CGNS file"); cg_version(cgnsfn, &Version); printf("File version = %lf\n", Version); printf("No of Bases = %d\n", nbases); if (nbases == 1) cgnsbase = 1; else { printf("Give base No to Post-Processed : "); scanf("%d", &cgnsbase); if (cgnsbase < 1 || cgnsbase > nbases) FATAL(NULL, "Invailed base index"); } if (cg_base_read(cgnsfn, cgnsbase, basename, &celldim, &phydim) || cg_nzones(cgnsfn, cgnsbase, &nZones)) FATAL(NULL, NULL); if (celldim != 2 || phydim != 2) FATAL(NULL, "Not A 2D Grid"); if (nZones > 1) FATAL(NULL, "Not A Single Zone"); printf("Base Number = %d\n", cgnsbase); printf("Base Name = %s\n", basename); printf("Cell Dimension = %d\n", celldim); printf("Physical Dimension = %d\n", phydim); read_cgns(); printf("No of Zones = %d\n", nZones); /* Print Zone Information */ for (z = Zones, nz = 1; nz <= nZones; nz++, z++) { printf("Zone No = %d\n", z->id); printf("Zone Name = %s\n", z->name); if (cg_ncoords(cgnsfn, cgnsbase, nz, &ncoords)) FATAL("Post-Processing ncoords", NULL); if (ncoords != 2) FATAL(NULL, "No 3D Support Now"); print_ZoneType(z->type); switch (z->type) { case 2: /* For Structured Grid */ printf("Dimensions = %d x %d x %d\n", z->dim[0], z->dim[1], z->dim[2]); break; case 3: /* For Unstructured Grid */ printf("No of Nodes = %d\n", z->dim[0]); printf("No of Cells = %d\n", z->dim[1]); break; default: /* Unknown Type Grids */ FATAL(NULL, "Unknown Grid Type"); } } /* Print Available Solution Fields */ for (z = Zones, nz = 1; nz <= nZones; nz++, z++) { if (z->nsols) { printf("No of Solutions Nodes = %d\n", z->nsols); for (s = z->sols, i = 1; i <= z->nsols; i++, s++) { printf("Solution Node = %d\n", i); if (s->nflds == 0) FATAL(NULL, "No Solution Fields: Exiting"); printf("\tNo of Fields = %d\n", s->nflds); for (j = 0; j < s->nflds; j++) { printf("\tField = %s\n", s->flds[j].name); } } } else FATAL(NULL, "No Solution Node Available: Exiting"); } /* Initialize Data Structure Only Once */ for (z = Zones, nz = 1; nz <= nZones; nz++, z++) InitializeGrid_2D(z); /* Do Post-Processing Operation Below */ /*****************/ /* Post Analysis Function Calls */ for (z = Zones, nz = 1; nz <= nZones; nz++, z++) { InitializeSolutionCGNS_2D(z); InitializeSolution_2D(); GetSolutionList_2D(); /* Visual Mode Option */ printf("Goto Visual Mode (0/1):"); scanf("%d", &visual); if (visual == 1) Graphics_2D(); else { GetFluidProperties(); GetReferenceQuantities(); PostAnalysis_2D(); } } /*****************/ /* Do Post-Processing Operation Above */ /* Close cgns Interface */ if (cg_close(cgnsfn)) FATAL(NULL, NULL); return 0; }
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; }