首页 \ 问答 \ fortran中变量声明的好风格是什么?(What is good style for variable declaration in fortran?)

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
更新时间:2023-11-18 15:11

最满意答案

好的,你需要:

  • 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();

在创建构建器之前。

显然,这不是以这种方式工作,并将在未来修复。

关于这个问题的更多信息:

java-gnome-developer邮件列表上的线程

Java-gnome-hackers邮件列表上的线程

希望这可以帮助......


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...

相关问答

更多