VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkXMLWriterF.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 /* 00016 * vtkXMLWriterF.h helps fortran programs call the C interface for 00017 * writing VTK XML files. A program can use this by writing one 00018 * vtkXMLWriterF.c file that includes this header. DO NOT INCLUDE 00019 * THIS HEADER ELSEWHERE. The fortran program then compiles 00020 * vtkXMLWriterF.c using a C compiler and links to the resulting 00021 * object file. 00022 */ 00023 00024 #if defined(__cplusplus) 00025 # error "This should be included only by a .c file." 00026 #endif 00027 00028 /* Calls will be forwarded to the C interface. */ 00029 #include "vtkXMLWriterC.h" 00030 00031 #include <stdio.h> /* fprintf */ 00032 #include <stdlib.h> /* malloc, free */ 00033 #include <string.h> /* memcpy */ 00034 00035 /* Define a static-storage default-zero-initialized table to store 00036 writer objects for the fortran program. */ 00037 #define VTK_XMLWRITERF_MAX 256 00038 static vtkXMLWriterC* vtkXMLWriterF_Table[VTK_XMLWRITERF_MAX+1]; 00039 00040 /* Fortran compilers expect certain symbol names for their calls to C 00041 code. These macros help build the C symbols so that the fortran 00042 program can link to them properly. The definitions here are 00043 reasonable defaults but the source file that includes this can 00044 define them appropriately for a particular compiler and override 00045 these. */ 00046 #if !defined(VTK_FORTRAN_NAME) 00047 # define VTK_FORTRAN_NAME(name, NAME) name##__ 00048 #endif 00049 #if !defined(VTK_FORTRAN_ARG_STRING_POINTER) 00050 # define VTK_FORTRAN_ARG_STRING_POINTER(name) const char* name##_ptr_arg 00051 #endif 00052 #if !defined(VTK_FORTRAN_ARG_STRING_LENGTH) 00053 # define VTK_FORTRAN_ARG_STRING_LENGTH(name) , const long int name##_len_arg 00054 #endif 00055 #if !defined(VTK_FORTRAN_REF_STRING_POINTER) 00056 # define VTK_FORTRAN_REF_STRING_POINTER(name) name##_ptr_arg 00057 #endif 00058 #if !defined(VTK_FORTRAN_REF_STRING_LENGTH) 00059 # define VTK_FORTRAN_REF_STRING_LENGTH(name) ((int)name##_len_arg) 00060 #endif 00061 00062 /*--------------------------------------------------------------------------*/ 00063 /* vtkXMLWriterF_New */ 00064 void VTK_FORTRAN_NAME(vtkxmlwriterf_new, VTKXMLWRITERF_NEW)( 00065 int* self 00066 ) 00067 { 00068 int i; 00069 00070 /* Initialize result to failure. */ 00071 *self = 0; 00072 00073 /* Search for a table entry to use for this object. */ 00074 for(i=1;i <= VTK_XMLWRITERF_MAX; ++i) 00075 { 00076 if(!vtkXMLWriterF_Table[i]) 00077 { 00078 vtkXMLWriterF_Table[i] = vtkXMLWriterC_New(); 00079 if(vtkXMLWriterF_Table[i]) 00080 { 00081 *self = i; 00082 } 00083 return; 00084 } 00085 } 00086 } 00087 00088 /*--------------------------------------------------------------------------*/ 00089 /* vtkXMLWriterF_Delete */ 00090 void VTK_FORTRAN_NAME(vtkxmlwriterf_delete, VTKXMLWRITERF_DELETE)( 00091 int* self 00092 ) 00093 { 00094 /* Check if the writer object exists. */ 00095 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00096 { 00097 /* Delete this writer object. */ 00098 vtkXMLWriterC_Delete(vtkXMLWriterF_Table[*self]); 00099 00100 /* Erase the table entry. */ 00101 vtkXMLWriterF_Table[*self] = 0; 00102 } 00103 else 00104 { 00105 fprintf(stderr, 00106 "vtkXMLWriterF_Delete called with invalid id %d.\n", 00107 *self); 00108 } 00109 00110 /* The writer object no longer exists. Destroy the id. */ 00111 *self = 0; 00112 } 00113 00114 /*--------------------------------------------------------------------------*/ 00115 /* vtkXMLWriterF_SetDataModeType */ 00116 void VTK_FORTRAN_NAME(vtkxmlwriterf_setdatamodetype, VTKXMLWRITERF_SETDATAMODETYPE)( 00117 const int* self, const int* objType 00118 ) 00119 { 00120 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00121 { 00122 vtkXMLWriterC_SetDataModeType(vtkXMLWriterF_Table[*self], *objType); 00123 } 00124 else 00125 { 00126 fprintf(stderr, 00127 "vtkXMLWriterF_SetDataModeType called with invalid id %d.\n", 00128 *self); 00129 } 00130 } 00131 00132 /*--------------------------------------------------------------------------*/ 00133 /* vtkXMLWriterF_SetDataObjectType */ 00134 void VTK_FORTRAN_NAME(vtkxmlwriterf_setdataobjecttype, VTKXMLWRITERF_SETDATAOBJECTTYPE)( 00135 const int* self, const int* objType 00136 ) 00137 { 00138 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00139 { 00140 vtkXMLWriterC_SetDataObjectType(vtkXMLWriterF_Table[*self], *objType); 00141 } 00142 else 00143 { 00144 fprintf(stderr, 00145 "vtkXMLWriterF_SetDataObjectType called with invalid id %d.\n", 00146 *self); 00147 } 00148 } 00149 00150 /*--------------------------------------------------------------------------*/ 00151 /* vtkXMLWriterF_SetExtent */ 00152 void VTK_FORTRAN_NAME(vtkxmlwriterf_setextent, VTKXMLWRITERF_SETEXTENT)( 00153 const int* self, int extent[6] 00154 ) 00155 { 00156 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00157 { 00158 vtkXMLWriterC_SetExtent(vtkXMLWriterF_Table[*self], extent); 00159 } 00160 else 00161 { 00162 fprintf(stderr, 00163 "vtkXMLWriterF_SetExtent called with invalid id %d.\n", 00164 *self); 00165 } 00166 } 00167 00168 /*--------------------------------------------------------------------------*/ 00169 /* vtkXMLWriterF_SetPoints */ 00170 void VTK_FORTRAN_NAME(vtkxmlwriterf_setpoints, VTKXMLWRITERF_SETPOINTS)( 00171 const int* self, const int* dataType, 00172 void* data, const vtkIdType* numPoints 00173 ) 00174 { 00175 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00176 { 00177 vtkXMLWriterC_SetPoints(vtkXMLWriterF_Table[*self], *dataType, 00178 data, *numPoints); 00179 } 00180 else 00181 { 00182 fprintf(stderr, 00183 "vtkXMLWriterF_SetPoints called with invalid id %d.\n", 00184 *self); 00185 } 00186 } 00187 00188 /*--------------------------------------------------------------------------*/ 00189 /* vtkXMLWriterF_SetOrigin */ 00190 void VTK_FORTRAN_NAME(vtkxmlwriterf_setorigin, VTKXMLWRITERF_SETORIGIN)( 00191 const int* self, double origin[3] 00192 ) 00193 { 00194 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00195 { 00196 vtkXMLWriterC_SetOrigin(vtkXMLWriterF_Table[*self], origin); 00197 } 00198 else 00199 { 00200 fprintf(stderr, 00201 "vtkXMLWriterF_SetOrigin called with invalid id %d.\n", 00202 *self); 00203 } 00204 } 00205 00206 /*--------------------------------------------------------------------------*/ 00207 /* vtkXMLWriterF_SetSpacing */ 00208 void VTK_FORTRAN_NAME(vtkxmlwriterf_setspacing, VTKXMLWRITERF_SETSPACING)( 00209 const int* self, double spacing[3] 00210 ) 00211 { 00212 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00213 { 00214 vtkXMLWriterC_SetSpacing(vtkXMLWriterF_Table[*self], spacing); 00215 } 00216 else 00217 { 00218 fprintf(stderr, 00219 "vtkXMLWriterF_SetSpacing called with invalid id %d.\n", 00220 *self); 00221 } 00222 } 00223 00224 /*--------------------------------------------------------------------------*/ 00225 /* vtkXMLWriterF_SetCoordinates */ 00226 void VTK_FORTRAN_NAME(vtkxmlwriterf_setcoordinates, VTKXMLWRITERF_SETCOORDINATES)( 00227 const int* self, const int* axis, const int* dataType, void* data, 00228 const vtkIdType* numCoordinates 00229 ) 00230 { 00231 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00232 { 00233 vtkXMLWriterC_SetCoordinates(vtkXMLWriterF_Table[*self], *axis, 00234 *dataType, data, *numCoordinates); 00235 } 00236 else 00237 { 00238 fprintf(stderr, 00239 "vtkXMLWriterF_SetCoordinates called with invalid id %d.\n", 00240 *self); 00241 } 00242 } 00243 00244 /*--------------------------------------------------------------------------*/ 00245 /* vtkXMLWriterF_SetCellsWithType */ 00246 void VTK_FORTRAN_NAME(vtkxmlwriterf_setcellswithtype, VTKXMLWRITERF_SETCELLSWITHTYPE)( 00247 const int* self, const int* cellType, const vtkIdType* ncells, 00248 vtkIdType* cells, const vtkIdType* cellsSize 00249 ) 00250 { 00251 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00252 { 00253 vtkXMLWriterC_SetCellsWithType(vtkXMLWriterF_Table[*self], *cellType, 00254 *ncells, cells, *cellsSize); 00255 } 00256 else 00257 { 00258 fprintf(stderr, 00259 "vtkXMLWriterF_SetCellsWithType called with invalid id %d.\n", 00260 *self); 00261 } 00262 } 00263 00264 /*--------------------------------------------------------------------------*/ 00265 /* vtkXMLWriterF_SetCellsWithTypes */ 00266 void VTK_FORTRAN_NAME(vtkxmlwriterf_setcellswithtypes, VTKXMLWRITERF_SETCELLSWITHTYPES)( 00267 const int* self, int* cellTypes, const vtkIdType* ncells, 00268 vtkIdType* cells, const vtkIdType* cellsSize 00269 ) 00270 { 00271 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00272 { 00273 vtkXMLWriterC_SetCellsWithTypes(vtkXMLWriterF_Table[*self], cellTypes, 00274 *ncells, cells, *cellsSize); 00275 } 00276 else 00277 { 00278 fprintf(stderr, 00279 "vtkXMLWriterF_SetCellsWithTypes called with invalid id %d.\n", 00280 *self); 00281 } 00282 } 00283 00284 /*--------------------------------------------------------------------------*/ 00285 /* vtkXMLWriterF_SetPointData */ 00286 void VTK_FORTRAN_NAME(vtkxmlwriterf_setpointdata, VTKXMLWRITERF_SETPOINTDATA)( 00287 const int* self, VTK_FORTRAN_ARG_STRING_POINTER(name), 00288 const int* dataType, void* data, const vtkIdType* numTuples, 00289 const int* numComponents, VTK_FORTRAN_ARG_STRING_POINTER(role) 00290 VTK_FORTRAN_ARG_STRING_LENGTH(name) 00291 VTK_FORTRAN_ARG_STRING_LENGTH(role) 00292 ) 00293 { 00294 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00295 { 00296 /* Prepare NULL-terminated strings. */ 00297 const char* name_ptr = VTK_FORTRAN_REF_STRING_POINTER(name); 00298 int name_length = VTK_FORTRAN_REF_STRING_LENGTH(name); 00299 char* name_buffer = malloc(name_length+1); 00300 const char* role_ptr = VTK_FORTRAN_REF_STRING_POINTER(role); 00301 int role_length = VTK_FORTRAN_REF_STRING_LENGTH(role); 00302 char* role_buffer = malloc(role_length+1); 00303 if(!name_buffer || !role_buffer) 00304 { 00305 fprintf(stderr, 00306 "vtkXMLWriterF_SetPointData failed to allocate name or role.\n"); 00307 if(name_buffer) { free(name_buffer); } 00308 if(role_buffer) { free(role_buffer); } 00309 return; 00310 } 00311 memcpy(name_buffer, name_ptr, name_length); 00312 name_buffer[name_length] = 0; 00313 memcpy(role_buffer, role_ptr, role_length); 00314 role_buffer[role_length] = 0; 00315 00316 /* Forward the call. */ 00317 vtkXMLWriterC_SetPointData(vtkXMLWriterF_Table[*self], name_buffer, 00318 *dataType, data, *numTuples, *numComponents, 00319 role_buffer); 00320 00321 /* Free the NULL-terminated strings. */ 00322 free(name_buffer); 00323 free(role_buffer); 00324 } 00325 else 00326 { 00327 fprintf(stderr, 00328 "vtkXMLWriterF_SetPointData called with invalid id %d.\n", 00329 *self); 00330 } 00331 } 00332 00333 /*--------------------------------------------------------------------------*/ 00334 /* vtkXMLWriterF_SetCellData */ 00335 void VTK_FORTRAN_NAME(vtkxmlwriterf_setcelldata, VTKXMLWRITERF_SETCELLDATA)( 00336 const int* self, VTK_FORTRAN_ARG_STRING_POINTER(name), 00337 const int* dataType, void* data, const vtkIdType* numTuples, 00338 const int* numComponents, VTK_FORTRAN_ARG_STRING_POINTER(role) 00339 VTK_FORTRAN_ARG_STRING_LENGTH(name) 00340 VTK_FORTRAN_ARG_STRING_LENGTH(role) 00341 ) 00342 { 00343 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00344 { 00345 /* Prepare NULL-terminated strings. */ 00346 const char* name_ptr = VTK_FORTRAN_REF_STRING_POINTER(name); 00347 int name_length = VTK_FORTRAN_REF_STRING_LENGTH(name); 00348 char* name_buffer = malloc(name_length+1); 00349 const char* role_ptr = VTK_FORTRAN_REF_STRING_POINTER(role); 00350 int role_length = VTK_FORTRAN_REF_STRING_LENGTH(role); 00351 char* role_buffer = malloc(role_length+1); 00352 if(!name_buffer || !role_buffer) 00353 { 00354 fprintf(stderr, 00355 "vtkXMLWriterF_SetCellData failed to allocate name or role.\n"); 00356 if(name_buffer) { free(name_buffer); } 00357 if(role_buffer) { free(role_buffer); } 00358 return; 00359 } 00360 memcpy(name_buffer, name_ptr, name_length); 00361 name_buffer[name_length] = 0; 00362 memcpy(role_buffer, role_ptr, role_length); 00363 role_buffer[role_length] = 0; 00364 00365 /* Forward the call. */ 00366 vtkXMLWriterC_SetCellData(vtkXMLWriterF_Table[*self], name_buffer, 00367 *dataType, data, *numTuples, *numComponents, 00368 role_buffer); 00369 00370 /* Free the NULL-terminated strings. */ 00371 free(name_buffer); 00372 free(role_buffer); 00373 } 00374 else 00375 { 00376 fprintf(stderr, 00377 "vtkXMLWriterF_SetCellData called with invalid id %d.\n", 00378 *self); 00379 } 00380 } 00381 00382 /*--------------------------------------------------------------------------*/ 00383 /* vtkXMLWriterF_SetFileName */ 00384 void VTK_FORTRAN_NAME(vtkxmlwriterf_setfilename, VTKXMLWRITERF_SETFILENAME)( 00385 const int* self, VTK_FORTRAN_ARG_STRING_POINTER(name) 00386 VTK_FORTRAN_ARG_STRING_LENGTH(name) 00387 ) 00388 { 00389 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00390 { 00391 /* Prepare NULL-terminated string. */ 00392 const char* name_ptr = VTK_FORTRAN_REF_STRING_POINTER(name); 00393 int name_length = VTK_FORTRAN_REF_STRING_LENGTH(name); 00394 char* name_buffer = malloc(name_length+1); 00395 if(!name_buffer) 00396 { 00397 fprintf(stderr, 00398 "vtkXMLWriterF_SetFileName failed to allocate name.\n"); 00399 return; 00400 } 00401 memcpy(name_buffer, name_ptr, name_length); 00402 name_buffer[name_length] = 0; 00403 00404 /* Forward the call. */ 00405 vtkXMLWriterC_SetFileName(vtkXMLWriterF_Table[*self], name_buffer); 00406 00407 /* Free the NULL-terminated string. */ 00408 free(name_buffer); 00409 } 00410 else 00411 { 00412 fprintf(stderr, 00413 "vtkXMLWriterF_SetFileName called with invalid id %d.\n", 00414 *self); 00415 } 00416 } 00417 00418 /*--------------------------------------------------------------------------*/ 00419 /* vtkXMLWriterF_Write */ 00420 void VTK_FORTRAN_NAME(vtkxmlwriterf_write, VTKXMLWRITERF_WRITE)( 00421 const int* self, int* success 00422 ) 00423 { 00424 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00425 { 00426 *success = vtkXMLWriterC_Write(vtkXMLWriterF_Table[*self]); 00427 } 00428 else 00429 { 00430 fprintf(stderr, 00431 "vtkXMLWriterF_Write called with invalid id %d.\n", 00432 *self); 00433 } 00434 } 00435 00436 /*--------------------------------------------------------------------------*/ 00437 /* vtkXMLWriterF_SetNumberOfTimeSteps */ 00438 void VTK_FORTRAN_NAME(vtkxmlwriterf_setnumberoftimesteps, VTKXMLWRITERF_SETNUMBEROFTIMESTEPS)( 00439 const int* self, const int* numTimeSteps 00440 ) 00441 { 00442 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00443 { 00444 vtkXMLWriterC_SetNumberOfTimeSteps(vtkXMLWriterF_Table[*self], 00445 *numTimeSteps); 00446 } 00447 else 00448 { 00449 fprintf(stderr, 00450 "vtkXMLWriterF_SetNumberOfTimeSteps called with invalid id %d.\n", 00451 *self); 00452 } 00453 } 00454 00455 /*--------------------------------------------------------------------------*/ 00456 /* vtkXMLWriterF_Start */ 00457 void VTK_FORTRAN_NAME(vtkxmlwriterf_start, VTKXMLWRITERF_START)( 00458 const int* self 00459 ) 00460 { 00461 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00462 { 00463 vtkXMLWriterC_Start(vtkXMLWriterF_Table[*self]); 00464 } 00465 else 00466 { 00467 fprintf(stderr, 00468 "vtkXMLWriterF_Start called with invalid id %d.\n", 00469 *self); 00470 } 00471 } 00472 00473 /*--------------------------------------------------------------------------*/ 00474 /* vtkXMLWriterF_WriteNextTimeStep */ 00475 void VTK_FORTRAN_NAME(vtkxmlwriterf_writenexttimestep, VTKXMLWRITERF_WRITENEXTTIMESTEP)( 00476 const int* self, const double* timeValue 00477 ) 00478 { 00479 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00480 { 00481 vtkXMLWriterC_WriteNextTimeStep(vtkXMLWriterF_Table[*self], *timeValue); 00482 } 00483 else 00484 { 00485 fprintf(stderr, 00486 "vtkXMLWriterF_WriteNextTimeStep called with invalid id %d.\n", 00487 *self); 00488 } 00489 } 00490 00491 /*--------------------------------------------------------------------------*/ 00492 /* vtkXMLWriterF_Stop */ 00493 void VTK_FORTRAN_NAME(vtkxmlwriterf_stop, VTKXMLWRITERF_STOP)( 00494 const int* self 00495 ) 00496 { 00497 if(*self > 0 && *self <= VTK_XMLWRITERF_MAX && vtkXMLWriterF_Table[*self]) 00498 { 00499 vtkXMLWriterC_Stop(vtkXMLWriterF_Table[*self]); 00500 } 00501 else 00502 { 00503 fprintf(stderr, 00504 "vtkXMLWriterF_Stop called with invalid id %d.\n", 00505 *self); 00506 } 00507 }