Topic
  • 5 replies
  • Latest Post - ‏2013-03-06T22:04:23Z by SystemAdmin
SystemAdmin
SystemAdmin
1883 Posts

Pinned topic How to get the project directory in the prepare section of a .dat file

‏2013-02-27T14:31:54Z |
Hi all,

my data is stored in a binary file which resides in my project directory. The format of the data is not supported by OPL but I can easily parse this data using a sequence of IloOplCallJava() calls.
My problem is that in order to do that I need to tell those IloOplCallJava() calls where to find the file.
I am running from the IDE and as far as I can tell the directory in which a project is executed is not the project directory but the directory from which the IDE was launched. So looking for a file "data.bin" will not look in the project directory. On the other hand, I found that IloOplInputFile("data.bin") looks for files in the project directory. That is what I need but unfortunately I cannot use IloOplInputFile since my data is binary and not text.
So assume I am in the prepare() section of a .dat file: how can I figure out what the project directory is? Is there an environment variable or property that I can use?

Thanks!
Updated on 2013-03-06T22:04:23Z at 2013-03-06T22:04:23Z by SystemAdmin
  • AlexFleischer
    AlexFleischer
    1831 Posts

    Re: How to get the project directory in the prepare section of a .dat file

    ‏2013-03-04T10:16:54Z  
    Hi,

    execute {
      
      writeln(" PATH = ",IloOplGetEnv("PATH"));
    }
    


    gives the env variable PATH.
    Could this help you?
    Updated on 2014-03-26T05:50:44Z at 2014-03-26T05:50:44Z by AlexFleischer
  • AlexFleischer
    AlexFleischer
    1831 Posts

    Re: How to get the project directory in the prepare section of a .dat file

    ‏2013-03-04T10:31:03Z  
    Hi,

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">execute { writeln(" PATH = ",IloOplGetEnv("PATH")); } </pre>

    gives the env variable PATH.
    Could this help you?
    or

    writeln(" CPLEXDIR = ",IloOplGetEnv("CPLEX_STUDIO_DIR125"));
    
    Updated on 2014-03-26T05:50:41Z at 2014-03-26T05:50:41Z by AlexFleischer
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: How to get the project directory in the prepare section of a .dat file

    ‏2013-03-04T10:41:38Z  
    or

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">writeln(" CPLEXDIR = ",IloOplGetEnv("CPLEX_STUDIO_DIR125")); </pre>
    No, sorry, none of that would help.
    The value of PATH does not help at all since that gives no clue from where the IDE was started. Same for CPLEXDIR.
    I could easily figure out the current working directory in the .dat file (by querying the user.dir property) but that does not help either since I would still have no clue how that relates to the project directory.
    So what I really need is a way to find the (absolute) path to the project directory of the project that is being run. Since IloOplInputFile and IloOplOutputFile seem to use this directory when resolving relative path names I thought that this information must be available somewhere?
  • AlexFleischer
    AlexFleischer
    1831 Posts

    Re: How to get the project directory in the prepare section of a .dat file

    ‏2013-03-06T19:44:29Z  
    No, sorry, none of that would help.
    The value of PATH does not help at all since that gives no clue from where the IDE was started. Same for CPLEXDIR.
    I could easily figure out the current working directory in the .dat file (by querying the user.dir property) but that does not help either since I would still have no clue how that relates to the project directory.
    So what I really need is a way to find the (absolute) path to the project directory of the project that is being run. Since IloOplInputFile and IloOplOutputFile seem to use this directory when resolving relative path names I thought that this information must be available somewhere?
    Hi,

    and what about

    writeln(thisOplModel.resolvePath("toto.mod"));
    


    that is available in a main context

    Regards
    Updated on 2014-03-26T05:50:31Z at 2014-03-26T05:50:31Z by AlexFleischer
  • SystemAdmin
    SystemAdmin
    1883 Posts

    Re: How to get the project directory in the prepare section of a .dat file

    ‏2013-03-06T22:04:23Z  
    Hi,

    and what about

    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">writeln(thisOplModel.resolvePath("toto.mod")); </pre>

    that is available in a main context

    Regards
    Thanks a lot! This does work. As argument to resolvePath() I just use the .dat file itself and the result is the absolute path to the .dat file.