VTK  9.1.0
vtkXMLWriterF.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkXMLWriterF.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
15#ifndef vtkXMLWriterF_h
16#define vtkXMLWriterF_h
17/*
18 * vtkXMLWriterF.h helps fortran programs call the C interface for
19 * writing VTK XML files. A program can use this by writing one
20 * vtkXMLWriterF.c file that includes this header. DO NOT INCLUDE
21 * THIS HEADER ELSEWHERE. The fortran program then compiles
22 * vtkXMLWriterF.c using a C compiler and links to the resulting
23 * object file.
24 */
25
26#if defined(__cplusplus)
27#error "This should be included only by a .c file."
28#endif
29
30/* Calls will be forwarded to the C interface. */
31#include "vtkXMLWriterC.h"
32
33#include <stdio.h> /* fprintf */
34#include <stdlib.h> /* malloc, free */
35#include <string.h> /* memcpy */
36
37/* Define a static-storage default-zero-initialized table to store
38 writer objects for the fortran program. */
39#define VTK_XMLWRITERF_MAX 256
41
42/* Fortran compilers expect certain symbol names for their calls to C
43 code. These macros help build the C symbols so that the fortran
44 program can link to them properly. The definitions here are
45 reasonable defaults but the source file that includes this can
46 define them appropriately for a particular compiler and override
47 these. */
48#if !defined(VTK_FORTRAN_NAME)
49#define VTK_FORTRAN_NAME(name, NAME) name##__
50#endif
51#if !defined(VTK_FORTRAN_ARG_STRING_POINTER)
52#define VTK_FORTRAN_ARG_STRING_POINTER(name) const char* name##_ptr_arg
53#endif
54#if !defined(VTK_FORTRAN_ARG_STRING_LENGTH)
55#define VTK_FORTRAN_ARG_STRING_LENGTH(name) , const long int name##_len_arg
56#endif
57#if !defined(VTK_FORTRAN_REF_STRING_POINTER)
58#define VTK_FORTRAN_REF_STRING_POINTER(name) name##_ptr_arg
59#endif
60#if !defined(VTK_FORTRAN_REF_STRING_LENGTH)
61#define VTK_FORTRAN_REF_STRING_LENGTH(name) ((int)name##_len_arg)
62#endif
63
64/*--------------------------------------------------------------------------*/
65/* vtkXMLWriterF_New */
66void VTK_FORTRAN_NAME(vtkxmlwriterf_new, VTKXMLWRITERF_NEW)(int* self)
67{
68 int i;
69
70 /* Initialize result to failure. */
71 *self = 0;
72
73 /* Search for a table entry to use for this object. */
74 for (i = 1; i <= VTK_XMLWRITERF_MAX; ++i)
75 {
76 if (!vtkXMLWriterF_Table[i])
77 {
80 {
81 *self = i;
82 }
83 return;
84 }
85 }
86}
87
88/*--------------------------------------------------------------------------*/
89/* vtkXMLWriterF_Delete */
90void VTK_FORTRAN_NAME(vtkxmlwriterf_delete, VTKXMLWRITERF_DELETE)(int* self)
91{
92 /* Check if the writer object exists. */
93 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
94 {
95 /* Delete this writer object. */
97
98 /* Erase the table entry. */
99 vtkXMLWriterF_Table[*self] = 0;
100 }
101 else
102 {
103 fprintf(stderr, "vtkXMLWriterF_Delete called with invalid id %d.\n", *self);
104 }
105
106 /* The writer object no longer exists. Destroy the id. */
107 *self = 0;
108}
109
110/*--------------------------------------------------------------------------*/
111/* vtkXMLWriterF_SetDataModeType */
112void VTK_FORTRAN_NAME(vtkxmlwriterf_setdatamodetype, VTKXMLWRITERF_SETDATAMODETYPE)(
113 const int* self, const int* objType)
114{
115 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
116 {
118 }
119 else
120 {
121 fprintf(stderr, "vtkXMLWriterF_SetDataModeType called with invalid id %d.\n", *self);
122 }
123}
124
125/*--------------------------------------------------------------------------*/
126/* vtkXMLWriterF_SetDataObjectType */
127void VTK_FORTRAN_NAME(vtkxmlwriterf_setdataobjecttype, VTKXMLWRITERF_SETDATAOBJECTTYPE)(
128 const int* self, const int* objType)
129{
130 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
131 {
133 }
134 else
135 {
136 fprintf(stderr, "vtkXMLWriterF_SetDataObjectType called with invalid id %d.\n", *self);
137 }
138}
139
140/*--------------------------------------------------------------------------*/
141/* vtkXMLWriterF_SetExtent */
142void VTK_FORTRAN_NAME(vtkxmlwriterf_setextent, VTKXMLWRITERF_SETEXTENT)(
143 const int* self, int extent[6])
144{
145 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
146 {
148 }
149 else
150 {
151 fprintf(stderr, "vtkXMLWriterF_SetExtent called with invalid id %d.\n", *self);
152 }
153}
154
155/*--------------------------------------------------------------------------*/
156/* vtkXMLWriterF_SetPoints */
157void VTK_FORTRAN_NAME(vtkxmlwriterf_setpoints, VTKXMLWRITERF_SETPOINTS)(
158 const int* self, const int* dataType, void* data, const vtkIdType* numPoints)
159{
160 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
161 {
162 vtkXMLWriterC_SetPoints(vtkXMLWriterF_Table[*self], *dataType, data, *numPoints);
163 }
164 else
165 {
166 fprintf(stderr, "vtkXMLWriterF_SetPoints called with invalid id %d.\n", *self);
167 }
168}
169
170/*--------------------------------------------------------------------------*/
171/* vtkXMLWriterF_SetOrigin */
172void VTK_FORTRAN_NAME(vtkxmlwriterf_setorigin, VTKXMLWRITERF_SETORIGIN)(
173 const int* self, double origin[3])
174{
175 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
176 {
178 }
179 else
180 {
181 fprintf(stderr, "vtkXMLWriterF_SetOrigin called with invalid id %d.\n", *self);
182 }
183}
184
185/*--------------------------------------------------------------------------*/
186/* vtkXMLWriterF_SetSpacing */
187void VTK_FORTRAN_NAME(vtkxmlwriterf_setspacing, VTKXMLWRITERF_SETSPACING)(
188 const int* self, double spacing[3])
189{
190 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
191 {
193 }
194 else
195 {
196 fprintf(stderr, "vtkXMLWriterF_SetSpacing called with invalid id %d.\n", *self);
197 }
198}
199
200/*--------------------------------------------------------------------------*/
201/* vtkXMLWriterF_SetCoordinates */
202void VTK_FORTRAN_NAME(vtkxmlwriterf_setcoordinates, VTKXMLWRITERF_SETCOORDINATES)(const int* self,
203 const int* axis, const int* dataType, void* data, const vtkIdType* numCoordinates)
204{
205 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
206 {
208 vtkXMLWriterF_Table[*self], *axis, *dataType, data, *numCoordinates);
209 }
210 else
211 {
212 fprintf(stderr, "vtkXMLWriterF_SetCoordinates called with invalid id %d.\n", *self);
213 }
214}
215
216/*--------------------------------------------------------------------------*/
217/* vtkXMLWriterF_SetCellsWithType */
218void VTK_FORTRAN_NAME(vtkxmlwriterf_setcellswithtype, VTKXMLWRITERF_SETCELLSWITHTYPE)(
219 const int* self, const int* cellType, const vtkIdType* ncells, vtkIdType* cells,
220 const vtkIdType* cellsSize)
221{
222 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
223 {
225 vtkXMLWriterF_Table[*self], *cellType, *ncells, cells, *cellsSize);
226 }
227 else
228 {
229 fprintf(stderr, "vtkXMLWriterF_SetCellsWithType called with invalid id %d.\n", *self);
230 }
231}
232
233/*--------------------------------------------------------------------------*/
234/* vtkXMLWriterF_SetCellsWithTypes */
235void VTK_FORTRAN_NAME(vtkxmlwriterf_setcellswithtypes, VTKXMLWRITERF_SETCELLSWITHTYPES)(
236 const int* self, int* cellTypes, const vtkIdType* ncells, vtkIdType* cells,
237 const vtkIdType* cellsSize)
238{
239 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
240 {
242 vtkXMLWriterF_Table[*self], cellTypes, *ncells, cells, *cellsSize);
243 }
244 else
245 {
246 fprintf(stderr, "vtkXMLWriterF_SetCellsWithTypes called with invalid id %d.\n", *self);
247 }
248}
249
250/*--------------------------------------------------------------------------*/
251/* vtkXMLWriterF_SetPointData */
252void VTK_FORTRAN_NAME(vtkxmlwriterf_setpointdata, VTKXMLWRITERF_SETPOINTDATA)(const int* self,
253 VTK_FORTRAN_ARG_STRING_POINTER(name), const int* dataType, void* data, const vtkIdType* numTuples,
254 const int* numComponents,
257{
258 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
259 {
260 /* Prepare nullptr-terminated strings. */
261 const char* name_ptr = VTK_FORTRAN_REF_STRING_POINTER(name);
262 int name_length = VTK_FORTRAN_REF_STRING_LENGTH(name);
263 char* name_buffer = malloc(name_length + 1);
264 const char* role_ptr = VTK_FORTRAN_REF_STRING_POINTER(role);
265 int role_length = VTK_FORTRAN_REF_STRING_LENGTH(role);
266 char* role_buffer = malloc(role_length + 1);
267 if (!name_buffer || !role_buffer)
268 {
269 fprintf(stderr, "vtkXMLWriterF_SetPointData failed to allocate name or role.\n");
270 if (name_buffer)
271 {
272 free(name_buffer);
273 }
274 if (role_buffer)
275 {
276 free(role_buffer);
277 }
278 return;
279 }
280 memcpy(name_buffer, name_ptr, name_length);
281 name_buffer[name_length] = 0;
282 memcpy(role_buffer, role_ptr, role_length);
283 role_buffer[role_length] = 0;
284
285 /* Forward the call. */
286 vtkXMLWriterC_SetPointData(vtkXMLWriterF_Table[*self], name_buffer, *dataType, data, *numTuples,
287 *numComponents, role_buffer);
288
289 /* Free the nullptr-terminated strings. */
290 free(name_buffer);
291 free(role_buffer);
292 }
293 else
294 {
295 fprintf(stderr, "vtkXMLWriterF_SetPointData called with invalid id %d.\n", *self);
296 }
297}
298
299/*--------------------------------------------------------------------------*/
300/* vtkXMLWriterF_SetCellData */
301void VTK_FORTRAN_NAME(vtkxmlwriterf_setcelldata, VTKXMLWRITERF_SETCELLDATA)(const int* self,
302 VTK_FORTRAN_ARG_STRING_POINTER(name), const int* dataType, void* data, const vtkIdType* numTuples,
303 const int* numComponents,
306{
307 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
308 {
309 /* Prepare nullptr-terminated strings. */
310 const char* name_ptr = VTK_FORTRAN_REF_STRING_POINTER(name);
311 int name_length = VTK_FORTRAN_REF_STRING_LENGTH(name);
312 char* name_buffer = malloc(name_length + 1);
313 const char* role_ptr = VTK_FORTRAN_REF_STRING_POINTER(role);
314 int role_length = VTK_FORTRAN_REF_STRING_LENGTH(role);
315 char* role_buffer = malloc(role_length + 1);
316 if (!name_buffer || !role_buffer)
317 {
318 fprintf(stderr, "vtkXMLWriterF_SetCellData failed to allocate name or role.\n");
319 if (name_buffer)
320 {
321 free(name_buffer);
322 }
323 if (role_buffer)
324 {
325 free(role_buffer);
326 }
327 return;
328 }
329 memcpy(name_buffer, name_ptr, name_length);
330 name_buffer[name_length] = 0;
331 memcpy(role_buffer, role_ptr, role_length);
332 role_buffer[role_length] = 0;
333
334 /* Forward the call. */
335 vtkXMLWriterC_SetCellData(vtkXMLWriterF_Table[*self], name_buffer, *dataType, data, *numTuples,
336 *numComponents, role_buffer);
337
338 /* Free the nullptr-terminated strings. */
339 free(name_buffer);
340 free(role_buffer);
341 }
342 else
343 {
344 fprintf(stderr, "vtkXMLWriterF_SetCellData called with invalid id %d.\n", *self);
345 }
346}
347
348/*--------------------------------------------------------------------------*/
349/* vtkXMLWriterF_SetFileName */
350void VTK_FORTRAN_NAME(vtkxmlwriterf_setfilename, VTKXMLWRITERF_SETFILENAME)(
352{
353 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
354 {
355 /* Prepare nullptr-terminated string. */
356 const char* name_ptr = VTK_FORTRAN_REF_STRING_POINTER(name);
357 int name_length = VTK_FORTRAN_REF_STRING_LENGTH(name);
358 char* name_buffer = malloc(name_length + 1);
359 if (!name_buffer)
360 {
361 fprintf(stderr, "vtkXMLWriterF_SetFileName failed to allocate name.\n");
362 return;
363 }
364 memcpy(name_buffer, name_ptr, name_length);
365 name_buffer[name_length] = 0;
366
367 /* Forward the call. */
369
370 /* Free the nullptr-terminated string. */
371 free(name_buffer);
372 }
373 else
374 {
375 fprintf(stderr, "vtkXMLWriterF_SetFileName called with invalid id %d.\n", *self);
376 }
377}
378
379/*--------------------------------------------------------------------------*/
380/* vtkXMLWriterF_Write */
381void VTK_FORTRAN_NAME(vtkxmlwriterf_write, VTKXMLWRITERF_WRITE)(const int* self, int* success)
382{
383 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
384 {
385 *success = vtkXMLWriterC_Write(vtkXMLWriterF_Table[*self]);
386 }
387 else
388 {
389 fprintf(stderr, "vtkXMLWriterF_Write called with invalid id %d.\n", *self);
390 }
391}
392
393/*--------------------------------------------------------------------------*/
394/* vtkXMLWriterF_SetNumberOfTimeSteps */
395void VTK_FORTRAN_NAME(vtkxmlwriterf_setnumberoftimesteps, VTKXMLWRITERF_SETNUMBEROFTIMESTEPS)(
396 const int* self, const int* numTimeSteps)
397{
398 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
399 {
401 }
402 else
403 {
404 fprintf(stderr, "vtkXMLWriterF_SetNumberOfTimeSteps called with invalid id %d.\n", *self);
405 }
406}
407
408/*--------------------------------------------------------------------------*/
409/* vtkXMLWriterF_Start */
410void VTK_FORTRAN_NAME(vtkxmlwriterf_start, VTKXMLWRITERF_START)(const int* self)
411{
412 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
413 {
415 }
416 else
417 {
418 fprintf(stderr, "vtkXMLWriterF_Start called with invalid id %d.\n", *self);
419 }
420}
421
422/*--------------------------------------------------------------------------*/
423/* vtkXMLWriterF_WriteNextTimeStep */
424void VTK_FORTRAN_NAME(vtkxmlwriterf_writenexttimestep, VTKXMLWRITERF_WRITENEXTTIMESTEP)(
425 const int* self, const double* timeValue)
426{
427 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
428 {
430 }
431 else
432 {
433 fprintf(stderr, "vtkXMLWriterF_WriteNextTimeStep called with invalid id %d.\n", *self);
434 }
435}
436
437/*--------------------------------------------------------------------------*/
438/* vtkXMLWriterF_Stop */
439void VTK_FORTRAN_NAME(vtkxmlwriterf_stop, VTKXMLWRITERF_STOP)(const int* self)
440{
441 if (*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self])
442 {
444 }
445 else
446 {
447 fprintf(stderr, "vtkXMLWriterF_Stop called with invalid id %d.\n", *self);
448 }
449}
450#endif
451// VTK-HeaderTest-Exclude: vtkXMLWriterF.h
@ extent
Definition: vtkX3D.h:351
@ spacing
Definition: vtkX3D.h:487
@ data
Definition: vtkX3D.h:321
int vtkIdType
Definition: vtkType.h:332
VTKIOXML_EXPORT void vtkXMLWriterC_SetDataModeType(vtkXMLWriterC *self, int datamodetype)
Set the VTK writer data mode to either:
VTKIOXML_EXPORT vtkXMLWriterC * vtkXMLWriterC_New(void)
Create a new instance of vtkXMLWriterC.
VTKIOXML_EXPORT void vtkXMLWriterC_SetExtent(vtkXMLWriterC *self, int extent[6])
Set the extent of a structured data set.
VTKIOXML_EXPORT void vtkXMLWriterC_SetCellsWithType(vtkXMLWriterC *self, int cellType, vtkIdType ncells, vtkIdType *cells, vtkIdType cellsSize)
Set a cell array on the data object to be written.
VTKIOXML_EXPORT void vtkXMLWriterC_SetCellsWithTypes(vtkXMLWriterC *self, int *cellTypes, vtkIdType ncells, vtkIdType *cells, vtkIdType cellsSize)
Set a cell array on the data object to be written.
VTKIOXML_EXPORT void vtkXMLWriterC_SetOrigin(vtkXMLWriterC *self, double origin[3])
Set the origin of an image data set.
VTKIOXML_EXPORT void vtkXMLWriterC_Stop(vtkXMLWriterC *self)
Stop writing a time-series to the output file.
VTKIOXML_EXPORT void vtkXMLWriterC_SetDataObjectType(vtkXMLWriterC *self, int objType)
Set the VTK data object type that will be written.
VTKIOXML_EXPORT void vtkXMLWriterC_Start(vtkXMLWriterC *self)
Start writing a time-series to the output file.
VTKIOXML_EXPORT void vtkXMLWriterC_SetCoordinates(vtkXMLWriterC *self, int axis, int dataType, void *data, vtkIdType numCoordinates)
Set the coordinates along one axis of a rectilinear grid data set.
VTKIOXML_EXPORT void vtkXMLWriterC_SetNumberOfTimeSteps(vtkXMLWriterC *self, int numTimeSteps)
Set the number of time steps that will be written between upcoming Start and Stop calls.
VTKIOXML_EXPORT void vtkXMLWriterC_SetCellData(vtkXMLWriterC *self, const char *name, int dataType, void *data, vtkIdType numTuples, int numComponents, const char *role)
VTKIOXML_EXPORT int vtkXMLWriterC_Write(vtkXMLWriterC *self)
Write the data to a file immediately.
VTKIOXML_EXPORT void vtkXMLWriterC_SetSpacing(vtkXMLWriterC *self, double spacing[3])
Set the spacing of an image data set.
VTKIOXML_EXPORT void vtkXMLWriterC_SetFileName(vtkXMLWriterC *self, const char *fileName)
Set the name of the file into which the data are to be written.
VTKIOXML_EXPORT void vtkXMLWriterC_SetPointData(vtkXMLWriterC *self, const char *name, int dataType, void *data, vtkIdType numTuples, int numComponents, const char *role)
Set a point or cell data array by name.
struct vtkXMLWriterC_s vtkXMLWriterC
vtkXMLWriterC is an opaque structure holding the state of an individual writer object.
Definition: vtkXMLWriterC.h:30
VTKIOXML_EXPORT void vtkXMLWriterC_SetPoints(vtkXMLWriterC *self, int dataType, void *data, vtkIdType numPoints)
Set the points of a point data set.
VTKIOXML_EXPORT void vtkXMLWriterC_WriteNextTimeStep(vtkXMLWriterC *self, double timeValue)
Write one time step of a time-series to the output file.
VTKIOXML_EXPORT void vtkXMLWriterC_Delete(vtkXMLWriterC *self)
Delete the writer object.
#define VTK_XMLWRITERF_MAX
Definition: vtkXMLWriterF.h:39
static vtkXMLWriterC * vtkXMLWriterF_Table[VTK_XMLWRITERF_MAX+1]
Definition: vtkXMLWriterF.h:40
#define VTK_FORTRAN_REF_STRING_POINTER(name)
Definition: vtkXMLWriterF.h:58
#define VTK_FORTRAN_ARG_STRING_POINTER(name)
Definition: vtkXMLWriterF.h:52
#define VTK_FORTRAN_REF_STRING_LENGTH(name)
Definition: vtkXMLWriterF.h:61
#define VTK_FORTRAN_NAME(name, NAME)
Definition: vtkXMLWriterF.h:49
#define VTK_FORTRAN_ARG_STRING_LENGTH(name)
Definition: vtkXMLWriterF.h:55