HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
WriteTecplot2D.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 !=2) {
33  fprintf(stderr,"Error in WriteTecplot2D(): This functions is hardcoded for 2-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 
41  FILE *out;
42  out = fopen(f,"w");
43  if (!out) {
44  fprintf(stderr,"Error: could not open %s for writing.\n",f);
45  return(1);
46  }
47 
48  /* writing tecplot data file headers */
49  fprintf(out,"VARIABLES=\"I\",\"J\",\"X\",\"Y\",");
50  char varname[3] = "00";
51  for (i = 0; i < nvars; i++) {
52  fprintf(out,"\"%s\",",varname);
53  if (varname[1] == '9') { varname[0]++; varname[1] = '0'; }
54  else varname[1]++;
55  }
56  fprintf(out,"\n");
57  fprintf(out,"ZONE I=%d,J=%d,F=POINT\n",imax,jmax);
58 
59  /* writing the data */
60  int done = 0; _ArraySetValue_(index,ndims,0);
61  while (!done) {
62  int i, p;
63  _ArrayIndex1D_(ndims,dim,index,0,p);
64  for (i=0; i<ndims; i++) fprintf(out,"%4d ",index[i]);
65  for (i=0; i<ndims; i++) {
66  int j,offset = 0; for (j=0; j<i; j++) offset += dim[j];
67  fprintf(out,"%+1.16E ",x[offset+index[i]]);
68  }
69  for (i=0; i<nvars; i++) fprintf(out,"%+1.16E ",u[nvars*p+i]);
70  fprintf(out,"\n");
71  _ArrayIncrementIndex_(ndims,dim,index,done);
72  }
73  fclose(out);
74  return(0);
75 }
Some basic definitions and macros.
int WriteTecplot2D(int ndims, int nvars, int *dim, double *x, double *u, char *f, int *index)
#define _ArrayIndex1D_(N, imax, i, ghost, index)
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
Contains macros and function definitions for common array operations.