From 47d4d8d3cf34eb29a4adddec3835900cccd331f3 Mon Sep 17 00:00:00 2001
From: David Robert Verelst <dave@dtu.dk>
Date: Sun, 2 Apr 2017 12:04:54 +0200
Subject: [PATCH] prepost.dlcdefs: more clear htc master file auto selection

---
 README.md               |  9 +++++----
 wetb/prepost/dlcdefs.py | 29 +++++++++++++++++++++--------
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index 99450330..715fc334 100644
--- a/README.md
+++ b/README.md
@@ -71,10 +71,11 @@ load calculations, and create load envelopes.
 
 Additional documentation can be found here:
 
-- [Auto-generation of Design Load Cases](docs/howto-make-dlcs.md)
-- [How to use the Statistics DataFrame](docs/using-statistics-df.md)
-- [Generate DLB spreadsheets](docs/generate-spreadsheet.md)
-
+- [Getting started with DLBs](docs/getting-started-with-dlbs.md)
+    - [Generate DLB spreadsheets](docs/generate-spreadsheet.md)
+    - [Auto-generation of Design Load Cases](docs/howto-make-dlcs.md)
+    - [House rules for storing results on ```mimer/hawc2sim```](docs/houserules-mimerhawc2sim.md)
+    - [How to use the Statistics DataFrame](docs/using-statistics-df.md)
 
 ### [fast](wetb/fast)
 Tools for working with NREL's FAST code (An aeroelastic computer-aided engineering (CAE) tool for horizontal axis wind turbines)
diff --git a/wetb/prepost/dlcdefs.py b/wetb/prepost/dlcdefs.py
index 6443ab5d..2a861991 100644
--- a/wetb/prepost/dlcdefs.py
+++ b/wetb/prepost/dlcdefs.py
@@ -13,10 +13,9 @@ from future.utils import viewitems
 from future import standard_library
 standard_library.install_aliases()
 
-
-
 import os
 import unittest
+from glob import glob
 
 import pandas as pd
 
@@ -62,16 +61,30 @@ def configure_dirs(verbose=False):
 
 
 def find_master_file(proot, htc_dir='htc', master_dir='_master',
-                     master_contains='_master_'):
+                     pattern='*_master_*'):
     """
     Find the master file name. It is assumed that the master file is in the
-    folder _master, under htc, and contains _master_ in the file name.
+    folder _master, under htc, and contains _master_ in the file name. If
+    multiple files contain pattern, the last file of the sorted list is
+    returned.
+
+    Parameters
+    ----------
+
+    proot
+
+    htc_dir : str, default: htc
+
+    master_dir : str, default: _master
+
+    pattern : str, default: *_master_*
+
     """
 
-    for root, dirs, files in os.walk(os.path.join(proot, htc_dir, master_dir)):
-        for fname in files:
-            if fname.find(master_contains) > -1:
-                return fname
+    fpath_search = os.path.join(proot, htc_dir, master_dir, pattern)
+    files = glob(fpath_search)
+    if len(files) > 0:
+        return sorted(files)[-1]
     return None
 
 
-- 
GitLab