source: trunk/src/project_profile.sh @ 56

Last change on this file since 56 was 12, checked in by pinsard, 10 years ago

fix because PYTHONPATH not always defined

  • Property svn:executable set to *
File size: 9.3 KB
Line 
1#! /bin/sh -x
2#+
3#
4# .. program:: project_profile.sh
5#
6# .. _project_profile.sh:
7#
8# ==================
9# project_profile.sh
10# ==================
11#
12# SYNOPSIS
13# ========
14#
15# Online usage:
16#
17# .. code-block:: bash
18#
19#    . ./project_profile.sh -d directory -i indir -o outdir -t tempdir -s saxo_dir -idl_cmd idl_cmd
20#
21# In ${HOME}/.profile, add the following line:
22#
23# .. code-block:: bash
24#
25#    . project_profile.sh -d directory  -i indir -o outdir -t tempdir -s saxo_dir
26#
27# DESCRIPTION
28# ===========
29#
30# .. option:: -d  <directory>
31# .. option:: -i  <indir>
32# .. option:: -o  <outdir>
33# .. option:: -t  <tempdir>
34# .. option:: -s  <saxo_dir>
35# .. option:: -idl_cmd  <idl_cmd>
36#
37# define PROJECT environment
38#
39# ${PROJECT} is the base directory of tools.
40#
41# ${PROJECT_LOG} is the directory where log files will be written.
42#
43# ${PROJECT_ID} is the directory where input files must be.
44#
45# ${PROJECT_OD} is the directory where output files will be written.
46#
47# ${SAXO_DIR} is the base directory of SAXO tools
48#
49# PATH is completed with ${PROJECT}/src/ and ${PROJECT}/adm/.
50#
51# PYTHONPATH is completed with ${PROJECT}/src/.
52#
53# FER_GO is completed with ${PROJECT}/src/.
54#
55# IDL_STARTUP is set to tell IDL where find tools.
56#
57# If :option:`-idl_cmd` is used, **idl_cmd** will be used as the IDL command
58# when launched from scripts. By default, ${IDL_CMD} is set to `idl`.
59#
60# MATLABPATH is initialize to tell matlab where find tools.
61#
62# SEE ALSO
63# ========
64#
65# for matlab/octave environment :
66#
67# :ref:`project_startup.m`
68#
69# for IDL/gdl and SAXO environment :
70#
71# :ref:`project_init.pro`
72# :ref:`cm_project.pro`
73#
74# EXAMPLES
75# ========
76#
77# For fplod, on halios.locean-ipsl.upmc.fr with gdl:
78#
79# .. code-block:: bash
80#
81#    cd /usr/home/fplod/incas/project/project_ws/
82#    . ./src/project_profile.sh \
83#    -d $(pwd) \
84#    -i /usr/temp/${LOGNAME}/project_d/ \
85#    -o /usr/temp/${LOGNAME}/project_d/ \
86#    -t /usr/temp/${LOGNAME}/log/ \
87#    -s /usr/home/fplod/SAXO_DIR/ \
88#    -idl_cmd gdl
89#
90# For fplod on cratos.locean-ipsl.umpc.fr with default IDL version:
91#
92# .. code-block:: bash
93#
94#    cd ${HOME}/incas/project/project_ws/
95#    . ./src/project_profile.sh \
96#    -d $(pwd) \
97#    -i /usr/temp/${LOGNAME}/project_d/ \
98#    -o /usr/temp/${LOGNAME}/project_d/ \
99#    -t /usr/temp/${LOGNAME}/log/ \
100#    -s ${HOME}/SAXO_DIR/
101#
102# For fplod on cratos.locean-ipsl.umpc.fr with IDL version 6.4:
103#
104# .. code-block:: bash
105#
106#    cd ${HOME}/incas/project/project_ws/
107#    . ./src/project_profile.sh \
108#    -d $(pwd) \
109#    -i /usr/temp/${LOGNAME}/project_d/ \
110#    -o /usr/temp/${LOGNAME}/project_d/ \
111#    -t /usr/temp/${LOGNAME}/log/ \
112#    -s ${HOME}/SAXO_DIR/ \
113#    -idl_cmd  /usr/local_linux/idl/idl_6.4/idl64/bin/idl
114#
115# For pinsard on camelot.ipsl.polytechnique.fr or merlin15-c.climserv:
116#
117# .. code-block:: bash
118#
119#    cd ${HOME}/project/
120#    . ./src/project_profile.sh \
121#    -d $(pwd) \
122#    -i /homedata/${LOGNAME}/project_d/ \
123#    -o /homedata/${LOGNAME}/project_d/ \
124#    -t /homedata/${LOGNAME}/log/ \
125#    -s ${HOME}/SAXO_DIR/
126#
127# For pinsard on loholt1 to use idl 6-4:
128#
129# .. code-block:: bash
130#
131#    cd ${HOME}/project/
132#    . ./src/project_profile.sh \
133#    -d $(pwd) \
134#    -i /homedata/${LOGNAME}/project_d/ \
135#    -o /homedata/${LOGNAME}/project_d/ \
136#    -t /homedata/${LOGNAME}/log/ \
137#    -s ${HOME}/SAXO_DIR/ \
138#    -idl_cmd /opt/idl-6.4/idl/bin/idl
139#
140# .. todo::
141#
142# ++ option bavarde
143#
144# ++ machine dependant
145#
146# ++ besoin de posix
147#
148# usage of PROJECT* instead of PROJECT* everywhere
149#
150# EVOLUTIONS
151# ==========
152#
153# $Id: project_profile.sh 532 2012-04-18 12:44:46Z pinsard $
154#
155# - fplod 20140516T091310Z callisto.locean-ipsl.upmc.fr (Linux)
156#
157#   * fix because PYTHONPATH not always defined
158#
159# - fplod 20140513T101841Z callisto.locean-ipsl.upmc.fr (Linux)
160#
161#   * add PYTHONPATH
162#
163# - fplod 20120424
164#
165#   * creation
166#
167#-
168system=$(uname)
169case "${system}" in
170    AIX|IRIX64)
171        echo " www : no specific posix checking"
172    ;;
173    *)
174        set -o posix
175    ;;
176esac
177unset system
178#
179set -u
180#
181LANG=C
182#
183# as this script might be launch in .profile, command is forced.
184command=project_profile.sh
185#
186usage="Usage : ${command} -d directory -i indir -o outdir -t tempdir -s saxo_dir [-idl_cmd idl_cmd]"
187#
188# default
189idl_cmd=idl
190#
191while [ ${#} -gt 0 ]
192do
193    case ${1} in
194        -d)
195            # directory for application choosen by user (see svn checkout command used)
196            directory=${2}
197            shift
198        ;;
199        -i)
200            # directory for inputs choosen by user
201            indir=${2}
202            shift
203        ;;
204        -o)
205            # directory for outputs choosen by user
206            outdir=${2}
207            shift
208        ;;
209        -t)
210            # directory for temporary outputs choosen by user
211            tempdir=${2}
212            shift
213        ;;
214        -s)
215            # directory for SAXO tools
216            saxo_dir=${2}
217            shift
218        ;;
219        -idl_cmd)
220            # command for idl
221            idl_cmd=${2}
222            shift
223        ;;
224        *)
225            # other choice
226            echo "eee : unknown option ${1}"
227            echo "${usage}"
228            # nb : no exit because this file should be launched by
229            # login process
230        ;;
231    esac
232    # next flag
233    shift
234done
235unset usage
236#
237# check for ${directory}
238if [ ! -d ${directory} ]
239then
240    echo " eee : ${directory} not found"
241    # nb : no exit because this file should be launched by login process
242fi
243#
244# check for permission on directory
245if [ ! -x ${directory} ]
246then
247    echo " eee : ${directory} not reachable"
248    # nb : no exit because this file should be launched by login process
249fi
250#
251PROJECT=${directory}
252export PROJECT
253unset drectory
254#
255# add PROJECT tools to PATH
256# if not already done
257suppath=$(echo ${PROJECT}/src | tr -s "/")
258echo ${PATH} | grep -q "${suppath}:"
259test_path=${?}
260if [ ${test_path} -ne 0 ]
261then
262    PATH=${suppath}:${PATH}
263    export PATH
264else
265    # option bavarde oui/non pas encore implantée ++
266    echo "${command} : iii : ${suppath} already in \${PATH}"
267fi
268unset test_path
269suppath=$(echo ${PROJECT}/adm| tr -s "/")
270echo ${PATH} | grep -q "${suppath}:"
271test_path=${?}
272if [ ${test_path} -ne 0 ]
273then
274    PATH=${suppath}:${PATH}
275    export PATH
276else
277    # option bavarde oui/non pas encore implantée ++
278    echo "${command} : iii : ${suppath} already in \${PATH}"
279fi
280unset test_path
281#
282# add PROJECT manuals to MANPATH
283# if not already done
284suppath=$(echo ${PROJECT}/doc/man | tr -s "/")
285set +u
286echo ${MANPATH} | grep -q "${suppath}:"
287test_manpath=${?}
288if [ ${test_manpath} -ne 0 ]
289then
290    MANPATH=${suppath}:${MANPATH}
291    export MANPATH
292else
293    # option bavarde oui/non pas encore implantée ++
294    echo "${command} : iii : ${suppath} already in \${MANPATH}"
295fi
296set -u
297unset test_manpath
298unset suppath
299#
300# add PROJECT tools to PYTHONPATH
301# if not already done
302set +u
303suppath=$(echo ${PROJECT}/src | tr -s "/")
304echo ${PYTHONPATH} | grep -q "${suppath}:"
305test_path=${?}
306if [ ${test_path} -ne 0 ]
307then
308    PYTHONPATH=${suppath}:${PYTHONPATH}
309    export PYTHONPATH
310else
311    echo "${command} : iii : ${suppath} already in \${PYTHONPATH}"
312fi
313set -u
314unset test_path
315unset suppath
316#
317PROJECT_LOG=${tempdir}
318export PROJECT_LOG
319unset tempdir
320if [ ! -d ${PROJECT_LOG} ]
321then
322    mkdir -p ${PROJECT_LOG}
323    status=${?}
324    if [ ${status} -ne 0 ]
325    then
326        echo "${command} : eee : can not create \${PROJECT_LOG}"
327        # nb : no exit because this file should be launched by login process
328    else
329        echo "${command} : iii : creation of \${PROJECT_LOG}"
330    fi
331    unset status
332fi
333# check for permission on PROJECT_LOG
334if [ ! -x ${PROJECT_LOG} ]
335then
336    echo " eee : ${PROJECT_LOG} not reachable"
337    # nb : no exit because this file should be launched by login process
338fi
339#
340# check for permission on PROJECT_LOG
341if [ ! -w ${PROJECT_LOG} ]
342then
343    echo " eee : ${PROJECT_LOG} not writable"
344    # nb : no exit because this file shouldreachable be launched by
345    # login process
346fi
347#
348EDITOR=vi
349export EDITOR
350#
351# io directories
352PROJECT_ID=${indir}
353export PROJECT_ID
354unset indir
355if [ ! -d ${PROJECT_ID} ]
356then
357    mkdir -p ${PROJECT_ID}
358    echo "${command} : iii : creation of \${PROJECT_ID}"
359fi
360# check for permission on PROJECT_ID
361if [ ! -x ${PROJECT_ID} ]
362then
363    echo " eee : ${PROJECT_ID} not reachable"
364    # nb : no exit because this file should be launched by login process
365fi
366#
367PROJECT_OD=${outdir}
368export PROJECT_OD
369unset outdir
370if [ ! -d ${PROJECT_OD} ]
371then
372    mkdir -p ${PROJECT_OD}
373    echo "${command} : iii : creation of \${PROJECT_OD}"
374fi
375# check for permission on PROJECT_OD
376if [ ! -x ${PROJECT_OD} ]
377then
378    echo " eee : ${PROJECT_OD} not reachable"
379    # nb : no exit because this file should be launched by login process
380fi
381if [ ! -w ${PROJECT_OD} ]
382then
383    echo " eee : ${PROJECT_OD} not writable"
384    # nb : no exit because this file should be launched by login process
385fi
386#
387# setup for ferret
388set +u
389FER_GO="${FER_GO} ${PROJECT}/src"
390export FER_GO
391set -u
392#
393# setup for matlab
394MATLABPATH=${PROJECT}
395export MATLABPATH
396#
397# set up for idl
398IDL_CMD=${idl_cmd}
399export IDL_CMD
400unset idl_cmd
401#
402# SAXO environment
403SAXO_DIR=${saxo_dir}
404export SAXO_DIR
405unset saxo_dir
406#
407PROJECT_ID=${PROJECT_ID}
408export PROJECT_ID
409PROJECT_OD=${PROJECT_OD}
410export PROJECT_OD
411PROJECT_LOG=${PROJECT_LOG}
412export PROJECT_LOG
413#
414# IDL startup
415IDL_STARTUP=${PROJECT}/src/project_init.pro
416export IDL_STARTUP
417#
418# end
419unset command
420set +u
421# nb : no exit because this file should be launched by login process
Note: See TracBrowser for help on using the repository browser.