Fortran Program for Runtime Log Generation
Budget: $30 – $250 AUD
I'm in need of a competent expert in Modern Fortran programming to create a lightweight program.
The primary task will be implementing functionality that generates a runtime log file. This isn't your average log file; each record should have the date and time appended to it. Your task is to ensure each execution of the program creates a new log file instead of overwriting the existing data.
In terms of filename format, I'm after a specific style. I want it to use the current date and time, formatted like so: "16/03/2024 8:40:13 AM".
Key skills needed:
- Proficient in Modern Fortran
- Experience working with log file generation
- Attention to detail (precise date/time formatting and file naming)
This task is a small but critical part of a larger project. Accuracy and precision are key. Apply if you're confident in your ability to deliver this requirement.
Here is the sample code generated by ChatGPT (check out the file: Fortran Program for Runtime Log Generation.txt - you will see the indentation):
Creating a Fortran runtime log that includes the date and time for each record in the specified format (dd/mm/yyyy hh:mm:ss AM/PM) involves using the intrinsic `date_and_time` and `time` functions to capture the current date and time, then formatting it accordingly. Fortran doesn't have built-in AM/PM formatting, so we'll need to manually convert from 24-hour to 12-hour format and decide whether it's AM or PM.
Here's an example program that demonstrates how to write log entries to a file with the specified date and time format:
```fortran
program logging_example
implicit none
character(len=8) :: date
character(len=10) :: time
integer :: hours, minutes, seconds, values(8)
character(len=2) :: am_pm
character(len=20) :: formatted_datetime
! Open the log file
open(unit=10, file='runtime_log.txt', status='unknown', action='write')
! Get the current date and time
call date_and_time(date, time, values)
read(time(1:2), *) hours
read(time(3:4), *) minutes
read(time(5:10), *) seconds
! Convert 24-hour to 12-hour format and set AM/PM
if (hours >= 12) then
am_pm = 'PM'
if (hours > 12) then
hours = hours - 12
end if
else
if (hours == 0) then
hours = 12
end if
am_pm = 'AM'
end if
! Format the datetime string
write(formatted_datetime, '(I2.2,"/",I2.2,"/",I4," ",I2.2,":",I2.2,":",I2.2," ",A2)') &
values(3), values(2), values(1), hours, minutes, seconds, am_pm
! Write a log entry
write(10, '(A)') 'Log entry at ' // trim(formatted_datetime) // ': Hello, World!'
! Close the log file
close(unit=10)
print *, 'Log entry added.'
end program logging_example
```
In this example, the program opens a file called `runtime_log.txt` and writes a single log entry with the current date and time formatted as requested. It uses `date_and_time` to get the current date and separates the time into hours, minutes, and seconds to manually format it to a 12-hour format with AM or PM.
The primary task will be implementing functionality that generates a runtime log file. This isn't your average log file; each record should have the date and time appended to it. Your task is to ensure each execution of the program creates a new log file instead of overwriting the existing data.
In terms of filename format, I'm after a specific style. I want it to use the current date and time, formatted like so: "16/03/2024 8:40:13 AM".
Key skills needed:
- Proficient in Modern Fortran
- Experience working with log file generation
- Attention to detail (precise date/time formatting and file naming)
This task is a small but critical part of a larger project. Accuracy and precision are key. Apply if you're confident in your ability to deliver this requirement.
Here is the sample code generated by ChatGPT (check out the file: Fortran Program for Runtime Log Generation.txt - you will see the indentation):
Creating a Fortran runtime log that includes the date and time for each record in the specified format (dd/mm/yyyy hh:mm:ss AM/PM) involves using the intrinsic `date_and_time` and `time` functions to capture the current date and time, then formatting it accordingly. Fortran doesn't have built-in AM/PM formatting, so we'll need to manually convert from 24-hour to 12-hour format and decide whether it's AM or PM.
Here's an example program that demonstrates how to write log entries to a file with the specified date and time format:
```fortran
program logging_example
implicit none
character(len=8) :: date
character(len=10) :: time
integer :: hours, minutes, seconds, values(8)
character(len=2) :: am_pm
character(len=20) :: formatted_datetime
! Open the log file
open(unit=10, file='runtime_log.txt', status='unknown', action='write')
! Get the current date and time
call date_and_time(date, time, values)
read(time(1:2), *) hours
read(time(3:4), *) minutes
read(time(5:10), *) seconds
! Convert 24-hour to 12-hour format and set AM/PM
if (hours >= 12) then
am_pm = 'PM'
if (hours > 12) then
hours = hours - 12
end if
else
if (hours == 0) then
hours = 12
end if
am_pm = 'AM'
end if
! Format the datetime string
write(formatted_datetime, '(I2.2,"/",I2.2,"/",I4," ",I2.2,":",I2.2,":",I2.2," ",A2)') &
values(3), values(2), values(1), hours, minutes, seconds, am_pm
! Write a log entry
write(10, '(A)') 'Log entry at ' // trim(formatted_datetime) // ': Hello, World!'
! Close the log file
close(unit=10)
print *, 'Log entry added.'
end program logging_example
```
In this example, the program opens a file called `runtime_log.txt` and writes a single log entry with the current date and time formatted as requested. It uses `date_and_time` to get the current date and separates the time into hours, minutes, and seconds to manually format it to a 12-hour format with AM or PM.