HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
WriteTecplot3D.c File Reference

Write a vector field and its grid to a 3D Tecplot file. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>

Go to the source code of this file.

Functions

int WriteTecplot3D (int ndims, int nvars, int *dim, double *x, double *u, char *f, int *index)
 

Detailed Description

Write a vector field and its grid to a 3D Tecplot file.

Author
Debojyoti Ghosh

Definition in file WriteTecplot3D.c.

Function Documentation

◆ WriteTecplot3D()

int WriteTecplot3D ( int  ndims,
int  nvars,
int *  dim,
double *  x,
double *  u,
char *  f,
int *  index 
)

Write a vector field and its associated grid to a 3D Tecplot file. This file can then be visualized using Tecplot (http://www.tecplot.org) (if available)

Note: It's essentially a text file, and apart from the first two lines with Tecplot specific headers, the data is written out in the same format as WriteText().

Parameters
ndimsNumber of spatial dimensions
nvarsNumber of variables at each grid point
dimInteger array with the number of grid points in each spatial dimension as its entries
xArray of spatial coordinates representing a Cartesian grid (no ghost points)
uArray containing the vector field to write (no ghost points)
fFilename
indexPreallocated integer array of size ndims

Definition at line 19 of file WriteTecplot3D.c.

31 {
32  if (ndims !=3) {
33  fprintf(stderr,"Error in WriteTecplot3D(): This functions is hardcoded for 3-dimensional ");
34  fprintf(stderr,"problems only. Instead, ndims=%d.\n",ndims);
35  return(1);
36  }
37  int i;
38  int imax = dim[0];
39  int jmax = dim[1];
40  int kmax = dim[2];
41 
42  FILE *out;
43  out = fopen(f,"w");
44  if (!out) {
45  fprintf(stderr,"Error: could not open %s for writing.\n",f);
46  return(1);
47  }
48 
49  /* writing tecplot data file headers */
50  fprintf(out,"VARIABLES=\"I\",\"J\",\"K\",\"X\",\"Y\",\"Z\",");
51  char varname[3] = "00";
52  for (i = 0; i < nvars; i++) {
53  fprintf(out,"\"%s\",",varname);
54  if (varname[1] == '9') { varname[0]++; varname[1] = '0'; }
55  else varname[1]++;
56  }
57  fprintf(out,"\n");
58  fprintf(out,"ZONE I=%d,J=%d,K=%d,F=POINT\n",imax,jmax,kmax);
59 
60  /* writing the data */
61  int done = 0; _ArraySetValue_(index,ndims,0);
62  while (!done) {
63  int i, p;
64  _ArrayIndex1D_(ndims,dim,index,0,p);
65  for (i=0; i<ndims; i++) fprintf(out,"%4d ",index[i]);
66  for (i=0; i<ndims; i++) {
67  int j,offset = 0; for (j=0; j<i; j++) offset += dim[j];
68  fprintf(out,"%+1.16E ",x[offset+index[i]]);
69  }
70  for (i=0; i<nvars; i++) fprintf(out,"%+1.16E ",u[nvars*p+i]);
71  fprintf(out,"\n");
72  _ArrayIncrementIndex_(ndims,dim,index,done);
73  }
74  fclose(out);
75  return(0);
76 }
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)