HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WriteTecplot2D.c File Reference

Write a vector field and its grid to a 2D 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 WriteTecplot2D (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 2D Tecplot file.

Author
Debojyoti Ghosh

Definition in file WriteTecplot2D.c.

Function Documentation

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

Write a vector field and its associated grid to a 2D 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 WriteTecplot2D.c.

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 }
#define _ArraySetValue_(x, size, value)
#define _ArrayIncrementIndex_(N, imax, i, done)
#define _ArrayIndex1D_(N, imax, i, ghost, index)