Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EN_saveinpfile function does not include section comments in INP file #800

Closed
YuChunTsao opened this issue Jun 12, 2024 · 3 comments
Closed

Comments

@YuChunTsao
Copy link
Contributor

I'm using the Epanet toolkit to generate INP files.

The EN_saveinpfile function does not include comments for properties in each section when it generates an INP file. This is inconsistent with the output from the EPANET GUI, which does include these comments.
These comments can increase readability when user opening the INP file using a text editor.

For example, this is a junction section of an INP file generated using the EN_saveinpfile function.
(I opened Net1.inp and exported a new file.)

[JUNCTIONS]
 10                                  710.0000
 11                                  710.0000
 12                                  700.0000
 13                                  695.0000
 21                                  700.0000
 22                                  695.0000
 23                                  690.0000
 31                                  700.0000
 32                                  710.0000

However, when we use EPANET 2.2 to export a network, the INP file will include property comments.

[JUNCTIONS]
;ID              	Elev        	Demand      	Pattern         
 10              	710         	0           	                	;
 11              	710         	150         	                	;
 12              	700         	150         	                	;
 13              	695         	100         	                	;
 21              	700         	150         	                	;
 22              	695         	200         	                	;
 23              	690         	150         	                	;
 31              	700         	100         	                	;
 32              	710         	100         	                	;

Maybe we can refer ExportDataBase function in Epanet 2.2 to update the saveinpfile function in the inpfile.c.

I modified some code in junction section for testing.

// Write [JUNCTIONS] section
// (Leave demands for [DEMANDS] section)
fprintf(f, "\n\n");
fprintf(f, s_JUNCTIONS);
// Add a comment for junction section.
fprintf(f, "\n;%-16s\t%-12s\t%-12s\t%-16s",
    "ID", "Elev", "Demand", "Pattern");
for (i = 1; i <= net->Njuncs; i++)
{
    node = &net->Node[i];
    // Update the format
    fprintf(f, "\n %-16s\t%-12.4f\t", node->ID, node->El * pr->Ucf[ELEV]);
    if (node->Comment) fprintf(f, "  ;%s", node->Comment);
}

This is the modified result.

[JUNCTIONS]
;ID              	Elev        	Demand      	Pattern         
 10              	710.0000    	
 11              	710.0000    	
 12              	700.0000    	
 13              	695.0000    	
 21              	700.0000    	
 22              	695.0000    	
 23              	690.0000    	
 31              	700.0000    	
 32              	710.0000    	

There is a issue may need to be discussed about output format.
The length of the ID is 31.
However, the length of the output format in the EPANET 2.2 ExportDataBase function is 16.

@LRossman
Copy link
Collaborator

@YuChunTsao some points of clarification:

  1. When you say "comments" you actually mean column headings. The comments assigned to individual elements are already saved to file when EN_saveinpfile is executed.
  2. When you say EPANET 2.2 you actually mean the EPANET GUI for Windows and not the EPANET 2.2 Toolkit API.
  3. The ExportDataBase function in the GUI will correctly write an ID name whose length is greater than 16 characters to file.
  4. If you modify the saveinpfile function in the Toolkit please write ID names using a %-31s format specifier and not %-16s.

@YuChunTsao
Copy link
Contributor Author

Thanks for the clarification!

@YuChunTsao
Copy link
Contributor Author

#802

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

No branches or pull requests

2 participants