diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C index 8f5a6c2d9789db56a14b93b00d408f4861464f47..c0da5cd9bf9fb7cc68184efdca3f7cfeecadc783 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C @@ -34,50 +34,38 @@ License template<class T, class BaseType> bool Foam::CompactIOField<T, BaseType>::readIOcontents(bool readOnProc) { - if (readOpt() == IOobject::MUST_READ) + if (isReadRequired() || (isReadOptional() && headerOk())) { - // Reading - } - else if (isReadOptional()) - { - if (!headerOk()) - { - readOnProc = false; - } - } - else - { - return false; - } - + // Do reading + Istream& is = readStream(word::null, readOnProc); - // Do reading - Istream& is = readStream(word::null, readOnProc); - - if (readOnProc) - { - if (headerClassName() == IOField<T>::typeName) + if (readOnProc) { - is >> static_cast<Field<T>&>(*this); - close(); - } - else if (headerClassName() == typeName) - { - is >> *this; - close(); - } - else - { - FatalIOErrorInFunction(is) - << "Unexpected class name " << headerClassName() - << " expected " << typeName - << " or " << IOField<T>::typeName << nl - << " while reading object " << name() - << exit(FatalIOError); + if (headerClassName() == IOField<T>::typeName) + { + is >> static_cast<Field<T>&>(*this); + close(); + } + else if (headerClassName() == typeName) + { + is >> *this; + close(); + } + else + { + FatalIOErrorInFunction(is) + << "Unexpected class name " << headerClassName() + << " expected " << typeName + << " or " << IOField<T>::typeName << nl + << " while reading object " << name() + << exit(FatalIOError); + } } + + return true; } - return true; + return false; } diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.C b/src/OpenFOAM/db/IOobjects/IOField/IOField.C index 89b3d2f8488267fcb08da254d7254fc4b4040323..e3588f81f0c8569514863c5a7946b8c49ab6aac2 100644 --- a/src/OpenFOAM/db/IOobjects/IOField/IOField.C +++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.C @@ -33,32 +33,20 @@ License template<class Type> bool Foam::IOField<Type>::readIOcontents(bool readOnProc) { - if (isReadRequired()) + if (isReadRequired() || (isReadOptional() && headerOk())) { - // Reading - } - else if (isReadOptional()) - { - if (!headerOk()) + // Do reading + Istream& is = readStream(typeName, readOnProc); + + if (readOnProc) { - readOnProc = false; + is >> *this; } - } - else - { - return false; + close(); + return true; } - - // Do reading - Istream& is = readStream(typeName, readOnProc); - - if (readOnProc) - { - is >> *this; - } - close(); - return true; + return false; }