xref: /phasta/phSolver/common/phIO.cc (revision ee150812e03b04b642c5c2bd3124e8eb86e98922)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <cstring>
4 #include <string>
5 #include <sstream>
6 #include "phIO.h"
7 #include "phComm.h"
8 #include "phio_base.h"
9 
10 #define PHIO_TRACING 0
11 namespace {
12   void trace(const char* key, const char* aux="", void* obj=NULL) {
13     if(PHIO_TRACING)
14       fprintf(stderr, "PHIO_TRACE entering %s %s %p\n", key, aux, obj);
15   }
16 }
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 void phio_readheader(
23     phio_fp f,
24     const  char keyphrase[],
25     void* valueArray,
26     int*  nItems,
27     const char  datatype[],
28     const char  iotype[] ) {
29   f->ops->readheader(f->file, keyphrase, valueArray,
30       nItems, datatype, iotype);
31 }
32 void phio_writeheader(
33     phio_fp f,
34     const char keyphrase[],
35     const void* valueArray,
36     const int* nItems,
37     const int* ndataItems,
38     const char datatype[],
39     const char iotype[] ) {
40   f->ops->writeheader(f->file, keyphrase, valueArray,
41       nItems, ndataItems, datatype, iotype);
42 }
43 void phio_readdatablock(
44     phio_fp f,
45     const  char keyphrase[],
46     void* valueArray,
47     int*  nItems,
48     const char  datatype[],
49     const char  iotype[] ) {
50   f->ops->readdatablock(f->file, keyphrase, valueArray,
51       nItems, datatype, iotype);
52 }
53 void phio_writedatablock(
54     phio_fp f,
55     const char keyphrase[],
56     const void* valueArray,
57     const int* nItems,
58     const char datatype[],
59     const char iotype[]) {
60   f->ops->writedatablock(f->file, keyphrase, valueArray,
61       nItems, datatype, iotype);
62 }
63 
64 void phio_constructName(
65     phio_fp f,
66     const char inName[],
67     char* outName) {
68   f->ops->constructname(inName, outName);
69 }
70 
71 void phio_openfile(
72     const char filename[],
73     phio_fp f) {
74   trace("openfile",filename,f);
75   f->ops->openfile(filename, f);
76 }
77 
78 void phio_closefile(phio_fp f) {
79   trace("closefile","unknown",f);
80   f->ops->closefile(f);
81 }
82 
83 void phio_appendInt(char* dest, int v) {
84   std::stringstream ss;
85   ss << dest << v << '.';
86   std::string s = ss.str();
87   strcpy(dest, s.c_str());
88 }
89 
90 #ifdef __cplusplus
91 }
92 #endif
93