/* WeaterDisplay のdefaultログファイルを標準的なcsv形式に変換する
2013/08/10 (C) H.Ishikawa */
package processlogs;
import java.io.*;
import java.text.*;
class weatherlogs {
public static void main(String args[]) throws IOException {
String yyyy;
DecimalFormat DF = new DecimalFormat("00");
BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in));
System.out.print("年をいれてください yyyy =");
yyyy = kbd.readLine().trim();
for (int mm = 1; mm <= 12; mm++){ //12ヶ月分
String MM = String.valueOf(DF.format(mm));
//標準的なcsv形式ログファイル
String filename0 = "D:\\MyDocuments\\weatherdata\\logfiles\\" + yyyy + MM + "log.csv";
//WeaterDisplay のログファイル
String filename1 = "D:\\MyDocuments\\wdisplay\\logfiles\\" + mm + yyyy + "lg.txt";
File f0 = new File(filename0);
File f1 = new File(filename1);
String string_out ;
String string_in;
String[] string_ary = new String[25];
try {
BufferedReader input1 = new BufferedReader(new FileReader(f1));
PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(f0)));
// 1行目読み飛ばし
string_in = input1.readLine();
// 1行目見出し、書き込み
string_out = "yyyy/MM/dd hh:mm:ss," + "temperature,humidity,dewpoint,barometer,wind speed," +
"gust speed,direction,rain last min,daily rain,monthly rain,yearly rain,heatindex";
output.println(string_out);
while ((string_in= input1.readLine()) != null) {
/*WeaterDisplay のログファイルは次のような形式
day month year hour minute temperature humidity dewpoint barometer windspeed
gustspeed direction rainlastmin dailyrain monthlyrain yearlyrain heatindex
*/
string_in = string_in.trim(); //前後のスペース削除
string_in = string_in.replace(" " , " "); //ダブルのスペースをシングルに
string_in = string_in.replace(" " , " "); //もう一度
string_ary = string_in.split(" "); //文字列を" "で分割し一つ一つを配列string_aryにいれる
//標準的なログファイルに整える
string_out = string_ary[2] + "/" + DF.format(Integer.parseInt(string_ary[1])) + "/" +
DF.format(Integer.parseInt(string_ary[0])) + " " + DF.format(Integer.parseInt(string_ary[3])) +":" +
DF.format(Integer.parseInt(string_ary[4])) + ":" + "00"+ "," + string_ary[5] + "," + string_ary[6] + "," +
string_ary[7] + "," + string_ary[8] + "," + string_ary[9] + "," + string_ary[10] + "," + string_ary[11] + ","
+ string_ary[12] + "," + string_ary[13] + "," + string_ary[14] + "," + string_ary[15] + "," + string_ary[16] ;
//書き込み
output.println(string_out);
}
input1.close();
output.close();
System.out.println(filename0 + "の書き込み終了");
}
catch(Exception e){
System.out.println("エラー: " + e);
}
}
System.out.println( "1年分の書き込み終了");
}
}
|