xref: /phasta/phSolver/common/phIO.cc (revision e81a6dc1f924882a3384f8e849eaba3a3575cfa5)
1064bab1dSCameron Smith #include <stdio.h>
2064bab1dSCameron Smith #include <stdlib.h>
336adee64SCameron Smith #include <cstring>
4064bab1dSCameron Smith #include <string>
536adee64SCameron Smith #include <sstream>
6d1293ce9SCameron Smith #include "phIO.h"
7d1293ce9SCameron Smith #include "phComm.h"
8064bab1dSCameron Smith #include "phio_base.h"
9f262839cSCameron Smith 
10d7abaf6cSCameron Smith #ifdef __cplusplus
11d7abaf6cSCameron Smith extern "C" {
12d7abaf6cSCameron Smith #endif
13d7abaf6cSCameron Smith 
1482f286aaSCameron Smith void phio_readheader(
15064bab1dSCameron Smith     phio_fp f,
16d1293ce9SCameron Smith     const  char keyphrase[],
17d1293ce9SCameron Smith     void* valueArray,
18d1293ce9SCameron Smith     int*  nItems,
19d1293ce9SCameron Smith     const char  datatype[],
20d1293ce9SCameron Smith     const char  iotype[] ) {
21064bab1dSCameron Smith   f->ops->readheader(f->file, keyphrase, valueArray,
22064bab1dSCameron Smith       nItems, datatype, iotype);
23d1293ce9SCameron Smith }
24fa18c524SCameron Smith void phio_writeheader(
2557517afcSCameron Smith     phio_fp f,
26fa18c524SCameron Smith     const char keyphrase[],
27fa18c524SCameron Smith     const void* valueArray,
28fa18c524SCameron Smith     const int* nItems,
29fa18c524SCameron Smith     const int* ndataItems,
30fa18c524SCameron Smith     const char datatype[],
31fa18c524SCameron Smith     const char iotype[] ) {
329ec3dd51SCameron Smith   f->ops->writeheader(f->file, keyphrase, valueArray,
339ec3dd51SCameron Smith       nItems, ndataItems, datatype, iotype);
34fa18c524SCameron Smith }
35f262839cSCameron Smith void phio_readdatablock(
36064bab1dSCameron Smith     phio_fp f,
37f262839cSCameron Smith     const  char keyphrase[],
38f262839cSCameron Smith     void* valueArray,
39f262839cSCameron Smith     int*  nItems,
40f262839cSCameron Smith     const char  datatype[],
41f262839cSCameron Smith     const char  iotype[] ) {
42064bab1dSCameron Smith   f->ops->readdatablock(f->file, keyphrase, valueArray,
43064bab1dSCameron Smith       nItems, datatype, iotype);
44f262839cSCameron Smith }
4566a3fa2cSCameron Smith void phio_writedatablock(
469ec3dd51SCameron Smith     phio_fp f,
4766a3fa2cSCameron Smith     const char keyphrase[],
4866a3fa2cSCameron Smith     const void* valueArray,
4966a3fa2cSCameron Smith     const int* nItems,
5066a3fa2cSCameron Smith     const char datatype[],
5166a3fa2cSCameron Smith     const char iotype[]) {
529ec3dd51SCameron Smith   f->ops->writedatablock(f->file, keyphrase, valueArray,
539ec3dd51SCameron Smith       nItems, datatype, iotype);
5466a3fa2cSCameron Smith }
55ab645d52SCameron Smith 
56ab645d52SCameron Smith void phio_constructName(
57ab645d52SCameron Smith     phio_format format,
58ab645d52SCameron Smith     const char inName[],
59ab645d52SCameron Smith     char* outName) {
60ab645d52SCameron Smith   std::string fullname(inName);
61ab645d52SCameron Smith   std::string gname("geombc");
62ab645d52SCameron Smith   //sync restart and geombc gets '-dat'
63ab645d52SCameron Smith   if( format == PHIO_SYNC )
647930919fSCameron Smith     fullname.append("-dat.");
65ab645d52SCameron Smith   //posix geombc gets '.dat'
66ab645d52SCameron Smith   else if( format == PHIO_POSIX &&
67ab645d52SCameron Smith     fullname.find(gname) != std::string::npos )
687930919fSCameron Smith       fullname.append(".dat.");
69ab645d52SCameron Smith   //posix restart gets nothing
70ab645d52SCameron Smith   sprintf(outName, "%s", fullname.c_str());
71ab645d52SCameron Smith }
72ab645d52SCameron Smith 
73ab645d52SCameron Smith void phio_openfile(
7482f286aaSCameron Smith     const char filename[],
75ab645d52SCameron Smith     phio_fp f) {
76ab645d52SCameron Smith   f->ops->openfile(filename, f);
7792bfab9aSCameron Smith }
78ab645d52SCameron Smith 
79ab645d52SCameron Smith void phio_closefile(phio_fp f) {
80ab645d52SCameron Smith   f->ops->closefile(f);
81064bab1dSCameron Smith }
82ab645d52SCameron Smith 
83*e81a6dc1SCameron Smith void phio_appendInt(char* dest, int v) {
8436adee64SCameron Smith   std::stringstream ss;
8536adee64SCameron Smith   ss << dest << v << '.';
8636adee64SCameron Smith   std::string s = ss.str();
8736adee64SCameron Smith   strcpy(dest, s.c_str());
8836adee64SCameron Smith }
89d7abaf6cSCameron Smith 
90d7abaf6cSCameron Smith #ifdef __cplusplus
91d7abaf6cSCameron Smith }
92d7abaf6cSCameron Smith #endif
93