[Debian-astro-commits] [gyoto] 101/221: make fullPath able to interpret `pwd`/

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

thibaut pushed a commit to branch master
in repository gyoto.

commit ea6cb0c53cd95fed2d0421d4fdd4a83b12c7a98e
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Fri Nov 21 11:49:41 2014 +0100

    make fullPath able to interpret `pwd`/
---
 doc/examples/example-fixedstar-rotstar3_1.xml  |  7 ++++++-
 doc/examples/example-moving-star.xml           |  8 +++++++-
 doc/examples/example-movingstar-rotstar3_1.xml |  7 ++++++-
 include/GyotoFactory.h                         | 15 ++++++++++++++-
 include/GyotoScreen.h                          |  6 +++++-
 lib/Factory.C                                  | 17 ++++++++++++-----
 6 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/doc/examples/example-fixedstar-rotstar3_1.xml b/doc/examples/example-fixedstar-rotstar3_1.xml
index aa1aec9..0447dd6 100644
--- a/doc/examples/example-fixedstar-rotstar3_1.xml
+++ b/doc/examples/example-fixedstar-rotstar3_1.xml
@@ -2,7 +2,12 @@
 <Scenery>
 
   <Metric kind = "RotStar3_1">
-    <File>../../bin/.check-lorene/resu.d</File>
+
+    The path is normally either absolute or relative to the XML file,
+    but it is interpreted as relative to the working directory if
+    prefixed with "`pwd`/" :
+    <File>`pwd`/.check-lorene/resu.d</File>
+
     <IntegKind>1</IntegKind>
     <!--0: integ 4D ; 1: integ 3D  -->
   </Metric>
diff --git a/doc/examples/example-moving-star.xml b/doc/examples/example-moving-star.xml
index 1d1089e..0150b54 100644
--- a/doc/examples/example-moving-star.xml
+++ b/doc/examples/example-moving-star.xml
@@ -11,7 +11,13 @@
     <FieldOfView> 0.314159265358979323846264338327950288419716 </FieldOfView>
     <Resolution> 128 </Resolution>
     <Spectrometer kind="wave" nsamples="1"> 2.0e-6 2.4e-6 </Spectrometer>
-    <Mask>../../bin/example-startrace.fits</Mask>
+
+    By using a cleverly pre-computed mask, on can avoid computing
+    pixels that are known to be black. The path is normally either
+    absolute or relative to the XML file, but it is interpreted as
+    relative to the working directory if prefixed with "`pwd`/" :
+    <Mask>`pwd`/example-startrace.fits</Mask>
+
   </Screen>
 
   <Astrobj kind = "Star">
diff --git a/doc/examples/example-movingstar-rotstar3_1.xml b/doc/examples/example-movingstar-rotstar3_1.xml
index 9cea441..69fbda6 100644
--- a/doc/examples/example-movingstar-rotstar3_1.xml
+++ b/doc/examples/example-movingstar-rotstar3_1.xml
@@ -1,7 +1,12 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <Scenery>
   <Metric kind = "RotStar3_1">
-    <File>../../bin/.check-lorene/resu.d</File>
+
+    The path is normally either absolute or relative to the XML file,
+    but it is interpreted as relative to the working directory if
+    prefixed with "`pwd`/" :
+    <File>`pwd`/.check-lorene/resu.d</File>
+
     <IntegKind>1</IntegKind>
     <!--0: integ 4D ; 1: integ 3+1 D  -->
   </Metric>
diff --git a/include/GyotoFactory.h b/include/GyotoFactory.h
index 7da351e..b5d92d9 100644
--- a/include/GyotoFactory.h
+++ b/include/GyotoFactory.h
@@ -393,7 +393,20 @@ class Gyoto::Factory
 
   /// Transform relative path into absolute path.
   /**
-   * \param relpath Path relative to XML file.
+   * relpath is interpreted as follows:
+   *
+   * If it starts with "/", it is interpreted as an absolute path and
+   * is returned as is.
+   *
+   * If it is prefixed with "`pwd`/", the rest of relpath is
+   * interpreted as relative to the current working directory,
+   * i.e. fullPath() tries to mimick how the shell would expand
+   * relpath into an absolute path.
+   *
+   * In any other circumstance, relpath is interpreted to relative to
+   * the directory where the XML file resides.
+   *
+   * \param relpath Path specification.
    * \return Absolute path to same file.
    */
   std::string fullPath(std::string relpath);
diff --git a/include/GyotoScreen.h b/include/GyotoScreen.h
index d1a926c..59bc57e 100644
--- a/include/GyotoScreen.h
+++ b/include/GyotoScreen.h
@@ -155,7 +155,11 @@ namespace Gyoto {
  * \endcode
  * The mask needs to be have the same size as the Screen itself, so
  * loading a mask also sets the resolution, and changing the
- * resolution after setting a mask also removes the mask.
+ * resolution after setting a mask also removes the mask. The content
+ * of the Mask entity is parsed by Factory::fullPath(), so it can be
+ * an absolute path, a path relative to where the XML file is stored,
+ * or relative to the current working directory if prefixed with
+ * "`pwd`/".
  *
  */
 class Gyoto::Screen : protected Gyoto::SmartPointee {
diff --git a/lib/Factory.C b/lib/Factory.C
index 27e3284..d1f3fcf 100644
--- a/lib/Factory.C
+++ b/lib/Factory.C
@@ -976,11 +976,18 @@ std::string Factory::fullPath(std::string fname) {
     free (cwd); cwd = NULL;
   }
 
-  if (xmlpath.compare(0, 1, "/")) fpath = curwd + "/" ;
-
-  fpath += xmlpath + "/";
-
-  fpath += fname;
+  string prefix="`pwd`/";
+  if (fname.compare(0, prefix.size(), prefix)) {
+    // fname does not start with "`pwd`/":
+    // it is relative to xmlpath
+    if (xmlpath.compare(0, 1, "/")) fpath = curwd + "/" ;
+    fpath += xmlpath + "/";
+    fpath += fname;
+  } else {
+    // fname starts with "`pwd`/": relative to working directory
+    fpath = curwd + "/";
+    fpath += fname.substr(prefix.size());
+  }
 
   GYOTO_DEBUG << "returns " << fpath << endl;
   return fpath;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git



More information about the Debian-astro-commits mailing list