我用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. jQuery获取Select选择的Text和 Value(转)用时比较方便寻找

    ---恢复内容开始--- jQuery获取Select选择的Text和Value:语法解释:1. $("#select_id").change(function(){//code. ...

  2. PHP学习笔记:MySQL数据库的操纵

    Update语句 Update 表名 set 字段1=值1, 字段2=值2  where  条件 练习: 把用户名带  ‘小’的人的密码设置为123456@ 语句:UPDATE crm_user SE ...

  3. vmware linux top si高以及网卡队列、软负载相关优化

    今日,测试公司自行开发的一rpc中间件,期间发现top si的比例很高,且几乎只有一个cpu是繁忙的,其他均基本为0. 经查,si主要是系统软中断,最后确定是网卡导致的系统中断.于是,往上搜了下资料, ...

  4. 解决Spring MVC @ResponseBody返回html中中文字符串乱码问题

    最近有个应用,通过responsebody返回完整的html页面时出现乱码是异常的问题,因为是通过responsebody返回,所以一开始设置了text/plain的字符集,如下: <mvc:a ...

  5. javascript小知识点

    大家对input中的value值研究的透彻么,今天看到一篇博客,很神奇  然后研究了一下input中的value值到底对应的是啥值 1.input中的value,这是大家在开发中进场遇到的一个问题 & ...

  6. 关于IE处理margin和padding值超出父元素高度的问题

    两个div,父div有padding值,子div有margin-top值,浏览器在解析实际父子位置关系时,他们之间的距离是父padding+子margin-top.现在把父div设置固定高度,并有意让 ...

  7. Mysql之执行计划

    1.explain分析sql语句 例如: EXPLAIN )  ORDER BY bi.`publish_time`  返回结果: 而今天检查的不是这条sql,远比这条复杂,不过也能反映情况了. (1 ...

  8. CSS3 实现简单轮播图

    用css3动画实现图片切换效果,原理还是改变left值.只有最简单的自动播放功能,切换后短时间静止,通过最后的位置克隆第一张图片,实现无缝切换. html结构 <div id="con ...

  9. ASP.NET MVC 微信公共平台开发之获取用户消息并处理

    ASP.NET MVC 微信公共平台开发 获取用户消息并处理 获取用户消息 用户发送的消息是在微信服务器发送的一个HTTP POST请求中包含的,获取用户发送的消息要从POST请求的数据流中获取 微信 ...

  10. 刚刚结束了公司EP流程,开始KMS项目开发了

    刚刚结束了公司EP流程,开始KMS项目开发了 EP流程:AGpoint+MOSS+C# KMS:MOSS上的文档管理系统