1 #include <string> 2 #include <sstream> 3 #include <phastaIO.h> 4 #include "phio_stream.h" 5 6 #define PHIO_STREAM_TRACING 0 7 namespace { 8 std::string appendPosix(const char* phrase) { 9 std::stringstream ss; 10 ss << phrase << "?"; 11 return ss.str(); 12 } 13 void traceEnter(const char* key, const char* aux="") { 14 if(PHIO_STREAM_TRACING) 15 fprintf(stderr, "CAKE entering %s %s\n", key, aux); 16 } 17 void traceExit(const char* key) { 18 if(PHIO_STREAM_TRACING) 19 fprintf(stderr, "CAKE exiting %s\n", key); 20 } 21 } 22 23 void stream_openfile( 24 const char filename[], 25 phio_fp f) { 26 traceEnter(__func__, filename); 27 stream_fp sf = (stream_fp) f; 28 if(sf->mode == 'w' && sf->rs != NULL) 29 sf->file = (int*) openRStreamWrite(sf->rs); 30 else if(sf->mode == 'r' && sf->grs != NULL) 31 sf->file = (int*) openGRStreamRead(sf->grs, filename); 32 else 33 fprintf(stderr, 34 "ERROR %s type of stream %s is unknown... exiting\n", 35 __func__, filename); 36 traceExit(__func__); 37 } 38 39 void stream_readheader( 40 int* fileDescriptor, 41 const char keyphrase[], 42 void* valueArray, 43 int* nItems, 44 const char datatype[], 45 const char iotype[] ) { 46 traceEnter(__func__, keyphrase); 47 readHeader((FILE*)fileDescriptor, keyphrase, 48 (int*)valueArray, *nItems, iotype); 49 traceExit(__func__); 50 } 51 52 void stream_writeheader( 53 const int* fileDescriptor, 54 const char keyphrase[], 55 const void* valueArray, 56 const int* nItems, 57 const int* ndataItems, 58 const char datatype[], 59 const char iotype[] ) { 60 traceEnter(__func__, keyphrase); 61 writeHeader((FILE*)fileDescriptor, keyphrase, 62 (int*)valueArray, *nItems, *ndataItems, datatype, iotype); 63 traceExit(__func__); 64 } 65 66 void stream_readdatablock( 67 int* fileDescriptor, 68 const char*, 69 void* valueArray, 70 int* nItems, 71 const char datatype[], 72 const char iotype[] ) { 73 traceEnter(__func__); 74 readDataBlock((FILE*)fileDescriptor, valueArray, *nItems, 75 datatype, iotype); 76 traceExit(__func__); 77 } 78 79 void stream_writedatablock( 80 const int* fileDescriptor, 81 const char*, 82 const void* valueArray, 83 const int* nItems, 84 const char datatype[], 85 const char iotype[]) { 86 traceEnter(__func__); 87 writeDataBlock((FILE*)fileDescriptor, valueArray, 88 *nItems, datatype, iotype); 89 traceExit(__func__); 90 } 91 92 void stream_closefile(phio_fp f) { 93 traceEnter(__func__); 94 stream_fp sf = (stream_fp) f; 95 fclose((FILE*)sf->file); 96 traceExit(__func__); 97 } 98 99 void stream_constructname(const char* in, char* out) { 100 traceEnter(__func__); 101 sprintf(out, "%s", in); 102 traceExit(__func__); 103 } 104