我用perl和python写了相同功能的一段程序,计算一维fdtd,用gnuplot动态显示,可是python的数据没有显示出来,看横纵坐标的变化数据是正确收到了的,如最后的图片,求大神指点,谢谢。

 #!/usr/bin/perl

 # Author : Leon  Email: yangli0534@gmail.com
# fdtd simulation , plotting with gnuplot, writting in perl
# perl and gnuplot software packages should be installed before running this program
# 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
# lossy dielectric material localted at > ez[150]
#use Time::HiRes qw(sleep);
#use autodie qw(:all);
use strict;
use warnings; #print "\@\n";
#my $terminal = "";
# open GNUPLOT_TERM, "echo 'show terminal;' | gnuplot 2>&1 |";
# while (<GNUPLOT_TERM>) {
# if (m/terminal type is (\w+)/) {
# $terminal=$1;
# }
# }
# close GNUPLOT_TERM; # unfortunately, the wxt terminal type does not support positioning.
# hardcode it...
# $terminal = "x11"; open my $PIPE ,"| gnuplot " || die "Can't initialize gnuplot number \n"; print $PIPE "set size 0.85, 0.85\n";
print $PIPE "set term png size 600, 400\n"; my $title = "fdtd simulation by leon,yangli0534\\\\@"."gmail.com";
print $PIPE "set terminal gif animate\n";# terminal type: png
print $PIPE "set output \"fdtd_simulation_abc_tfsf_match_diel.gif\"\n";#output file name
print $PIPE "set title \"{/Times:Italic $title}\"\n";# title name and font
#print $PIPE "set title \"fdtd simulation by leon,yangli0534\\\\@ gmail.com\"\n";# title name and font
print $PIPE "set title font \",10\" norotate tc rgb \"white\"\n";
print $PIPE "unset key\n";
print $PIPE "set tics textcolor rgb \"white\"\n";# text color
print $PIPE "set border lc rgb \"orange\"\n";
print $PIPE "set grid lc rgb\"orange\"\n";
print $PIPE "set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb \"gray10\" behind\n";#background color
print $PIPE "set xlabel\" {/Times:Italic distance: wave length}\" tc rgb \"white\" \n";# xlabel
print $PIPE "set ylabel\"{/Times:Italic amplitude: v}\" tc rgb \"white\"\n";#ylabel
print $PIPE "set autoscale\n"; my $size = ;#physical distance
my @ez;#electric field
my @hy;#magnetic field
my @ceze;#
my @cezh;#
my @chye;#
my @chyh;#
my $LOSS_LAYER = ; #my @epsR;
my $LOSS = 0.01;
my $imp0 = 377.0;
#initalization
for (my $i = ; $i < $size; $i++){
$ez[$i] = 0.0;
$hy[$i] = 0.0;
if ($i < ) {
#$epsR[$i] = 1.0;
$ceze[$i] = 1.0;
$cezh[$i] = $imp0;
}
elsif($i < $LOSS_LAYER){
#$epsR[$i] = 1.0;
$ceze[$i] = 1.0;
$cezh[$i] = $imp0/9.0;
}
else {
#$epsR[$i] = 9.0;
$ceze[$i] = (1.0-$LOSS)/(1.0+$LOSS);
$cezh[$i] = $imp0 / /(1.0+$LOSS);
}
} for ( my $i = ; $i < $size; $i++){ if($i < $LOSS_LAYER){
#$epsR[$i] = 1.0;
$chye[$i] = 1.0/$imp0;
$chyh[$i] = 1.0;
}
else {
#$epsR[$i] = 9.0;
$chye[$i] = 1.0/ $imp0 /(1.0+$LOSS);
$chyh[$i] = (1.0-$LOSS)/(1.0+$LOSS);
}
}
my $qTime;
my $MaxTime = ;
my $pi = 3.141592563589793;
print $PIPE "set xrange [0:$size-1]\n";
my $mm = ; #do time stepping
for($qTime = ; $qTime < $MaxTime; $qTime+=){ # update magnetic field
#$hy[$size - 1] = $hy[$size - 2 ];#abc
for( $mm = ; $mm < $size - ; $mm++){
$hy[$mm] = $hy[$mm]*$chyh[$mm] + ($ez[$mm+] - $ez[$mm])*$chye[$mm];
}
$hy[] -=exp(-($qTime - 30.0)*($qTime - 30.0)/100.0)/$imp0;
# update electric field
$ez[] = $ez[];#abc
#$ez[$size-1] = $ez[$size-2];
for( $mm = ; $mm < $size- ; $mm++){
$ez[$mm] = $ez[$mm]*$ceze[$mm] + ($hy[$mm] - $hy[$mm-])*$cezh[$mm];
} if($qTime % == ){ print $PIPE "plot \"-\" w l lw 1.5 lc rgb \"green\"\n";
my $cnt = ;
for my $elem ( @ez) {
#print " ".$elem;
print $PIPE $cnt." ".$elem."\n";
$cnt += ;
}
print $PIPE "e\n";
}
#hardwire a source
$ez[] += exp(-($qTime +0.5-(-0.5)- 30.0)*($qTime +0.5-(-0.5)- 30.0)/100.0);
} #print $PIPE "set terminal x11\n"; print $PIPE "set output\n"; close($PIPE);

正常结果

python的程序

 #!/usr/bin/env python

 import sys
import math
import os
# Author : Leon Email: yangli0534@gmail.com
# fdtd simulation , plotting with gnuplot, writting in python
# perl and gnuplot software packages should be installed before running this program
# 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
# lossy dielectric material localted at > ez[150]
gp = os.popen('gnuplot','w')
#gp .write('plot sin(x)\n');
#gp .flush();
#p .close();
gp.write('set size 0.85, 0.85\n')
gp.write('set term png size 600, 400\n')
title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com'
gp.write('set terminal gif animate\n')
gp.write('set output "fdtd_simulation_abc_tfsf_match_diel_py.gif"\n')
gp.write(''.join(['set title "{/Times:Italic ',title, '}"\n']))
gp.write('set title font ",10" norotate tc rgb "white"\n')
gp.write('unset key\n')
gp.write('set tics textcolor rgb "white"\n')
gp.write('set border lc rgb "orange"\n')
gp.write('set grid lc rgb"orange"\n')
gp.write('set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb "gray10" behind\n')
gp.write('set xlabel" {/Times:Italic distance: wave length}" tc rgb "white" \n')
gp.write('set ylabel"{/Times:Italic amplitude: v}" tc rgb "white"\n')
gp.write('set autoscale\n'); size = 400#physical distance
ez=size * [0.00]#electric field
hy=size * [0.00]#magnetic field
ceze=size * [0.00]#
cezh=size * [0.00]#
chye=size * [0.00]#
chyh=size * [0.00]#
imp0 = 377.00
LOSS = 0.01
LOSS_LAYER = 250
MaxTime = 18000
cnt = 0
elem = 0.00000
gp.write(''.join(['set xrange [0:',str(size),'-1]\n']));
for i in range(0,size):
ez[i] = 0.0
hy[i] = 0.0
if (i < 100):
#$epsR[$i] = 1.0;
ceze[i] = 1.0
cezh[i] = imp0
elif(i < LOSS_LAYER):
#$epsR[$i] = 1.0;
ceze[i] = 1.0
cezh[i] = imp0/9.0
else :
#$epsR[$i] = 9.0;
ceze[i] = (1.0-LOSS)/(1.0+LOSS)
cezh[i] = imp0 / 9 /(1.0+LOSS)
if( i < LOSS_LAYER):
chye[i] = 1.0/imp0
chyh[i] = 1.0
else:
chye[i] = 1.0/imp0/(1.0+LOSS)
chyh[i] = (1.0-LOSS)/(1.0+LOSS)
for qTime in range(0, MaxTime):
# update magnetic field
for mm in range(0, size-1):
hy[mm] = hy[mm]*chyh[mm] + (ez[mm+1]-ez[mm])*chye[mm]
hy[49] = hy[49]-math.exp(-(qTime - 30.0)*(qTime - 30.0)/100.0)/imp0
# update electric field
ez[0] = ez[1]#abc
#$ez[$size-1] = $ez[$size-2];
for mm in range(1, size-1):
ez[mm] = ez[mm]*ceze[mm] + (hy[mm] - hy[mm-1])*cezh[mm]
if(qTime % 20 == 0):
gp.write('plot "-" w l lw 1.5 lc rgb "white"\n')
cnt = 0
for elem in ez:
#gp.write([cnt,' ',elem,'\n'])
gp.write(''.join([str(cnt),' ',str(elem),'\n']))
#gp.write(' ')
#gp.write(str(elem))
#gp.write('\n')
cnt += 1
gp.write('e\n')
ez[50] = ez[50]+math.exp(-(qTime +0.5-(-0.5)- 30.0)*(qTime +0.5-(-0.5)- 30.0)/100.0);
gp.write('set output\n')
gp.close()

结果就是

SOS: gnuplot fdtd的一个问题求助 perl vs python的更多相关文章

  1. Perl 和 Python 的比较 【转】

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&id=4662991&uid=608135 作为万年Perl 党表示最近开 ...

  2. 【脚本语言对比】BASH,PERL以及PYTHON

    据说: BASH能调用linux的应用程序,这是其最大的优点,也是其最大的缺点. PERL那复杂的语法确实看得让人想吐. python很优美,但是据说对正则的支持不够,没有perl强大. 总结一下学习 ...

  3. 常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript

    常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用 ...

  4. Perl,Python,Ruby,Javascript 四种脚本语言比较

    Perl 为了选择一个合适的脚本语言学习,今天查了不少有关Perl,Python,Ruby,Javascript的东西,可是发现各大阵营的人都在吹捧自己喜欢的语言,不过最没有争议的应该是Javascr ...

  5. 关于CGI:Tomcat、PHP、Perl、Python和FastCGI之间的关系

    如前文所述,Web服务器是一个很简单的东西,并不负责动态网页的构建,只能转发静态网页.同时Apache也说,他能支持perl,生成动态网页.这个支持perl,其实是apache越位了,做了一件额外的事 ...

  6. 【原创】控制perl和python脚本执行过程中脚本文件是否关闭的方法

    引子 跟踪perl和python脚本对文件的访问,实际过程中,perl和python解析器在解析完脚本后,直接关闭了 脚本文件,在进程中查询不到是访问文件的脚本文件名称. shell.perl和pyt ...

  7. 正则表达式匹配可以更快更简单 (but is slow in Java, Perl, PHP, Python, Ruby, ...)

    source: https://swtch.com/~rsc/regexp/regexp1.html translated by trav, travmymail@gmail.com 引言 下图是两种 ...

  8. Perl &amp; Python编写CGI

    近期偶然玩了一下CGI,收集点资料写篇在这里留档. 如今想做HTTP Cache回归測试了,为了模拟不同的响应头及数据大小.就须要一个CGI按须要传回指定的响应头和内容.这是从老外的測试页面学习到的经 ...

  9. 分享一个获取代理ip的python函数

    分享一个获取代理ip的python函数 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #coding:utf-8 from bs4 import Beaut ...

随机推荐

  1. Studio for WPF:定制 C1WPFChart 标记

    在本篇文章中,我们将阐述如何定制 C1WPFChart 数据点的标记. 下面分步讲解实现: 1.定制自定义样式: 1: <Window.Resources> 2: <Style x: ...

  2. LGLDatePickerView

    这个是封装 系统的PickerView 使用也比较简单, gihub地址:https://github.com/liguoliangiOS/LGLDatePickerView.git 效果图 使用方法 ...

  3. PHP json编码遇到的问题

    今天遇到了json编码解码之后中文消失的问题,一探究竟,写下这篇文章 PHP中提供了json_encode  和json_decode 这对函数 将PHP中 值转化成 字符串,但是遇到中文的时候,很容 ...

  4. mvc与三层结构终极区别

    http://blog.csdn.net/csh624366188/article/details/7183872 http://www.cnblogs.com/zhhh/archive/2011/0 ...

  5. java微信开发(wechat4j)——得到微信请求参数

    微信平台会在请求的post数据中带有一些参数,例如用户的openid之类的信息,当你使用了wechat4j之后,得到这些信息是非常方便的. public class Lejian extends We ...

  6. C# Sqlite 序列

    sqlite 不能直接创建自定义函数,不能像 sql server中那样方便创建并使用.不过我们照样可以创建它,创建成功后,我们照样可以随心所欲(比如批量更新等) 序列是一个数据库中很常用的操作,在其 ...

  7. PHP调用SQL Server存储过程

    一.安装SQL Server Driver for PHP     在微软官网上发现了这个东西,他提供了一套PHP对MS2005/2008操作的全新函数库,并且支持UTF8,作为PHP的扩展运行.看来 ...

  8. JavaScript hasOwnProperty() 函数详解

    hasOwnProperty()函数用于指示一个对象自身(不包括原型链)是否具有指定名称的属性.如果有,返回true,否则返回false. 该方法属于Object对象,由于所有的对象都"继承 ...

  9. 访问SAP的Domain的Value Range

    访问Domain的Value Range有两种方法: 1.直接访问表 dd07l和dd07T     select * from dd07l            where domname   = ...

  10. STL--集和多集(set/multiset)

    与基本容器相比,关联容器更注重快速和高效地检索数据的能力.这些容器是根据键值(key)来检索数据的,键可以是值也可以是容器中的某一成员.这一类中的成员在初始化后都是按一定顺序排好序的. 本文地址:ht ...