-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUNUSED_V5DtoVTK.hs
46 lines (40 loc) · 1.66 KB
/
UNUSED_V5DtoVTK.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Main where
import V5D
import System.Environment (getArgs)
import System.IO
main = do { [nm] <- getArgs
; (file, (i,j,k)) <- readV5Dfile nm
; let fields = map name $ grids file
; let times = nr_times file
; mapM_ (outgrid nm file) [0 .. times-1]
}
outgrid base file t
= do { let g0 = head $ grids file
; let dx = (nr_rows g0) - 1
; let dy = (nr_cols g0) - 1
; let dz = (nr_levs g0) - 1
; let ext = "0 " ++ (show dx) ++ " 0 " ++ (show dy) ++ " 0 " ++ (show dz)
; h <- openFile (base ++ "-" ++ (show t) ++ ".vti") WriteMode
; hPutStrLn h $ "<?xml version=\"1.0\"?>"
; hPutStrLn h $ "<VTKFile type=\"ImageData\" version=\"0.1\" byte_order=\"LittleEndian\">"
; hPutStrLn h $ "<ImageData WholeExtent=\"" ++ ext ++ "\" Origin=\"0 0 0\" Spacing=\"1 1 1\">"
; hPutStrLn h $ " <Piece Extent=\"" ++ ext ++ "\">"
; hPutStrLn h $ " <PointData>"
; mapM_ (outfield h) [((name gr), fst $ dataset file (name gr) t) | gr <- grids file]
; hPutStrLn h $ " </PointData>"
; hPutStrLn h $ " </Piece>"
; hPutStrLn h $ "</ImageData>"
; hPutStrLn h $ "</VTKFile>"
; hClose h
}
outfield :: Handle -> (String, [Float]) -> IO ()
outfield h (name, vals)
= do { hPutStr h $ "<DataArray type=\"Float32\" Name=\""
; hPutStr h $ name
; hPutStrLn h "\" format=\"ascii\">"
; mapM_ (outvals h) $ split 8 vals
; hPutStrLn h "</DataArray>"
}
where split _ [] = []
split n vs = let (us, ws) = splitAt n vs in us : split n ws
outvals h vs = mapM_ (\v -> hPutStr h (show v) >> hPutStr h " ") vs >> hPutStrLn h ""