CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Script for updating headers of files to current OF version (https://www.cfd-online.com/Forums/openfoam-programming-development/236036-script-updating-headers-files-current-version.html)

otaolafr May 11, 2021 04:27

Script for updating headers of files to current OF version
 
1 Attachment(s)
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 (Attachment 84293):

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!

olesen May 12, 2021 03:57

Might be able to reuse most of this:


https://develop.openfoam.com/Develop...CaseFileHeader

otaolafr May 12, 2021 05:17

Quote:

Originally Posted by olesen (Post 803632)
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.

bigphil December 4, 2022 10:59

Quote:

Originally Posted by olesen (Post 803632)
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.

olesen December 8, 2022 10:27

Quote:

Originally Posted by bigphil (Post 840546)
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 December 14, 2022 10:11

Thanks Mark


All times are GMT -4. The time now is 15:40.