SF_IOTOOLS
IOFILE submodule
Description
Contains procedures for generating output files
Quick access
- Routines:
create_dir(),file_bunzip(),file_bzip(),file_gunzip(),file_gzip(),file_info(),file_length(),file_size(),file_tarbz2(),file_targz(),file_untarbz2(),file_untargz(),file_unxz(),file_xz(),free_unit(),free_units(),get_filename(),get_filepath(),newunit(),print_matrix(),reg(),reverse(),set_store_size(),str(),to_lower(),to_upper(),txtfy()
Subroutines and functions
- interface iofile/str(i4, npad, r8, c, bool, txt[, d, lead])
This function converts an integer, real, complex, logical or character variable into a character string, left-justified and without leading or trailing blanks. The specific procedures cover
an integer, optionally zero padded to
Npadcharacters,str(12)gives12andstr(12,5)gives00012a real, written in fixed format with
d+leaddecimals (defaultsd=6,lead=1) if \(|r| \ge 10^{-lead}\), and in scientific format withddecimals otherwise,str(3.14159d0)gives3.1415900a complex, written as
(re,im)with each part formatted as a reala logical, written as
TorFa character string, stripped of leading and trailing blanks
- Parameters:
i4 [integer] – integer to convert
npad [integer] – number of characters of the zero padded string
r8 [real] – real to convert
c [complex] – complex to convert
bool [logical] – logical to convert
txt [character(len=*)] – character string to strip of leading and trailing blanks
- Result:
string [character(len=:), allocatable]
- Options:
d [integer] – digits parameter of the format (default 6)
lead [integer] – values with abs < 10**(-lead) use scientific format (default 1)
- interface iofile/txtfy(i4, npad, r8, c, bool, txt[, d, lead])
This function is obsolete, it is a synonym of
str, with the same specific procedures.- Parameters:
i4 [integer] – integer to convert
npad [integer] – number of characters of the zero padded string
r8 [real] – real to convert
c [complex] – complex to convert
bool [logical] – logical to convert
txt [character(len=*)] – character string to strip of leading and trailing blanks
- Result:
string [character(len=:), allocatable]
- Options:
d [integer] – digits parameter of the format (default 6)
lead [integer] – values with abs < 10**(-lead) use scientific format (default 1)
- interface iofile/reg(file)
This function removes the leading and trailing blanks of the character string
file. The result has lengthlen_trim(adjustl(file)).- Parameters:
file [character(len=*), in] – string whose leading and trailing blanks are removed
- Result:
reg [character(len=len_trim(trim(adjustl(trim(file)))))]
- interface iofile/create_dir(dir_name)
This subroutine creates the directory
dir_nameby calling the commandmkdir -v. The parent directories are not created, and the error message ofmkdiris printed if the directory can not be created, for example if it already exists.- Parameters:
dir_name [character(len=*)] – name of the directory to create
- interface iofile/newunit()
This function returns a free unit number, see
free_unit.- Result:
unit [integer]
- interface iofile/print_matrix(m[, file, w, d])
This subroutine prints the real or complex matrix
Mrow by row, on the standard output or in the filefileif present. Each element is written with widthwandddecimals, separated by a blank. Complex elements are written as(re,im). The file is opened with a unit given byfree_unit, and it is not closed by the subroutine.- Parameters:
m (•, •) [real/complex] – matrix to print
- Options:
file [character(len=*)] – file where to print the matrix (default: standard output)
w [integer] – width of each printed number (default 5)
d [integer] – number of decimals of each printed number (default 2)
- function iofile/reverse(string[, n])
This function returns the last
ncharacters of the character stringstringin reverse order, so the length of the result isn. Ifnis absent all the characters are reversed, hencereverse("abcdef")returnsfedcbaandreverse("abcdef",3)returnsfed.- Parameters:
string [character(len=*), in] – string to reverse
- Options:
n [integer, in] – number of characters to reverse, taken from the end of string (default len(string))
- Result:
reverse_string [character(len=:), allocatable]
- function iofile/get_filename(string)
This function returns the name of a file without its path, that is the part of
stringafter the last/, without leading or trailing blanks. It is the whole string if it contains no/.- Parameters:
string [character(len=*)] – path of a file, directories separated by / character(len=len_trim(string)) :: fname
- Result:
fname [character(len=:), allocatable]
- function iofile/get_filepath(string)
This function returns the path of a file, that is the part of
stringup to and including the last/, without leading or trailing blanks. It is an empty string ifstringcontains no/.- Parameters:
string [character(len=*)] – path of a file, directories separated by / character(len=len_trim(string)) :: pname
- Result:
pname [character(len=:), allocatable]
- function iofile/free_unit([n])
This function returns the lowest unit number larger than 100 that is not connected to a file, and stops the program if there is no free unit smaller than 900. If
nis present it is set to the same value. The unit is not reserved, so it must be opened before the function is called again. The function is also available under the namenewunit.- Options:
n [integer]
- Result:
unit [integer]
- function iofile/free_units(n)
This function returns an array of
ndifferent unit numbers larger than 100 that are not connected to a file at the time of the call. The program stops if no free unit smaller than 900 is found.- Parameters:
n [integer] – number of free units to return
- Result:
unit (n) [integer]
- function iofile/file_size(file[, printf])
This function returns the size in Kb of the file
file, rounded to the nearest integer, obtained with thefstatsystem call. If the file does not exist a message is printed and the returned value is not set. Ifprintfis true a message with the file name and its size is printed.- Parameters:
file [character(len=*)] – file name
- Options:
printf [logical] – if T print the size of the file (default F)
- Result:
size [integer]
- function iofile/file_info(file)
This function prints on the screen the information on the file
filereturned by thefstatsystem call: device, inode, mode, number of links, owner and group ids, size, times, block size and number of blocks. It returns 0 if the file does not exist, otherwise the returned value is not set.- Parameters:
file [character(len=*)] – file name
- Result:
file_info [integer]
- function iofile/file_length(file[, verbose, incl_comments])
This function returns the number of lines of the file
file. Blank lines, and comment lines, that is lines whose first item contains the character#, are not counted unlessincl_commentsis true, in which case only the blank lines are skipped. If the file does not exist but a compressed version with extension.gz,.bz2or.xzdoes, the file is first uncompressed withfile_gunzip,file_bunziporfile_unxz. If no file is found a message is printed and 0 is returned. Ifverboseis true, which is the default, the number of lines is printed.- Parameters:
file [character(len=*)] – file name, or name without extension of a .gz, .bz2 or .xz compressed file
- Options:
verbose [logical] – if T print the number of lines (default T)
incl_comments [logical] – if T count the comment lines too (default F)
- Result:
lines [integer]
- subroutine iofile/set_store_size(size)
This subroutine sets the size
size, in Kb, used as default threshold byfile_gzip,file_bzipandfile_xz: files that are not larger than this value are not compressed. The default is 2048 Kb. The new value is printed on the screen.- Parameters:
size [integer] – size threshold in Kb above which files are compressed (default 2048)
- subroutine iofile/file_gzip(file[, size])
This subroutine compresses the file
filewithgzip -fv --best --rsyncable, producingfile.gz, if its size given byfile_sizeis larger thansizeKb. The default threshold is the store size, 2048 Kb unless changed withset_store_size. Smaller files are left untouched.- Parameters:
file [character(len=*)] – file to compress
- Options:
size [integer] – size threshold in Kb, smaller files are not compressed (default: store size)
- subroutine iofile/file_gunzip(filename)
This subroutine uncompresses the file
filename.gzwithgunzip -fv, producingfilename. Nothing is done iffilenamealready exists. The program stops with a message if neitherfilenamenorfilename.gzexists.- Parameters:
filename [character(len=*)] – name of the uncompressed file, without the compression extension
- subroutine iofile/file_bzip(file[, size])
This subroutine compresses the file
filewithbzip2 -zfv, producingfile.bz2, if its size given byfile_sizeis larger thansizeKb. The default threshold is the store size, 2048 Kb unless changed withset_store_size. Smaller files are left untouched.- Parameters:
file [character(len=*)] – file to compress
- Options:
size [integer] – size threshold in Kb, smaller files are not compressed (default: store size)
- subroutine iofile/file_bunzip(filename)
This subroutine uncompresses the file
filename.bz2withbzip2 -dv, producingfilename. Nothing is done iffilenamealready exists. The program stops with a message if neitherfilenamenorfilename.bz2exists.- Parameters:
filename [character(len=*)] – name of the uncompressed file, without the compression extension
- subroutine iofile/file_xz(file[, size])
This subroutine compresses the file
filewithxz -zfv, producingfile.xz, if its size given byfile_sizeis larger thansizeKb. The default threshold is the store size, 2048 Kb unless changed withset_store_size. Smaller files are left untouched.- Parameters:
file [character(len=*)] – file to compress
- Options:
size [integer] – size threshold in Kb, smaller files are not compressed (default: store size)
- subroutine iofile/file_unxz(filename)
This subroutine uncompresses the file
filename.xzwithxz -dv, producingfilename. Nothing is done iffilenamealready exists. The program stops with a message if neitherfilenamenorfilename.xzexists.- Parameters:
filename [character(len=*)] – name of the uncompressed file, without the compression extension
- subroutine iofile/file_targz(tarball, pattern[, size])
This subroutine stores the files matching
patternin the compressed tarballtarball.tgz, created withtar -czf. If the command succeeds the archived files are removed withrm -f. The argumentsizeis accepted for consistency withfile_gzipbut it is not used: the tarball is always written.- Parameters:
tarball [character(len=*)] – tarball name, without the .tgz or .tar.bz2 extension
pattern [character(len=*)] – files to archive, they are removed after a successful archive
- Options:
size [integer] – not used
- subroutine iofile/file_untargz(tarball)
This subroutine extracts the tarball
tarball.tgzwithtar -xzf, and removes it if the command succeeds. A message is printed and nothing is done if the tarball does not exist.- Parameters:
tarball [character(len=*)] – tarball name, without the .tgz or .tar.bz2 extension
- subroutine iofile/file_tarbz2(tarball, pattern[, size])
This subroutine stores the files matching
patternin the bzip2 compressed tarballtarball.tar.bz2, created withtar -cjSf. If the command succeeds the archived files are removed withrm -f. The argumentsizeis accepted for consistency withfile_bzipbut it is not used: the tarball is always written.- Parameters:
tarball [character(len=*)] – tarball name, without the .tgz or .tar.bz2 extension
pattern [character(len=*)] – files to archive, they are removed after a successful archive
- Options:
size [integer] – not used
- subroutine iofile/file_untarbz2(tarball)
This subroutine extracts the tarball
tarball.tar.bz2withtar -xjf, and removes it if the command succeeds. A message is printed and nothing is done if the tarball does not exist.- Parameters:
tarball [character(len=*)] – tarball name, without the .tgz or .tar.bz2 extension
- function iofile/to_upper(strin)
This function returns the character string
StrInwith the lower case letters a-z converted to upper case. The other characters are unchanged.- Parameters:
strin [character(len=*), in] – string to convert
- Result:
strout [character(len=len(strin))]
- function iofile/to_lower(strin)
This function returns the character string
StrInwith the upper case letters A-Z converted to lower case. The other characters are unchanged.- Parameters:
strin [character(len=*), in] – string to convert
- Result:
strout [character(len=len(strin))]
IOREAD submodule
Description
Contains procedures for reading files
Quick access
- Routines:
Used modules
iofile: Contains procedures for generating output files
Subroutines and functions
- interface ioread/sread(pname, x, y1)
This subroutine reads a real or complex array of rank 1 to 7 from the file
pname, together with the abscissaX, and is the counterpart ofsplot. The last dimension ofY1runs alongX, and each line of the file containsX(k) Y1(...,k)for a real array andX(k) Im Y1(...,k) Re Y1(...,k)for a complex array. The blank lines between the curves are skipped. If the file, or its.gzversion, is not found a message is printed, the program waits 5 seconds, and then stops with an end-of-file error when reading.- Parameters:
pname [character(len=*)] – name of the input file
x (various shapes) [real, in,required]
y1 (various shapes) [real/complex]
- interface ioread/read_array(pname, y1[, order, wspace])
This subroutine reads a real or complex scalar, or array of rank 1 to 7,
Y1from the filepname, and is the counterpart ofsave_array. Ifpnamedoes not exist the filepname.bz2is first uncompressed withfile_bunzip, and after reading the file is compressed again withfile_bzipif it is larger than the store size, seeset_store_size. If the file, or its.gzversion, is not found a message is printed, the program waits 5 seconds, and then stops with an end-of-file error when reading.For rank 2 to 7 the order of the elements is set by
order. Withorder="R"the last index varies fastest, withorder="C"the first index varies fastest. The program stops iforderdoes not start withRorC. The blank lines separating the runs are skipped, sowspacehas no effect when reading.- Parameters:
pname [character(len=*)] – name of the input file
y1 (various shapes) [real/complex]
- Options:
order [character(len=*)] – R (default): last index varies fastest, C: first index varies fastest
wspace [logical] – not used when reading, present for consistency with save_array
IOPLOT submodule
Quick access
- Routines:
Used modules
iofile: Contains procedures for generating output files
Subroutines and functions
- interface ioplot/splot(pname, x, y1[, append])
This subroutine writes a real or complex array
Y1of rank 1 to 7 to the filepname, together with the abscissaX, in a format that can be plotted with gnuplot. The last dimension ofY1runs alongX. Each line of the file containsX(k) Y1(...,k)for a real arrayX(k) Im Y1(...,k) Re Y1(...,k)for a complex array, so the imaginary part is in column 2 and the real part in column 3
For rank 2 to 7 a blank line follows each set of
size(X)lines, so that each one-dimensional slice is a separate curve. Ifappendis true the data are added at the end of the file, after a blank line if the file already exists, otherwise an existing file is overwritten. The data can be read back withsread.- Parameters:
pname [character(len=*)] – name of the output file
x (various shapes) [real, in,required] – abscissa, one per element of the last dimension of Y1
y1 (various shapes) [real/complex] – function values Y1(…,k) at X(k), real or complex, rank 1 to 7
- Options:
append [logical] – if T add to an existing file instead of overwriting it (default F)
- interface ioplot/splot3d(pname, x1, x2, y[, xmin, xmax, ymin, ymax, nosurface, wlines, nlines])
This subroutine writes a function of two variables, given on the grid
X1\(\times\)X2, to files that can be plotted with gnuplot as a color map and as a surface. The specific procedures cover a real or complex arrayYof shape(size(X1),size(X2)), and a real or complex sequence ofNtframesYof shape(size(X1),size(X2),Nt)for an animated map.For a real
Ythe data filepnamecontains the linesX1(i) X2(j) Y(i,j), with a blank line after each value ofi. The gnuplot scriptspname_map.gp(color map) and, unlessnosurfaceis true,pname_surface.gp(surface view) are written next to it. Ifwlinesis present, whatever its value, the filepname_withlinesis also written with everynlines-th value ofi, to be plotted as lines over the surface.For a complex
Ythe real and imaginary parts are written in the filesre_nameandim_name, in the directory ofpname, with the scriptspname_re_map.gp,pname_im_map.gp,pname_re_surface.gpandpname_im_surface.gp.The animate procedures write all the frames in the data file, one block per frame, and only the map script(s), which loop over the frames with a color range common to all of them. They stop if the first two dimensions of
Ydo not matchX1andX2. The plot ranges default to the extrema ofX1andX2, seexmin.- Parameters:
pname [character(len=*)] – name of the data file, base name of the gnuplot scripts
x1 (•) [real, in,required] – grid points along x, first dimension of Y
x2 (•) [real, in,required] – grid points along y, second dimension of Y
y (various shapes) [real/complex] – values Y(i,j)=F(X1(i),X2(j)); Y(i,j,m) for animate
- Options:
xmin [real]
xmax [real]
ymin [real]
ymax [real] – plot ranges in x and y (default: extrema of X1, X2)
nosurface [logical] – if T do not write the gnuplot script of the surface (default F)
wlines [logical] – if present also write the _withlines file (any value)
nlines [integer] – step of the first index in the _withlines file (default 5)
- interface ioplot/save_array(pname, y1[, order, wspace])
This subroutine writes a real or complex scalar, or array of rank 1 to 7,
Y1to the filepnameusing list-directed output, one element per line, complex elements as(re,im). After writing, the file is compressed withfile_bzipif it is larger than the store size, seeset_store_size.For rank 2 to 7 the order of the elements is set by
order. Withorder="R"the last index varies fastest, withorder="C"the first index varies fastest. Ifwspaceis true a blank line is written after each run of the fastest index. The program stops iforderdoes not start withRorC. The data can be read back withread_array.- Parameters:
pname [character(len=*)] – name of the output file
y1 (various shapes) [real/complex] – data to write: scalar or array of rank 1 to 7, real or complex
- Options:
order [character(len=*)] – R (default): last index varies fastest, C: first index varies fastest
wspace [logical] – if T (default) write a blank line after each run of the fastest index