Error when running python script from Modern Fortran book(page 50)

Hi @milancurcic ,
I have been following the tsunami example, and I have reached page 50. However, there is an error when trying to plot

Command terminal:

[agnelo@fedora Lesson 2]$ caf tsunami.f90 -o tsunami
[agnelo@fedora Lesson 2]$ cafrun -n 1 ./tsunami >tsunami_output.txt
[agnelo@fedora Lesson 2]$ python3 plot_height_multipanel.py tsunami_output.txt
  File "/home/agnelo/Documents/Modern Fortran lessons/Lesson 2/plot_height_multipanel.py", line 61
    <title>tsunami/plot_height_multipanel.py at master · modern-fortran/tsunami · GitHub</title>
                                                       ^
SyntaxError: invalid character '·' (U+00B7)
[agnelo@fedora Lesson 2]$ 

The code :

program tsunami
  implicit none

  integer :: i,n
  integer,parameter :: grid_size = 100
  integer,parameter :: num_time_steps = 100
  
  real,parameter ::  dt = 1. !time step [s]
  real,parameter :: dx = 1. !grid spacing [m]
  real,parameter :: c = 1.  !bacckground flow speed [m/s]

  real :: h(grid_size), dh(grid_size)

  integer,parameter :: icenter = 25
  real,parameter :: decay = 0.02

  if(grid_size <= 0) stop 'grid_size must be > 0'
  if(dt <= 0) stop 'time dt must be > 0'
  if(dx<=0) stop 'grid spacing dx must be > 0'
  if(c <= 0) stop 'background flow speed must be > 0'


  do concurrent (i = 1:grid_size)
     h(i) = exp(-decay * (i-icenter)**2)
  end do

  time_loop: do n = 1,num_time_steps
     dh(1) = h(1) - h(grid_size)

     do i=2,grid_size
        dh(i)=h(i) - h(i-1)
     end do

     do i=1,grid_size
        h(i)=h(i) - c*dh(i) / dx *dt
     end do

     print *, n,h
     
  end do time_loop

  
  

  
end program tsunami
1 Like

Hi @Aurelius_Nero, it looks like you might have not downloaded the plotting script (plot_height_multipanel.py) correctly. If you open the script in your code editor it should match this source: tsunami/plot_height_multipanel.py at master · modern-fortran/tsunami (github.com).

You can redownload the script correctly with this link: https://raw.githubusercontent.com/modern-fortran/tsunami/master/src/ch02/plot_height_multipanel.py

For future reference: use the Raw button to download things from Github.

3 Likes

Thank you for the suggestion @lkedward . I downloaded the correct file by pressing the raw button, but the program runs and nothing appears. Could it be that the plots just appear and disappear and we need to pause it somehow ?

Good to hear it’s now running. Did it create a file water_height_ch02.svg in the current directory?

2 Likes

omg, yes. :smiley: I don’t know how I missed it ! Thank you so much :slight_smile:

2 Likes