'My major'에 해당되는 글 117건

  1. 2009/11/18 JAVA (redirection of standard output and error streams)
  2. 2009/11/13 JAVA Vector sorting
  3. 2009/10/12 Windows XP 0x0000007B Exception
  4. 2009/07/24 JACOB
  5. 2009/07/08 C# 유용한 예제 모음
2009/11/18 04:49 My major/JAVA
 Redirection of the standard output and error streams to log files.

FileOutputStream fos = new FileOutputStream("out.stdout", true);
BufferedOutputStream bos = new BufferedOutputStream(fos);
System.setOut(new PrintStream(bos, true));
fos = new FileOutputStream("error.stderr", true);
bos = new BufferedOutputStream(fos);
System.setErr(new PrintStream(bos, true));

posted by joyoungtae
2009/11/13 04:03 My major/JAVA
1. Create target class for sorting and define compareTo() function

class TargetClass implements Comparable{
  int id;
  String name;
  public TargetClass(int id, String name){
    id = id;
    name = name;
  }
  public int compareTo(Object o){
    TargetClass tc = (TargetClass)o;
    if(this.id > tc.id)
      return 1;
    else if(this.id == tc.id)
      return 0;
    else
      return -1;
  }
}

2. sort
public class mainClass{
  public static void main(String argv[]){
    Vector<TargetClass> vec = new Vector<TargetClass> ();
    for(int i=10; i>0; i--){
      TargetClass item = new TargetClass(i, "jo"+i);
      vec.add(item);
    }
    Collections.sort(vec);
  }
}
posted by joyoungtae
2009/10/12 12:08 My major/Etc.
There are several reasons why 0x0000007B exception occurred during Windows XP installation. In this article, I'm gonna mention just one of the reason related to SATA/RAID. If you want to see other reasons visit here.

If your computer has a SATA/RAID drive, you should install the additional SATA/RAID drivers because Windows XP does not have default SATA/RAID drivers. Windows XP ask user to add SATA/RAID driver with F6 key at the begining of the installation. You can add driver though a floppy disk but it's not convenient.

I suppose that the most convenient and easiest way is to make new Windows XP CD that SATA/RAID drivers are added. See here if you want to make it. The web-site above is written by Korean If you can not read Korean, just do a googling ^^. You could find English documents about it easily.
posted by joyoungtae
2009/07/24 04:45 My major/VISSIM
JAVA 와 COM 을 연결해 주는 JAVA-COM bridge 에는 여러 라이브러리들이 있다. 그중 오픈 소스로 가장 활발히 개발되었던 것이 JACOB이다. 현재 JACOB을 이용해 VISSIM 시뮬레이터를 컨트롤해 본 결과 사용으로 판매되는 jacozoom과 같은 라이브러리에 비해 속도가 2배정도 느리다. 그리고 시뮬레이션을 오래 하다 보면 메모리 오버플로우가 일어난다..ㅡㅡ;;

하지만 간단한 엑셀이나 워드 같은 프로그램 컨트롤할때는 쓸만할것 같다. 밑의 소스는 JACOB 라이브러리를 이용해 VISSIM 파일 읽어 들인 후 VISSIM내의 디텍터 갯수, ID, 시뮬레이션 시간을 출력하고 시뮬레이션 동안 특정 하나의 디텍터에 자동차가 감지되면 "1"을 출력하도록 만든 소스이다.

 
import com.jacob.com.*;
import com.jacob.activeX.*;

public class testJacob {
    private ActiveXComponent vissim;
    private Dispatch sim;
    private Dispatch net;
    private Dispatch dets;
    private Dispatch scs;
    private Dispatch det_sc;
    private Dispatch[] det;
    private Dispatch vipts;
    private Dispatch vipt;
    private Dispatch delays;
    private Dispatch[] delay;
    private Dispatch vehs;
    private Dispatch veh;
    private Dispatch enumberator;
    private Variant val1, val2;
    
    private Dispatch trcms;
    private Dispatch[] trcm;
    
    public void start(){
        try {
            vissim = new ActiveXComponent("VISSIM.Vissim");
            Dispatch.call((Dispatch)vissim, "LoadNet", "D:\\Youngtae\\java-work\\testJacob\\roundabout.inp", 0);
            sim = vissim.getProperty("Simulation").toDispatch();
            net = vissim.getProperty("Net").toDispatch();
            scs = Dispatch.get(net, "SignalControllers").toDispatch();
            det_sc = Dispatch.call(scs, "GetSignalControllerByNumber", 1).toDispatch();
            dets = Dispatch.get(det_sc, "Detectors").toDispatch();
            delays = Dispatch.get(net, "Delays").toDispatch();
            
            int tempVal;
            Object obj1, obj2;
            obj1 = Dispatch.get(dets, "Count");
            tempVal = Integer.parseInt(obj1.toString());
            
            det = new Dispatch[tempVal];
            System.out.println("Count:" + tempVal);
            
            Variant vi = new Variant();
            
            vi = Dispatch.call(sim, "AttValue", "PERIOD");
            
            System.out.println("period::::" + vi);
            
            int[] det_id = new int[tempVal];
            for(int i=0; i<tempVal; i++){
                vi.putInt(i+1);
                det[i] = Dispatch.invoke(det_sc, "Detectors", Dispatch.Get, new Object[]{vi}, new int[1]).toDispatch();
                Variant ID = Dispatch.get(det[i], "ID");
                Variant name = Dispatch.get(det[i], "Name");
                System.out.println(ID + " " + name);
                det_id[i] = ID.getInt();
            }
            
            System.out.println(Dispatch.get(det[0], "ID"));
            
            int simTime, simPeriod, simResolution;
            obj1 = Dispatch.get(sim, "Period");
            obj2 = Dispatch.get(sim, "Resolution");
            simPeriod = (int)Double.parseDouble(obj1.toString());
            simResolution = Integer.parseInt(obj2.toString());
            simTime = simPeriod * simResolution;
            System.out.println("simTime:" + simTime);

            //Dispatch.
            for(int i=1; i<simTime; i++){
                Dispatch.call(sim, "RunSingleStep");
                vi = Dispatch.call(det[3], "AttValue", "IMPULSE");
                if(vi.getInt() == 1){
                    System.out.println("1");
                }
            }
            
            } catch (Exception e) {
              e.printStackTrace();
            }
    }
    public static void main(String[] args){
        testJacob tj = new testJacob();
        tj.start();
        
    }
}



posted by joyoungtae
2009/07/08 03:51 My major/JAVA
1. 소켓 통신

 [ SERVER ]
 private int PORT = 4000;

IPAddress ip = IPAddress.Parse("210.000.000.000");
TcpListener listener = new TcpListener(ip, 4000);
listener.Start();
while(true){
            TcpClient client = listener.AcceptTcpClient();
            NetworkStream ns = client.GetStream();
            Console.WriteLine("accept the TCP connection request  ");
            Console.WriteLine("(" + DateTime.Now + ":" + ")");
            Runner rn = new Runner(ns);
            ThreadStart ts = new ThreadStart(rn.run);
            Thread th = new Thread(ts);
            th.Start();
}


2. JAVA의 StringTokenizer와 같은 역할을 할만한 루틴..

 String[] stringToken = SharedData.name.Split(new char[1]{'.'});
  String outputName = stringToken[0] + ".xls";


3. 엑셀파일 저장 및 열기

 object missingType = Type.Missing;
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks.Add(missingType);
Microsoft.Office.Interop.Excel.Worksheet flowWorksheet =                (Microsoft.Office.Interop.Excel.Worksheet)
excelBook.Worksheets.Add(missingType, missingType, missingType, missingType);
excelApp.Visible = false;
                for (int i = 0; i < flow.Length; i++)
                {
                    flowWorksheet.Cells[0, i] = det_id[i];
                    for (int k = 0; k < flow[i].Length; k++)
                    {
                        flowWorksheet.Cells[k + 2, i] = flow[i][k];
                    }
                }
excelBook.SaveAs(@outputName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, missingType, missingType , missingType, missingType, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missingType,
 missingType, missingType, missingType, missingType);


3. File dialog

 OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "VISSIM File(*.inp)|*.inp";
openDialog.Title = "Open Vissim file";

                if (openDialog.ShowDialog() == DialogResult.OK)
                {
                    //MessageBox.Show(openDialog.FileName);
                    vis = new Vissim();                        //create simulation
                    vis.LoadNet(openDialog.FileName, 0);
                }
                else
                {
                    mainForm.PrintMessage("File is not correct");
                    return;
                }





추가중..
posted by joyoungtae
 <PREV 1 2 3 4 5 ... 24    NEXT>