Advertisement
Guest User

Untitled

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