Skip to content

LTN/Plone

Sections
Personal tools
You are here: Home » Members » poonlap's Home » gnuplot

gnuplot + thai patch

test

Postscript patch สำหรับ gnuplot

gnuplot เป็นโปรแกรมสำหรับเขียนกราฟแบบบรรทัดคำสั่ง(command-line interface). สามารถใช้เขียนกราฟฟังชั่นคณิตศาสตร์หรือข้อมูลได้ทั้ง 2 มิติและ 3 มิติ และสามารถบันทึกกราฟที่เขียนได้หลายฟอร์แมต. โปรแกรมนี้มีประโยชน์อย่างยิ่งสำหรับนักวิทยาศาตร์, วิศวกรม, นักศึกษา หรือบุคคลทั่วไปที่สนใจในโปรแกรมเขียนกราฟ.

จุดประสงค์

จุดประสงค์ของ patch นี้มีเพื่อทำให้ gnuplot-3.7.2 สามารถ export ไฟล์แบบ eps (Encapsulated PostScript) ที่ใช้ภาษาไทยได้. ไฟล์แบบ eps เป็นไฟล์กราฟฟิกคุณภาพสูง, เมื่อย่อหรือขยาดรูปจะไม่เสียคุณภาพ. ในกรณีที่ต้องการใช้ภาษาไทยเขียนชื่อกราฟ, ชื่อแกน หรือคำประกอบ มีความจำเป็นที่ต้องทำให้ gnuplot รู้จักรหัสภาษาไทยและฟอนต์ PostScript ภาษาไทย. gnuplot ที่ได้ปรับแต่งแล้วสามารถ export เป็นไฟล์ eps ได้. ถ้าระบุฟอนต์ต่อไปนี้, ตัวโปรแกรมจะฝังฟอนต์ในไฟล์ eps ให้.
  • Garuda
  • GarudaBold
  • GarudaItalic
  • GarudaBoldItalic
การฝังฟอนต์เอื้อเฟื้อความสะดวกแก่ผู้ใช้, กล่าวคือผู้ใช้ไม่ต้องติดตั้งฟอนต์สำหรับ ghostscript ก็สามารถใช้ดูไฟล์์ eps ได้ทันที.

ความต้องการพื้นฐาน

  1. ระบบที่สามารถใช้ภาษาไทยรหัส TIS-620 ได้.
  2. Ghostscript

ดาว์นโหลด

รหัสต้นฉบับและ patch

RPMS

ตัวอย่างไฟล์

  • thplot.gnu (ไฟล์รหัส TIS-620 ที่เขียนคำสั่งของโปรแกรม gnuplot ไว้)
  • thplot.eps (ตัวอย่างไฟล์ eps ที่สร้างโดย gnuplot ที่ patch แล้ว)

ตัวอย่างการติดตั้ง(RPM)

# rpm -e --nodeps gnuplot
# rpm -ihv gnuplot-3.7.2-1tle.i386.rpm
Preparing... ########################################### [100%]
1:gnuplot ########################################### [100%]

ตัวอย่างการคอมไพล์และติดตั้ง

[poonlap@luminor tmp]$ ls
gnuplot-3.7.2.tar.gz gnuplot-3.7.2-thai.patch
[poonlap@luminor tmp]$ tar xzf gnuplot-3.7.2.tar.gz
[poonlap@luminor tmp]$ cd gnuplot-3.7.2
[poonlap@luminor gnuplot-3.7.2]$ patch -p1 < ../gnuplot-3.7.2-thai.patch
patching file set.c
patching file setshow.h
patching file term/post.trm
[poonlap@luminor gnuplot-3.7.2]$ ./configure
..........
[poonlap@luminor gnuplot-3.7.2]$ make
[poonlap@luminor gnuplot-3.7.2]$ su
Password:
[root@luminor gnuplot-3.7.2]# make install
..........
[root@luminor gnuplot-3.7.2]# exit
exit
[poonlap@luminor gnuplot-3.7.2]$ /usr/local/bin/gnuplot

ตัวอย่างการใช้งาน

  1. สร้างไฟล์คำสั่ง gnuplot เช่น(ไม่ต้องเขียนหมายเลขบรรทัด)
    01	#!/usr/bin/gnuplot
    02	set encoding tis_620  
    03	set term postscript eps color "Garuda" 20     
    04	set output 'thplot.eps'
    05	set title 'ทดสอบการวาดกราฟภาษาไทย'
    06	set xlabel 'แกน x'
    07	set ylabel 'แกน y'
    08	set grid
    09	plot sin(x), 0.6 * sin(2 *x)
    สมมติว่าบันทึกไฟล์ให้มีชื่อว่า thplot.gnu และผู้ใช้ติดตั้ง gnuplot ที่ patch แล้วใน /usr/bin. การเข้ารหัส(encoding)ของไฟล์นี้ต้องเป็น TIS-620 เท่านั้น. ถ้าผู้ใช้สร้างไฟล์ที่ใช้การเข้ารหัสเป็น UTF-8 ให้ใช้คำสั่ง iconv แปลงเป็น TIS-620.

    บรรทัดที่ 2 บ่งบอกว่าการเข้ารหัสของไฟล์ที่ใช้เป็น TIS-620. บรรทัดนี้ต้องเขียนเสมอถ้าต้องการใช้ภาษาไทย. บรรทัดที่ 3 เป็นวิธีการระบุฟอนต์ที่ต้องการใช้. ในที่นี้ใช้ฟอนต์ Garuda. ชื่อฟอนต์ที่ใช้เป็นชื่อฟอนต์แบบ postscript. ถ้าใช้ฟอนต์ Garuda, GarudaBold, GarudaItalic หรือ GarudaBoldItalic โปรแกรมจะฝังฟอนต์ให้. ถ้าใช้ฟอนต์อื่น, ผู้ใช้ต้องติดตั้งฟอนต์ภาษาไทยสำหรับ postscript เอง. ถ้าต้องการไฟล์แบบ postscript ไม่ต้องเขียน eps และให้เปลี่ยน output เป็น thplot.ps แทน.
  2. ใช้ gnuplot
    [poonlap@luminor gnuplot]$ gnuplot
    
            G N U P L O T
            Version 3.7 patchlevel 2
            last modified Sat Jan 19 15:23:37 GMT 2002
            System: Linux 2.4.18-14
    
            Copyright(C) 1986 - 1993, 1998 - 2002
            Thomas Williams, Colin Kelley and many others
    
            Type `help` to access the on-line reference manual
            The gnuplot FAQ is available from
            http://www.gnuplot.info/gnuplot-faq.html
    
            Send comments and requests for help to 
            Send bugs, suggestions and mods to 
    
    
    Terminal type set to 'x11'
    gnuplot> load 'thplot.gnu'
    gnuplot> exit
    
    วิธีใช้อีกแบบคือทำให้ไฟล์ thplot.gnu ที่สร้างไว้รันได้ (chmod +x) แล้วรันไฟล์นั้น.
    [poonlap@luminor gnuplot]$ chmod +x thplot.gnu
    [poonlap@luminor gnuplot]$ ./thplot.gnu 
  3. ดูไฟล์ eps ที่สร้างด้วย ggv, gv หรือ kghostview

    thplot.png

  4. ผู้ใช้สามารถแปลงไฟล์ eps เป็นไฟล์แบบอื่นได้โดยใช้ ghostscript เช่น
    [poonlap@luminor gnuplot]$ gs -sOutputFile=thplot.jpg -sDEVICE=jpeg -dBATCH -dNOPAUSE thplot.eps

    จากตัวอย่างข้างบนเป็นการแปลงไฟล์ eps เป็น JPEG.

ติดต่อสอบถาม



Created by poonlap
Contributors : Poonlap Veerathanabutr
poonlap@linux.thai.net
Last modified 2005-06-01 02:53 PM
 

Powered by Plone

This site conforms to the following standards: