DOUG 0.2

txt2xdr.F90

Go to the documentation of this file.
00001 !==========================================================
00005 program txt2xdr
00006 
00007 use RealKind
00008 
00009 implicit none
00010 include 'fxdr.inc'
00011 
00012 integer         :: i
00013 integer         :: n, nnz, indi, indj
00014 real(kind=rk)   :: val
00015 integer         :: ixdrs, ierr
00016 character(1000) :: pname, form, fnamein, fnameout
00017 
00018 if (iargc() /= 3) then
00019         write (6,*) 'Usage: '// pname //' format input.unf output.xdr'
00020         stop 1
00021 endif
00022 
00023 call getArg(0, pname)
00024 call getArg(1, form)
00025 call getArg(2, fnamein)
00026 call getArg(3, fnameout)
00027 
00028 form = trim(form)
00029 fnamein = trim(fnamein)
00030 fnameout = trim(fnameout)
00031 
00032 ixdrs = initxdr( fnameout, 'w', .FALSE. )
00033 
00034 if (form.EQ.'sparseassembled') then             ! Sparse assembled matrix
00035         open( 7, FILE=fnamein, STATUS='OLD', FORM='FORMATTED', ERR=444 )
00036         read( 7, FMT=*, END=500 ) n,nnz
00037 
00038         ierr  = ixdrint( ixdrs, n )
00039         ierr  = ixdrint( ixdrs, nnz )
00040 
00041         do i=1,nnz
00042                 read( 7, FMT=*,END=500 ) indi, indj, val
00043                 ierr = ixdrint( ixdrs, indi )
00044                 ierr = ixdrint( ixdrs, indj )
00045                 ierr = ixdrdouble( ixdrs, val )
00046         enddo
00047         
00048 elseif (form.EQ.'vector') then                  ! Vector
00049         open( 7, FILE=fnamein, STATUS='OLD', FORM='FORMATTED', ERR=444)
00050     read(7, '(i6)', END=500) n  
00051     
00052     ierr = ixdrint( ixdrs, n)
00053 
00054     do i=1,n
00055         read(7, '(e21.14)', END=500) val
00056         ierr = ixdrdouble( ixdrs, val)
00057         enddo
00058 
00059 else
00060         write(6,*) 'Format not recognized. Possible formats: sparseassembled, vector'
00061 endif
00062 
00063 close( 7 )
00064 ierr = ixdrclose( ixdrs )
00065 
00066 stop 0
00067 
00068 444 write(6,*) 'Unable to open input file: '//fnamein//' '
00069         stop 1
00070 500 continue ! End of file reached too soon
00071     write(6,*) 'File '//fnamein//' too short! '
00072     stop 1
00073 end program txt2xdr