diff --git a/README.md b/README.md index 9fa35ee..34f1f31 100644 --- a/README.md +++ b/README.md @@ -91,4 +91,12 @@ origin x y z Default origin is `0 0 0`. This command just sets the origin for where the simulation cell starts building. -*Example:* `origin 10 0 1` \ No newline at end of file +*Example:* `origin 10 0 1` + +### Mode Convert + +``` +cacmb --convert infile outfile +``` + +This mode converts a file of type infile to a file of type outfile \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 58507b4..22c84eb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,8 +1,8 @@ FC=ifort -FFLAGS=-mcmodel=large -g -O0 -stand f08 -fpe0 -traceback -check bounds,uninit -warn all -implicitnone +FFLAGS=-mcmodel=large -g -O0 -stand f08 -fpe0 -traceback -check bounds,uninit -warn all -implicitnone -no-wrap-margin #FFLAGS=-c -mcmodel=large -Ofast -MODES=mode_create.o -OBJECTS=main.o elements.o io.o subroutines.o functions.o atoms.o call_mode.o $(MODES) +MODES=mode_create.o mode_merge.o mode_convert.o +OBJECTS=main.o elements.o io.o subroutines.o functions.o atoms.o call_mode.o box.o $(MODES) .SUFFIXES: .SUFFIXES: .c .f .f90 .F90 .o @@ -28,6 +28,6 @@ $(OBJECTS) : parameters.o atoms.o subroutines.o testfuncs.o : functions.o main.o io.o build_subroutines.o: elements.o call_mode.o : $(MODES) -$(MODES) io.o: atoms.o +$(MODES) io.o: atoms.o box.o $(MODES) main.o : io.o testfuncs.o elements.o mode_create.o: subroutines.o diff --git a/src/call_mode.f90 b/src/call_mode.f90 index 1ad4f0f..8c58d3f 100644 --- a/src/call_mode.f90 +++ b/src/call_mode.f90 @@ -3,6 +3,7 @@ subroutine call_mode(arg_num,mode) !mode module. use mode_create + use mode_convert use parameters implicit none @@ -12,8 +13,9 @@ subroutine call_mode(arg_num,mode) select case(mode) case('--create') - call create() - + call create + case('--convert') + call convert case default print *, "Mode ", mode, " currently not accepted. Please check documentation for ", & "accepted modes and rerun." diff --git a/src/io.f90 b/src/io.f90 index 4801de1..e5c111d 100644 --- a/src/io.f90 +++ b/src/io.f90 @@ -7,12 +7,13 @@ module io implicit none - integer :: outfilenum = 0 - character(len=100) :: outfiles(10) + integer :: outfilenum = 0, infilenum = 0 + character(len=100) :: outfiles(10), infiles(10) public contains + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Subroutines for writing out data files !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! subroutine get_out_file(filename) implicit none @@ -305,7 +306,7 @@ module io !Write out atoms first do i = 1, atom_num - write(11,*) type_atom(i), r_atom(:,i) + write(11,*) i, type_atom(i), r_atom(:,i) end do !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 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 \ No newline at end of file diff --git a/src/mode_convert.f90 b/src/mode_convert.f90 new file mode 100644 index 0000000..b46b07f --- /dev/null +++ b/src/mode_convert.f90 @@ -0,0 +1,27 @@ +module mode_convert + + use parameters + use box + use elements + use io + + public + contains + + subroutine convert + !This subroutine converts a single input file from one format to another + character(len=100) :: infile, outfile + + !We have to allocate the element and atom arrays with a size of 1 for the read in code to work + call alloc_ele_arrays(1,1) + !First read in the file + call get_command_argument(2, infile) + call get_in_file(infile) + call read_in + + !Now get the outfile, writing is done after all the codes complete + call get_command_argument(3, outfile) + call get_out_file(outfile) + + end subroutine convert +end module mode_convert \ No newline at end of file