Specifying relative paths in SPSS 18 - deployment

In SPSS 11 it was possible to specify relative paths. Example:
FILE HANDLE myfile='..\..\data\current.txt' /LRECL=533.
DATA LIST FILE=myfile /
...
This worked because apparently, SPSS 11 set the working folder to the path where the source .SPS file is saved. It seems that SPSS 18 always sets it's working folder to the installation folder of SPSS itself. Which is not at all the same thing.
Is there an option to change this behaviour? Or am I stuck with changing everything to absolute filenames?

Instead of a relative path, you could define a directory path and use it inside other file handle declarations to save typing:
FILE HANDLE directoryPath /NAME='C:\Directory\Path\' .
FILE HANDLE myFile /NAME='directoryPath/fileName.xyz' .
GET FILE='myFile' .
This will get the file: C:\Directory\Path\fileName.xyz.
The direction of the slashes may be important.
(Works in version 17)

If you use the INSERT command to run an sps file, it has an option to change the working directory to that location.
You could use the HOST command to SUBST a drive letter (on PCs) and reference everything through that.
You could define a FILE HANDLE to the common root location and use that in file references.
You could use Python programmability to find the path to the active syntax window and issue an SPSS CD command to set the backend working directory appropriately.
HTH,
Jon Peck

With Python, you can get the full path of the current syntax window (or any other one) and get its path. Using that you can issue an SPSS cd command to change the backend working directory accordingly.
If you define an environment variable, though, you can use that in file specifications within SPSS.
p.s. SPSS has an extensive set of apis and helper modules for Python (as well as for R and .NET languages). You can get information about this from SPSS Developer Central, www.spss.com/devcentral. All the language extensions are free once you have the base SPSS Statistics product.
Regards,
Jon Peck

Or use "CD" command to change your default working directory. See also:
http://www.spss-tutorials.com/change-your-working-directory/
For example, if your default directory is C:\project, then GET FILE 'data\data_file.sav'. will open data_file.sav from C:\project\data.
And then, a few minutes later, i came across this little python script from jignesh-sutar (see here: SPSS syntax - use path of the file.
With his python code you can use the path of the syntax file as starting point for all the paths in your syntax.

Related

Powershell dot sourcing opens up file in notepad

Everytime i dot source a file in PowerShell it opens a copy of the file in notepad.
Exe:
.\MyScript.ps1
The script runs fine - its just really annoying having these pop up all the time. Is there a way to suppress this?
I'm on windows 7 x64 and using the latest version of PowerShell.
Ex2: This is still launching notepad.
cls
Set-Location "\\PSCWEBP00129\uploadedFiles\psDashboard\"
. .\assets\DCMPull\Powershell\SqlServerTransfer.psm1
. .\assets\DCMPull\Powershell\RunLogging.psm1
You cannot dot source PowerShell files with the .psm1 file extension. One option is to rename them to .ps1.
Alternatively (and, in my opinion the better approach), you can load the PowerShell modules using Import-Module <module.psm1>. Just note that the behavior of Import-Module is different from dot sourcing it. Dot sourcing runs the script in the current scope and also persists all variables, functions, etc.in the current scope. Import-Module does not do that.
Although not very common, you can also export variables from modules with Export-ModuleMember.
Adding to Raziel's answer, there's a lot of thought that went into only being able to dot source files with .ps1 extension, and otherwise why it tries to run it as a system executable. Here's a snippet from PeterWhittaker on GitHub:
. ./afile would only execute something if there's either an
extension-less but executable aFile in the current dir, or a
(not-required-to-be-executable) afile.ps1 file, with the former taking
precedence if both are present; if the file exists, but is neither
executable nor has extension .ps1, it is opened as if it were a
document.
. <filename> with <filename> being a mere name (no path component) by
(security-minded) design only ever looks for a file of that name in
the directories listed in $env:PATH (see below), not in the current
directory.
I encountered exactly the same situation : If the point source imports the .psm1 file, the file will be opened directly instead of importing the code in the file.
Because the function of point source import is only valid in the file with suffix of.ps1, if the suffix does not meet the requirements, it will not be regarded as path, but as a code , so it is like running the corresponding string directly, and the effect is naturally to open the file.
So,this phenomenon is not aimed at .PSM1,if you change the extension to TXT, it will have the same effect. It will have the same effect for any file whose suffix is not .PS1.
You can bypass this problem by creating symbolic links or hard links!
In PowerShell 7, it's easy to create links using New-Item.

How to add load libraries, change directory, etc. on startup?

Is there a way to automatically load libraries, change to a certain working directory, etc. when launching Dymola?
The question is slightly ambiguous - the other answer is quite good for one scenario. (The openModel call in Step 2 can be modified.)
However, if you always want to launch Dymola in a specific directory etc it is possible using the GUI. How depends on version.
Dymola 2020 x (and later)
Allows changing start-up directory through File>Working Directory
And has Tools>Library Management>Modelica Path where you can add the directory containing your external libraries.
To make libraries appear preloaded you have to add a libraryInfo.mos script in the corresponding library; you can look at Modelica Standard Library in the Dymola installation for inspiration.
The latter is described in more detail in the section "More about libraries and the building of menus of libraries and demo" (somewhere in the User Manual).
Dymola 2017 FD01 (and slightly differently from Dymola 2016 FD01):
Change Directory (File>Change Directory)
Add to Modelica Path (File>Modelica Path)
Save those settings (Edit>Options>Settings: Select Startup and Modelica Path)
If you want to "preload" libraries there are some options:
In a startup script you can use import MyPackage; or openModel("...\\MyPackage.mo"); alternatively if you are administrator you could modify Dymola/insert/dymodraw.ini and add a line: Dymola5LibraryMenu "MyPackage" (technically it doesn't "load" - it just shows the library in the package browser).
An important difference is that changing dymodraw.ini keeps the library "loaded" even after "Clear All".
In recent years there are two options that might help you.
File>Library Management>Install This dialog allows you to open a
zip-file or something similar of a distributed library, install it,
update MODELICAPATH to find it again, and even update the File>Libraries
menu to include it for future use. All in one operation.
Simulation>Edit startup.mos If you prefer to edit the startup
script, this is the convenient way to find it end open it for
editing.
Here is a procedure which allows to load a set of libraries with one click.
It makes use of the fact that the dymola.exe can be started with a .mos script as first argument.
It is designed for situations such as
You are using Windows
You are working on one or more projects
Where every project requires a set of libraries to be loaded
Every project uses it's own working directory
Other users might collaborate, so they need the very same setup
Requirements
The setup is a bit of work the first time, but very quickly done for further projects. You need:
a start.mos file in your library
the environment variables DYMOLA_WD and MODELICA_LIBS
(This is only required to allow other users to use different paths for their libraries and working directories)
a file short-cut to dymola.exe
This is how start.mos looks like for a specific project (usually you only change the first two lines):
// user setup
libs = {"Buildings 6.0.0", "PhotoVoltaics", "MyProject"}
wd = "myproject"
// open all libs
lib_dir = Modelica.Utilities.System.getEnvironmentVariable("MODELICA_LIBS");
lib_dir = Modelica.Utilities.Strings.replace(lib_dir, "\\", "/")
for l in libs loop
openModel(lib_dir + "/" + l + "/package.mo");
end for;
// change to wd
wd = Modelica.Utilities.System.getEnvironmentVariable("DYMOLA_WD") + "/" + wd;
wd = Modelica.Utilities.Strings.replace(wd, "\\", "/")
Modelica.Utilities.Files.createDirectory(wd)
cd(wd)
Now you create a shortcut to dymola.exe in the windows file explorer. In the field Target you set
"C:\Program Files\Dymola 2020\bin64\Dymola.exe" "%MODELICA_LIBS%\MyProject\Resources\scripts\start.mos"
Example
Assuming a user has set the environment variables
MODELICA_LIBS = E:\modelica
DYMOLA_WD = E:\dymola_wds
the folder structure on the users hard disk must look as follows for the script above to work:
E:\modelica
|- Buildings 6.0.0
|- package.mo
|- ...
|- PhotoVoltaics
|- package.mo
|- ...
|- MyProject
|- package.mo
|- ...
|- Resources
| |- scripts
| |- start.mos
|- ...
Now the dymola.exe-shortcut is used to start Dymola, which will automatically load the required libraries for the project and change the working directory.
For another project a new shortcut is required, along with a new start.mos script.
This method has been tested for Dymola 2017FD01. Prior versions used a different method via a setup.mos script that is no longer available. As of this posting, there is no option to perform this actions via the Dymola GUI.
It can be easily accomplished via a .mos file with the steps shown below:
Create a .mos file in a location that makes sense. For example, C:\Users\USERNAME\Documents\Dymola\startup.mos
Add the actions desired to .mos file. For example, to load a library add openModel("C:\\Users\\USERNAME\\Documents\\ModelicaLibrary\\package.mo");
Dymola always puts its auto-generated files in the current working directory. It's often a good idea to have that location be the same location so there is no need to hunt down the location of output files. Therefore, at the end of the .mos file change the current directory: cd("C:\\Users\\USERNAME\\Documents\\Dymola");
If no shortcut exists to the Dymola.exe file, then create one.
Right click the shortcut and go to Properties. Under Shortcut>Target append "C:\Users\USERNAME\Documents\Dymola\startup.mos"at the end. The contents of that cell should now look something like this: "C:\Program Files (x86)\Dymola 2017 FD01\bin64\Dymola.exe" "C:\Users\vmg\Documents\Dymola\startup.mos"
That's it. When Dymola is launched from that shortcut the actions specified in the .mos file should be carried out.
Another suggestion where you don't need to hardcode your package into an environment variable of your operating system (and maybe more safe for inexperienced programmers):
Go to the folder where Dymola is installed (e.g. C:\Program Files\Dymola 2020).
Search for the Dymola.mos file in the insert-folder. 'insert' folder
Open the script (e.g., in notepad++)
Add the link(s) to your Dymola-library-package.mo file(s) here with the openModel statement
e.g., openModel("C:/IDEAS/package.mo"); Dymola.mos script
Save the script. Now, every time you open Dymola, your libraries will be loaded automatically.

Netbeans, phpdocumentor, and custom phpdoc.dist.xml by project

I am using Netbeans 8.0.2 and phpdocumentor 2.8.2 on a windows 7 platform.
I would like to use custom phpdoc.dist.xml config files by project so I can specify framework directories and etc. to exclude from the generated doc. I also want to keep my Netbeans PHPDOC plugin config as generic as possible, without specific output directories, ignore options, config path parameters, etc., so on, so that that the config will apply to all my projects.
The phpdoc.dist.xml file works great. The doc generated is exactly what I want.
The problem or feature, and it seems to be a phpdocumentor one as it also applies from plain command line, is that the phpdoc.bat command (without a specific config parm) has to be run from the same root directory as the phpdoc.dist.xml file, or it ignores it. No problem if I'm using command line as I can change into that directory first, but I would like to use Netbeans. I have searched on this extensively and cannot find an answer.
I considered whether to modify the phpdocumentor files to insert cd /D path/to/myproject/dir to change the directory using some Netbeans variable to represent myproject/dir, but I could not find the right place in the code or the variable to use. Plus, then I'm supporting a custom mod to phpdocumentor.
I did find these directions for a PHPStorm setup, where the author specified a PHPStorm variable for the --config command line option to point to his custom phpdoc.dist.xml.
--config="$ProjectFileDir$/phpdoc.dist.xml"
If I could do the same in Netbeans like maybe "${BASE_DIR}/phpdoc.dist.xml" it would be great, but so far I haven't hit on anything Netbeans will recognize/pay attention to in the PhpDoc script: box.
I have also tried writing a wrapper .bat file to capture my own command line variable %1 and do the directory change to that before calling phpdoc.bat, but Netbeans throws and error and says that's not a valid .bat file. I cannot find any phpdocumentor parameter to configure by specific Netbeans project but the output directory. And I would prefer not to be defining a bunch of projects on subdirectories in Netbeans, just to address phpdocumentor.
Now I am out of ideas. Can anyone point me to a solution?

Do Doxygen config files support variables?

For instance I set the source code path as c:\code\testapp\src. Is this then available as a var I can use - for instance so I can spit out a tag file in a location relative to this, not relative to the working dir of doxygen? I think I'm looking for something like how Ant defines vars for just about everything and these can be re-used; does Doxygen have special vars for any of the config values?
I'm thinking like $PROJECT-NAME or %VERSION% or whatever...
You can use environment variables in the configuration file; the syntax is the same as in a makefile, i.e. $(VAR_NAME)
I am not sure, but I have seen people use variables as part of their build process. For example the lemon graph library uses cmake, sets a variable for the absolute file path in cmake and the doxygen config file includes variables such as #abs_top_srcdir#. Through the build process these variables are replaced with the relevant text.

How do I "source" something in my .vimrc file?

I've been working on expanding my vim-foo lately and I've run across a couple of plugins (autotag.vim for example) that require them to be "sourced" in my .vimrc file. What exactly does this mean and how do I do it?
Sourcing a file is 'executing' it. Essentially, each line of the file is considered a command. Sourcing it is the same as typing each command in order. You source with the command :source (usually shortened to :so).
So if you source myStuff.vim
:so myStuff.vim
and if myStuff.vim contained these lines
set xx iI just intersted this<C-]>
set yy bbbb4dw
It's the same as if you typed those commands into Vim
:set xx iI just intersted this<C-]>
:set yy bbbb4dw
The only file sourced by default is the .vimrc(_vimrc on windows) so that's a place you can keep all the commands you use to set up Vim every time.
Where it gets interesting is the fact that since a sourced file is just a series of commands, and sourcing is a command, you can source files from your source files. So plugins you use every time could be sourced when you start up Vim by adding a line to your .vimrc like this
so myPlugin.vim
Files in your .vim/plugin directory are sourced (loaded) automatically.
There is always the :source file command. I usually write .vimrc that contains custom commands and what not for the console application and then a .gvimrc that contains additional goodies that are appropriate for a windowed version. My .gvimrc starts with source $HOME/.vimrc to pick up everything from the console version before adding in new stuff.
There are normally two vimrc files, one is _vimrc and the other _gvimrc (in the first one are the things for vim, and in the second for gvim - graphical things) - although most people I know just put everything in _vimrc.
A good practice is to keep all your extra files (plugins, colorschemes, snippets ...) in a separate (your own) vimfiles directory (which you can take with you).
If you do
:help vimfiles
vim will tell your vimfiles directory should be located. It depends somewhat on the platform (win, unix). On windows the usual is in your user folder (documents and settings, then user ...).
In vimfiles directory there are a couple of subdirectories. Amongst them is the "plugin" subdirectory. Plugins put in that dir will be loaded automatically (also plugins put in subdirectories of "plugin").
If you do not wish to load it automatically, just put it in your "vimfiles", or some other directory, and
:so plugin_name.vim (with the appropriate path)
(you can use the $vim, $vimfiles, and $home as shortcuts when defining path to plugin)