Skip to content

Add : Python Fortran Rosetta Stone (Transfer content from fortran90.org #112) #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

henilp105
Copy link
Member

@henilp105 henilp105 commented Oct 2, 2022

This PR adds Fortran90 content Python Fortran Rosetta Stone, We are grateful to the original owners (@certik) of the content for opensourcing it . This content has been taken from https://github.com/certik/fortran90.org . This content has been formatted with pandoc and converted to myst markdown for consistency.

This PR Resolves:

Closes #112

Thanks and Regards,
Henil

CC @awvwgk @vmagnin

@henilp105 henilp105 changed the title Add : Python Fortran Rosetta Stone (Transfer content from fortran90.org #122) Add : Python Fortran Rosetta Stone (Transfer content from fortran90.org #112) Oct 2, 2022
@henilp105
Copy link
Member Author

#build_preview

@github-actions
Copy link

github-actions bot commented Oct 2, 2022

This PR has been built with Sphinx and can be previewed at: https://fortran-lang.github.io/webpage/pr/175

@henilp105
Copy link
Member Author

@awvwgk Should we add Rosetta stone to minibook tutorials ?

@vmagnin
Copy link
Member

vmagnin commented Oct 2, 2022

The "Mini-book Tutorials > Getting started" section seems the right place.

Concerning the tables, is it possible to improve the vertical alignments of the Python / Fortran tables? For example by simply adding void lines to have the same number of lines in the two languages?

Do you think syntax coloring could be added?

Finally, we will have to modernize the code. At first sight, the main problem seems to be that is Python 2. We will have to replace print by print(). Probably not much more. But I think it could be good to test one by one all these Python and Fortran codes with nowadays interpreters/compilers.

I have also detected that in some tables the Python (compulsory) indentations are lacking, for example:

i = 5

def f(x):
return x + 5

@vmagnin
Copy link
Member

vmagnin commented Oct 2, 2022

The "Timings on Acer 1830T with gfortran 4.6.1" will also need updating...

@awvwgk
Copy link
Member

awvwgk commented Oct 2, 2022

I have used a couple of two column code listings in https://awvwgk.github.io/foopss/, note that those were carefully constructed to always have the same number of lines to make it look better. Either sphinx-design grids or tabs are used there, but they are certainly not optimal, just an example.

Edit: Maybe it would be a good idea to just transfer the above page to the learn section, open for discussion in #177.

@henilp105
Copy link
Member Author

The "Mini-book Tutorials > Getting started" section seems the right place.

Sure sir , will add it there.

I have also detected that in some tables the Python (compulsory) indentations are lacking, for example:

I had noticed them but it is due to pandoc. so they must be resolved manually.

Finally, we will have to modernize the code. At first sight, the main problem seems to be that is Python 2. We will have to replace print by print(). Probably not much more. But I think it could be good to test one by one all these Python and Fortran codes with nowadays interpreters/compilers.

Maybe we could add that The above Python code is Python 2 and similarly for Fortran.

Thanks and Regards,
Henil

@henilp105
Copy link
Member Author

#build_preview

@github-actions
Copy link

github-actions bot commented Oct 2, 2022

This PR has been built with Sphinx and can be previewed at: https://fortran-lang.github.io/webpage/pr/175

@awvwgk
Copy link
Member

awvwgk commented Oct 2, 2022

Maybe we could add that The above Python code is Python 2 and similarly for Fortran.

Since Python 2 is end-of-life we should rather modernize to Python 3 instead.

@vmagnin
Copy link
Member

vmagnin commented Oct 2, 2022

The Fortran snippets can be quickly tested in the Fortran Playground https://play.fortran-lang.org/
For example, I saw that in the first output an empty line is missing in the middle. It should look like that:

1           2           3
4           5           6

1           3           5
2           4           6

It is also missing on the Python side.

</tbody>
</table>

In Python, just save the code to a file `a.py` and execute using
Copy link
Member

@awvwgk awvwgk Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a.py and a.f90 are bad choices for the name here. Especially for newcomers it might not be immediately clear that a.out is not obtained by using the basename of the Fortran source file. Rather we should call them example.py or test.f90.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure Sir, actually I had been re-writing the entire document in myst , so will also add this. Thanks.

Comment on lines 54 to 68
> - Fortran counts (by default) from 1, NumPy always from 0
> - Fortran array sections (slices) include both ends, in NumPy the
> initial point is included, the final is excluded
> - In C the array is stored row wise in the memory (by default NumPy
> uses C storage), while in Fortran it is stored column wise (this
> only matters in the next two points)
> - By default `reshape` uses Fortran ordering in Fortran, and C
> ordering in NumPy (in both cases an optional argument `order`
> allows to use the other ordering). This also matters when
> `reshape` is used implicitly in other operations like flattening.
> - The first index is the fastest in Fortran, while in NumPy, the
> last index is the fastest
> - By default NumPy prints the 2d array nicely, while in Fortran one
> has to specify a format to print it (also Fortran prints column
> wise, so one has to transpose the array for row wise printing)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that be a block quote or should we rather aim for an admonition.

Comment on lines 905 to 915
module constants
use types, only: dp
implicit none
private
public pi, e, I
! Constants contain more digits than double precision, so that
! they are rounded correctly:
real(dp), parameter :: pi = 3.1415926535897932384626433832795_dp
real(dp), parameter :: e = 2.7182818284590452353602874713527_dp
complex(dp), parameter :: I = (0, 1)
end module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not get highlighted correctly

Comment on lines 11 to 21
<table>
<colgroup>
<col style="width: 49%" />
<col style="width: 50%" />
</colgroup>
<tbody>
<tr class="odd">
<td>NumPy</td>
<td><blockquote>
<p>Fortran</p>
</blockquote></td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's rather cumbersome to edit, can we find a pure MyST equivalent? Maybe something like

:::::{grid}
::::{grid-item}
```{code-block} python
:caption: Python
# ...
```
::::
::::{grid-item}
```{code-block} fortran
:caption: Fortran
! ...
```
::::
:::::

I have to admit that MyST seems to be only a minor improvement over raw HTML in this context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure sir. Thanks

@certik
Copy link
Member

certik commented Oct 7, 2022

What's the status here --- I see some force pushes into main and I can't see any changes in this PR.

P.S. We should never be force pushing into main, we should even forbid it in GitHub itself.

@henilp105
Copy link
Member Author

We will be opening a new pr soon.

@henilp105
Copy link
Member Author

Actually due to a rebase this has been closed . Will open a new one

@certik
Copy link
Member

certik commented Oct 7, 2022

Ok, thanks. Once you do, please post a link here.

@henilp105
Copy link
Member Author

@certik I have opened a new PR here : #185 .Thanks

@henilp105
Copy link
Member Author

#delete_preview

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

The preview build for this PR has now been deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transfer fortran90.org content
4 participants