Production Level Knowledge & Tips

  1. 未分類
  2. 12 view

[Haskell]Input PGM file part1

Target

I could output PGM file with Haskell.
So I want to make a program which read PGM file.

Program

At first only input header and output it.
import System.IO
import System.Environment (getArgs)

main = do
    args <- getArgs
    if length args == 0 then do
        print "usage : ./pgm-input test.pgm"
    else do
        infile <- openFile (head args) ReadMode

        -- Read PGM Header
        pgm_type <- hGetLine infile
        pgm_comment <- hGetLine infile
        pgm_max_brightness <- hGetLine infile
        pgm_size <- hGetLine infile
        hClose infile

        -- Output PGM File
        putStrLn pgm_type
        putStrLn pgm_comment
        putStrLn pgm_max_brightness
        putStrLn pgm_size
Run.
$ ./pgm-input test.pgm
P5
# PGM type grayscale image
255 255
255

未分類 recent post

  1. Install sbt 1.0.0 and run sample template

  2. Visualization of Neural Network and its Train…

  3. [Machine Learning]Created docker image includ…

  4. [Node.js]How to write batch script with Node.…

  5. [Hive]Get top n items for each category

関連記事

PAGE TOP