EPANET icon indicating copy to clipboard operation
EPANET copied to clipboard

ENsaveinpfile ignore vertices

Open Mariosmsk opened this issue 5 years ago • 5 comments

The following code ignores saveauxdata when we call and save with the same inpname.

https://github.com/OpenWaterAnalytics/EPANET/blob/bbe4fb7a0b183976f06704506a940ed6397f10e6/src/inpfile.c#L37

ENopen('Anytown.inp');
ENsaveinpfile('Anytown.inp');

anytown.zip

Mariosmsk avatar Jul 30 '19 14:07 Mariosmsk

When the saveinpfile() function in inpfile.c opens "Anytown.inp" for writing any existing contents of the file are lost. When saveauxdata() looks for the [VERTICES], [TAGS], etc. sections in "Anytown.inp" it can't find them so no auxilary data gets saved. Two possible solutions for this situation are:

  1. Just live with it and note somewhere in the docs that this will happen when duplicate file names are used.
  2. Have EN_saveinpfile() issue an error message if the file to be saved has the same name as the file used to open the project.

LRossman avatar Jul 31 '19 14:07 LRossman

@LRossman, If we use a temporary tempname for all epanet input files and then copy the tempname to the inpname who user set. What do you think?

Mariosmsk avatar Jul 31 '19 14:07 Mariosmsk

Btw, I agree with the two possible solutions above!

Mariosmsk avatar Jul 31 '19 14:07 Mariosmsk

@Mariosmsk I don't think just manipulating file names will help. You would have to copy the original input file to a temporary file, write the non-auxilary data in memory to the user-named file, read the auxilary data from the temporary file and write it to the user-named file, and finally delete the temporary file. Seems like a lot of work.

Why can't the app that's calling EN_saveinpfile call it with a different user-supplied file name and then use a file copy function (not part of the toolkit) to copy its contents into the original .inp file?

LRossman avatar Jul 31 '19 14:07 LRossman

Why can't the app that's calling EN_saveinpfile call it with a different user-supplied file name and then use a file copy function (not part of the toolkit) to copy its contents into the original .inp file?

@LRossman, That we use until now. So we continue to use this. :)

But the solutions above I think it's good both to use in the toolkit.

Mariosmsk avatar Jul 31 '19 14:07 Mariosmsk