Difficulty making Healpix compatible with GDL - idl-programming-language

PROBLEM:
I am having difficulty running Healpix-IDL routines with GDL with the current version of Healpix, Healpix_3.20.
The easiest thing to do would be to follow user gilo in this post:
http://sourceforge.net/p/gnudatalanguage/discussion/338692/thread/6546b9ad/?limit=25#324d
All Healpix IDL routines are downloaded in ~/user/downloads/Healpix_3.20/src/idl
Then, use !PATH i.e.:
GDL> !PATH = expand_path('+/user/myname/downloads/HEALPix_3.20/')+':'+!PATH
and after that you have access to all healpix procedures within gdl
That doesn't work for me. I try the command hidl and hididle in the Terminal (I'm using Mac OS X Yosemite, 10.10.5):
GDL> hidl
% Procedure not found: HIDL
% Execution halted at: $MAIN$
Any other solutions?
POSSIBLE SOLUTIONS:
In the installation procedures install.pdf, Section 7.6 hidl usage describes that hidl is sometimes not recognized. A fix is setting the environment variable IDL STARTUP to be equal to the HEALPix startup file HEALPix startup including the directory path to the file, i.e. use
setenv IDL_STARTUP /disk1/user1/HEALPix_2.15a/src/idl/HEALPix_startup for C shell, csh
export IDL_STARTUP="+/disk1/user1/HEALPix_2.15a/src/idl/HEALPix_startup" for s, sh, bash
For my routines, this should be
export IDL_STARTUP="+/usr/downloads/HEALPix_3.20/src/idl/HEALPix_startup"
on bash Terminal
(Recall syntax:
export key=value is sh, ksh, bash
setenv key value is csh)
This doesn't work for me. After executing the command, and entering gdl, I get:
% Error opening startup file: /user/myname/downloads/HEALPix_3.20/src/idl/HEALPix_startup
Following Section 7.8 Using GDL instead of IDL, I try
$ export IDL_TMPDIR=/tmp
$ gdl
This doesn't work either.
Following Using HEALPix IDL together with other IDL libraries in the IDL routines manual, idl.pdf, I try
export IDL_PATH="+/user/myname/downloads/HEALPix_3.20/src/idl/:+/opt/local/share/gnudatalanguage/lib:<IDL_DEFAULT>"
export IDL_STARTUP="+/user/myname/downloads/HEALPix_3.20/src/idl/HEALPix_startup"gdl`
output error:
% Error opening startup file: /user/myname/downloads/HEALPix_3.20/src/idl/HEALPix_startup.
I try
export IDL_PATH="+/opt/local/share/gnudatalanguage/lib:<IDL_DEFAULT>"
hidl
output error:
-bash: hidl: command not found
Nothing works.
BACKGROUND:
Healpix has the installation procedures here, at source forge.net: healpix.sourceforge.net/pdf/install.pdf
and the IDL routines here: healpix.sourceforge.net/pdf/idl.pdf
The sourcecode is here: sourceforge.net/projects/healpix/
In order to install Healpix, you use ./configure and then make. (See install.pdf, section 4)
Healpix IDL routines are downloaded in /user/myname/downloads/HEALPix_3.20/
GDL routines are located in /opt/local/share/gnudatalanguage/lib/

hidl is an alias to start IDL with the Healpix startup file and path. Type it on the system command line, not the IDL command line. You must run through their configure system to define hidl.

In subdirectory ~/.healpix/3_20_Darwin there are two files, config and idl.sh.
The config is
# configuration for Healpix 3.20
HEALPIX=/Users/myname/downloads/Healpix_3.20 ; export HEALPIX
HPX_CONF_DIR=/Users/myname/.healpix/3_20_Darwin
if [ -r ${HPX_CONF_DIR}/idl.sh ] ; then . ${HPX_CONF_DIR}/idl.sh ; fi
if [ -r ${HPX_CONF_DIR}/f90.sh ] ; then . ${HPX_CONF_DIR}/f90.sh ; fi
if [ -r ${HPX_CONF_DIR}/cpp.sh ] ; then . ${HPX_CONF_DIR}/cpp.sh ; fi
if [ -r ${HPX_CONF_DIR}/c.sh ] ; then . ${HPX_CONF_DIR}/c.sh ; fi
The idl.sh file is
# IDL configuration for HEALPix Fri MONTH DAY TIME EDT YEAR
# make sure IDL related variables are global
export IDL_PATH IDL_STARTUP
# back up original IDL config, or give default value
OIDL_PATH="${IDL_PATH-<IDL_DEFAULT>}"
OIDL_STARTUP="${IDL_STARTUP}"
# create Healpix IDL config, and return to original config after running Healpix-enhanced IDL
HIDL_PATH="+${HEALPIX}/src/idl:${OIDL_PATH}"
HIDL_STARTUP="${HEALPIX}/src/idl/HEALPix_startup"
alias hidl="IDL_PATH=\"${HIDL_PATH}\" ; IDL_STARTUP=${HIDL_STARTUP} ; idl ; IDL_PATH=\"${OIDL_PATH}\" ; IDL_STARTUP=${OIDL_STARTUP} "
alias hidlde="IDL_PATH=\"${HIDL_PATH}\" ; IDL_STARTUP=${HIDL_STARTUP} ; idlde ; IDL_PATH=\"${OIDL_PATH}\" ; IDL_STARTUP=${OIDL_STARTUP} "
So, if I manually set the paths in this idl.sh file and run config, i.e ~/.config. This should then allow one to use hidl in the command line to run the Healpix IDL routines, right?

Related

How can I activate a '.js' script from R?

I have a '.js' script that I usually activate from the terminal using the command node script.js. As this is part of a process where I first do some data analysis in R, I want to avoid the manual step of opening the terminal and typing the command by simply having R do it for me. My goal would be something like this:
...R analysis
write.csv(df, "data.csv")
system('node script.js')
However, when I use that specific code, I get the error:
sh: 1: node: not found
Warning message:
In system("node script.js") : error in running command
Of course, the same command runs without problem if I type it directly on the terminal.
About my Software
I am using:
Linux computer with the PopOS!
RStudio 2021.09.1+372 "Ghost Orchid"
R version 4.0.4.
The error message node: not found indicates that it couldn't find the program node. It's likely in PATH in your terminal's shell, but not in system()'s shell (sh).
In your terminal, locate node by executing which node. This will show the full path to the executable. Use that full path in system() instead.
Alternatively, run echo $PATH in your terminal, and run system('echo $PATH') or Sys.getenv('PATH') in R. Add any missing directories to R's path with Sys.setenv(PATH = <your new path string>)
Note that system2() is recommended over system() nowadays - but for reasons unimportant for your case. See ?system and ?system2 for a comparison.
Examples
Terminal
$ which node
/usr/bin/node
R
system('/usr/bin/node script.js')
# alternatively:
system2('/usr/bin/node', c('script.js'))
or adapt your PATH permanently:
Terminal
% echo $PATH
/usr/local/bin:/home/caspar/programs:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
R
> Sys.getenv('PATH')
[1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Applications/RStudio.app/Contents/MacOS/postback"
> Sys.setenv(PATH = "/home/caspar/programs:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Applications/RStudio.app/Contents/MacOS/postback")

What does `python3 ()` do?

While trying to execute a timeit command on the command line using the python command line interface I accidentally put .function() on the outside of the command like so:
$ python3 -m timeit '<code>'.function()
Rather than the timeit command being executed, I was prompted as such:
function>
Thinking I had entered the python repl I tried to quit with q. Yes, I'm aware quit() is the correct way to do this. Having returned to the command line, I noticed the error and corrected it like so:
$ python3 -m timeit `<code>.function()`
I expected this code to execute correctly, but instead I received the following error:
python3:7: command not found: q
After discussing it with some colleagues, it was suggested that I check which python was being used:
$ which python3
python3 () {
q
}
This was not what I was expecting! Normally the result would be /usr/local/bin/python3. Through some trial and error I was able to determine that the minimal case to reproduce this is:
$ python3 ()
function> q
$
Now that the context is out of the way, I have two questions about the behaviour I witnessed:
1. What exactly does python3 () do?
2. How do I return execution to its original state in the same terminal window? I'm aware I can open a new terminal window and the original state exists in that window.
The syntax foo () is used in POSIX-compliant shells (such as bash, dash, and zsh) to define a function. Your entire snippet defines a function called python3 and executes the command q when it's ran. You can bypass shell functions and aliases using the command command: command -p python3 myfile.py
To remove the function from the current shell process, you can use unset -f python3. If it keeps coming back after starting new shells, then it's likely defined in one of you shell initialization files.

How to add context menu option to start a program in the given working directory

When you install Git on windows, it adds a context menu option when you right-click on a folder to "Git Bash Here". The way it does this is by adding a registry key like this:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\git_shell\command]
#="\"C:\\Program Files\\Git\\git-bash.exe\" \"--cd=%1\""
Notice the cd argument at the end that passes the directory name to the program.
I would like to do something similar for R (and other programs). Unfortunately R doesn't accept a cd argument. This will launch R:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\R\command]
#="\"C:\\Program Files\\R\\R-3.4.3\\bin\\x64\\Rgui.exe\" \"--cd=%1\""
but it gives an error message saying the cd argument is not recognized, and Rgui will start with whatever the default working directory is, defeating the entire point.
What I really want it to do is the equivalent of this command:
start "R" /D %1 "C:\Program Files\R\R-3.4.3\bin\x64\Rgui.exe"
where %1 is the folder that was right-clicked on. Is this possible?
You can write R code that runs on startup and checks the commandline arguments.
You can put the following code at the end of C:\Program Files\R\R-3.4.3\etc\Rprofile.site (or any other file that gets executed at startup):
local({
processArg <- function(arg) {
parts <- strsplit(arg, "=")[[1]]
if (length(parts) == 2) {
if (parts[1] == "R_startup_wd") {
setwd(parts[2])
}
}
}
invisible(sapply(commandArgs(FALSE), processArg))
})
It checks if R was called with an argument R_startup_wd=your_working_dir and changes the working directory if yes.
You can then call R like
"C:\Program Files\R\R-3.4.3\bin\x64\Rgui.exe" "R_startup_wd=your_working_dir"
Note that the argument name is given without "--", i.e. we have R_startup_wd and not --R_startup_wd. Otherwise RGui will complain about "unknown arguments"
You can of course still use R without the argument given.

R script from command line

I wanted to run this example script: http://mazamascience.com/WorkingWithData/?p=912 from Windows command line. So I opened the command line and typed Rscript tryCatch.R 1. However, I keep getting the error message Error: R not found. I did set the PATH environment variable as C:\Programme\R\R-3.0.1\bin. If I just type R.exe, it does start R, but it cannot find the packages that are to be loaded at start (e.g. package 'utils' in options<"defaultPackages"> was not found). I guess I have to set another path to the libraries somewhere, but I haven't got any idea where to do this.
UPDATE: After explicitly typing PATH C:\Programme\R\R-3.0.1\bin (rather than just adding this to the value of the environment variable PATH) it seems that R is found. However, a new problem occurs: In normalizePath<path.expand(path), winslash, mustWork>: path[2] = "C:/Programme/R/R-3.0.1/library": Access denied, the same than for the methods library. Then: Calls: .First ... library -> .getRequiredPackages2 -> library -> normalizePath Execution stopped. I'm using Windows 7 and I do have administrator rights.
Rscript is very handy (R CMD BATCH is the old way to ) specially under windows, But generally under I create a batch file to avoid all path's headache.
For example say launcher.bat:
#echo off
C:
PATH C:\Programme\R\R-3.0.1\bin;%path%
cd PATH_TO_YOUR_RSCRIPT
Rscript tryCatch.R 1
pause
And open a console(using cmd) , go where you have stored your launcher.bat and launch it. Or from the R cosnole using shell:
shell('path_to_launcher\launcher.bat')
I've found out that it was a language-specific problem on Windows 7, similar to what is described here: https://stat.ethz.ch/pipermail/r-help/2011-May/276932.html
After changing PATH to C:\Program Files\R\R-3.0.1\bin the script is properly executed from the command prompt.
Thanks to everyone who tried to help!
I ran into this problem under windows 7, apparently, when setting environment variables>user variables the path is not added into the PATH, so the user must add this path in system variables > PATH
at the end just add the path to your .EXE files and voila.

Cygwin: Unable to find Java path.

I am using cygwin on windows 7 env and it is unable to locate java, error message i get is that
ERROR: /cygdrive/c/Program
Files/Java/jdk1.6.0_22 does not exist!
wired path is if I do echo $JAVA_HOME then it shows me
$ echo $JAVA_HOME
/cygdrive/c/Program Files/Java/jdk1.6.0_22
not sure what is happening here, any suggestions?
The problem is that the pathname contains spaces. You need to escape the spaces as described here:
http://www.cygwin.com/faq/faq.using.html#faq.using.filename-spaces
Adding this line to your .bashrc should do it:
export JAVA_HOME='/cygdrive/c/Program Files/Java/jdk1.6.0_22'
Edit: You could try running this script which I found in this blog post:
case "`uname`" in
CYGWIN*) cygwin=true ;;
esac
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
CLASSPATH=`cygpath --windows --path "$CLASSPATH"`
fi
Use the old school way:
export JAVA_HOME=/cygdrive/c/Progra~1/Java/jdk1.6.0_22
It worked for me.

Resources