Title20110603


Main Programming Languages
ASP.NET C# Fortran Matlab
Ph.D
Major News CFD
OS
ubuntu windows IPAD
Review

[0] Vortex Sound
[1] Sound and Source of Sound
[2] Back-Scattering correction and further extensions of Amiets TE noise model Part 1: theory

Life
[0] 잡담 [1] 사진

이 블로그 검색

2011년 12월 27일 화요일



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;
}



}
}


댓글 없음:

댓글 쓰기

twitter leegse