fortran中变量声明的好风格是什么?(What is good style for variable declaration in fortran?)
所以我需要声明很多变量,原始代码如下所示:
DIMENSION energy_t(20000),nrt(20000),npsh(1000),xx(1000),yy(1000), :step(1000),stepz(1000),r1(1000),rr(1000),ic(1000),diffrr(1000)
我把它重写为:
DIMENSION :energy_t(20000), :nrt(20000), :npsh(1000), :step(1000), :r1(1000), :rr(1000), :ic(1000), :diffrr(1000)
这被认为是好的风格,还是有更好的方法? 请注意,第二种方式允许对每个变量进行注释,如果我可以添加另一个变量,则不必使用行继续。
PS:有没有关于Fortran编程风格和良好实践的共识/风格圣经/广泛认可的来源?
So I have a whole lot of variables I need to declare, and the original code looked like this:
DIMENSION energy_t(20000),nrt(20000),npsh(1000),xx(1000),yy(1000), :step(1000),stepz(1000),r1(1000),rr(1000),ic(1000),diffrr(1000)
And I rewrote it as this:
DIMENSION :energy_t(20000), :nrt(20000), :npsh(1000), :step(1000), :r1(1000), :rr(1000), :ic(1000), :diffrr(1000)
Is this considered good style, or are there better ways? Note that the second way allows for comments with each variable, and I don't have to use line continuations if I might add another variable.
P.S.: is there a consensus/style bible/widely regarded source on Fortran programming style & good practices?
原文:https://stackoverflow.com/questions/22331165
最满意答案
好的,你需要:
- Init GTK库
- 创建一个Builder对象
- 检索窗口小部件
- 显示窗口小部件
我假设您已经在Linux系统中安装了java-gnome库并在eclipse项目中导入了jar(项目属性 - java构建路径 - 添加外部jar - /usr/share/java/gtk.jar)。
示例代码:
Gtk.init(args); //Init library Builder b = new Builder(); //Create builder b.addFromFile("filename.glade"); //Load layout from file Window w = (Window) b.getObject("myWindowName"); //Retrieve an object w.showAll(); //Show window Gtk.main();
这是它应该工作的方式。 如果要在对象(例如按钮)上设置侦听器,则可以按照之前的窗口检索对象,然后:
button.connect(new Clicked() { @Override public void onClicked(Button arg0) { // Do what you want } });
它适合你吗? 嗯,这不适合我。 问题是我的代码在调用Builder.addFromFile(filename)时抛出异常
java.text.ParseException:无效的对象类型`GtkLabel'
错误是关于树中的第一个元素。 经过深入研究后,我发现,由于一个从未修复的已知错误,您需要在使用之前预先定义每个小部件:在这种情况下只需调用
new Label();
在创建构建器之前。
显然,这不是以这种方式工作,并将在未来修复。
关于这个问题的更多信息:
希望这可以帮助......
Ok, you need to:
- Init GTK library
- Create a Builder object
- Retrieve the window widget
- Display the window widget
I assume you have already installed the java-gnome library in your Linux system and imported the jar in your eclipse project (project properties - java build path - add external jars - /usr/share/java/gtk.jar).
A sample code:
Gtk.init(args); //Init library Builder b = new Builder(); //Create builder b.addFromFile("filename.glade"); //Load layout from file Window w = (Window) b.getObject("myWindowName"); //Retrieve an object w.showAll(); //Show window Gtk.main();
This is the way it should work. If you want to set a listener on an object, e.g. a button, you retrieve the oject by name as seen before with the window and then:
button.connect(new Clicked() { @Override public void onClicked(Button arg0) { // Do what you want } });
Is it working for you? Well, it's not for me. The problem was my code was throwing an exception when calling Builder.addFromFile(filename)
java.text.ParseException: Invalid object type `GtkLabel'
The error is about the first element in the tree. After a deep research I found that, due to a known bug never fixed, you need to pre-define every widget before using it: in this case just call
new Label();
before creating the builder.
This is, obviously, not intended to work in this way, and will be fixed in the future.
More info on this issue:
Thread on java-gnome-developer mailing list
Thread on Java-gnome-hackers mailing list
Hope this can help...
相关问答
更多-
在不同操作系统上基于.glade文件的GTK + 3应用程序(GTK+ 3 applications based on .glade file on different OS)[2022-12-16]
我刚刚打开了我的gui.glade文件属性,问题变得很明显。 默认情况下,Glade需要在您的计算机上安装最新版本的GTK +。 我使用Debian不稳定,所以对我来说它是GTK 3.20。 当我在稳定的系统上测试它时,它不起作用,因为它上面安装了GTK 3.18。 为了解决这个问题,我通过Glage改变了我的gui.glade属性,并将所需的GTK版本减少到3.10。 I've just opened my gui.glade file properties and the problem became ... -
如何使用Glade创建GtkApplicationWindow小部件?(How do I create a GtkApplicationWindow widget with Glade?)[2024-01-19]
在你的ui xml改变 -
好的,你需要: Init GTK库 创建一个Builder对象 检索窗口小部件 显示窗口小部件 我假设您已经在Linux系统中安装了java-gnome库并在eclipse项目中导入了jar(项目属性 - java构建路径 - 添加外部jar - /usr/share/java/gtk.jar)。 示例代码: Gtk.init(args); //Init library Builder b = new Builder(); //Create builder b.addFromFile("filename. ...
-
glade-3.8.x系列是支持Gtk + 2的最后一个版本。 林间空地> 3.8.x目标是Gtk + 3。 Ubuntu提供了包装3.8.x版本的glade-gtk2软件包,而glade软件包包装了最新的Gtk + 3版本。 因此,如果您要定位Gtk + 2,则需要安装glade-gtk2并使用该版本的glade。 注意:同样在Fedora上, glade包装出Gtk + 3版本,而glade3 (不是真正的最佳名称)是Gtk + 2版本。 The glade-3.8.x series is the la ...
-
为什么需要生成.rb文件? 代码生成是Frowned Upon™。 那么你用Gtk :: Builder实例加载glade文件吗? 获得Builder对象后,可以调用get_object方法来获取特定的小部件。 这是关于林间空地3的非常好的教程,它不包括红宝石,但是python足够接近。 这是一个有点过时的,所以如果你使用最近版本的林间空地3,已经修复了一些错误。 def initialize_combobox_script_select() #get combobox widget from gl ...
-
Matplotlib作为Glade / GTK小部件:移植到新版本(Matplotlib as Glade/GTK widget: porting to new version)[2023-03-03]
我有一个简单的版本工作。 随意发布改进。 我还发布了一个pull请求,因此可能会将其添加到matplotlib文档中。 Python 3文件: #!/usr/bin/env python3 from gi.repository import Gtk, Gio from matplotlib.figure import Figure from matplotlib.axes import Subplot from numpy import arange, sin, ... -
我以前没有真正使用PyGTK,但从我看到的问题很可能是在startcycletimer方法中: 它应该是GObject.timeout_add_seconds(1, self.displaytimer)而不是GObject.timeout_add_seconds(1, self.displaytimer(counter)) 。 您需要将调用者传递给函数而不是输出。 I haven't really used PyGTK before, but from what I see the issue is mos ...
-
GTK + Glade和CSS(GTK+ Glade and CSS)[2021-11-22]
你快到了; 最后一步是获取GtkCssProvider并将其添加到GtkStyleContext。 由于您使用的是.ui文件和.css文件,我假设您希望将CSS应用于应用程序中的所有小部件。 在这种情况下,您可以使用gtk_style_context_add_provider_for_screen() ,将gdk_screen_get_default()作为GdkScreen传递。 (这应该是安全的;这是GTK + Inspector所做的.IIRC有一个更具体的原因,为什么这应该是安全的......) 您 ... -
我设法自己解决了这个问题。 所以很简单,使用macports来安装林间空地。 第1步:在您的Mac上安装X11或更新它 第2步:安装Xcode 第3步:安装macports - macOS Sierra: https : //github.com/macports/macports-base/releases/download/v2.3.5/MacPorts-2.3.5-10.12-Sierra.pkg OS X El Captain: https : //github.com/macports/macpo ...
-
避免此类问题的一种方法是修改构建脚本以从glade文件生成目标代码,并将这些符号链接到可执行文件中。 例如,您可以为glade文件创建构建目标(我假设您正在使用make和makefile) gladetarget: ld -r -b binary -o somefile.o somefile.glade 然后,您将修改主可执行文件的构建目标,以首先构建此目标,并包含目标文件: main: gladetarget g++ main.cc somefile.o -o mypr ...