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