How to resolve the algorithm Take notes on the command line step by step in the Fortran programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Take notes on the command line step by step in the Fortran programming language
Table of Contents
Problem Statement
Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then all the arguments, joined with spaces, prepended with a tab, and appended with a trailing newline, are written to NOTES.TXT. If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Take notes on the command line step by step in the Fortran programming language
Source code in the fortran programming language
program notes
implicit none
integer :: i, length, iargs, lun, ios
integer,dimension(8) :: values
character(len=:),allocatable :: arg
character(len=256) :: line
character(len=1),parameter :: tab=char(9)
iargs = command_argument_count()
open(file='notes.txt',newunit=lun,action='readwrite',position='append',status='unknown')
if(iargs.eq.0)then
rewind(lun)
do
read(lun,'(a)',iostat=ios)line
if(ios.ne.0)exit
write(*,'(a)')trim(line)
enddo
else
call date_and_time(VALUES=values)
write(lun,'(*(g0))')values(1),"-",values(2),"-",values(3),"T",values(5),":",values(6),":",values(7)
write(lun,'(a)',advance='no')tab
do i=1,iargs
call get_command_argument(number=i,length=length)
arg=repeat(' ',length)
call get_command_argument(i, arg)
write(lun,'(a,1x)',advance='no')arg
enddo
write(lun,*)
endif
end program notes
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the HicEst programming language
You may also check:How to resolve the algorithm Show the epoch step by step in the PHP programming language
You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Maxima programming language
You may also check:How to resolve the algorithm Singly-linked list/Element insertion step by step in the REXX programming language
You may also check:How to resolve the algorithm Tic-tac-toe step by step in the C++ programming language