| 1 |
!----------------------------------------------------------------- |
| 2 |
! |
| 3 |
! This file is (or was) part of SPLASH, a visualisation tool |
| 4 |
! for Smoothed Particle Hydrodynamics written by Daniel Price: |
| 5 |
! |
| 6 |
! http://users.monash.edu.au/~dprice/splash |
| 7 |
! |
| 8 |
! SPLASH comes with ABSOLUTELY NO WARRANTY. |
| 9 |
! This is free software; and you are welcome to redistribute |
| 10 |
! it under the terms of the GNU General Public License |
| 11 |
! (see LICENSE file for details) and the provision that |
| 12 |
! this notice remains intact. If you modify this file, please |
| 13 |
! note section 2a) of the GPLv2 states that: |
| 14 |
! |
| 15 |
! a) You must cause the modified files to carry prominent notices |
| 16 |
! stating that you changed the files and the date of any change. |
| 17 |
! |
| 18 |
! Copyright (C) 2005-2014 Daniel Price. All rights reserved. |
| 19 |
! Contact: [email protected] |
| 20 |
! |
| 21 |
!----------------------------------------------------------------- |
| 22 |
|
| 23 |
!------------------------------------------------ |
| 24 |
! reads an exact solution from a file |
| 25 |
! |
| 26 |
! file should contain two or more columns containing |
| 27 |
! x axis data and y axis data |
| 28 |
! |
| 29 |
! this is plotted as a line on the chosen graph |
| 30 |
!------------------------------------------------ |
| 31 |
module exactfromfile |
| 32 |
implicit none |
| 33 |
|
| 34 |
public :: exact_fromfile |
| 35 |
|
| 36 |
private |
| 37 |
|
| 38 |
contains |
| 39 |
|
| 40 |
subroutine exact_fromfile(filename,xexact,yexact,ixcolfile,iycolfile,iexactpts,ierr) |
| 41 |
use asciiutils, only:get_ncolumns,get_nrows |
| 42 |
character(len=*), intent(in) :: filename |
| 43 |
real, intent(inout), dimension(:), allocatable :: xexact, yexact |
| 44 |
integer, intent(in) :: ixcolfile,iycolfile |
| 45 |
integer, intent(out) :: iexactpts, ierr |
| 46 |
integer :: i,j,ncolumns,nheaderlines,nrows |
| 47 |
integer, parameter :: lu = 33 |
| 48 |
character(len=10) :: str |
| 49 |
real :: dum |
| 50 |
|
| 51 |
ierr = 0 |
| 52 |
open(unit=lu,file=filename,iostat=ierr,status='old',form='formatted') |
| 53 |
if (ierr /= 0) then |
| 54 |
ierr = 1 |
| 55 |
print*,'error opening ',filename |
| 56 |
return |
| 57 |
endif |
| 58 |
|
| 59 |
!--query number of header lines |
| 60 |
call get_ncolumns(lu,ncolumns,nheaderlines) |
| 61 |
call get_nrows(lu,nheaderlines,nrows) |
| 62 |
rewind(lu) |
| 63 |
if (nrows > size(xexact) .or. nrows > size(yexact)) then |
| 64 |
if (allocated(xexact)) deallocate(xexact) |
| 65 |
if (allocated(yexact)) deallocate(yexact) |
| 66 |
allocate(xexact(nrows),yexact(nrows)) |
| 67 |
endif |
| 68 |
|
| 69 |
!--skip header lines |
| 70 |
do i=1,nheaderlines |
| 71 |
read(lu,*) |
| 72 |
enddo |
| 73 |
|
| 74 |
!--read data from file |
| 75 |
do i=1,size(xexact) |
| 76 |
if (ixcolfile > iycolfile) then |
| 77 |
read(lu,*,end=10,err=20) (dum,j=1,iycolfile-1),yexact(i),(dum,j=iycolfile+1,ixcolfile-1),xexact(i) |
| 78 |
elseif (ixcolfile==iycolfile) then |
| 79 |
read(lu,*,end=10,err=20) (dum,j=1,ixcolfile-1),xexact(i) |
| 80 |
yexact(i) = xexact(i) |
| 81 |
else |
| 82 |
read(lu,*,end=10,err=20) (dum,j=1,ixcolfile-1),xexact(i),(dum,j=ixcolfile+1,iycolfile-1),yexact(i) |
| 83 |
endif |
| 84 |
enddo |
| 85 |
read(lu,*,end=10,iostat=ierr) ! read one more line to see if we are at the end |
| 86 |
print*,'WARNING: reached array limits in ',trim(filename),': partial solution read' |
| 87 |
ierr = -1 |
| 88 |
close(lu) |
| 89 |
return |
| 90 |
10 continue |
| 91 |
iexactpts = i-1 |
| 92 |
write(str,"(i10)") iexactpts |
| 93 |
print "(a)",' finished reading '//trim(filename)//': '//trim(adjustl(str))//' read' |
| 94 |
close(lu) |
| 95 |
return |
| 96 |
20 print*,'error reading ',trim(filename),': partial solution read' |
| 97 |
iexactpts = i - 1 |
| 98 |
ierr = -2 |
| 99 |
close(lu) |
| 100 |
return |
| 101 |
|
| 102 |
end subroutine exact_fromfile |
| 103 |
|
| 104 |
end module exactfromfile |