@ -7,12 +7,13 @@ module io
implicit none
implicit none
integer :: outfilenum = 0
integer :: outfilenum = 0 , infilenum = 0
character ( len = 100 ) :: outfiles ( 10 )
character ( len = 100 ) :: outfiles ( 10 ) , infiles ( 10 )
public
public
contains
contains
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! Subroutines for writing out data files ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
subroutine get_out_file ( filename )
subroutine get_out_file ( filename )
implicit none
implicit none
@ -305,7 +306,7 @@ module io
! Write out atoms first
! Write out atoms first
do i = 1 , atom_num
do i = 1 , atom_num
write ( 11 , * ) type_atom( i ) , r_atom ( : , i )
write ( 11 , * ) i, type_atom( i ) , r_atom ( : , i )
end do
end do
! Write out the elements , this is written in two stages , one line for the element and then 1 line for
! Write out the elements , this is written in two stages , one line for the element and then 1 line for
@ -320,4 +321,130 @@ module io
end do
end do
end subroutine write_mb
end subroutine write_mb
! ! ! ! ! ! ! ! ! ! ! ! ! Below are subroutines for reading files ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
subroutine get_in_file ( filename )
implicit none
character ( len = 100 ) , intent ( in ) :: filename
character ( len = 100 ) :: temp_infile
logical :: file_exists
! If no filename is provided then this function is called with none and prompts user input
if ( filename == 'none' ) then
print * , "Please specify a filename or extension to output to:"
read ( * , * ) temp_infile
else
temp_infile = filename
end if
! Infinite loop which only exists if user provides valid filetype
do while ( . true . )
! Check to see if file exists , if it does then ask user if they would like to overwrite the file
inquire ( file = trim ( temp_infile ) , exist = file_exists )
if ( . not . file_exists ) then
print * , "The file " , filename , " does not exist. Please input a filename that exists"
read ( * , * ) temp_infile
cycle
end if
select case ( temp_infile ( scan ( temp_infile , '.' , . true . ) + 1 : ) )
case ( 'xyz' , 'lmp' , 'vtk' , 'mb' )
infilenum = infilenum + 1
infiles ( infilenum ) = temp_infile
exit
case default
print * , "File type: " , trim ( temp_infile ( scan ( temp_infile , '.' , . true . ) : ) ) , "not currently accepted. " , &
"please input a filename with extension from following list: mb."
read ( * , * ) temp_infile
end select
end do
end subroutine get_in_file
subroutine read_in
! This subroutine loops over alll of the outfile types defined and calls the correct writing subroutine
integer :: i
do i = 1 , infilenum
! Pull out the extension of the file and call the correct write subroutine
select case ( trim ( adjustl ( infiles ( i ) ( scan ( infiles ( i ) , '.' , . true . ) + 1 : ) ) ) )
case ( 'mb' )
call read_mb ( infiles ( i ) )
case default
print * , "The extension " , trim ( adjustl ( outfiles ( i ) ( scan ( outfiles ( i ) , '.' , . true . ) + 1 : ) ) ) , &
" is not accepted for writing. Please select from: mb and try again"
stop
end select
end do
end subroutine read_in
subroutine read_mb ( file )
! This subroutine reads in an mb file for operation
character ( len = 100 ) , intent ( in ) :: file
integer :: i , j , k , n , inod , ibasis , type , size , in_atoms , in_eles
character ( len = 100 ) :: etype
real ( kind = dp ) :: temp_box_bd ( 6 ) , r ( 3 )
real ( kind = dp ) , allocatable :: r_innode ( : , : , : )
! First open the file
open ( unit = 11 , file = trim ( adjustl ( file ) ) , action = 'read' , position = 'rewind' )
! Read in the box boundary and grow the current active box bd
read ( 11 , * ) temp_box_bd ( : )
call grow_box ( temp_box_bd )
! Read in the number of sub_boxes and allocate the variables
read ( 11 , * ) n
call alloc_sub_box ( n )
! Read in subbox orientations and boundaries
do i = 1 , sub_box_num
! Read in orientation with column major ordering
read ( 11 , * ) ( ( sub_box_ori ( j , k , i ) , j = 1 , 3 ) , k = 1 , 3 )
! Read in subbox boundaries
read ( 11 , * ) sub_box_bd ( : , i )
end do
! Read in the number of atom types and all their names
read ( 11 , * ) atom_types , ( type_to_name ( i ) , i = 1 , atom_types )
! Read the number of lattice types , basisnum , and number of nodes for each lattice type
read ( 11 , * ) lattice_types , ( basisnum ( i ) , i = 1 , lattice_types ) , ( ng_node ( i ) , i = 1 , lattice_types )
! Define max_ng_node and max_basis_num
max_basisnum = maxval ( basisnum )
max_ng_node = maxval ( ng_node )
! Read the basis atom types for every lattice
read ( 11 , * ) ( ( basis_type ( i , j ) , i = 1 , basisnum ( j ) ) , j = 1 , lattice_types )
! Read number of elements and atoms and allocate arrays
read ( 11 , * ) in_atoms , in_eles
call grow_ele_arrays ( in_eles , in_atoms )
allocate ( r_innode ( 3 , max_basisnum , max_ng_node ) )
! Read the atoms
do i = 1 , in_atoms
read ( 11 , * ) j , type , r ( : )
call add_atom ( type , r )
end do
! Read the elements
do i = 1 , in_eles
read ( 11 , * ) n , type , size , etype
do inod = 1 , ng_node ( type )
do ibasis = 1 , basisnum ( type )
read ( 11 , * ) j , k , r_innode ( : , ibasis , inod )
end do
end do
call add_element ( etype , size , type , r_innode )
end do
end subroutine read_mb
end module io
end module io