template<class ArrayT>
Definition at line 37 of file PxReadWriteRaw.h. References ArrayCPB(), Impala::NativeTypeRead(), PX_COUT, PX_ENDL, PxAbortSystem(), PxBcastArray(), PxMyCPU(), and PxRootCPU(). 00038 { 00039 typedef typename ArrayT::StorType StorT; 00040 00041 FILE* fp; 00042 00043 if (PxMyCPU() == PxRootCPU()) { 00044 if (! (fp = fopen(fileName.c_str(), "r"))) { 00045 PX_COUT << "PxReadRaw: unable to open file " << fileName 00046 << PX_ENDL; 00047 PxAbortSystem(); 00048 } 00049 } 00050 00051 std::string typeStr = Element::TypeString<StorT>(0); 00052 std::string formatStr = std::string("version: 1, binary: %d, type: ") 00053 + typeStr 00054 + std::string(", elemSize: %d, width: %d, height: %d, nr: %d"); 00055 int binary; 00056 int elemSize; 00057 int width; 00058 int height; 00059 int nrA; 00060 char buf[200]; 00061 00062 if (PxMyCPU() == PxRootCPU()) { 00063 fgets(buf, 200, fp); 00064 int res = sscanf(buf, formatStr.c_str(), 00065 &binary, &elemSize, &width, &height, &nrA); 00066 if ((res != 5) || 00067 (elemSize != ArrayT::ElemSize()) || (nrA != 1)) { 00068 fclose(fp); 00069 PX_COUT << "Header of " << fileName << " is not compatible" 00070 << PX_ENDL; 00071 PxAbortSystem(); 00072 } 00073 } 00074 int blockSize = width*height*elemSize; 00075 00076 int sizes[2]; 00077 sizes[0] = width; 00078 sizes[1] = height; 00079 MPI_Bcast(sizes, 2, MPI_INT, PxRootCPU(), MPI_COMM_WORLD); 00080 00081 if (dst == 0) 00082 dst = ArrayCreate<ArrayT>(sizes[0], sizes[1]); 00083 00084 if (PxMyCPU() == PxRootCPU()) { 00085 StorT* dstPtr = ArrayCPB(dst, 0, 0); 00086 if (binary) { 00087 fclose(fp); 00088 fp = fopen(fileName.c_str(), "rb"); 00089 fread(buf, sizeof(char), 200, fp); 00090 for (int n=0 ; n<nrA ; n++) { 00091 fread(dstPtr, sizeof(StorT), blockSize, fp); 00092 dstPtr += blockSize; 00093 } 00094 } else { 00095 for (int n=0 ; n<nrA ; n++) { 00096 for(int i=0 ; i<height ; i++) { 00097 for(int j=0 ; j<width ; j++) { 00098 for (int k=0 ; k<elemSize ; k++) { 00099 NativeTypeRead(fp, dstPtr); 00100 dstPtr++; 00101 } 00102 } 00103 } 00104 } 00105 } 00106 fclose(fp); 00107 } 00108 // NOTE: Here we haven't used PxInitDistribution yet!!!! 00109 PxBcastArray(dst, PxRootCPU()); 00110 return dst; 00111 }
Here is the call graph for this function:
|