Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
d64c6371
Commit
d64c6371
authored
2 months ago
by
Mark OLESEN
Browse files
Options
Downloads
Patches
Plain Diff
ENH: foamDictionary now respects header format [ascii/binary] (
#3329
)
parent
2d246cd5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
applications/utilities/miscellaneous/foamDictionary/foamDictionary.C
+56
-12
56 additions, 12 deletions
...s/utilities/miscellaneous/foamDictionary/foamDictionary.C
with
56 additions
and
12 deletions
applications/utilities/miscellaneous/foamDictionary/foamDictionary.C
+
56
−
12
View file @
d64c6371
...
...
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2017-202
3
OpenCFD Ltd.
Copyright (C) 2017-202
5
OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -140,6 +140,38 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Read dictionary from IFstream, setting the stream to ascii/binary mode
//- depending on the 'FoamFile' header content
dictionary
readDictionary
(
Istream
&
is
)
{
auto
format
=
is
.
format
();
// If the file starts with 'FoamFile { ... }'
token
tok
;
if
(
(
tok
.
read
(
is
)
&&
tok
.
isWord
(
"FoamFile"
))
&&
(
tok
.
read
(
is
)
&&
tok
.
isPunctuation
(
token
::
BEGIN_BLOCK
))
)
{
is
.
putBack
(
tok
);
// Put back '{'
// FoamFile sub-dictionary content
dictionary
header
(
is
);
// Get "format" if present
format
=
IOstreamOption
::
formatEnum
(
"format"
,
header
,
format
);
}
// Start again. Probably does not work well with IPstream though
is
.
rewind
();
is
.
format
(
format
);
// Read, preserving headers
return
dictionary
(
is
,
true
);
}
//- Convert very old ':' scope syntax to less old '.' scope syntax,
// but leave anything with '/' delimiters untouched
bool
upgradeScope
(
word
&
entryName
)
...
...
@@ -266,6 +298,8 @@ void removeDict(dictionary& dict, const dictionary& dictToRemove)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int
main
(
int
argc
,
char
*
argv
[])
{
argList
::
addNote
...
...
@@ -273,7 +307,7 @@ int main(int argc, char *argv[])
"Interrogate and manipulate dictionaries"
);
argList
::
noBanner
();
argList
::
noBanner
();
// Essential if redirecting stdout
argList
::
noJobInfo
();
argList
::
addArgument
(
"dict"
,
"The dictionary file to process"
);
argList
::
addBoolOption
(
"keywords"
,
"List keywords"
);
...
...
@@ -336,7 +370,7 @@ int main(int argc, char *argv[])
"disableFunctionEntries"
,
"Disable expansion of dictionary directives - #include, #codeStream etc"
);
profiling
::
disable
();
// Disable profiling (and its output)
profiling
::
disable
();
// Disable profiling (and its output)
argList
args
(
argc
,
argv
);
...
...
@@ -369,7 +403,7 @@ int main(int argc, char *argv[])
const
auto
dictFileName
=
args
.
get
<
fileName
>
(
1
);
auto
dictFile
=
autoPtr
<
IFstream
>::
New
(
dictFileName
);
if
(
!
dictFile
().
good
())
if
(
!
dictFile
||
!
dictFile
().
good
())
{
FatalErrorInFunction
<<
"Cannot open file "
<<
dictFileName
...
...
@@ -379,8 +413,13 @@ int main(int argc, char *argv[])
bool
changed
=
false
;
// Read but preserve headers
dictionary
dict
(
dictFile
(),
true
);
// Read, preserving headers
//// dictionary dict(dictFile(), true);
dictionary
dict
=
readDictionary
(
dictFile
());
// The extracted dictionary format
const
auto
dictFormat
=
dictFile
().
format
();
if
(
listIncludes
)
{
...
...
@@ -414,8 +453,10 @@ int main(int argc, char *argv[])
<<
exit
(
FatalError
,
1
);
}
// Read but preserve headers
diffDict
.
read
(
diffFile
,
true
);
// Read, preserving headers
//// diffDict.read(diffFile, true);
diffDict
=
readDictionary
(
diffFile
);
optDiff
=
true
;
}
else
if
(
args
.
readIfPresent
(
"diff-etc"
,
diffFileName
))
...
...
@@ -436,8 +477,9 @@ int main(int argc, char *argv[])
<<
exit
(
FatalError
,
1
);
}
// Read but preserve headers
diffDict
.
read
(
diffFile
,
true
);
// Read, preserving headers
//// diffDict.read(diffFile, true);
diffDict
=
readDictionary
(
diffFile
);
optDiff
=
true
;
}
}
...
...
@@ -592,10 +634,12 @@ int main(int argc, char *argv[])
dict
.
write
(
Info
,
false
);
}
// Close the input file
dictFile
.
reset
();
if
(
changed
)
{
dictFile
.
clear
();
OFstream
os
(
dictFileName
);
OFstream
os
(
dictFileName
,
dictFormat
);
IOobject
::
writeBanner
(
os
);
IOobject
::
writeDivider
(
os
);
dict
.
write
(
os
,
false
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment