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