Advertisement
Guest User

Untitled

a guest
May 24th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.90 KB | None | 0 0
  1. open Printf
  2. open ExtLib
  3.  
  4. let vtk = "test.vtk";;
  5.  
  6. let grabVtkSizeInfo path =
  7.         let ic = open_in path in
  8.         let rec iterateTillInfoFilled l channel =
  9.                 if (List.length l) = 2 then l
  10.                 else
  11.                         let line = input_line channel in
  12.                         if ((String.exists line "DIMENSIONS") || (String.exists line "POINT_DATA")) then
  13.                                 iterateTillInfoFilled ((List.tl (String.nsplit line " ")) :: l) channel
  14.                         else iterateTillInfoFilled l channel
  15.                 in
  16.         try Some (iterateTillInfoFilled [] ic) with End_of_file -> None
  17.  
  18.  
  19.  
  20.  
  21. let pgm = "test.pgm";;
  22.  
  23. let oc = open_out pgm;;
  24.  
  25. let dimInfo = String.join " " (List.hd (List.filter (fun l -> (List.length l) > 1) (Option.default [] (grabVtkSizeInfo "140408aX_t01_ch01.vtk"))));;
  26.  
  27. fprintf oc "P2\n%d %d\n%d\n%s" 5 5 255 dimInfo;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement