Skip to content

SIP78 Convert switches to run time options#96

Merged
dlebauer merged 19 commits into
masterfrom
SIP78_convert_switches_to_run_time_options
Jun 19, 2025
Merged

SIP78 Convert switches to run time options#96
dlebauer merged 19 commits into
masterfrom
SIP78_convert_switches_to_run_time_options

Conversation

@Alomir

@Alomir Alomir commented Jun 11, 2025

Copy link
Copy Markdown
Collaborator

#78

This is Part 1, since this is a good place to partition the work, and I've made enough huge PRs recently...

This PR:

  • Creates a global Context struct to hold config options
  • Reads options from both sipnet.in and the command line, merging them into the Context object (command line has precedence)
  • Adds command-line options for a few params as proof of concept
  • Updates the help text with this change
  • Uses a hash_map (based on uthash, a third-party header file) to manage metadata about context params, including what source the param value comes from
  • Adds option to dump the final merged config into a file named <inputfile>.config (e.g., niwot.config)
  • Removes namelistinput, as that is superseded by the Context

Part 2 of this task will be to convert the compiler switches that we are keeping as options to run-time args, update the Context and cli for these options, and remove/massage code related to the flags that we are removing or hard-coding on.

@Alomir Alomir marked this pull request as ready for review June 11, 2025 21:23
@Alomir Alomir requested review from dlebauer and infotroph June 11, 2025 21:41

@dlebauer dlebauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, given my limited experience.

What are your plans regarding testing this core new functionality? I don't want to require it here, just want to make sure it is on the radar (e.g. after all the major refactoring is complete?)

Comment thread src/sipnet/cli.c
printf("\n");
printf("Info options:\n");
printf(" -h, --help Print this message and exit\n");
printf(" -v, --version Print version information and exit\n");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exciting news!

$ ./sipnet -v       
SIPNET version 2.0.0

Comment thread src/sipnet/cli.c Outdated
}

// Print the version when requested
void version(void) { printf("SIPNET version 2.0.0\n"); }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this! Though I don't think we want to hard code this ... could this go in VERSION or src/version.h?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It definitely should go somewhere not here - I was thinking src/version.h too, but was leaving it open for now (obviously). I'l switch to that, and we can see how we feel about that.

Comment thread src/sipnet/cli.c
printf("Flag options: (prepend flag with 'no_' to force off, eg '--no_print_header')\n");
printf("\n");
printf(" --dump_config Print final config to <input_file>.config (0)\n");
printf(" --print_header Whether to print header row in output files (1)\n");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the default really on?

./sipnet --input_file tests/smoke/sipnet.in

head -n 2 tests/smoke/niwot.out
       0 1998 305  0.00  5759.77  1133.88 16000.06     8.00  1919.90  1919.64   400.00    0.500     6.00    0.500     0.00    -0.32     0.74     0.74     0.00    0.164    0.578    0.159    0.324    0.419    0.742 0.00302126   0.0000   0.0000
       0 1998 305  7.00  5759.63  1133.71 16000.08     8.00  1919.77  1919.10   400.00    0.500     5.99    0.500     0.00    -0.30     0.97     1.71     0.22    0.271    0.917    0.251    0.522    0.666    1.188 0.00240544   0.0022   0.5821

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urm... no, it isn't 😬

Well, to be clear - our coded sipnet.in files explicitly turn it off. The actual default is currently on.

@Alomir Alomir Jun 16, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, I strongly suspect all existing sipnet.in files turn it off, unless someone wanted it on. Or, more to the point, I bet that all existing sipnet.in's set it to something, so the default is somewhat moot.

Comment thread src/common/util.c Outdated
(!strcmp(mode, "r") || !strcmp(mode, "rb")) ? "reading" : "writing";
fprintf(stderr,
"Error %s '%s': %s\n",
mode_word, name, strerror(errno));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this msg more helpful, and in the process learned about the strerror function, though I still don't exactly understand how it finds "no such file or directory" from SIPNET's custom error codes!?

before:

Error opening sipnet.in for r

after:

Error reading 'sipnet.in': No such file or directory
Error writing 'tests/smoke/niwot.out': No such file or directory

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this better too!

strerror isn't using sipnet's error codes; that errno is a bit of system global variable trickery, it's actually the error code from the fopen call.

Comment thread src/sipnet/context.c
CREATE_CHAR_CONTEXT(inputFile, "INPUT_FILE", DEFAULT_INPUT_FILE, CTX_DEFAULT);
CREATE_CHAR_CONTEXT(runType, "RUN_TYPE", RUN_TYPE_STANDARD, CTX_DEFAULT);
CREATE_CHAR_CONTEXT(fileName, "FILENAME", "", CTX_DEFAULT);
CREATE_INT_CONTEXT(location, "LOCATION", 0, CTX_DEFAULT);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will references to location and LOC be obsolete following #92?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they will!

Comment thread src/sipnet/context.c
// strip names down by removing chars like dashes and underscores, and
// converting to lowercase. This will allow different versions to still find
// the relevant metadata, while retaining uniqueness.
void nameToKey(const char *name) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this normalization be documented? i.e. is this a 'feature' or should we expect users to use the correct form but silently accept others?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's a good question! This is here partly to reconcile params like RUNTYPE in existing sipnet.in files, but also differences (at least in appearance) between command line options and input file naming.

I'd say, when we get to documenting putting these in the input file (which might be part of the next PR? Maybe a follow-on?), we go ahead and doc it. Hopefully people won't start using In&PuT-*_fiL:E!, for inputFile, even though it would work, lol.

@Alomir

Alomir commented Jun 16, 2025

Copy link
Copy Markdown
Collaborator Author

Re: testing

There should be no change in model functionality from this (and the follow-on) PR; I think a good plan would be to do #103:

  • expand it to include a couple of different flag options
  • record the "good" answers before this PR goes in

@Alomir Alomir requested a review from dlebauer June 18, 2025 15:24

@dlebauer dlebauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@dlebauer dlebauer enabled auto-merge (squash) June 19, 2025 19:46
@dlebauer dlebauer merged commit 262fbf0 into master Jun 19, 2025
7 checks passed
@dlebauer dlebauer deleted the SIP78_convert_switches_to_run_time_options branch June 19, 2025 19:46
@Alomir Alomir restored the SIP78_convert_switches_to_run_time_options branch July 9, 2025 16:31
@Alomir Alomir deleted the SIP78_convert_switches_to_run_time_options branch July 15, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants