Updated My Coding Tool

Baymax found a pillow. It’s actually Mark’s Steam Deck case, but it works for the cat.

Baymax is going home tomorrow! We’re really going to miss him. Oh, Mark is also going home tomorrow. We’ll miss him a lot too. It’s been nice having Baymie here for about two months! It’s also been nice having Mark here for a few days. Two months would have been even better!

Many days have gone by again since my last post. But I have not been inactive. Mostly inactive, true. But not entirely.

IDE Worries

I’ve been using a web-based application called Code-Server. It’s a clone of VS Code, but without the telemetry. At least that’s how it’s advertised. I think its main strength is that since it’s web-based, I can code from anywhere. Just open a browser, log in, and start. It works with GitHub and has extensions for pretty much every language and tool that you can find on VS Code. Pretty cool. I’ve written a tiny bit of sample Python code as a proof of concept and it’s pretty slick.

One problem: I can’t seem to get FORTRAN working on it.

FORTRAN Woes

Heaven knows I’ve tried. There is a FORTRAN extension or two. I installed one, pasted some FORTRAN code into the IDE, and . . . It didn’t compile. As I recall, the source code was formatted as a FORTRAN program, but the ‘Run” button didn’t appear.

I figured maybe I didn’t have an actual compiler installed on the server hosting the IDE. So I installed one via command line, compiled the little programs I had written (sort of – more detail later), and went back to the IDE to try again. Still nothing. So I gave up.

And It’s Resolved, Mostly

I installed VS Code on Shemp the Mac Studio. I got it hooked up to GitHub, installed a few extensions , brought up my Python demo, and it works great!

That’s as far as I got before I ran out of time. I’ll try it again tomorrow or Sunday.

The good thing about GitHub it that I can install VS Code on any machine I want to use to develop and have them all synchronized with my code libraries. it still kind of prefer my web-based code server, but it just wasn’t working with FORTRAN. And who doesn’t want to code in FORTRAN?

Speaking of which, I had ChatGPT write me a couple of little programs: one to write a list of very large random numbers to a file and another to add them all up. Silly, but it’s a reasonable demo of FORTRAN’s large number handling capabilities. I’ll dig up the source code and post it here:

Here’s the program to generate the random numbers:

program generate_large_random_numbers
    implicit none
    integer, parameter :: dp = kind(1.0d0)
    real(dp) :: number
    integer :: i
    intege :: unit, ios
    real(dp) :: scale
    call random_seed()  ! Initialize the random number generator
 
    unit = 10  ! File unit number
    scale = 1.0e10_dp  ! Scale factor to generate large numbers
 
    ! Open the file for writing
    open(unit, file='numbers.txt', status='replace', action='write', iostat=ios)
    if (ios /= 0) then
        print *, 'Error opening file'
        stop
    end if
 
    ! Generate and write 50 large random numbers
    do i = 1, 50
        call random_number(number)  ! Generate a random number between 0 and 1
        number = number * scale  ! Scale it to a larger range
        write(unit, '(F30.10)', iostat=ios) number
        if (ios /= 0) then
            print *, 'Error writing number ', i
            stop
        end if
    end do
 
    ! Close the file
    close(unit)
 
    print *, '50 large random numbers have been written to numbers.txt'
 
end program generate_large_random_numbers

And here’s the one to sum the numbers up:

program sum_large_numbers
    implicit none
    integer, parameter :: dp = kind(1.0d0)
    real(dp) :: sum
    real(dp) :: number
    integer :: i
    integer :: unit, ios
 
    sum = 0.0_dp
    unit = 10  ! File unit number
 
    ! Open the file for reading
    open(unit, file='numbers.txt', status='old', action='read', iostat=ios)
    if (ios /= 0) then
        print *, 'Error opening file'
        stop
    end if
 
    ! Read and sum the numbers
    do i = 1, 50
        read(unit, *, iostat=ios) number
        if (ios /= 0) then
            print *, 'Error reading number ', i
            stop
        end if
        sum = sum + number
    end do
 
    ! Close the file
    close(unit)
 
    ! Print the result
    print *, 'The sum of the 50 large numbers is: ', sum
 
end program sum_large_numbers

Try ‘em out!

Leave a Reply

Your email address will not be published. Required fields are marked *