Eötvös Quantum Utilities  v4.9.146
Providing the Horsepowers in the Quantum Realm
MatrixIO.F90
Go to the documentation of this file.
1 !#include "fintrf.h"
2 !======================================================================
3 ! Test program to test the
4 ! Copyright (C) 2018 Peter Rakyta, Ph.D.
5 !
6 ! This program is free software: you can redistribute it and/or modify
7 ! it under the terms of the GNU General Publi! License as published by
8 ! the Free Software Foundation, either version 3 of the License, or
9 ! (at your option) any later version.
10 !
11 ! This program is distributed in the hope that it will be useful,
12 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ! GNU General Public License for more details.
15 !
16 ! You should have received a copy of the GNU General Public License
17 ! along with this program. If not, see http://www.gnu.org/licenses/.
18 !
19 !======================================================================
20 ! Gateway routine
21  PROGRAM matrixio
22 
23  use getpartialinv
24 
25 
26 ! Declarations
27  implicit none
28 
29 
30  integer::narg,cptarg !#of arg & counter of arg
31  character(len=100):: name !Arg name
32  logical lookforfilename, lookforinvdim
33  logical lookforoutput
34  logical fileexist
35  character(len=100) :: filename, output
36 
37 ! Array information:
38  integer*4 nonzerosa !number of nonzeros elements in A
39  integer*4 sizeam, sizean !size of the matrix A (rows, and cols)
40  integer*4 sizeinv !the size of the partial inverse to be calculated
41  character(len=20) sizeinv_string !the size of the partial inverse -- string from the input
42  character(len=8) out_status
43 
44 ! Arguments for computational routine:
45  integer*4, allocatable :: ia(:), ja(:)
46 #ifdef COMP
47  COMPLEX*16, ALLOCATABLE :: a(:)
48 #else
49  real*8, ALLOCATABLE :: a(:)
50 #endif
51 
52 #ifdef COMP
53  COMPLEX*16, allocatable :: inva(:,:)
54 #else
55  real*8, allocatable :: inva(:,:)
56 #endif
57 !
58 
59  integer i,j
60 
61 #ifdef DEBUG
62 ! Debug parameters
63  integer*4 tmp
64  character*800 line
65 #endif
66 
67 ! https://genomeek.wordpress.com/2012/02/09/fortran-command-line-arguments/
68  !Check if any arguments are found
69  lookforfilename = .false.
70  lookforinvdim = .false.
71  lookforoutput = .false.
72  filename = ''
73  output = ''
74  sizeinv = 0
75 
76  narg=command_argument_count()
77  !Loop over the arguments
78  if(narg>0)then
79  !loop across options
80  do cptarg=1,narg
81  call get_command_argument(cptarg,name)
82  select case(adjustl(name))
83  case("--help","-h")
84  write(0,*)"This is program calculates a " , &
85  "partial inverse of a sparse matirix. Usage: ./MatrixIO ", &
86  "--filename FILENAME --invDim INTEGER --Output FILENAME"
87  stop
88  case("--filename","-F", "--Filename")
89  lookforfilename = .true.
90  case("--output","-o", "--Output")
91  lookforoutput = .true.
92  case("--invDim","-I")
93  lookforinvdim = .true.
94  case default
95  if (lookforfilename) then
96  filename=adjustl(name) !assign a value to pedfile
97  lookforfilename = .false.
98  elseif (lookforoutput) then
99  output=adjustl(name) !assign a value to pedfile
100  lookforoutput = .false.
101  elseif (lookforinvdim) then
102  sizeinv_string = trim(adjustl(name))
103  READ( sizeinv_string, * ) sizeinv
104  lookforinvdim = .false.
105  else
106  write(0,*)"Option ",adjustl(name),"unknown"
107  end if
108  end select
109  end do
110  end if
111 
112  if (output.eq.'') then
113  output = filename
114  end if
115 
116 #ifdef DEBUG
117  write(0,*) 'Input file name:', trim(filename)
118  write(0,*) 'Output file name:', trim(output)
119 #endif
120 
121 ! Testing the existance of the input file containing the sparse matrix A
122  inquire(file=trim(filename),exist=fileexist)!check if it exist
123  if(.not.fileexist)then
124  write(0,*)"file ",trim(filename)," not found!"
125  stop
126  endif
127 
128 ! Opening the file to read in data
129  OPEN(unit=6, file=trim(filename),status='OLD',form='UNFORMATTED')
130 
131  READ(6,end=999,err=1000) sizean
132  READ(6,end=999,err=1000) nonzerosa
133 
134  allocate(ia(sizean+1))
135  allocate(ja(nonzerosa))
136  allocate(a(nonzerosa))
137 
138  READ(6,end=999,err=1000) ia(:)
139  READ(6,end=999,err=1000) ja(:)
140  READ(6,end=999,err=1000) a(:)
141 
142 
143 
144 ! Closing the input file
145  CLOSE(unit=6)
146 
147 #ifdef DEBUG
148  write(0,*) 'Size of the partial inverse:', sizeinv
149  write(0,*) 'The size of the input MATRIX:', sizean
150  write(0,*) 'Nonzeros in the input matrix:', nonzerosa
151  write(0,*) 'The input MATRIX:'
152  i = 0
153  do j = 1, size(a)
154  if (j >= ia(i+1)) then
155  i=i+1
156  end if
157 
158  if (j < ia(i+1)) then
159  !write(0,*) 'row', i, 'col', ja(j), 'element of A = ', a(j)
160  end if
161  end do
162 
163 #endif
164 
165 
166 
167 
168 ! Calculating the partial inverse
169  ALLOCATE(inva(sizeinv, sizeinv))
170 
171  CALL dgetpartialinv(sizean, nonzerosa, a, ia, ja, sizeinv, inva)
172 
173 ! deallocate the fortran matrix A
174  deallocate(ia)
175  deallocate(ja)
176  deallocate(a)
177 #ifdef DEBUG
178  do i=1, sizeinv
179  do j=1, sizeinv
180  write(0,*) 'row', i, 'col', j, ' element of A = ', inva(i,j)
181  end do
182  end do
183 #endif
184 
185 
186 ! Deallocating memory for the partial inverse
187 
188  if ( allocated(inva) ) then
189  DEALLOCATE(inva)
190  endif
191 
192 
193  stop
194 
195  999 write(*,'(/"End-of-file when i = ",I5)') i
196  stop
197 
198  1000 write(*,'(/"ERROR reading when i = ",I5)') i
199  stop
200  end
201 
202 
Module to calculate the partial inverse of a real/complex sparse matrix via the PARDISO libraries.
program matrixio
Definition: MatrixIO.F90:21
subroutine dgetpartialinv(sizeA, nonzerosA, a, ia, ja, sizeInv, invA, error)
Get the partial inverse of double valued real matrices.