提供更多细节。我有三个不同的输入文件,名为
total.Cu.dat
、total.Zn.dat
和 total.Mn.dat
。其中每个文件都会生成 31 个具有相同名称的输出文件,例如 0-2.emf
。我希望每个 .dat
文件的输出文件存储在各自的目录中,例如 'Cu-emf
是 total.Cu.dat
输出的主管。
如何编辑以下脚本来执行此操作?
#!/usr/local/Cellar/gnuplot/5.4.10/bin/gnuplot
### Batch create EMF files from multiple subblocks
set terminal emf font "{/:Bold}Sans,25"
set terminal emf size 850,530
set border 15 front linecolor rgb "black" linewidth 3.000 dashtype solid
set format x "%.1f"
set format y "%.1f"
set nokey
set key top right outside reverse
set key font "{/:Bold,15}"
set xrange [0:1.23]
set yrange [-2.2:2.2]
set xlabel "U (V vs. RHE)"
set xlabel offset character 0,0.6,0 font "{/:Bold},23"
set ylabel "{/Symbol D}G (eV)"
set ylabel offset character 1.0, 0, 0 font "{/:Bold},23"
set xtics nomirror font "{/:Bold},24"
set ytics nomirror font "{/:Bold},24"
myFileOut(s) = sprintf("%s.emf",s)
PATH-1 = system("ls /Users/davidrodriguez/Desktop/DAC-phase/3d-TM/*.dat")
PATH-2 = system("ls /Users/davidrodriguez/Desktop/DAC-phase/3d-TM/*.emf)
FILES = system("basename ".PATH-1)
DIRECTORY = system("basename ".PATH-2)
do for [i=0:2] {
stats FILES index i every ::::0 u (s=strcol(5),0) nooutput
set output myFileOut(s)
plot FILES index i u 1:2 w l lw 3 title columnheader(2), \
"" index i u 1:3 w l lw 3 title columnheader(3), \
"" index i u 1:2 w l lw 4 title columnheader(4)
}
set output
我相信这可能会成为某种类型的嵌套循环,因为当前循环会生成 31 个输出文件,但我真的不确定如何实现。预先感谢您的帮助
下面的数据集是使用的
"potential" "Bare" "1/2ML OH Fe" "1/2ML OH Cu" "0-5"
0.00 0 0.649 0.000
1.23 0 -0.581 0.000
"potential" "Bare" "1/2ML OH Fe" "1/2ML OH Cu" "0-9"
0.00 0 0.297 0.000
1.23 0 -0.933 0.000
"potential" "Bare" "1/2ML OH Fe" "1/2ML OH Cu" "1-3"
0.00 0 -0.275 0.000
1.23 0 -1.505 0.000
假设你有一个输入文件名数组和一个输出目录数组,你可以使用嵌套循环来处理每个输入文件并在指定目录中生成相应的输出文件。 使用 System.IO;
命名空间文件处理 { 班级计划 { 静态无效主(字符串[]参数) { string[] inputFiles = { "input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt", "input6.txt" }; string[] 输出目录 = { "outputDir1", "outputDir2", "outputDir3", "outputDir4", "outputDir5", "outputDir6" };
for (int i = 0; i < inputFiles.Length; i++)
{
string inputFileName = inputFiles[i];
string outputDirectory = outputDirectories[i];
// Create the output directory if it doesn't exist
Directory.CreateDirectory(outputDirectory);
for (int j = 1; j <= 31; j++)
{
string outputFileName = $"output{j}.txt";
string inputFilePath = Path.Combine(outputDirectory, inputFileName);
string outputFilePath = Path.Combine(outputDirectory, outputFileName);
// Perform your processing here, e.g., copying, modifying, or generating output files
// For this example, let's copy the input file to the output file
File.Copy(inputFilePath, outputFilePath, true);
Console.WriteLine($"Copied {inputFileName} to {outputFilePath}");
}
}
Console.WriteLine("Processing complete.");
}
}
}此代码假设您有 6 个输入文件和 6 个相应的输出目录。然后它循环遍历每个输入文件,如果不存在则创建相应的输出目录,并相应地处理文件(在本例中是复制它们)。