jupyter notebookでFORTRAN

pythonが流行ってる中、今さらですがFORTRANをやらなくてはいかん、ということになりまして。jupyter notebookの便利さに慣れてしまった今、viでコードを書いてコンパイルして実行してみて、またエディタに戻って、という環境には戻れまん。

調べてみると、jupyterから使えるそうではないですか。弘前大の ココとか

ですがインストール指南が日本語で見つかりませんので、記録(初心者の典型的失敗記)を残すことにしました。

私の環境: MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports), macOS Big Sur, homebrew, python3

 

jupyter notebookで使えるFORTRANカーネルは2通りあるみたいで、

 

このうち簡単そうなminimal fortran kernelの方を入れてみました。

README.mdのManual Instrationに従って1ステップずつ進めて行きます。

 

まず要件として以下のものがインストールされていること:

 

  • gfortran
  • jupyter
  • python 3
  • pip

jupyterまではインストール済みなので、gfortranのインストールから始めました。

 

  • gfortranのインストール

mypc:~ Toyokawa$ brew install gfortran
Warning: gcc 10.2.0_4 is already installed and up-to-date.
To reinstall 10.2.0_4, run:
brew reinstall gcc

 

おや?gccがインストール済み?ここで初心者の私はgccの再インストールを試み、また同じエラーが出るので、わけがわからず、homebrewの再インストールからやってしまったわけですが、わきまえておられる皆様にとってはなんてことないですね:

gfortranはgccに含まれている

 

 

ということでした。この瞬間まで私はgccというのはC言語コンパイラだと思ってたのですが、正しくはGNU compiler collectionの略でした。

 

さて、ここからがStep-by-stepのインストール手順です。

  • git clone git@github.com:ZedThree/jupyter-fortran-kernel.git

 

ここでまた失敗です

 

mypc:python Toyokawa$ git clone git@github.com:ZedThree/jupyter-fortran-kernel.git
Cloning into 'jupyter-fortran-kernel'...
The authenticity of host 'github.com (13.114.40.48)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,13.114.40.48' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

 

途中、Are you sure you want to continue connecting?にyesと入れていますが、アクセス権があるか、リポジトリが存在するか確認せよ、と言ってきます。githubは登録したことはあるのですが、ほとんど使っておらず使うための準備ができていなかった。

まずは自分のgithubのアカウントに、ダウンロード予定の端末のssh公開鍵を登録しておかなくてはいけなかったのですね。こちらの手順は検索すればたくさん出てきますので、他に譲ります。

さて、ssh-keygenしてpubic_keyをgithubに登録してから再トライ。

 

mypc:python Toyokawa$ git clone git@github.com:ZedThree/jupyter-fortran-kernel.git
Cloning into 'jupyter-fortran-kernel'...
The authenticity of host 'github.com (13.114.40.48)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,13.114.40.48' (RSA) to the list of known hosts.
Enter passphrase for key '/Users/Toyokawa/.ssh/id_rsa':
remote: Enumerating objects: 172, done.
remote: Total 172 (delta 0), reused 0 (delta 0), pack-reused 172
Receiving objects: 100% (172/172), 304.30 KiB | 678.00 KiB/s, done.
Resolving deltas: 100% (88/88), done.
mypc:python Toyokawa$

 

無事1ステップ目はクリアです。

残り4ステップはそのまま何事もなく通過しましたので、この記事はここまでです。

上に述べた弘前大のページで実行例や使い方は見れます。完結してないプログラムをステップごとに実行することはできないのですが、今のところFORTRAN入門を学んでる段階では便利に使えています。