forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Basic query about plotting

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
arctica



Joined: 10 Sep 2006
Posts: 105
Location: United Kingdom

PostPosted: Wed Dec 27, 2023 1:40 pm    Post subject: Basic query about plotting Reply with quote

Hello all,

I would like to plot the output from the following program but not sure on the best methodology. Looking to plot(real_part, imaginary_part) to get the orbit plot:

Code:

program Riemann_Zeta

  integer, parameter :: k = 10001
  integer, allocatable :: t(:)
  real, allocatable :: vec(:)
  integer i, j, n
  real real_part(k), imaginary_part(k), start, finish, a, inc
  complex s(k)

  call clock@(start)

  open(25,file='complex_zeta.csv',status='replace')
 
  t=(/0, (i,i=1,k)/)

  a = 0.    ! initial value
  inc = 0.01 ! increment value
  n = 10001   ! number of values 
  allocate(vec(n))
  vec = [(a + (i-1) * inc, i=1,n)]  ! array constructor

  do j = 1, k
     s(j) = cmplx(0.5,vec(j)) ! Generate array of complex numbers (0-100)
  end do

  real_part = real(zeta_3(s,1000))
  imaginary_part = aimag(zeta_3(s,1000))

  !do i = 1, k
  write(25,'(f15.12,",",f15.12)') (real_part(i), imaginary_part(i), i=1,k) ! write data to csv file
  !end do

  close(25)
  call clock@(finish)

  print *, zeta_3(cmplx(0.5,1.0),10000) ! complex number fixed value

  print *, 'Processing time was ', finish-start, ' seconds'

contains
 
elemental function zeta_3(s,n) result(zs1)
   integer,allocatable :: nn(:)
   integer, intent(in) :: n
   complex zs1
   complex, intent(in) :: s
   allocate (nn(n))
   nn = (/(i,i=1,n)/)
   zs1 = sum((-1)**(nn + 1)/(nn**s ))
   zs1 = 1/(1 - 2**( 1-s ))*zs1
end function zeta_3
 
end program


Any advice on the best way to plot would be most helpful.

Thanks
Lester
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 697
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Wed Dec 27, 2023 2:57 pm    Post subject: Reply with quote

Does this help? I have added a few lines to your program which allows the phase plane plot to be displayed using the %pl format code. Further details can be found searching the help file for "Native Graph Plotting"

Code:
program Riemann_Zeta
 
  use clrwin
  integer :: iw
 
  integer, parameter :: k = 10001
  integer, allocatable :: t(:)
  real, allocatable :: vec(:)
  integer i, j, n
  real real_part(k), imaginary_part(k), start, finish, a, inc
  complex s(k)

  call clock@(start)

  open(25,file='complex_zeta.csv',status='replace')
 
  t=(/0, (i,i=1,k)/)

  a = 0.    ! initial value
  inc = 0.01 ! increment value
  n = 10001   ! number of values
  allocate(vec(n))
  vec = [(a + (i-1) * inc, i=1,n)]  ! array constructor

  do j = 1, k
     s(j) = cmplx(0.5,vec(j)) ! Generate array of complex numbers (0-100)
  end do

  real_part = real(zeta_3(s,1000))
  imaginary_part = aimag(zeta_3(s,1000))

  write(25,'(f15.12,",",f15.12)') (real_part(i), imaginary_part(i), i=1,k) ! write data to csv file

  close(25)
  call clock@(finish)
  print *, zeta_3(cmplx(0.5,1.0),10000) ! complex number fixed value
  print *, 'Processing time was ', finish-start, ' seconds'

  iw = winio@('%mn[Exit]&','Exit')
  iw = winio@('%fn[Consolas]%ts%bf&',1.5d0)
  call winop@('%pl[native,x_array,frame,gridlines,width=2,link=curves,colour=blue]')
  call winop@('%pl[xaxis="Re(z)",yaxis="Im(z)"]')
  call winop@('%pl[Title="Orbit plot"]')
  iw = winio@('%pl&',800,800,k,dble(real_part),dble(imaginary_part))
  iw = winio@('')
 
contains
elemental function zeta_3(s,n) result(zs1)
   integer,allocatable :: nn(:)
   integer, intent(in) :: n
   complex zs1
   complex, intent(in) :: s
   allocate (nn(n))
   nn = (/(i,i=1,n)/)
   zs1 = sum((-1)**(nn + 1)/(nn**s ))
   zs1 = 1/(1 - 2**( 1-s ))*zs1
end function zeta_3
end program
Back to top
View user's profile Send private message Visit poster's website
arctica



Joined: 10 Sep 2006
Posts: 105
Location: United Kingdom

PostPosted: Wed Dec 27, 2023 4:23 pm    Post subject: Reply with quote

Many thanks Kenneth! That worked fine with the Clearwin usage. Will have to study that more.

Haven't had a thorough look yet, but can the plot be easily saved or exported to an image file?

Thanks
Lester
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 697
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Fri Dec 29, 2023 7:55 pm    Post subject: Reply with quote

Yes, the plot can be exported to the clipboard via the function GRAPHICS_TO_CLIPBOARD@ and thereafter "pasted" in to a word document, or the function EXPORT_IMAGE@ can used used to save the image to a graphics file (such as .jpeg format).
Back to top
View user's profile Send private message Visit poster's website
arctica



Joined: 10 Sep 2006
Posts: 105
Location: United Kingdom

PostPosted: Sat Dec 30, 2023 9:46 am    Post subject: Reply with quote

Hi Kenneth,

Thanks for the pointer, not sure how to get the syntax working. Just adding export_image@(Riemann1.jpg') just makes a blank image file?

Code:

  iw = winio@('%mn[Exit]&','Exit')
  iw = winio@('%fn[Consolas]%ts%bf&',1.5d0)
  call winop@('%pl[native,x_array,frame,gridlines,width=1.5,link=curves,colour=red,colour=blue]')
  call winop@('%pl[xaxis="Real(t)",yaxis="Zeta(s)"]')
  !call winop@('%pl[Title="Orbit plot"]')
  call winop@('%pl[Title="Riemann Zeta function (s = 0.5 + i*t)"]')
  iw = winio@('%pl&',1400,800,k,dble(vec),dble(real_part),dble(imaginary_part))
  !iw = winio@('%pl&',800,800,k,dble(vec),dble(imaginary_part))
  iw=export_image@('Riemann1.jpg')
  iw = winio@('')


Is there some extra syntax needed?

Thanks
Lester
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 697
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Sat Dec 30, 2023 8:34 pm    Post subject: Reply with quote

Lester,

In your example, you are calling export_image@ before the terminating winio@ call. This is too soon to call export_image@ as the window containing the graphic does not yet exist.

Export_image@ needs to be called while the window containing the graphic exists and is displayed.

Look at this example, which provides three different ways to generate the .jpg file.

Code:
program lester
use clrwin
implicit none
integer, parameter :: n = 11
integer :: i, iw
real :: x(n), y(n)
integer :: export_cb
external:: export_cb
  x = [(i-1, i=1,n)]
  y = x*x
  iw = winio@('%mn[Exit]&','Exit')
!  iw = winio@('%mn[Export]&',export_cb)   !Uncomment this line to provide a menu item to generate .jpg file
!  iw = winio@('%^bt[Export]&',export_cb)  !Uncomment this line to provide a button to generate .jpg file
!  iw = winio@('%sc&',export_cb)           !Uncomment this line to automatically create .jpg file when window is formed
  iw = winio@('%fn[Consolas]%ts%bf&',2.d0)
  call winop@('%pl[native,n_graphs=1,x_array,frame,etched,gridlines,width=3,link=curves,colour=blue]')
  call winop@('%pl[xaxis=" x ",yaxis="x**2"]')
  iw = winio@('%ff%pl&',1400,800,n,dble(x),dble(y))
  iw = winio@('')
end program lester

integer function export_cb()
use clrwin
  i = EXPORT_IMAGE@('plot.jpg')
  export_cb = 2
end function export_cb
Back to top
View user's profile Send private message Visit poster's website
arctica



Joined: 10 Sep 2006
Posts: 105
Location: United Kingdom

PostPosted: Sun Dec 31, 2023 8:51 am    Post subject: Reply with quote

Hi Kenneth,

Thanks for explaining the correct syntax for image export, makes it a lot easier to understand to see example code.

Lester
Back to top
View user's profile Send private message
DanRRight



Joined: 10 Mar 2008
Posts: 2816
Location: South Pole, Antarctica

PostPosted: Sun Dec 31, 2023 9:45 am    Post subject: Reply with quote

If
1) saving graphs into JPG and PNG would be added to Designer's mode (with revolving file numbers like with our cellphone cameras) and
2) font names, plot title and axis names were editable there too

the beginners would start learning Clearwin almost instantly and getting perfect quality plots with adding just one single line of Fortran to their existing codes
Code:
i=winio@('%PL[file=settings.set, N_GRAPHS=1]', 1000, 800, n, x, y)


Title and axis names of course can fit into one line too but this makes this approach little bit less amazing for the most common plots

Code:
i=winio@('%PL[file=settings.set, title="Ex Field",x_axis="Distance ( um )",y_axis="Ex field ( arb.un.)",N_GRAPHS=1]',1000,800,n,x,y)


or (dble(x), dble(y) because in the above example single precision x,y were initially used but Clearwin uses double precision (not always but for this exact purpose - yes).

Then you just click on icon in left top corner and change the plot parameters to have best looking plot, no additional programming is needed


Last edited by DanRRight on Mon Jan 01, 2024 12:47 pm; edited 3 times in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Sun Dec 31, 2023 12:28 pm    Post subject: Reply with quote

I find that the "Snipping Tool" is very useful.

On a modern machine you just press the Windows key with Shift+S.
Back to top
View user's profile Send private message AIM Address
DanRRight



Joined: 10 Mar 2008
Posts: 2816
Location: South Pole, Antarctica

PostPosted: Sun Dec 31, 2023 4:04 pm    Post subject: Reply with quote

I use this in Windows and Linux when save stuff from the internet but for own codes the only convenient method is to use Clearwin like Ken showing above. Often used plots of the code need their own "Save Plot" button. I use this in 100 different places. This is specifically needed for creating animations out of stills because the size of frames have to be the same and you need to save plots fast. By the way Cearwin is missing animation utility very much
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Mon Jan 01, 2024 1:24 pm    Post subject: Reply with quote

It is not as concise as Ken's example, but this is my plot file generation code, that allows repeat menu selection
(I hope it fits in post!)
Code:
!==SCREEN_DUMP_FUNC==========================================================
  module plot_info

      integer       :: x_size, y_size                                   ! plot size in pixels
      character*140 :: plot_desc                                        ! plot title
      character*80  :: sap_lis_file = 'result_v5-5-d10fst_hist.lis'     ! data file
      character*40  :: plot_prefix = 'hist_result_plot'                 ! dump file prefix
      character*4   :: plot_ext    = '.png'                             ! dump file type

  contains
 
    integer function draw_legend ()
    include<windows.ins>
     integer lx, ly
     lx = 15
     ly = 20
     call draw_characters@ ( trim(plot_desc), lx, ly, 0 )
     ly = y_size - 30
     call draw_characters@ ( trim(sap_lis_file), lx, ly, 0 )

     draw_legend = 2
   end function draw_legend
   
  end module plot_info

  integer*4 function Screen_Dump_func ()
  use plot_info
!
!  dumps a png file from active selected region
!
    character message*50
!
      call Dump_png_func ( plot_prefix, plot_ext, message )  ! uses export_image@ (file_png)
!
      write (*,*)  '  Exiting Screen_Dump_func ', trim (message)
      Screen_Dump_func = 2
    return
  end function Screen_Dump_func
 
  Subroutine Dump_png_func ( prefix, ext, message )
!
!  dumps a png file from active selected region
!
!    use mswin
      include <clearwin.ins>
!
      character message*(*), prefix*(*), ext*4
!
      integer*4 error_png, file_num, nx, ny
      character file_png*80
      data file_num / 99 /

!  develop a screen dump file name
!      write (*,*)  '    Entering Dump_png_func; file_num =',file_num
      call get_next_dump_file_name (file_num, file_png, prefix, ext)
       if (file_num > 999) then
         error_png = -999
       else
!
!         write (*,*) '     Dumping screen to ',trim (file_png)              !feb18
         error_png = export_image@ (file_png)
       end if
!
      call get_graphical_resolution@ ( nx, ny )
      write ( *,1000) ext, trim(file_png), nx, ny, error_png
 1000 format (a,' DUMP file ',a,  &
              ' Size : ',i0,' x ',i0,' (export_image@ = ',i0,')')
!
      if (error_png > 0) then
         message = ext // ' dump to ' // file_png
      else if (error_png == -999) then
         message = 'Unable to open ' // file_png
      else
         message = 'Unable to use ' // file_png
      end if
!
  end subroutine Dump_png_func
 
  subroutine get_next_dump_file_name (file_nn, file_name, prefix, ext)
!
!    develop a screen dump file name
!
      integer*4 file_nn
      character file_name*(*), prefix*(*), ext*4
      integer   iostat
      logical   exist, opened
!
      DO
        file_nn = file_nn + 1
        if (file_nn > 999) exit
!
        if (len_trim (prefix) > 0) then
          write (file_name, '(a,i3.3,a)') trim(prefix) // '_dump', file_nn, ext
        else
          write (file_name, '(a,i3.3,a)') 'screen_dump', file_nn, ext
        end if
        WRITE (*,*) '    get_next_dump_file > TESTING :', TRIM( file_name )
       
        INQUIRE (FILE=file_name, EXIST=exist, OPENED=opened, IOSTAT=iostat)
        if ( .not. exist .and. .not.opened ) EXIT
        if ( exist .or. opened             ) CYCLE
      END DO

  end subroutine get_next_dump_file_name


I find .png is best for reports
I am sure it can be enhanced, but some ideas
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group