编程语言
首页 > 编程语言> > 自己写的一个java小脚本,用于comsol仿真声子晶体的能带图数据直接生成origin可以用的csv文件!

自己写的一个java小脚本,用于comsol仿真声子晶体的能带图数据直接生成origin可以用的csv文件!

作者:互联网

import javax.security.auth.login.CredentialException;
import java.io.*;
import java.util.Arrays;

public class Hannscript {
    //判断几行
    public static int count = 0;
    public static void main(String[] args) throws IOException {
        //String path = Thread.currentThread().getClass().getClassLoader().getResource("structer1.csv").getPath();
        int i = 0;
        int j = 0;
        double[][] a  = Creat2DArray();
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\MasterPiece\\Desktop\\structer4.csv"));
        String line = null;
        while((line = reader.readLine())!= null){
            String[] item = line.split(",");
            //String last = item[item.length-1];
        //这里改为数组行-1
            if(i >36){
                break;
            }
            System.out.println(Double.parseDouble(item[0]));
            a[i][0] =  Double.parseDouble(item[0]);

            i++;

            if(Double.parseDouble(item[0]) == 3){
                count++;
            }
            System.out.println(Arrays.toString(item));
        }
        int i1 = 0;
        BufferedReader reader1 = new BufferedReader(new FileReader("C:\\Users\\MasterPiece\\Desktop\\structer4.csv"));
        j=1;
        while((line = reader1.readLine())!= null){
            String[] item = line.split(",");

       //同样改为列-1
            if(j>50){
                break;
            }
            a[i1][j] = Double.parseDouble(item[1]);
            i1++;

            if(Double.parseDouble(item[0]) == 3){
                j++;
                i1 = 0;
            }

        }
        System.out.println(Arrays.toString(Creat2DArray()));
        System.out.println(count);


        //output csv files
        BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\MasterPiece\\Desktop\\csv4.txt"));
        for(int i2 = 0; i2 < 37;i2++){
            for(int j2 = 0;j2<51;j2++){
          //这里需要改为数组列-1 if(j2 == 50){ writer.write(""+a[i2][j2]); }else { writer.write(""+a[i2][j2]+","); } writer.flush(); } writer.newLine(); } writer.flush(); } public static double[][] Creat2DArray(){
     //注意在这里要改成你所需要的二维数组 double[][] a= new double[37][51]; return a; } }

comosol提取的能带数据为  参数频率重复,因此不能直接导入origin绘图,需要手动复制粘贴,如果扫描参数较多,那么会非常麻烦,因此写了这么一个小脚本,科研之路长路漫漫啊!

标签:声子,java,String,int,writer,j2,item,new,csv
来源: https://www.cnblogs.com/-mySmellerArea/p/14384526.html