 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
arctica
Joined: 10 Sep 2006 Posts: 146 Location: United Kingdom
|
Posted: Wed Feb 05, 2025 5:58 pm Post subject: Learning Clearwin |
|
|
Hello
I built a test code using the tutorial as a template:
Code: | winapp
module schwarzschildmodule
use clrwin
implicit none
real(kind=2) :: mass = 1.0
real(kind=2), parameter :: sol = 1.989e30 ! 1 solar mass in kg
real(kind=2), parameter :: velocity_of_light = 2.99792458e8 ! m/s
real(kind=2), parameter :: gravitational_constant = 6.67430e-11 ! m^3 kg^1 s^2
character(50) :: str = ''
contains
function Schwarzschild_radius(mass) result(Rs)
real(kind=2), intent(in) :: mass
real(kind=2) :: Rs
Rs = 2 * gravitational_constant * mass / velocity_of_light**2
end function Schwarzschild_radius
integer function calculate_radius()
implicit none
real(kind=2) :: SRadius
if (mass <= 0) then
str = 'Mass must be positive!'
else
SRadius = Schwarzschild_radius(mass * sol)
write(str, '("Schwarzschild radius: ", F15.5, " meters")') SRadius
end if
call window_update@(str)
calculate_radius = 1
end function calculate_radius
integer function about()
implicit none
integer :: iw
iw= winio@('%ca[about Schwarzschild calculator]&')
iw= winio@('%fn[times new roman]%ts%bf%cnSchwarzschild Radius Calculator&', 2.0d0)
iw= winio@('%ts%4nl&', 1.0d0)
iw= winio@('%cnProgram to calculate Schwarzschild radius for a given mass in solar masses%2nl&')
iw= winio@('%ts%tc%cn%bfclearwin+&', 1.5d0, rgb@(255,0,0))
iw= winio@('%tc%sf%2nl%cnby&', -1)
iw= winio@('%2nl%cnSalford Software&')
iw= winio@('%2nl%cn%9`bt[ok]')
about = 1
end function about
end module schwarzschildmodule
!==================================================================
program schwarzschild_calculator
use schwarzschildmodule
implicit none
integer :: iw
iw= winio@('%ca[Schwarzschild Radius Calculator]&')
iw= winio@('%mn[&file[e&xit]]&', 'exit')
iw= winio@('%mn[&help[&about Schwarzschild calculator]]&', about)
iw= winio@('%il&', 0, 1000)
iw= winio@('Mass in solar masses: %rf&', mass)
iw= winio@('%ta%`^bt[Calculate Radius]&', calculate_radius)
iw= winio@('%2nl%tc[red]%ob%42st%cb', str)
end program schwarzschild_calculator
|
How can I add several function outputs to the final output? Is it a call back function for each module function, and is there an easy way of grouping things to avoid repetition?
Lester |
|
Back to top |
|
 |
wahorger

Joined: 13 Oct 2014 Posts: 1255 Location: Morrison, CO, USA
|
Posted: Wed Feb 05, 2025 11:48 pm Post subject: |
|
|
Since you only compute a single value, there appears to be only one output, given the input "mass".
I'm not understanding the question, and would be glad to help, as would most folks on this forum.
As an aside, in some of my windows, I will click on a single button to start a function, and have several variables that contain intermediate results displayed. as or after the function executes. Is that what you are asking?
Bill |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 801 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Thu Feb 06, 2025 12:14 am Post subject: |
|
|
Lester,
Like Bill, I'm struggling to understand what you are trying to achieve.
However, I played about with your code and it may be that this provides something like what you are looking for? One "Calculate" button, %rb radio buttons to select one or more different functions, with the output written to a %re edit box.
The output to the %re is determined by the status of the control values for %rb, and the single callback simply works serial on each in turn, doing the necessary calculations (which may be further function calls) if required.
Code: | winapp
module schwarzschildmodule
use clrwin
implicit none
real(kind=2) :: mass = 1.0
real(kind=2), parameter :: sol = 1.989e30 ! 1 solar mass in kg
real(kind=2), parameter :: velocity_of_light = 2.99792458e8 ! m/s
real(kind=2), parameter :: gravitational_constant = 6.67430e-11 ! m^3 kg^1 s^2
character(50) :: str = ''
character(len=32*1024) :: buffer = ''
integer :: sr_control = 1, sin_control = 0, cos_control = 0, random_control = 0
contains
integer function calculate_cb()
implicit none
real(kind=2) :: val
buffer = ''
if (SR_control .eq. 1) then
if (mass <= 0) then
str = 'Mass must be positive!'
else
val = 2 * gravitational_constant * mass * sol / velocity_of_light**2
write(str, '("Schwarzschild radius: ", F15.5, " meters")') val
end if
call append2buffer
end if
if (SIN_control .eq. 1) then
val = sin(mass)
write(str, '("Sin: ", F15.5)') val
call append2buffer
end if
if (COS_control .eq. 1) then
val = cos(mass)
write(str, '("Cos: ", F15.5)') val
call append2buffer
end if
if (RANDOM_control .eq. 1) then
call random_number(val)
write(str, '("Random", F15.5)') val
call append2buffer
end if
call window_update@(buffer)
calculate_cb = 2
end function calculate_cb
subroutine append2buffer
if (len_trim(buffer) .eq. 0) then
buffer = str
else
buffer = trim(buffer)//achar(13)//achar(10)//str
end if
end subroutine append2buffer
end module schwarzschildmodule
program schwarzschild_calculator
use schwarzschildmodule
implicit none
integer :: iw
iw= winio@('%ca[Schwarzschild Radius Calculator]&')
iw= winio@('%mn[&file[e&xit]]&', 'exit')
iw= winio@('%il&', 0, 1000)
iw= winio@('Mass in solar masses: %rf%2nl&', mass)
iw= winio@('%rb[Schwarzschild Radius]%nl&',SR_control)
iw= winio@('%rb[Sin]%nl&',SIN_control)
iw= winio@('%rb[Cos]%nl&',COS_control)
iw= winio@('%rb[Random]%2nl&',Random_control)
iw= winio@('%cn%`^tt[Calculate]%2nl&', calculate_cb)
iw= winio@('%42.10re[VSCROLLBAR]',buffer)
end program schwarzschild_calculator |
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8184 Location: Salford, UK
|
Posted: Thu Feb 06, 2025 7:37 am Post subject: |
|
|
Users who are getting started with ClearWin+ should take a look at the book "Fortran and the Art of Windows Programming" written by Eddie Broomhead.
This can be found in pdf form, installed in the folder \Silverfrost\FTN95\doc. |
|
Back to top |
|
 |
arctica
Joined: 10 Sep 2006 Posts: 146 Location: United Kingdom
|
Posted: Thu Feb 06, 2025 1:45 pm Post subject: |
|
|
Thanks Ken for the code idea, that works for the basic structure I was looking to build.
Found the guide Paul, that will be a good start; a bit of a learning curve.
I did try to load the original code up but it did not work, so guess there must be limit.
Lester |
|
Back to top |
|
 |
Robert

Joined: 29 Nov 2006 Posts: 457 Location: Manchester
|
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 801 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Fri Feb 07, 2025 10:30 am Post subject: |
|
|
There is also the Clearwin Examples folder at the Silverfrost GitLab folder. Link on the RHS of the Silverfrost homepage which points to https://gitlab.com/silverfrost
I have found the content of the Controls Demo folder particularly helpful.
Once in the folder, the entire contents can be downloaded as a zip file via the blue code button on the RHS.
Once downloaded, you can compile and run the single demo program and study the source code to understand what the controls do. |
|
Back to top |
|
 |
arctica
Joined: 10 Sep 2006 Posts: 146 Location: United Kingdom
|
Posted: Fri Feb 07, 2025 11:38 am Post subject: |
|
|
Thanks Ken for the pointer to the Clearwin examples folder; that really helps.
Have updated the existing code with sliders for mass and velocity which worked! It is a start, but interesting to learn the basics. Fortran is interesting to code just for interest and learning new methods.
Is Dropbox the way to share large code samples? The code block here seems limited.
Lester |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 801 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Fri Feb 07, 2025 1:54 pm Post subject: |
|
|
Lester,
Yes, there is a limit of about 70 lines of code that can be posted here.
Dropbox file sharing is one alternative, which seems to work well. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Sat Feb 08, 2025 5:33 am Post subject: |
|
|
I would also recommend reading Eddie's book "Fortran and the Art of Windows Programming".
It has been a few/many years since I last wrote clearwin+ programs, and the discussion of the approach to the %xx options is a useful help.
I started with his homer.f90 example program in "first steps" and have just added more features. ( .f90 helps with longer coding lines! )
I actually spent a year first developing the data structures and analysis phase. Now I can see how to improve the analysis ! |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Sat Feb 08, 2025 5:36 am Post subject: Re: |
|
|
Kenneth_Smith wrote: | Lester,
Yes, there is a limit of about 70 lines of code that can be posted here.
Dropbox file sharing is one alternative, which seems to work well. |
Could the forum have a scrollable code box with more capacity ? |
|
Back to top |
|
 |
wahorger

Joined: 13 Oct 2014 Posts: 1255 Location: Morrison, CO, USA
|
Posted: Sun Feb 09, 2025 4:30 pm Post subject: |
|
|
Robert, thanks for the on-line link! |
|
Back to top |
|
 |
|
|
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
|