Advertisement
Guest User

Untitled

a guest
May 24th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.85 KB | None | 0 0
  1. open Printf
  2. open ExtLib
  3.  
  4. let vtk = "test.vtk";;
  5.  
  6.  
  7. let stream_filter p stream =
  8.         let rec next i =
  9.                 try
  10.                         let value = Stream.next stream in
  11.                         if p value then Some value else next i
  12.                 with Stream.Failure -> None in
  13.         Stream.from next;;
  14.  
  15.  
  16.  
  17. let grabVtkSizeInfo path =
  18.         let ic = open_in path in
  19.         let lineStream = Stream.from (fun _ ->
  20.                 try Some (input_line ic) with End_of_file -> None) in
  21.         let s = (stream_filter (fun s -> String.exists s "DIMENSIONS") lineStream) in
  22.         try Some (Stream.next s) with Stream.Failure -> None;;
  23.  
  24.                
  25.  
  26.  
  27. let pgm = "test.pgm";;
  28.  
  29. let oc = open_out pgm;;
  30.  
  31. let info = Option.default "" (grabVtkSizeInfo "140408aX_t01_ch01.vtk");;
  32.  
  33. fprintf oc "P2\n%d %d\n%d\n%s" 5 5 255 info;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement