From b16dacb87e348b8ebe2ee3547bd4ce04373b2fc6 Mon Sep 17 00:00:00 2001 From: "Marios S. Kyriakou" Date: Thu, 1 Aug 2024 17:06:32 +0300 Subject: [PATCH] Add a new pattern or use an existing pattern - EN_loadpatternfile Co-Authored-By: Lew Rossman --- src/epanet.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 52c5a5ad..16e7bf6f 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -4538,16 +4538,14 @@ int DLLEXPORT EN_loadpatternfile(EN_Project p, const char *filename, const char file = fopen(filename, "r"); if (file == NULL) return 302; - // Add the new pattern - if ((err = EN_addpattern(p, id)) != 0) { - fclose(file); - return err; - } - - // Get the index of the newly added pattern - if ((err = EN_getpatternindex(p, id, &i)) != 0) { - fclose(file); - return err; + // Add a new pattern or use an existing pattern. + err = EN_getpatternindex(p, id, &i); + if (err == 205) { + if ((err = EN_addpattern(p, id)) != 0) { + fclose(file); + return err; + } + i = p->network.Npats; } // Read pattern values