OpenWaterAnalytics / EPANET

The Water Distribution System Hydraulic and Water Quality Analysis Toolkit
MIT License
272 stars 201 forks source link

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

Closed YuChunTsao closed 1 week ago

YuChunTsao commented 3 weeks ago

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 commented 3 weeks ago

@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_saveinpfileis 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 ExportDataBasefunction in the GUI will correctly write an ID name whose length is greater than 16 characters to file.
  4. If you modify the saveinpfilefunction in the Toolkit please write ID names using a %-31sformat specifier and not %-16s.
YuChunTsao commented 3 weeks ago

Thanks for the clarification!

YuChunTsao commented 1 week ago

802