1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Fortran Rappture Library Source |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Derrick Kearney, Purdue University |
---|
7 | * Copyright (c) 2004-2007 Purdue Research Foundation |
---|
8 | * |
---|
9 | * See the file "license.terms" for information on usage and |
---|
10 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #include "RpLibraryFInterface.h" |
---|
15 | #include "RpBindingsDict.h" |
---|
16 | #include "RpLibraryFStubs.c" |
---|
17 | #include "RpDXWriter.h" |
---|
18 | |
---|
19 | /**********************************************************************/ |
---|
20 | // FUNCTION: rp_lib(const char* filePath, int filePath_len) |
---|
21 | /// Open the file at 'filePath' and return Rappture Library Object. |
---|
22 | /** |
---|
23 | */ |
---|
24 | |
---|
25 | int rp_lib(const char* filePath, int filePath_len) { |
---|
26 | |
---|
27 | RpLibrary* lib = NULL; |
---|
28 | int handle = -1; |
---|
29 | std::string inFilePath = ""; |
---|
30 | |
---|
31 | inFilePath = null_terminate_str(filePath, filePath_len); |
---|
32 | |
---|
33 | // create a RapptureIO object and store in dictionary |
---|
34 | lib = new RpLibrary(inFilePath); |
---|
35 | |
---|
36 | if (lib) { |
---|
37 | handle = storeObject_Void((void*)lib); |
---|
38 | } |
---|
39 | |
---|
40 | return handle; |
---|
41 | } |
---|
42 | |
---|
43 | /**********************************************************************/ |
---|
44 | // FUNCTION: rp_lib_element_obj() |
---|
45 | /// Return the node located at 'path'. |
---|
46 | /** |
---|
47 | */ |
---|
48 | int rp_lib_element_obj(int* handle, /* integer handle of library */ |
---|
49 | char* path, /* null terminated path */ |
---|
50 | int path_len |
---|
51 | ) |
---|
52 | { |
---|
53 | int newObjHandle = -1; |
---|
54 | |
---|
55 | std::string inPath = ""; |
---|
56 | |
---|
57 | RpLibrary* lib = NULL; |
---|
58 | RpLibrary* retObj = NULL; |
---|
59 | |
---|
60 | inPath = null_terminate_str(path,path_len); |
---|
61 | |
---|
62 | if ((handle) && (*handle != 0)) { |
---|
63 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
64 | if (lib) { |
---|
65 | retObj = lib->element(inPath); |
---|
66 | |
---|
67 | if (retObj) { |
---|
68 | newObjHandle = storeObject_Void((void*)retObj); |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | return newObjHandle; |
---|
74 | } |
---|
75 | |
---|
76 | /**********************************************************************/ |
---|
77 | // FUNCTION: rp_lib_element_comp() |
---|
78 | /// Return the component name of the node located at 'path'. |
---|
79 | /** |
---|
80 | */ |
---|
81 | void rp_lib_element_comp( int* handle, /* integer handle of library */ |
---|
82 | char* path, /* null terminated path */ |
---|
83 | char* retText, /* return buffer for fortran*/ |
---|
84 | int path_len, |
---|
85 | int retText_len /* length of return text buffer */ |
---|
86 | ) |
---|
87 | { |
---|
88 | std::string inPath = ""; |
---|
89 | RpLibrary* lib = NULL; |
---|
90 | std::string retStr = ""; |
---|
91 | |
---|
92 | inPath = null_terminate_str(path,path_len); |
---|
93 | |
---|
94 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
95 | |
---|
96 | if (lib) { |
---|
97 | retStr = lib->element(inPath)->nodeComp(); |
---|
98 | if (!retStr.empty()) { |
---|
99 | fortranify(retStr.c_str(),retText,retText_len); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | /**********************************************************************/ |
---|
106 | // FUNCTION: rp_lib_element_id() |
---|
107 | /// Return the 'id' of node located at 'path'. |
---|
108 | /** |
---|
109 | */ |
---|
110 | void rp_lib_element_id( int* handle, /* integer handle of library */ |
---|
111 | char* path, /* path of element within xml */ |
---|
112 | char* retText, /* return buffer for fortran */ |
---|
113 | int path_len, |
---|
114 | int retText_len /* length of return text buffer */ |
---|
115 | ) |
---|
116 | { |
---|
117 | std::string inPath = ""; |
---|
118 | RpLibrary* lib = NULL; |
---|
119 | std::string retStr = ""; |
---|
120 | |
---|
121 | inPath = null_terminate_str(path,path_len); |
---|
122 | |
---|
123 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
124 | |
---|
125 | if (lib) { |
---|
126 | retStr = lib->element(inPath)->nodeId(); |
---|
127 | if (!retStr.empty()) { |
---|
128 | fortranify(retStr.c_str(),retText,retText_len); |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | /**********************************************************************/ |
---|
134 | // FUNCTION: rp_lib_element_type() |
---|
135 | /// Return the type of the node located at 'path'. |
---|
136 | /** |
---|
137 | */ |
---|
138 | void rp_lib_element_type( int* handle, /* integer handle of library */ |
---|
139 | char* path, /* search path inside xml */ |
---|
140 | char* retText, /* return buffer for fortran*/ |
---|
141 | int path_len, |
---|
142 | int retText_len /* length of return text buffer */ |
---|
143 | ) |
---|
144 | { |
---|
145 | std::string inPath = ""; |
---|
146 | RpLibrary* lib = NULL; |
---|
147 | std::string retStr = ""; |
---|
148 | |
---|
149 | inPath = null_terminate_str(path,path_len); |
---|
150 | |
---|
151 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
152 | |
---|
153 | if (lib) { |
---|
154 | retStr = lib->element(inPath)->nodeType(); |
---|
155 | fortranify(retStr.c_str(),retText,retText_len); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | /**********************************************************************/ |
---|
160 | // FUNCTION: rp_lib_children(const char* filePath, int filePath_len) |
---|
161 | /// Retrieve the next child of 'path' from the Rappture Library Object. |
---|
162 | /** |
---|
163 | */ |
---|
164 | int rp_lib_children ( int* handle, /* integer handle of library */ |
---|
165 | char* path, /* search path of the xml */ |
---|
166 | int* childHandle, /*integer hanlde of last returned child*/ |
---|
167 | int path_len /* length of the search path buffer */ |
---|
168 | ) { |
---|
169 | |
---|
170 | std::string inPath = ""; |
---|
171 | RpLibrary* lib = NULL; |
---|
172 | RpLibrary* childNode = NULL; |
---|
173 | int newObjHandle = -1; |
---|
174 | |
---|
175 | inPath = null_terminate_str(path,path_len); |
---|
176 | |
---|
177 | if (handle && (*handle >= 0) ) { |
---|
178 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
179 | if (lib) { |
---|
180 | |
---|
181 | if (*childHandle > 0) { |
---|
182 | // check to see if there were any previously returned children |
---|
183 | childNode = (RpLibrary*) getObject_Void(*childHandle); |
---|
184 | } |
---|
185 | |
---|
186 | // call the children base method |
---|
187 | childNode = lib->children(inPath,childNode); |
---|
188 | |
---|
189 | // store the childNode in the dictionary. |
---|
190 | // |
---|
191 | // because the base method is using static memory to get store the |
---|
192 | // children we should be able to check and see if the childHandle |
---|
193 | // was valid. |
---|
194 | // if so, then we can just return the childHandle back to the user |
---|
195 | // if not, store the object in the dictionary and return the new |
---|
196 | // handle. |
---|
197 | |
---|
198 | if (childNode) { |
---|
199 | if (*childHandle < 1) { |
---|
200 | newObjHandle = storeObject_Void((void*)childNode); |
---|
201 | } |
---|
202 | else { |
---|
203 | newObjHandle = storeObject_Void((void*)childNode,*childHandle); |
---|
204 | } |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | return newObjHandle; |
---|
210 | |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | //int rp_lib_child_comp ( int* handle, /* integer handle of library */ |
---|
215 | // char* path, /* DOM path of requested object */ |
---|
216 | // char* type, /* specific name of element */ |
---|
217 | // int* childNum, /* child number for iteration */ |
---|
218 | // char* retText, /* buffer to store return text */ |
---|
219 | // int path_len, /* length of path */ |
---|
220 | // int type_len, /* length of type */ |
---|
221 | // int retText_len /* length of return text buffer */ |
---|
222 | // ) |
---|
223 | /* |
---|
224 | { |
---|
225 | int retVal = 0; |
---|
226 | |
---|
227 | char* inPath = NULL; |
---|
228 | char* inType = NULL; |
---|
229 | |
---|
230 | inPath = null_terminate(path,path_len); |
---|
231 | inType = null_terminate(type,type_len); |
---|
232 | |
---|
233 | if (inPath) { |
---|
234 | path_len = strlen(inPath) + 1; |
---|
235 | } |
---|
236 | else { |
---|
237 | path_len = 0; |
---|
238 | } |
---|
239 | |
---|
240 | if (inType) { |
---|
241 | type_len = strlen(inType) + 1; |
---|
242 | } |
---|
243 | else { |
---|
244 | type_len = 0; |
---|
245 | } |
---|
246 | |
---|
247 | retVal = rp_lib_child_str( handle, |
---|
248 | inPath, |
---|
249 | "component", |
---|
250 | inType, |
---|
251 | childNum, |
---|
252 | retText, |
---|
253 | path_len, |
---|
254 | 10, |
---|
255 | type_len, |
---|
256 | retText_len |
---|
257 | ); |
---|
258 | |
---|
259 | if (inPath) { |
---|
260 | free(inPath); |
---|
261 | inPath = NULL; |
---|
262 | } |
---|
263 | |
---|
264 | if (inType) { |
---|
265 | free(inType); |
---|
266 | inType = NULL; |
---|
267 | } |
---|
268 | |
---|
269 | return retVal; |
---|
270 | } |
---|
271 | */ |
---|
272 | |
---|
273 | //int rp_lib_child_id( int* handle, /* integer handle of library */ |
---|
274 | // char* path, /* DOM path of requested object */ |
---|
275 | // char* type, /* specific name of element */ |
---|
276 | // int* childNum, /* child number for iteration */ |
---|
277 | // char* retText, /* buffer to store return text */ |
---|
278 | // int path_len, /* length of path */ |
---|
279 | // int type_len, /* length of type */ |
---|
280 | // int retText_len /* length of return text buffer */ |
---|
281 | // ) |
---|
282 | /* |
---|
283 | { |
---|
284 | int retVal = 0; |
---|
285 | char* inPath = NULL; |
---|
286 | char* inType = NULL; |
---|
287 | |
---|
288 | inPath = null_terminate(path,path_len); |
---|
289 | inType = null_terminate(type,type_len); |
---|
290 | |
---|
291 | if (inPath) { |
---|
292 | path_len = strlen(inPath) + 1; |
---|
293 | } |
---|
294 | else { |
---|
295 | path_len = 0; |
---|
296 | } |
---|
297 | |
---|
298 | if (inType) { |
---|
299 | type_len = strlen(inType) + 1; |
---|
300 | } |
---|
301 | else { |
---|
302 | type_len = 0; |
---|
303 | } |
---|
304 | |
---|
305 | retVal = rp_lib_child_str( handle, |
---|
306 | inPath, |
---|
307 | "id", |
---|
308 | inType, |
---|
309 | childNum, |
---|
310 | retText, |
---|
311 | path_len, |
---|
312 | 3, |
---|
313 | type_len, |
---|
314 | retText_len |
---|
315 | ); |
---|
316 | |
---|
317 | if (inPath) { |
---|
318 | free(inPath); |
---|
319 | inPath = NULL; |
---|
320 | } |
---|
321 | |
---|
322 | if (inType) { |
---|
323 | free(inType); |
---|
324 | inType = NULL; |
---|
325 | } |
---|
326 | |
---|
327 | return retVal; |
---|
328 | } |
---|
329 | */ |
---|
330 | |
---|
331 | //int rp_lib_child_type ( int* handle, /* integer handle of library */ |
---|
332 | // char* path, /* DOM path of requested object */ |
---|
333 | // char* type, /* specific name of element */ |
---|
334 | // int* childNum, /* child number for iteration */ |
---|
335 | // char* retText, /* buffer to store return text */ |
---|
336 | // int path_len, /* length of path */ |
---|
337 | // int type_len, /* length of type */ |
---|
338 | // int retText_len /* length of return text buffer */ |
---|
339 | // ) |
---|
340 | /* |
---|
341 | { |
---|
342 | int retVal = 0; |
---|
343 | char* inPath = NULL; |
---|
344 | char* inType = NULL; |
---|
345 | |
---|
346 | inPath = null_terminate(path,path_len); |
---|
347 | inType = null_terminate(type,type_len); |
---|
348 | |
---|
349 | if (inPath) { |
---|
350 | path_len = strlen(inPath) + 1; |
---|
351 | } |
---|
352 | else { |
---|
353 | path_len = 0; |
---|
354 | } |
---|
355 | |
---|
356 | if (inType) { |
---|
357 | type_len = strlen(inType) + 1; |
---|
358 | } |
---|
359 | else { |
---|
360 | type_len = 0; |
---|
361 | } |
---|
362 | |
---|
363 | retVal = rp_lib_child_str( handle, |
---|
364 | inPath, |
---|
365 | "type", |
---|
366 | inType, |
---|
367 | childNum, |
---|
368 | retText, |
---|
369 | path_len, |
---|
370 | 5, |
---|
371 | type_len, |
---|
372 | retText_len |
---|
373 | ); |
---|
374 | |
---|
375 | if (inPath) { |
---|
376 | free(inPath); |
---|
377 | inPath = NULL; |
---|
378 | } |
---|
379 | |
---|
380 | if (inType) { |
---|
381 | free(inType); |
---|
382 | inType = NULL; |
---|
383 | } |
---|
384 | |
---|
385 | return retVal; |
---|
386 | } |
---|
387 | */ |
---|
388 | |
---|
389 | /* |
---|
390 | int rp_lib_child_obj ( int* handle, |
---|
391 | char* path, |
---|
392 | char* type, |
---|
393 | int path_len, |
---|
394 | int type_len |
---|
395 | ) |
---|
396 | { |
---|
397 | int newObjHandle = -1; |
---|
398 | |
---|
399 | PyObject* lib = NULL; |
---|
400 | PyObject* list = NULL; |
---|
401 | |
---|
402 | char* inPath = NULL; |
---|
403 | char* inType = NULL; |
---|
404 | |
---|
405 | inPath = null_terminate(path,path_len); |
---|
406 | inType = null_terminate(type,type_len); |
---|
407 | |
---|
408 | if (rapptureStarted) { |
---|
409 | if ((handle) && (*handle != 0)) { |
---|
410 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
411 | |
---|
412 | if (lib) { |
---|
413 | list = rpChildren_f(lib, inPath, "object"); |
---|
414 | if (list) { |
---|
415 | // store the whole list, |
---|
416 | // need to make a way to read the nodes |
---|
417 | newObjHandle = storeObject_Void((void*)list); |
---|
418 | // Py_DECREF(list); |
---|
419 | } |
---|
420 | else { |
---|
421 | |
---|
422 | } |
---|
423 | } |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | if (inPath) { |
---|
428 | free(inPath); |
---|
429 | inPath = NULL; |
---|
430 | } |
---|
431 | |
---|
432 | if (inType) { |
---|
433 | free(inType); |
---|
434 | inType = NULL; |
---|
435 | } |
---|
436 | |
---|
437 | return newObjHandle; |
---|
438 | |
---|
439 | } |
---|
440 | */ |
---|
441 | |
---|
442 | /**********************************************************************/ |
---|
443 | // FUNCTION: rp_lib_get() |
---|
444 | /// Get data located at 'path' and return it as a string value. |
---|
445 | /** |
---|
446 | */ |
---|
447 | void rp_lib_get( int* handle, /* integer handle of library */ |
---|
448 | char* path, /* null terminated path */ |
---|
449 | char* retText, /* return text buffer for fortran*/ |
---|
450 | int path_len, |
---|
451 | int retText_len /* length of return text buffer */ |
---|
452 | ) |
---|
453 | { |
---|
454 | std::string xmlText = ""; |
---|
455 | |
---|
456 | RpLibrary* lib = NULL; |
---|
457 | |
---|
458 | std::string inPath = ""; |
---|
459 | |
---|
460 | inPath = null_terminate_str(path,path_len); |
---|
461 | |
---|
462 | if ((handle) && (*handle != 0)) { |
---|
463 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
464 | |
---|
465 | if (lib) { |
---|
466 | xmlText = lib->get(inPath); |
---|
467 | if (!xmlText.empty()) { |
---|
468 | fortranify(xmlText.c_str(),retText,retText_len); |
---|
469 | } |
---|
470 | |
---|
471 | } |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | /**********************************************************************/ |
---|
476 | // FUNCTION: rp_lib_get_str() |
---|
477 | /// Get data located at 'path' and return it as a string value. |
---|
478 | /** |
---|
479 | */ |
---|
480 | void rp_lib_get_str( int* handle, /* integer handle of library */ |
---|
481 | char* path, /* null terminated path */ |
---|
482 | char* retText, /* return text buffer for fortran*/ |
---|
483 | int path_len, |
---|
484 | int retText_len /* length of return text buffer */ |
---|
485 | ) |
---|
486 | { |
---|
487 | std::string xmlText = ""; |
---|
488 | |
---|
489 | RpLibrary* lib = NULL; |
---|
490 | |
---|
491 | std::string inPath = ""; |
---|
492 | |
---|
493 | inPath = null_terminate_str(path,path_len); |
---|
494 | |
---|
495 | if ((handle) && (*handle != 0)) { |
---|
496 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
497 | |
---|
498 | if (lib) { |
---|
499 | xmlText = lib->getString(inPath); |
---|
500 | if (!xmlText.empty()) { |
---|
501 | fortranify(xmlText.c_str(),retText,retText_len); |
---|
502 | } |
---|
503 | |
---|
504 | } |
---|
505 | } |
---|
506 | } |
---|
507 | |
---|
508 | |
---|
509 | /**********************************************************************/ |
---|
510 | // FUNCTION: rp_lib_get_double() |
---|
511 | /// Get data located at 'path' and return it as a double precision value. |
---|
512 | /** |
---|
513 | */ |
---|
514 | double rp_lib_get_double( int* handle, /* integer handle of library */ |
---|
515 | char* path, /* null terminated path */ |
---|
516 | int path_len |
---|
517 | ) |
---|
518 | { |
---|
519 | double retVal = 0.0; |
---|
520 | |
---|
521 | RpLibrary* lib = NULL; |
---|
522 | |
---|
523 | std::string inPath = ""; |
---|
524 | |
---|
525 | inPath = null_terminate_str(path,path_len); |
---|
526 | |
---|
527 | if ((handle) && (*handle != 0)) { |
---|
528 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
529 | |
---|
530 | if (lib) { |
---|
531 | retVal = lib->getDouble(inPath); |
---|
532 | } |
---|
533 | } |
---|
534 | |
---|
535 | return retVal; |
---|
536 | } |
---|
537 | |
---|
538 | |
---|
539 | /**********************************************************************/ |
---|
540 | // FUNCTION: rp_lib_get_integer() |
---|
541 | /// Get data located at 'path' and return it as an integer value. |
---|
542 | /** |
---|
543 | */ |
---|
544 | int rp_lib_get_integer( int* handle, /* integer handle of library */ |
---|
545 | char* path, /* null terminated path */ |
---|
546 | int path_len |
---|
547 | ) |
---|
548 | { |
---|
549 | int retVal = 0; |
---|
550 | |
---|
551 | RpLibrary* lib = NULL; |
---|
552 | |
---|
553 | std::string inPath = ""; |
---|
554 | |
---|
555 | inPath = null_terminate_str(path,path_len); |
---|
556 | |
---|
557 | if ((handle) && (*handle != 0)) { |
---|
558 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
559 | |
---|
560 | if (lib) { |
---|
561 | retVal = lib->getInt(inPath); |
---|
562 | } |
---|
563 | } |
---|
564 | |
---|
565 | return retVal; |
---|
566 | } |
---|
567 | |
---|
568 | |
---|
569 | /**********************************************************************/ |
---|
570 | // FUNCTION: rp_lib_get_boolean() |
---|
571 | /// Get data located at 'path' and return it as an integer value. |
---|
572 | /** |
---|
573 | */ |
---|
574 | int rp_lib_get_boolean( int* handle, /* integer handle of library */ |
---|
575 | char* path, /* null terminated path */ |
---|
576 | int path_len |
---|
577 | ) |
---|
578 | { |
---|
579 | bool value = false; |
---|
580 | int retVal = 0; |
---|
581 | |
---|
582 | RpLibrary* lib = NULL; |
---|
583 | |
---|
584 | std::string inPath = ""; |
---|
585 | |
---|
586 | inPath = null_terminate_str(path,path_len); |
---|
587 | |
---|
588 | if ((handle) && (*handle != 0)) { |
---|
589 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
590 | |
---|
591 | if (lib) { |
---|
592 | value = lib->getBool(inPath); |
---|
593 | if (value == true) { |
---|
594 | retVal = 1; |
---|
595 | } |
---|
596 | else { |
---|
597 | retVal = 0; |
---|
598 | } |
---|
599 | } |
---|
600 | } |
---|
601 | |
---|
602 | return retVal; |
---|
603 | } |
---|
604 | |
---|
605 | |
---|
606 | /**********************************************************************/ |
---|
607 | // FUNCTION: rp_lib_get_file() |
---|
608 | /// Get data located at 'path' and write it to the file 'fileName'. |
---|
609 | /** |
---|
610 | * Returns if any bytes were written to the file |
---|
611 | */ |
---|
612 | int rp_lib_get_file ( int* handle, /* integer handle of library */ |
---|
613 | char* path, /* null terminated path */ |
---|
614 | char* fileName, /* name of file to write data to */ |
---|
615 | int path_len, /* length of the path variable */ |
---|
616 | int fileName_len /* length of the fileName variable */ |
---|
617 | ) |
---|
618 | { |
---|
619 | size_t nbytes = 0; |
---|
620 | int ret = 0; |
---|
621 | |
---|
622 | RpLibrary* lib = NULL; |
---|
623 | |
---|
624 | std::string inPath = ""; |
---|
625 | std::string filePath = ""; |
---|
626 | |
---|
627 | inPath = null_terminate_str(path,path_len); |
---|
628 | filePath = null_terminate_str(fileName,fileName_len); |
---|
629 | |
---|
630 | if ((handle) && (*handle != 0)) { |
---|
631 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
632 | |
---|
633 | if (lib) { |
---|
634 | nbytes = lib->getFile(inPath, filePath); |
---|
635 | } |
---|
636 | } |
---|
637 | |
---|
638 | if (nbytes > 0) { |
---|
639 | ret = 1; |
---|
640 | } |
---|
641 | |
---|
642 | return ret; |
---|
643 | } |
---|
644 | |
---|
645 | |
---|
646 | |
---|
647 | /**********************************************************************/ |
---|
648 | // FUNCTION: rp_lib_put_str() |
---|
649 | /// Put string into Rappture Library Object at location 'path'. |
---|
650 | /** |
---|
651 | */ |
---|
652 | void rp_lib_put_str( int* handle, |
---|
653 | char* path, |
---|
654 | char* value, |
---|
655 | int* append, |
---|
656 | int path_len, |
---|
657 | int value_len |
---|
658 | ) |
---|
659 | { |
---|
660 | std::string inPath = ""; |
---|
661 | std::string inValue = ""; |
---|
662 | RpLibrary* lib = NULL; |
---|
663 | |
---|
664 | inPath = null_terminate_str(path,path_len); |
---|
665 | inValue = null_terminate_str(value,value_len); |
---|
666 | |
---|
667 | if ((handle) && (*handle != 0)) { |
---|
668 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
669 | |
---|
670 | if (lib) { |
---|
671 | lib->put(inPath,inValue,"",*append); |
---|
672 | } |
---|
673 | } |
---|
674 | |
---|
675 | return; |
---|
676 | |
---|
677 | } |
---|
678 | |
---|
679 | |
---|
680 | /**********************************************************************/ |
---|
681 | // FUNCTION: rp_lib_put_id_str() |
---|
682 | /// Put string into Rappture Library Object at location 'path' with id = 'id' |
---|
683 | /** |
---|
684 | */ |
---|
685 | void rp_lib_put_id_str ( int* handle, |
---|
686 | char* path, |
---|
687 | char* value, |
---|
688 | char* id, |
---|
689 | int* append, |
---|
690 | int path_len, |
---|
691 | int value_len, |
---|
692 | int id_len |
---|
693 | ) |
---|
694 | { |
---|
695 | RpLibrary* lib = NULL; |
---|
696 | |
---|
697 | std::string inPath = ""; |
---|
698 | std::string inValue = ""; |
---|
699 | std::string inId = ""; |
---|
700 | |
---|
701 | inPath = null_terminate_str(path,path_len); |
---|
702 | inValue = null_terminate_str(value,value_len); |
---|
703 | inId = null_terminate_str(id,id_len); |
---|
704 | |
---|
705 | if ((handle) && (*handle != 0)) { |
---|
706 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
707 | |
---|
708 | if (lib) { |
---|
709 | lib->put(inPath,inValue,inId,*append); |
---|
710 | } |
---|
711 | } |
---|
712 | |
---|
713 | } |
---|
714 | |
---|
715 | |
---|
716 | /**********************************************************************/ |
---|
717 | // FUNCTION: rp_lib_put_data() |
---|
718 | /// Put string into Rappture Library Object at location 'path'. |
---|
719 | /** |
---|
720 | */ |
---|
721 | void rp_lib_put_data( int* handle, |
---|
722 | char* path, |
---|
723 | char* bytes, |
---|
724 | int* nbytes, |
---|
725 | int* append, |
---|
726 | int path_len, |
---|
727 | int bytes_len |
---|
728 | ) |
---|
729 | { |
---|
730 | std::string inPath = ""; |
---|
731 | RpLibrary* lib = NULL; |
---|
732 | int bufferSize = 0; |
---|
733 | |
---|
734 | inPath = null_terminate_str(path,path_len); |
---|
735 | |
---|
736 | if (*nbytes < bytes_len) { |
---|
737 | bufferSize = *nbytes; |
---|
738 | } |
---|
739 | else { |
---|
740 | bufferSize = bytes_len; |
---|
741 | } |
---|
742 | |
---|
743 | if ((handle) && (*handle != 0)) { |
---|
744 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
745 | |
---|
746 | if (lib) { |
---|
747 | lib->putData(inPath,bytes,bufferSize,*append); |
---|
748 | } |
---|
749 | } |
---|
750 | |
---|
751 | return; |
---|
752 | |
---|
753 | } |
---|
754 | |
---|
755 | |
---|
756 | /**********************************************************************/ |
---|
757 | // FUNCTION: rp_lib_put_file() |
---|
758 | /// Put string into Rappture Library Object at location 'path'. |
---|
759 | /** |
---|
760 | */ |
---|
761 | void rp_lib_put_file( int* handle, |
---|
762 | char* path, |
---|
763 | char* fileName, |
---|
764 | int* compress, |
---|
765 | int* append, |
---|
766 | int path_len, |
---|
767 | int fileName_len |
---|
768 | ) |
---|
769 | { |
---|
770 | std::string inPath = ""; |
---|
771 | std::string inFileName = ""; |
---|
772 | RpLibrary* lib = NULL; |
---|
773 | |
---|
774 | inPath = null_terminate_str(path,path_len); |
---|
775 | inFileName = null_terminate_str(fileName,fileName_len); |
---|
776 | |
---|
777 | if ((handle) && (*handle != 0)) { |
---|
778 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
779 | |
---|
780 | if (lib) { |
---|
781 | lib->putFile(inPath,inFileName,*compress,*append); |
---|
782 | } |
---|
783 | } |
---|
784 | |
---|
785 | return; |
---|
786 | |
---|
787 | } |
---|
788 | |
---|
789 | |
---|
790 | void rp_lib_put_obj( int* handle, |
---|
791 | char* path, |
---|
792 | int* valHandle, |
---|
793 | int* append, |
---|
794 | int path_len |
---|
795 | ) |
---|
796 | { |
---|
797 | std::string inPath = ""; |
---|
798 | RpLibrary* lib = NULL; |
---|
799 | // Rp_Obj does not currently exist |
---|
800 | Rappture::DXWriter* obj = NULL; |
---|
801 | char* objStr = NULL; |
---|
802 | |
---|
803 | |
---|
804 | inPath = null_terminate_str(path,path_len); |
---|
805 | |
---|
806 | if ((handle) && (*handle != 0)) { |
---|
807 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
808 | if (!lib) { |
---|
809 | // return error, lib was not found |
---|
810 | } |
---|
811 | |
---|
812 | obj = (Rappture::DXWriter*) getObject_Void(*valHandle); |
---|
813 | if (!obj) { |
---|
814 | // return error, obj was not found |
---|
815 | } |
---|
816 | |
---|
817 | // textsize function does not currently exist |
---|
818 | objStr = (char*) malloc(obj->size()*sizeof(char)); |
---|
819 | obj->write(objStr); |
---|
820 | lib->put(inPath,objStr,"",*append); |
---|
821 | free(objStr); |
---|
822 | } |
---|
823 | } |
---|
824 | |
---|
825 | |
---|
826 | /* |
---|
827 | void rp_lib_put_id_obj ( int* handle, |
---|
828 | char* path, |
---|
829 | int* valHandle, |
---|
830 | char* id, |
---|
831 | int* append, |
---|
832 | int path_len, |
---|
833 | int id_len |
---|
834 | ) |
---|
835 | { |
---|
836 | PyObject* lib = NULL; |
---|
837 | PyObject* value = NULL; |
---|
838 | |
---|
839 | char* inPath = NULL; |
---|
840 | char* inId = NULL; |
---|
841 | |
---|
842 | inPath = null_terminate(path,path_len); |
---|
843 | inId = null_terminate(id,id_len); |
---|
844 | |
---|
845 | if (rapptureStarted) { |
---|
846 | if ((handle) && (*handle != 0)) { |
---|
847 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
848 | value = (RpLibrary*) getObject_Void(*valHandle); |
---|
849 | |
---|
850 | if (lib && value) { |
---|
851 | // retObj is a borrowed object |
---|
852 | // whose contents must not be modified |
---|
853 | rpPutObj(lib, inPath, value, inId, *append); |
---|
854 | } |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | if (inPath) { |
---|
859 | free(inPath); |
---|
860 | inPath = NULL; |
---|
861 | } |
---|
862 | |
---|
863 | if (inId) { |
---|
864 | free(inId); |
---|
865 | inId = NULL; |
---|
866 | } |
---|
867 | |
---|
868 | } |
---|
869 | */ |
---|
870 | |
---|
871 | /* |
---|
872 | int rp_lib_remove (int* handle, char* path, int path_len) |
---|
873 | { |
---|
874 | int newObjHandle = -1; |
---|
875 | |
---|
876 | PyObject* lib = NULL; |
---|
877 | PyObject* removedObj = NULL; |
---|
878 | |
---|
879 | char* inPath = NULL; |
---|
880 | |
---|
881 | inPath = null_terminate(path,path_len); |
---|
882 | |
---|
883 | if (rapptureStarted) { |
---|
884 | if ((handle) && (*handle != 0)) { |
---|
885 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
886 | |
---|
887 | if (lib) { |
---|
888 | removedObj = rpRemove(lib, inPath); |
---|
889 | |
---|
890 | if (removedObj) { |
---|
891 | newObjHandle = storeObject_Void((void*)removedObj); |
---|
892 | // Py_DECREF(removedObj); |
---|
893 | } |
---|
894 | |
---|
895 | } |
---|
896 | } |
---|
897 | } |
---|
898 | |
---|
899 | if (inPath) { |
---|
900 | free(inPath); |
---|
901 | inPath = NULL; |
---|
902 | } |
---|
903 | |
---|
904 | return newObjHandle; |
---|
905 | } |
---|
906 | */ |
---|
907 | |
---|
908 | /* |
---|
909 | int rp_lib_xml_len (int* handle) |
---|
910 | { |
---|
911 | int length = -1; |
---|
912 | char* xmlText = NULL; |
---|
913 | |
---|
914 | PyObject* lib = NULL; |
---|
915 | |
---|
916 | if (rapptureStarted) { |
---|
917 | if ((handle) && (*handle != 0)) { |
---|
918 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
919 | |
---|
920 | if (lib) { |
---|
921 | // dont modify xmlText, borrowed pointer |
---|
922 | xmlText = rpXml(lib); |
---|
923 | |
---|
924 | if (xmlText) { |
---|
925 | length = strlen(xmlText) + 1; |
---|
926 | free(xmlText); |
---|
927 | // printf("len = :%d:\n",length); |
---|
928 | } |
---|
929 | } |
---|
930 | } |
---|
931 | } |
---|
932 | return length; |
---|
933 | } |
---|
934 | */ |
---|
935 | |
---|
936 | /**********************************************************************/ |
---|
937 | // FUNCTION: rp_lib_write_xml() |
---|
938 | /// Write the xml text into a file. |
---|
939 | /** |
---|
940 | * \sa {rp_result} |
---|
941 | */ |
---|
942 | int rp_lib_write_xml(int* handle, char* outFile, int outFile_len) |
---|
943 | { |
---|
944 | int retVal = -1; |
---|
945 | RpLibrary* lib = NULL; |
---|
946 | std::string inOutFile = ""; |
---|
947 | std::string xmlText = ""; |
---|
948 | std::fstream file; |
---|
949 | |
---|
950 | inOutFile = null_terminate_str(outFile, outFile_len); |
---|
951 | |
---|
952 | if (!inOutFile.empty() ) { |
---|
953 | file.open(inOutFile.c_str(),std::ios::out); |
---|
954 | } |
---|
955 | |
---|
956 | if ( file.is_open() ) { |
---|
957 | if ((handle) && (*handle != 0)) { |
---|
958 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
959 | |
---|
960 | if (lib) { |
---|
961 | xmlText = lib->xml(); |
---|
962 | if (!xmlText.empty()) { |
---|
963 | file << xmlText; |
---|
964 | retVal = 0; |
---|
965 | } |
---|
966 | } |
---|
967 | } |
---|
968 | |
---|
969 | file.close(); |
---|
970 | } |
---|
971 | |
---|
972 | return retVal; |
---|
973 | } |
---|
974 | |
---|
975 | /**********************************************************************/ |
---|
976 | // FUNCTION: rp_lib_xml() |
---|
977 | /// Return this node's xml text |
---|
978 | /** |
---|
979 | */ |
---|
980 | void rp_lib_xml(int* handle, char* retText, int retText_len) |
---|
981 | { |
---|
982 | std::string xmlText = ""; |
---|
983 | |
---|
984 | RpLibrary* lib = NULL; |
---|
985 | |
---|
986 | if ((handle) && (*handle != 0)) { |
---|
987 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
988 | |
---|
989 | if (lib) { |
---|
990 | xmlText = lib->xml(); |
---|
991 | if (!xmlText.empty()) { |
---|
992 | fortranify(xmlText.c_str(), retText, retText_len); |
---|
993 | } |
---|
994 | } |
---|
995 | } |
---|
996 | } |
---|
997 | |
---|
998 | /**********************************************************************/ |
---|
999 | // FUNCTION: rp_lib_node_comp() |
---|
1000 | /// Return this node's component name |
---|
1001 | /** |
---|
1002 | */ |
---|
1003 | void rp_lib_node_comp ( int* handle, char* retText, int retText_len ) { |
---|
1004 | |
---|
1005 | std::string retStr = ""; |
---|
1006 | RpLibrary* node = NULL; |
---|
1007 | |
---|
1008 | if ((handle) && (*handle != 0)) { |
---|
1009 | node = (RpLibrary*) getObject_Void(*handle); |
---|
1010 | |
---|
1011 | if (node) { |
---|
1012 | retStr = node->nodeComp(); |
---|
1013 | if (!retStr.empty()) { |
---|
1014 | fortranify(retStr.c_str(), retText, retText_len); |
---|
1015 | } |
---|
1016 | } |
---|
1017 | } |
---|
1018 | } |
---|
1019 | |
---|
1020 | /**********************************************************************/ |
---|
1021 | // FUNCTION: rp_lib_node_type() |
---|
1022 | /// Return this node's type |
---|
1023 | /** |
---|
1024 | */ |
---|
1025 | void rp_lib_node_type ( int* handle, char* retText, int retText_len ) { |
---|
1026 | |
---|
1027 | std::string retStr = ""; |
---|
1028 | RpLibrary* node = NULL; |
---|
1029 | |
---|
1030 | if ((handle) && (*handle != 0)) { |
---|
1031 | node = (RpLibrary*) getObject_Void(*handle); |
---|
1032 | |
---|
1033 | if (node) { |
---|
1034 | retStr = node->nodeType(); |
---|
1035 | if (!retStr.empty()) { |
---|
1036 | fortranify(retStr.c_str(), retText, retText_len); |
---|
1037 | } |
---|
1038 | } |
---|
1039 | } |
---|
1040 | } |
---|
1041 | |
---|
1042 | /**********************************************************************/ |
---|
1043 | // FUNCTION: rp_lib_node_id() |
---|
1044 | /// Return this node's id. |
---|
1045 | /** |
---|
1046 | */ |
---|
1047 | void rp_lib_node_id ( int* handle, char* retText, int retText_len ) { |
---|
1048 | |
---|
1049 | std::string retStr = ""; |
---|
1050 | RpLibrary* node = NULL; |
---|
1051 | |
---|
1052 | if ((handle) && (*handle != 0)) { |
---|
1053 | node = (RpLibrary*) getObject_Void(*handle); |
---|
1054 | |
---|
1055 | if (node) { |
---|
1056 | retStr = node->nodeId(); |
---|
1057 | if (!retStr.empty()) { |
---|
1058 | fortranify(retStr.c_str(), retText, retText_len); |
---|
1059 | } |
---|
1060 | } |
---|
1061 | } |
---|
1062 | } |
---|
1063 | |
---|
1064 | /**********************************************************************/ |
---|
1065 | // FUNCTION: rp_result() |
---|
1066 | /// Write xml text to a run.xml file and signal the program has completed |
---|
1067 | /** |
---|
1068 | */ |
---|
1069 | void rp_result(int* handle) { |
---|
1070 | RpLibrary* lib = NULL; |
---|
1071 | |
---|
1072 | if (handle && *handle != 0) { |
---|
1073 | lib = (RpLibrary*) getObject_Void(*handle); |
---|
1074 | if (lib) { |
---|
1075 | lib->put("tool.version.rappture.language", "fortran"); |
---|
1076 | lib->result(); |
---|
1077 | } |
---|
1078 | } |
---|
1079 | |
---|
1080 | // do no delete this, still working on testing this |
---|
1081 | cleanLibDict(); |
---|
1082 | } |
---|
1083 | |
---|