xref: /phasta/phastaIO/phastaIO.h (revision 595995161822a203c8467e0e4a253d7bd7d6df32)
1 /*  Primary interface for the Phasta Binary read and write routines these*/
2 /*  functions are 'C' callable.( All arguments have been kept as pointers to*/
3 /*  facilitate calling from Fortran )*/
4 /*  Anil Kumar Karanam  Spring 2003*/
5 #ifndef _PHASTAIO_H_
6 #define _PHASTAIO_H_
7 
8 #include <FCMangle.h>
9 #include <mpi.h>
10 
11 #ifdef intel
12 #define ios_base ios
13 #endif
14 
15 #define queryphmpiio FortranCInterface_GLOBAL_(queryphmpiio,QUERYPHMPIIO)
16 #define initphmpiio FortranCInterface_GLOBAL_(initphmpiio,INITPHMPIIO)
17 #define initphmpiiosub FortranCInterface_GLOBAL_(initphmpiiosub,INITPHMPIIOSUB)
18 #define finalizephmpiio FortranCInterface_GLOBAL_(finalizephmpiio,FINALIZEPHMPIIO)
19 
20 #define openfile FortranCInterface_GLOBAL_(openfile, OPENFILE)
21 #define closefile FortranCInterface_GLOBAL_(closefile, CLOSEFILE)
22 #define readheader FortranCInterface_GLOBAL_(readheader, READHEADER)
23 #define readdatablock FortranCInterface_GLOBAL_(readdatablock, READDATABLOCK)
24 #define writeheader FortranCInterface_GLOBAL_(writeheader, WRITEHEADER)
25 #define writedatablock FortranCInterface_GLOBAL_(writedatablock, WRITEDATABLOCK)
26 #define writestring FortranCInterface_GLOBAL_(writestring, WRITESTRING)
27 #define togglestrictmode FortranCInterface_GLOBAL_(togglestrictmode, TOGGLESTRICTMODE)
28 #define SwapArrayByteOrder FortranCInterface_GLOBAL_(swaparraybyteorder, SWAPARRAYBYTEORDER)
29 #define isLittleEndian FortranCInterface_GLOBAL_(islittleendian, ISLITTLEENDIAN)
30 
31 
32 #if defined (__cplusplus)
33 extern "C" {
34 #endif
35 
36   void mem_alloc( void* p, char* type, int size );
37 
38   void
39   queryphmpiio( const char filename[],
40 		 int *nfields,
41 		 int *nppf );
42 
43   int
44   initphmpiio( int *nfields,
45 		int *nppf,
46 		int *nfiles,
47 		int *filehandle,
48 		const char mode[] );
49   int
50   initphmpiiosub( int *nfields,
51 		  int *nppf,
52 		  int *nfiles,
53 		  int *filehandle,
54 		  const char mode[],
55                   MPI_Comm my_local_comm );
56 
57   void
58   finalizephmpiio( int *fileDescriptor );
59 
60     void
61     SwapArrayByteOrder( void* array,
62                          int   nbytes,
63                          int   nItems ) ;
64     void
65 
66     openfile( const char filename[],
67                const char mode[],
68                int* fileDescriptor );
69 
70     void
71     closefile( int* fileDescriptor,
72                 const char mode[] );
73 
74     void
75     readheader( int*   fileDescriptor,
76                  const char  keyphrase[],
77                  void*  valueArray,
78                  int*   nItems,
79                  const char   datatype[],
80                  const char   iotype[] );
81 
82     void
83     writeheader( const int*  fileDescriptor,
84                   const char keyphrase[],
85                   const void* valueArray,
86                   const int*  nItems,
87                   const int*  ndataItems,
88                   const char  datatype[],
89                   const char  iotype[] );
90 
91     void
92     readdatablock( int*  fileDescriptor,
93                     const char keyphrase[],
94                     void* valueArray,
95                     int*  nItems,
96                     const char  datatype[],
97                     const char  iotype[] );
98 
99 
100     void
101     writedatablock( const int*   fileDescriptor,
102                      const char  keyphrase[],
103                      const void*  valueArray,
104                      const int*   nItems,
105                      const char   datatype[],
106                      const char   iotype[]  );
107 
108     void
109     writestring( int* fileDescriptor,
110                   const char inString[] );
111 
112     void
113     togglestrictmode( );
114 
115   int
116   isLittleEndian( ) ;
117 
118   int computeColor( int myrank, int numprocs, int nfiles);
119 
120 #ifdef __cplusplus
121 } // end of extern "C".
122 
123 #include <string>
124 
125 namespace PHASTA {
126 template<class T>
127 struct PhastaIO_traits;
128 
129 template<>
130 struct PhastaIO_traits<int> {
131   static const char* const type_string;
132 };
133 
134 
135 template<>
136 struct PhastaIO_traits<double> {
137   static const char* const type_string;
138 };
139 
140 
141 template<class T>
142 void
143 write_data_block( const int   fileDescriptor,
144 		  const std::string keyphrase,
145 		  const T* const  valueArray,
146 		  const int   nItems,
147 		  const bool inBinary = false) {
148   writedatablock(&fileDescriptor,
149 		  keyphrase.c_str(),
150 		  reinterpret_cast<const void*>(valueArray),
151 		  &nItems,
152 		  PhastaIO_traits<T>::type_string,
153 		  inBinary ? "binary" : "text");
154 
155 }
156 template<class T>
157 void
158 write_header( const int  fileDescriptor,
159 		 const std::string& keyphrase,
160 		 const T* valueArray,
161 		 const int  nItems,
162 		 const int  nDataItems,
163 		 const bool inBinary = false) {
164       writeheader(&fileDescriptor,
165 		   keyphrase.c_str(),
166 		   reinterpret_cast<const void*>(valueArray),
167 		   &nItems,
168 		   &nDataItems,
169 		   PhastaIO_traits<T>::type_string,
170 		   inBinary ? "binary" : "text");
171 }
172 
173 
174 } // namespace PHASTA
175 
176 #endif // __cplusplus
177 
178 #endif // _PHASTAIO_H_
179