Sub 加入文件名与加分页符的合并WORD文档() '''WORD中的VBA代码 '''把代码所在的doc文件也放到需要合并的文件夹中 ,所有需要合并的doc文件都放在这个文件夹中。 '''每合并一篇文章后插入一分页符,以区别不同的文章。 '''合并后生成新文档。 '''---by daode1212 2010-11-06 Dim fs As FileSearch, i As Long, n As Long On Error Resume Next Set fs = Application.FileSearch ml = ActiveDocument.Path '当前路径 bwj = ActiveDocument.Name '本DOC文档名 Documents.Add MsgBox ml "\" bwj With fs .NewSearch .LookIn = ml '在当前路径中搜索 .FileType = msoFileTypeWordDocuments '''只合并DOC文档 If .Execute 0 Then For i = 1 To .FoundFiles.Count If InStr(.FoundFiles.Item(i), "合并全部WORD文档") = 0 Then '先插入文件名: Selection.TypeText " ]]" '再插入一换行: Selection.TypeParagraph '再插入文件: Selection.InsertFile FileName:=.FoundFiles.Item(i) '最后插入分页符: Selection.InsertBreak Type:=wdPageBreak n = n + 1 MsgBox .FoundFiles.Item(i) " ---已经完成合并!" End If Next End If End With MsgBox "共合并了" n "篇文档" End Sub Sub 带文件对话框的doc文档批量合并工具() '''WORD中的VBA代码 '''把代码所在的doc文件也放到需要合并的文件夹中 ,所有需要合并的doc文件都放在这个文件夹中。 '''合并后内容在本文档中 ''' ---by daode1212 2010-11-06 Dim myDialog As FileDialog Dim i As Long Set myDialog = Application.FileDialog(msoFileDialogFilePicker) With myDialog .Title = "请选择要合并的文档(可以多选)" .AllowMultiSelect = True .Filters.Clear .Filters.Add "所有 WORD 文件", "*.doc", 1 End With On Error Resume Next If myDialog.Show -1 Then Exit Sub For i = 1 To myDialog.SelectedItems.Count Selection.InsertFile FileName:=myDialog.SelectedItems(i) MsgBox myDialog.SelectedItems(i) " ---已经成功合并进来!" Next MsgBox "已经完成合并数:" myDialog.SelectedItems.Count End Sub
dos_split文件 from: http://blog.sina.com.cn/s/blog_52e8ac6201009e13.html #ksh默认路径/bin/ksh,要求在dos_split文件所在文件夹下有DOSCAR和OUTCAR,vp文件默认路径为BIN/vp,vp所在文件夹要有POSCAR,OUTCAR #这个script很老的,没有考虑d态,你自己还得修改一下,主要类似下列的行: sed-n''$start','$end'p'$dosfile|awk'{printf"%12.8f%12.8f%12.8f%12.8f%12.8f%12.8f%12.8f\n",$1+(-1)*'$efermi',$2,-1*$3,$4,-1*$5,$6,-1*$7}'DOS$i 要把DOSCAR中的d态或f态都添加进来 #!/bin/ksh # Script to break the VASP DOSCAR file into segments for # each atomic site. # JMS NRL 5/0/02 # Modified to also align the Fermi level from the ground state # to E=0.0 # JMS NRL 6/19/02 # Executables reside here BIN=~/bin if ; then echo "Usage: split_dos" exit 2 fi # Script to split the DOSCAR file into the atomic # projections labeled by atom number dosfile=DOSCAR outfile=OUTCAR infile=INCAR # Token for splitting the files token=$(sed -n '6 p' $dosfile | awk '{print $1}') #sed语法为sed '{command}' #将DOSCAR的第6行第一个字段赋给token # Number of points nl=$(sed -n '6 p' $dosfile | awk '{print $3}') # Number of atoms natom=$(sed -n '1 p' $dosfile | awk '{print $1}') #natom是原子个数 # Get the Fermi level if the OUTCAR file is present, # else we set it to zero. #若OUTCAR存在,efermi为Fermi能,否则设为0 if ; then echo "The" $outfile "exists, we use it to get the Fermi level," echo "the RWIGS tag and the number of spins." efermi=$(grep "E-fermi" $outfile | tail -1 | awk '{print $3}') echo "Fermi level:" $efermi #efermi:Fermi能 nspin=$(grep "ISPIN" $outfile | tail -1 | awk '{print $3}') #nspin:ISPIN if ; then echo "Spin polarized calculation" else echo "Unpolarized calculation" fi #以上判断极化还是非极化计算 # 2.a # JMS 2/3/03 Modified to accept specification by LORBIT token. # lorbit=$(grep "LORBIT" $outfile | tail -1 | awk '{print $3}') #LORBIT值,0 simple, 1 ext, 2 COOP (PROOUT) if ; then #lorbit大于等于10 (算得的为1),"WARNING: not completely test for vasp.4.*",form=1 echo "LORBIT 10" echo "WARNING: not completely test for vasp.4.*" echo "Use at your own risk. Please check results for consistency." form=1 else # 2.a rwigs=$(grep "RWIGS" $outfile | tail -1 | awk '{print $3}' | sed 's/\.//g') #RWIGS,wigner-seitz radius(A) (算得的RWIGS = 2.840; RWIGS = 1.503 因为有两种原子,这里应该取了rwigs = 2.840) if ; then #rwigs=100,"RWIGS token not set",form=0 echo "RWIGS token not set" form=0 else #否则form=1 echo "RWIGS token set" form=1 fi # 2.a fi # 2.a else echo "The" $outfile "does not exist, we set the Fermi level to 0" echo "assume an unpolarized calculation, and RWIGS not set" form=0 nspin=1 efermi=0.0 fi # 注意!!If the outcar file is not present and you wish to set something by hand # you should do it here. Uncomment the tokens below and set them by hand. #efermi=2.255 #form= #nspin= # Get the atomic coordinates $BIN/vp | tmp.dat #注意!!文件vp路径:BIN/vp tail -$natom tmp.dat | awk '{printf "%s %12.8f %12.8f %12.8f \n", "#", $2, $3, $4}' | tmp.dat2 # Total is first DOS if ; then i=0 else i=0 fi #为何不管form是1还是0,i都是0呢? start=7 #从DOSCAR的第七行开始 end=$((start+nl-1)) #echo $start $end #调试时可显示start、end #exit 0 rm -f DOS0 if ; then #form=1 #i从0开始 while ; do #echo $i $start $end if ; then sed -n ''$i' p' tmp.dat2 | DOS$i fi if ; then #i大于等于0 # Atomic projected DOS if ; then #对自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5, $6, -1*$7}' DOS$i else #对非自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3, $4 }' DOS$i fi else #即i没有大于等于0 # Total DOS if ; then #对自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5 }' DOS$i else #对非自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3 }' DOS$i fi fi start=$((end+2)) end=$((start+nl-1)) i=$((i+1)) done else #form=0 while ; do #echo $i $start $end if ; then sed -n ''$i' p' tmp.dat2 | DOS$i fi if ; then #i大于等于0 # Atomic projected DOS if ; then #对自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5, $6, -1*$7}' DOS$i else #对非自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3, $4 }' DOS$i fi else #i没有大于等于0 # Total DOS if ; then #对自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5 }' DOS$i else #对非自旋极化计算 sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3 }' DOS$i fi fi start=$((end+2)) end=$((start+nl-1)) i=$((i+1)) done fi exit 0 #分割后的DOS0,DOS1…等文件的能量值是以费米能级作为能量参考零点。DOS0的第一列数据是能量值,单位为 eV;第二列数据是总态密度的值,单位 State/eV.unit cell;第三列数据是总态密度的积分值,也就是电子 数,单位为electrons。DOS1是第一个原子的分波态密度值,其中的第一列数据是能量值,单位为eV;第二、三、 四列数据分别对应于s、p、d态的分波态密度值,单位为State/eV.atom。其他的DOS文件与DOS1类似。