HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WriteTecplot3D.c
Go to the documentation of this file.
1 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <basic.h>
9 #include <arrayfunctions.h>
10 
20  int ndims,
21  int nvars,
22  int *dim,
24  double *x,
26  double *u,
28  char *f,
29  int *index
30  )
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 _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
int WriteTecplot3D(int, int, int *, double *, double *, char *, int *)
Some basic definitions and macros.
Contains macros and function definitions for common array operations.