using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace LIO
{
public class LStr
{
static public string SafeFileNM(string _FullName)
{
string str = _FullName.Substring(_FullName.LastIndexOf("\\") + 1);
return str;
}
static public string SafePath(string _FullName)
{
string str = _FullName.Substring(0, _FullName.LastIndexOf("\\"));
return str;
//_FullName=SafePath+"\\"+SafeFileNM
}
static public string[] GetSplit(string line)
{
char[] split = { ' ', '=', ',', '\t', '\"', '/' };
return line.Split(split, StringSplitOptions.RemoveEmptyEntries);
}
static public string[] GetSplit(string line, char[] _split)
{
return line.Split(_split, StringSplitOptions.RemoveEmptyEntries);
}
}
public class CopyMove
{
public static void FCopy(string _source, string _dest, bool _Isoverwrite)
{
if (_source != _dest)
File.Copy(_source, _dest, _Isoverwrite);
}
public static void DirCopy(string _source, string _target)
{
if (Directory.Exists(_source))
{
string[] files = Directory.GetFiles(_source);
string fileName = "";
string sourceFile = "";
// Copy the files and overwrite to destinationif they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = Path.GetFileName(s);
sourceFile = Path.Combine(_target, fileName);
FCopy(s, sourceFile, true);
}
}
}
public static void DirCopy(string _source, string _target, int _lenOfFile, int _preFix)
{
if (Directory.Exists(_source))
{
string[] files = Directory.GetFiles(_source);
string fileName = "";
string sourceFile = "";
for (int i = 0; i < _lenOfFile; i++)
{
string Start = "";
if (_preFix == 2)
Start = String.Format("{0:00}", i);
else if (_preFix == 3)
Start = String.Format("{0:000}", i);
else if (_preFix == 4)
Start = String.Format("{0:0000}", i);
// Copy the files and overwrite to destinationif they already exist.
foreach (string s in files)
{
// Use static Path methods to extract only the file name from the path.
fileName = Path.GetFileName(s);
fileName = Start + fileName;
sourceFile = Path.Combine(_target, fileName);
FCopy(s, sourceFile, true);
}
}
}
}
}
public class SRead
{
//read two columns datas in the file
//and return two columns arrary
//
//1 2
//3 4
//5 6
//...
public string[,] Read(string FileName)
{
StreamReader SR = new StreamReader(FileName);
string RDLine = "";
string[,] RDLines;
int i = 0;
while ((RDLine = SR.ReadLine()) != null)
i++;
RDLines = new string[i, 2];
i = 0;
SR.Close();
SR = new StreamReader(FileName);
while ((RDLine = SR.ReadLine()) != null)
{
RDLines[i, 0] = LStr.GetSplit(RDLine)[0];
RDLines[i, 1] = LStr.GetSplit(RDLine)[1];
i++;
}
SR.Close();
return RDLines;
}
public string[,] Read(string FileName,int _Irow, int _Icol)
{
string RDLine = "";
string[,] RDLines;
int i = 0;
RDLines = new string[_Irow, _Icol];
StreamReader SR = new StreamReader(FileName);
while ((RDLine = SR.ReadLine()) != null)
{
for (int j = 0; j < _Icol; j++)
{
RDLines[i, j] = LStr.GetSplit(RDLine)[j];
}
i++;
}
SR.Close();
return RDLines;
}
public string[,] Read(string FileName, int _Irow, int _Icol, char[] _split)
{
string RDLine = "";
string[,] RDLines;
int i = 0;
RDLines = new string[_Irow, _Icol];
StreamReader SR = new StreamReader(FileName);
while ((RDLine = SR.ReadLine()) != null)
{
for (int j = 0; j < _Icol; j++)
{
RDLines[i, j] = LStr.GetSplit(RDLine, _split)[j];
}
i++;
}
SR.Close();
return RDLines;
}
public static float LinearDataPolation(float[] pEffX, float[] pEffY, float pX)
{
int i = 0;
for (i = 0; i < pEffX.Length; i++)
if (i != 0)
if ((pEffX[i] > pX && pEffX[i - 1] < pX) || pEffX[i] == pX)
return (
pEffY[i-1] +
(
(pEffY[i] - pEffY[i - 1])
/(pEffX[i] - pEffX[i - 1])
)
* (pX-pEffY[i-1])
);
return -10.0f;
}
}
}
이광세 (Lee, Gwang-Se)
School of Mechanical Engineering, Pusan National University
(Wind Turbine Noise & Broadband Airfoil-Self Noise)
lee.gse@gmail.com / gs.lee@pusan.ac.kr / twitter.com/leegse
Title20110603
이 블로그 검색
2011년 12월 27일 화요일
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기