From 559472675f595fe8a6761b737fd6b9d6105e6135 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Barriat <pierre-yves.barriat@uclouvain.be> Date: Wed, 20 Oct 2021 12:11:41 +0200 Subject: [PATCH] Cleaning --- notebooks/03_dataxy | 61 ----- notebooks/03_gnuxy | 6 - ...{Untitled.ipynb => training_fortran.ipynb} | 215 +++++++++++++++++- 3 files changed, 212 insertions(+), 70 deletions(-) delete mode 100644 notebooks/03_dataxy delete mode 100644 notebooks/03_gnuxy rename notebooks/{Untitled.ipynb => training_fortran.ipynb} (69%) diff --git a/notebooks/03_dataxy b/notebooks/03_dataxy deleted file mode 100644 index 6245636..0000000 --- a/notebooks/03_dataxy +++ /dev/null @@ -1,61 +0,0 @@ - 0.00000000 0.00000000 - 0.100000001 9.98334214E-02 - 0.200000003 0.198669329 - 0.300000012 0.295520216 - 0.400000006 0.389418334 - 0.500000000 0.479425550 - 0.600000024 0.564642489 - 0.699999988 0.644217670 - 0.800000012 0.717356086 - 0.900000036 0.783326924 - 1.00000000 0.841470957 - 1.10000002 0.891207397 - 1.20000005 0.932039082 - 1.30000007 0.963558197 - 1.39999998 0.985449731 - 1.50000000 0.997494996 - 1.60000002 0.999573588 - 1.70000005 0.991664827 - 1.80000007 0.973847628 - 1.89999998 0.946300089 - 2.00000000 0.909297407 - 2.10000014 0.863209307 - 2.20000005 0.808496356 - 2.29999995 0.745705247 - 2.40000010 0.675463140 - 2.50000000 0.598472118 - 2.60000014 0.515501261 - 2.70000005 0.427379847 - 2.79999995 0.334988207 - 2.90000010 0.239249244 - 3.00000000 0.141120002 - 3.10000014 4.15805206E-02 - 3.20000005 -5.83741926E-02 - 3.29999995 -0.157745644 - 3.40000010 -0.255541205 - 3.50000000 -0.350783229 - 3.60000014 -0.442520559 - 3.70000005 -0.529836178 - 3.79999995 -0.611857831 - 3.90000010 -0.687766254 - 4.00000000 -0.756802499 - 4.09999990 -0.818277061 - 4.20000029 -0.871575892 - 4.30000019 -0.916166008 - 4.40000010 -0.951602101 - 4.50000000 -0.977530122 - 4.59999990 -0.993690968 - 4.70000029 -0.999923289 - 4.80000019 -0.996164620 - 4.90000010 -0.982452571 - 5.00000000 -0.958924294 - 5.09999990 -0.925814748 - 5.20000029 -0.883454502 - 5.30000019 -0.832267344 - 5.40000010 -0.772764444 - 5.50000000 -0.705540299 - 5.59999990 -0.631266713 - 5.70000029 -0.550685287 - 5.80000019 -0.464602023 - 5.90000010 -0.373876572 - 6.00000000 -0.279415488 diff --git a/notebooks/03_gnuxy b/notebooks/03_gnuxy deleted file mode 100644 index 0c9b7a0..0000000 --- a/notebooks/03_gnuxy +++ /dev/null @@ -1,6 +0,0 @@ - set xlabel 'x' - set xrange [0:6] - set ylabel 'y' - set yrange [-1.2:1.2] - plot "03_dataxy" using 1:2 title 'sin(x)' with lines lt rgb "red" - pause -1 diff --git a/notebooks/Untitled.ipynb b/notebooks/training_fortran.ipynb similarity index 69% rename from notebooks/Untitled.ipynb rename to notebooks/training_fortran.ipynb index 1afce04..1545273 100644 --- a/notebooks/Untitled.ipynb +++ b/notebooks/training_fortran.ipynb @@ -431,7 +431,7 @@ }, { "cell_type": "markdown", - "id": "558d962e", + "id": "31f27416", "metadata": {}, "source": [ "This code is going to create 2 files: \"03_dataxy\" and \"03_gnuxy\".\n", @@ -442,14 +442,223 @@ "gnuplot 03_gnuxy\n", "```\n", "\n", - "<img src=\"../assets/sin.png\">" + "<img src=\"https://gogs.elic.ucl.ac.be/pbarriat/learning-fortran/raw/master/assets/sin.png\">" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, + "id": "df362a1a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Try to solve \"x**3+x-10=0\"\n", + " What is your initial guess for the solution?\n", + "\n" + ] + } + ], + "source": [ + "program newton\n", + "\n", + " implicit none\n", + "\n", + " ! Use a Newton iteration to solve a polynomial equation\n", + "\n", + " integer :: i\n", + "\n", + " write(*,*) 'Try to solve \"x**3+x-10=0\"'\n", + " write(*,*) 'What is your initial guess for the solution?'\n", + "\n", + " do while( .TRUE. )\n", + " \n", + " write(*,*)\n", + " exit\n", + "\n", + " end do\n", + "\n", + "end program\n", + "\n", + "! ******************************************************************************************\n", + "\n", + "subroutine derivate()\n", + "\n", + "! Evaluate the function f(x)=x**3+x-10\n", + "! also return the derivative of the function\n", + "\n", + "\n", + "end subroutine\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, "id": "4b517d6b", "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Before the call:\n", + " a = 2 , b = 0 , c = 1\n", + " After the call:\n", + " a = 2 , b = 3 , c = 2\n" + ] + } + ], + "source": [ + " PROGRAM test_arg\n", + "\n", + " implicit none\n", + " integer a,b,c\n", + "\n", + " common /arg/ a,b,c\n", + "\n", + " a = 2\n", + " c = 1\n", + "\n", + " print *, 'Before the call:'\n", + " print *, 'a = ',a,', b = ',b,', c = ',c\n", + "\n", + " call sub\n", + "\n", + " print *, 'After the call:'\n", + " print *, 'a = ',a,', b = ',b,', c = ',c\n", + "\n", + " END PROGRAM\n", + "\n", + " SUBROUTINE sub\n", + "\n", + " implicit none\n", + "\n", + " integer a,b,c\n", + " common /arg/ a,b,c\n", + "\n", + " b = a + c\n", + " c = c + 1\n", + " \n", + " END SUBROUTINE" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "71f26006", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Before the call:\n", + " a = 2, b = 0, c = 1\n", + " After the call:\n", + " a = 2, b = 3, c = 2\n" + ] + } + ], + "source": [ + "MODULE arg\n", + " implicit none\n", + " integer :: a,b,c\n", + " real(8) :: x\n", + "END MODULE arg\n", + "\n", + "! * * * * * * * \n", + "\n", + "PROGRAM test_arg\n", + " USE arg\n", + " implicit none\n", + "\n", + " a = 2\n", + " c = 1\n", + "\n", + " write(*,*) 'Before the call:'\n", + " write(*,'(3(A5,I3))') ' a = ',a,', b = ',b,', c = ',c\n", + "\n", + " call sub\n", + "\n", + " write(*,*) 'After the call:'\n", + " write(*,'(3(A5,I3))') 'a = ',a,', b = ',b,', c = ',c\n", + "\n", + "END PROGRAM test_arg\n", + "\n", + "! * * * * * * * \n", + "\n", + "SUBROUTINE sub\n", + " USE arg, only : a,b,c ! seuls a b et c sont utiles\n", + " implicit none\n", + "\n", + " b = a + c\n", + " c = c + 1\n", + "\n", + "END SUBROUTINE sub" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "e3791d4f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Before:\n", + " lon_min = 0.00, lon_max = -0.00, lat_min = 0.00, lat_max = -0.00\n", + " Between:\n", + " lon_min = 0.00, lon_max = 360.00, lat_min = 0.00, lat_max = -0.00\n", + " After:\n", + " lon_min = 0.00, lon_max = 360.00, lat_min = -90.00, lat_max = 90.00\n" + ] + } + ], + "source": [ + "PROGRAM test_namelist\n", + "\n", + " implicit none\n", + "\n", + " real(8) lon_min, lon_max, lat_min, lat_max\n", + "\n", + " NAMELIST/namlon/ lon_min, lon_max\n", + " NAMELIST/namlat/ lat_min, lat_max\n", + "\n", + " write(*,*) 'Before:'\n", + " call print_res(lon_min, lon_max, lat_min, lat_max)\n", + "\n", + " open(161,file='../src/07_namelist.def',status='old',form='formatted')\n", + " read(161,NML=namlon)\n", + "\n", + " write(*,*) 'Between:'\n", + " call print_res(lon_min, lon_max, lat_min, lat_max)\n", + "\n", + " read(161,NML=namlat)\n", + " close (161)\n", + "\n", + " write(*,*) 'After:'\n", + " call print_res(lon_min, lon_max, lat_min, lat_max)\n", + "\n", + "END\n", + "\n", + "SUBROUTINE print_res(a,b,c,d)\n", + " implicit none\n", + " real(8), intent(in) :: a,b,c,d\n", + " write(*,'(4(A12,F6.2))') ' lon_min = ',a,', lon_max = ',b, &\n", + " ', lat_min = ',c,', lat_max = ',d\n", + " RETURN\n", + "END" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "27748335", + "metadata": {}, "outputs": [], "source": [] } -- GitLab