【问题标题】:Gnuplot reading not locale encoding fileGnuplot 读取非语言环境编码文件
【发布时间】:2014-09-28 19:22:28
【问题描述】:

我想绘制 ISO_8859_1 编码文件的数据(两列数字)。这些是文件的前 10 个数据点:

#Pe2
        1   0.8000
        2   0.8000
        3   0.8000
        4   0.8000
        5   0.8000
        6   0.8000
        7   0.8000
        8   0.8000
        9   0.8000
       10   0.8000

原始文件有 15000 个数据点。我用 MATLAB 创建了这个数据,特别是设置了 ISO_8859_1 编码,所以我确信这就是编码。这是matlab代码的sn-p:

 slCharacterEncoding('ISO-8859-1');             %Instruction before writing anything to the file.

 fprintf(fileID,'  %7d  %7.4f',Tempo(i),y(i));  %For loop in this instruction

 fprintf(fileID,'\r');                          %Closing the file
 fclose(fileID);

这是我运行的脚本。此文件使用默认的 Windows txt 文件编码进行编码:

set encoding iso_8859_1
set terminal wxt size 1000,551 
# Line width of the axes
set border linewidth 1.5
# Line styles
set style line 1 lc rgb '#dd181f' lt 1 lw 1 pt 0   # red
# Axes label
set xlabel 'tiempo'
set ylabel 'valor'
plot 'Pe2.txt' with lines ls 1

这是我运行脚本时 gnuplot 控制台的输出。之后我输入“显示编码”:

        G N U P L O T
        Version 4.6 patchlevel 5    last modified February 2014
        Build System: MS-Windows 32 bit 

        Copyright (C) 1986-1993, 1998, 2004, 2007-2014
        Thomas Williams, Colin Kelley and many others

        gnuplot home:     http://www.gnuplot.info
        faq, bugs, etc:   type "help FAQ"
        immediate help:   type "help"  (plot window: hit 'h')

Terminal type set to 'wxt'
gnuplot> cd 'C:\Example'
gnuplot> load 'script.txt'
         "script.txt", line 10: warning: Skipping data file with no valid points

gnuplot> plot 'Pe2.txt' with lines ls 1
                                       ^
         "script.txt", line 10: x range is invalid

gnuplot> show encoding

        nominal character encoding is iso_8859_1
        however LC_CTYPE in current locale is Spanish_Spain.1252

gnuplot> 

如果我打开文件,进行一些更改撤消更改并保存文件,gnuplot 绘制文件。我猜这是因为它使用本地编码保存它,这是 gnuplot 用来读取文件的一种。

如何使用 gnuplot 绘制不是本地编码格式的文件?

当我使用 VS2010Css 输出文件时,我也遇到了类似的问题。如果我没有专门设置文化:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

我无法保存 gnuplot 能够绘制的文件。我相信最后一个问题是因为“,”和“。”

在 Css 中我用这个保存文件:

StreamWriter Writer = new StreamWriter(dir + @"\" + + (k+1) + "_" + nombre  + extension);

                Writer.WriteLine("#" + (k+1) + "_" + nombre);
                Writer.WriteLine();
                Writer.WriteLine("{0,32} {1,32}", "#tiempo", "#valor");

                for (int i = 0; i < tiempo.GetLength(0); i++)
                {
                    Writer.WriteLine("{0,32} {1,32}", tiempo[i].ToString(), valor[i, k]);
                }

谢谢。

【问题讨论】:

  • 请展示你在做什么。有这么多可能出错的地方...显示一个minimal数据文件和一个short,显示问题(包括终端设置)等的可运行脚本。跨度>
  • 我认为它已经完成了。如果你想要更多的东西,现在让我来。非常感谢。
  • 很难找到错误来源。我知道,字节顺序标记 (BOM) 会导致问题,但错误消息应该不同。否则编码应该不是问题,因为您只绘制数字而没有标签。您可以在某处上传完整的有问题的文件吗?
  • 我已经把完整的文件上传到我找到的第一个网站,这里是链接:filedropper.com/pe1 感谢您抽出宝贵的时间。

标签: encoding plot gnuplot iso-8859-1


【解决方案1】:

您的文件只有回车符 (\r 0xd) 作为换行符,这不适用于 gnuplot。您必须只使用换行符 (\n0xa),但 \r\n 也可以。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    相关资源
    最近更新 更多