CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Script for updating headers of files to current OF version

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By olesen
  • 1 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 11, 2021, 04:27
Default Script for updating headers of files to current OF version
  #1
Senior Member
 
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 6
otaolafr is on a distinguished road
hello,

I have been playing around doing some scripts for other things, and I took the time to do a small script that will update the headers of the files to the current version of OF, and I thought to share it.

It is more or less aesthetic, but as I use the files that I adapted to work in newer versions of OF (and that it had lost compatibility with the older ones...) I found updating the headers could be helpful.

the script looks for all the files in the case, confirms that is an OF file by comparing the first and seventh line of the header (that is constant among the different versions of OF... or at least the ones I have used)
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
and then it recovers the headers of a tutorial case of the actual OF installed in the computer by:
Code:
headerFile=$(find $FOAM_TUTORIALS -name "*controlDict*" |head -1)
and replace it in each file.
it is not a complicated thing to do but I thought that maybe someone will appreciate the share.
in any case here it is (RenameHeaders.txt):

Code:
#!/bin/bash
cd "${0%/*}" || exit                                # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions        # Tutorial run functions
#------------------------------------------------------------------------------

str1='/*--------------------------------*- C++ -*----------------------------------*\'
str7='\*---------------------------------------------------------------------------*/'
headerFile=$(find $FOAM_TUTORIALS -name "*controlDict*" |head -1)
header=$(head -7 $headerFile)
echo "Renaming headers to:"
echo "$header"
for dir in ./*/*; do
        #echo "$(head -1 $dir)"
		if [ -f "$dir" ]; then
			if [ "$str1" = "$(head -1 $dir)" ]; then
				if [ "$str7" = "$(head -7 $dir|tail -1)" ]; then
				#echo "$dir"_Temp
				tail +8 $dir > "$dir"_Temp
				echo "$header" | cat - "$dir"_Temp > temp && mv temp "$dir"_Temp
				mv "$dir"_Temp "$dir"
				fi
			fi
		fi
done
hope someone will find it usefull
best regards!
otaolafr is offline   Reply With Quote

Old   May 12, 2021, 03:57
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,689
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Might be able to reuse most of this:


https://develop.openfoam.com/Develop...CaseFileHeader
bigphil likes this.
olesen is offline   Reply With Quote

Old   May 12, 2021, 05:17
Default
  #3
Senior Member
 
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 6
otaolafr is on a distinguished road
Quote:
Originally Posted by olesen View Post
Might be able to reuse most of this:


https://develop.openfoam.com/Develop...CaseFileHeader
thanks for the share but I was not looking for anything with the post,
the script I uploaded in the first post of the thread works correctly, at least for my needs, I only wanted to share it with the community for anyone that could give a use or might be interested in it.
best regards.
otaolafr is offline   Reply With Quote

Old   December 4, 2022, 10:59
Default
  #4
Super Moderator
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,089
Rep Power: 34
bigphil will become famous soon enoughbigphil will become famous soon enough
Quote:
Originally Posted by olesen View Post
Might be able to reuse most of this:


https://develop.openfoam.com/Develop...CaseFileHeader
Hi Mark,

Is there a script like this for updating source code files?

EDIT: I see that foam-extend has a foamChangeCopyright script.

Last edited by bigphil; December 4, 2022 at 11:16. Reason: Add reference to foamChangeCopyright
bigphil is offline   Reply With Quote

Old   December 8, 2022, 10:27
Default
  #5
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,689
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by bigphil View Post
Hi Mark,

Is there a script like this for updating source code files?

EDIT: I see that foam-extend has a foamChangeCopyright script.

Hi Phil,
This isn't something that we've needed much, since we like to preserve copyrights etc. However, on the few occasions where I've needed to make larger changes I have misc script snippets that I repurpose as needed.


Cheers,
/mark
bigphil likes this.
olesen is offline   Reply With Quote

Old   December 14, 2022, 10:11
Default
  #6
Super Moderator
 
bigphil's Avatar
 
Philip Cardiff
Join Date: Mar 2009
Location: Dublin, Ireland
Posts: 1,089
Rep Power: 34
bigphil will become famous soon enoughbigphil will become famous soon enough
Thanks Mark
bigphil is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
reactingFoam crashes with no iterations uckmhnds OpenFOAM Running, Solving & CFD 3 July 17, 2022 18:41
different results form openfoam 3.0.1 to 1912 yuno OpenFOAM Running, Solving & CFD 0 September 28, 2020 03:09
paraview installation woes vex OpenFOAM Installation 15 January 30, 2011 07:11
[OpenFOAM] Problem with paraFoam on a linux-64 bit bunni ParaView 4 April 14, 2010 20:55
OpenFOAM15 paraFoam bug koen OpenFOAM Bugs 19 June 30, 2009 10:46


All times are GMT -4. The time now is 07:21.