How to resolve the algorithm File size step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm File size step by step in the Fortran programming language

Table of Contents

Problem Statement

Verify the size of a file called     input.txt     for a file in the current working directory, and another one in the file system root.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm File size step by step in the Fortran programming language

Source code in the fortran programming language

    use :: iso_fortran_env, only : FILE_STORAGE_SIZE
    implicit none
    character(len=*),parameter :: filename(*)=[character(len=256) :: 'input.txt', '/input.txt']
    integer                    :: file_size, i
    do i=1,size(filename)
       INQUIRE(FILE=filename(i), SIZE=file_size)  ! return -1 if cannot determine file size
       write(*,*)'size of file '//trim(filename(i))//' is ',file_size * FILE_STORAGE_SIZE /8,' bytes'
    enddo
    end


   20     READ (INF,21, END = 30) L	!R E A D  A  R E C O R D - but only its length.
   21     FORMAT(Q)			!This obviously indicates the record's length.
          NRECS = NRECS + 1	!CALL LONGCOUNT(NRECS,1)	!C O U N T  A  R E C O R D.
          NNBYTES = NNBYTES + L	!CALL LONGCOUNT(NNBYTES,L)	!Not counting any CRLF (or whatever) gibberish.
          IF (L.LT.RMIN) THEN		!Righto, now for the record lengths.
            RMIN = L			!This one is shorter.
            RMINR = NRECS		!Where it's at.
          ELSE IF (L.GT.RMAX) THEN	!Perhaps instead it is longer?
            RMAX = L			!Longer.
            RMAXR = NRECS		!Where it's at.
          END IF			!So much for the lengths.
          GO TO 20			!All I wanted to know...


  

You may also check:How to resolve the algorithm Loops/Do-while step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the Java programming language
You may also check:How to resolve the algorithm Knapsack problem/0-1 step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Mind boggling card trick step by step in the zkl programming language
You may also check:How to resolve the algorithm Miller–Rabin primality test step by step in the PHP programming language