KJ7LNW / xnec2c

Xnec2c is a high-performance multi-threaded electromagnetic simulation package to model antenna near- and far-field radiation patterns for Linux and UNIX operating systems.
https://www.xnec2c.org/
GNU General Public License v3.0
78 stars 17 forks source link

`--batch` option still doesn't work properly #45

Closed ProtonTheFox closed 6 months ago

ProtonTheFox commented 6 months ago

Hi, here's an other issue about the --batch option. The last fix did not work for me and the last thread was tagged as closed (#44 ), so I open another one.

I noticed that opening the frequency plot window starts the frequency loop automatically if the batch option is activated. I decided to dig further into main.c and this piece of code confirms that this behavior is expected:

https://github.com/KJ7LNW/xnec2c/blob/master/src/main.c#L627-L637

As rc_config.main_loop_start had been set to 1 by the previously modified code.

A quick and dirty modification forces the frequency loop to run if rc_config.main_loop_start has been set to 1:

  // MODIFIED
  if( rc_config.main_loop_start )
    Start_Frequency_Loop();

  /* Re-initiate frequency plots if window open */
  if( isFlagSet(PLOT_ENABLED) )
  {
    GtkWidget *box = Builder_Get_Object( freqplots_window_builder, "freqplots_box" );
    gtk_widget_show( box );

    // MODIFIED
    if( rc_config.main_loop_start )
      Main_Freqplots_Activate();
  }

This now works as it should, so it's good enough for me. But it shows another flaw: it runs the frequency loop at startup even without the batch option, because the frequency loop start state is stuck to 1 in my xnec2c.conf file. That's a 2-bugs-in-1 issue.

I also previously thought about forcing the plot window to show up in --batch mode, just like it does in --optimize mode. I didn't manage to do that because my knowledge of xnec2c's source code is very limited, but it would be useful to have a real time preview of your results when doing batch simulations. In addition of that, the logic in the code portion I modified would remain unchanged.

Edit: well, a quick fix for the frequency loop start when neither --batch nor --optimize is on would be this little modification. I changed this:

https://github.com/KJ7LNW/xnec2c/blob/master/src/main.c#L383-L384

To this:

  if (rc_config.batch_mode)
      rc_config.main_loop_start = 1;
  else
      rc_config.main_loop_start = 0;

Still no change in the conf file, but these flags seem to override what's written inside anyway.

KJ7LNW commented 6 months ago

Thank you for the detailed report. I am glad you have a temporary fix in place for your own use at the moment.

It will probably take me awhile to get back to this to solve this in more detail, but we will take care of it.

ProtonTheFox commented 6 months ago

Thanks for the quick reply, I'll stay tuned.

KJ7LNW commented 6 months ago

I think this has been solved in the latest commit. Please give it a try and reopen the issue if you notice any problems or have additional feedback.

Thank you for your help!