# Automatic variable renaming in large libraries

**URL:** <https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730>\
**Category:** Uncategorized\
**Created:** [February 18, 2021, 10:04pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730 "2021-02-18T22:04:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcs](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rcs](https://fortran-lang.discourse.group/u/rcs)\
**Post date:** [February 18, 2021, 10:04pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/1 "2021-02-18T22:04:47Z")

</div>

Hi all,

you may have come across a situation where you rename variables in large projects and it takes you a week to get it consistent such that the compiler doesn’t complain. For example, changing subroutine `subroutine s(foo,bar)` to `subroutine s(fooo,bar)` will require to change any `call s(foo=a,bar=b)` to `call s(fooo=a,bar=b)`. The same holds for derived type member variables where the variable is accessed directly (so not through get/set).

I am wondering whether there is any automatic tool to do this job.

thanks.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [February 18, 2021, 10:28pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/2 "2021-02-18T22:28:45Z")

</div>

Maybe [Photran](https://help.eclipse.org/2020-12/index.jsp?topic=%2Forg.eclipse.photran.doc.user%2Fhtml%2Fadvanced%2FRefactoring.html), recommended [here](https://fortran-lang.discourse.group/t/refactoring-code-into-a-subroutine/566/5). I have not tried it.

---

<div class="post-metadata">

**Author:** ![billlong](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@billlong](https://fortran-lang.discourse.group/u/billlong)\
**Post date:** [February 18, 2021, 10:40pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/3 "2021-02-18T22:40:09Z")

</div>

And here I thought Photran was the name of an Asian restaurant near the University of Illinois (UIUC) campus.

---

<div class="post-metadata">

**Author:** ![interkosmos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/interkosmos/32/296_2.png) [@interkosmos](https://fortran-lang.discourse.group/u/interkosmos)\
**Post date:** [February 19, 2021, 1:16pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/4 "2021-02-19T13:16:35Z")

</div>

[CLion](https://www.jetbrains.com/clion/) ($) features a Fortran plug-in and does quite well in source code refactoring.

---

<div class="post-metadata">

**Author:** ![rcs](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rcs](https://fortran-lang.discourse.group/u/rcs)\
**Post date:** [February 20, 2021, 3:09am UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/5 "2021-02-20T03:09:57Z")

</div>

Is anybody using eclipse/eclipse-photran actively?

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [February 20, 2021, 11:52pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/6 "2021-02-20T23:52:38Z")

</div>

We’re about evaluate it in a project I’m working on for doing (hopefully) removal of unused variables and arguments.

---

<div class="post-metadata">

**Author:** ![rcs](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rcs](https://fortran-lang.discourse.group/u/rcs)\
**Post date:** [February 21, 2021, 8:56am UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/7 "2021-02-21T08:56:18Z")

</div>

Isn’t there a compiler flag for unused variables?!

I just had a quick glance at the eclipse interface, and for somebody coming from the emacs/makefile league it looks all too much. However, I was wondering how I can attached an existing project to it which runs from an operational makefile, e.g. five hierachical libraries and several executables using those libraries. Any hint appreciated.

cheers

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [February 21, 2021, 11:32pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/8 "2021-02-21T23:32:56Z")

</div>

Yes, most compilers have flags that will tell you about unused variables and arguments, but if you’ve got lots of them, it’d be nice to have a tool that can automatically remove them all from your source code. Or at least make the process a lot easier.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [February 22, 2021, 8:43pm UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/9 "2021-02-22T20:43:54Z")

</div>

I am interested in a tool that removes unused variables. They commonly arise in my code when I have refactored a chunk of code into a subroutine. Here is Python 3 code that splits declarations (after the `real ::` part) into individual variables. One can use it to rewrite declarations after omitting specified variables.

```
# https://stackoverflow.com/questions/40770990/split-string-by-comma-but-ignore-commas-in-brackets-or-in-quotes
import re
str = "x,y(n),z(n,n),a(m)"
words = re.split('(,(?=[^\\)]*(?:\\(|$)))',str)
var = [w for w in words if w != ","]
print(var)

```

gives output `['x', 'y(n)', 'z(n,n)', 'a(m)']`. I know I am recreating the wheel.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [February 23, 2021, 1:12am UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/10 "2021-02-23T01:12:27Z")

</div>

[Camfort/fortran-src](https://github.com/camfort/fortran-src) is a currently maintained Haskell tool on GitHub that

> Provides lexing, parsing, and basic analyses of Fortran code covering standards: FORTRAN 66, FORTRAN 77, Fortran 90, Fortran 95 and part of Fortran 2003. Includes data flow and basic block analysis, a **renamer** , and type analysis.

I have not tried it.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [April 18, 2021, 10:40am UTC](https://fortran-lang.discourse.group/t/automatic-variable-renaming-in-large-libraries/730/11 "2021-04-18T10:40:43Z")

</div>

The web page is here:  
[https://camfort.github.io/](https://camfort.github.io/)

A 1.0.1 release is in preparation. Does anyone already used that tool?
