source: trunk/src/project_profile.sh

Last change on this file was 204, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 9.4 KB
Line 
1#! /bin/sh
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 -idl_cmd idl_cmd
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# PATH is completed with ${PROJECT}/src/.
48#
49# ${SAXO_DIR} is the base directory of SAXO tools
50#
51# IDL_STARTUP is set to tell IDL where find tools.
52#
53# If :option:`idl_cmd` is used, **idl_cmd** will be used as the IDL command
54# when launched from scripts.
55# By default, ${IDL_CMD} is set to `idl`.
56#
57# FER_GO is completed with ${PROJECT}/src/ and ${PROJECT}/src/test/.
58#
59# SEE ALSO
60# ========
61#
62# for IDL/gdl and SAXO environment :
63#
64# :ref:`project_init.pro`
65# :ref:`cm_project.pro`
66#
67# EXAMPLES
68# ========
69#
70# For fplod, on halios.locean-ipsl.upmc.fr using gdl (to be tested):
71#
72# .. code-block:: bash
73#
74#    cd /usr/home/fplod/incas/tropflux/tropflux_ws/
75#    . ./src/project_profile.sh \
76#    -d $(pwd)/ \
77#    -i /usr/temp/${LOGNAME}/tropflux_d/ \
78#    -o /usr/temp/${LOGNAME}/tropflux_d/ \
79#    -t /usr/temp/${LOGNAME}/log/ \
80#    -s /usr/home/fplod/SAXO_DIR/ \
81#    -idl_cmd gdl
82#
83# For fplod on cratos.locean-ipsl.umpc.fr using idl 7.0:
84#
85# .. code-block:: bash
86#
87#    cd ${HOME}/incas/tropflux/tropflux_ws/
88#    . ./src/project_profile.sh \
89#    -d $(pwd)/ \
90#    -i /usr/temp/${LOGNAME}/tropflux_d/ \
91#    -o /usr/temp/${LOGNAME}/tropflux_d/ \
92#    -t /usr/temp/${LOGNAME}/log/ \
93#    -s ${HOME}/SAXO_DIR/ \
94#    -idl_cmd idl70
95#
96# For pinsard on camelot.ipsl.polytechnique.fr or merlin15-c.climserv to use
97# idl6.4:
98#
99# .. code-block:: bash
100#
101#    cd ${HOME}/tropflux/
102#    . ./src/project_profile.sh \
103#   -d $(pwd)/ \
104#   -i /homedata/${LOGNAME}/tropflux_d/ \
105#   -o /homedata/${LOGNAME}/tropflux_d/ \
106#   -t /homedata/${LOGNAME}/log/ \
107#   -s ${HOME}/SAXO_DIR/ \
108#   -idl_cmd /opt/idl-6.4/idl/bin/idl
109#
110# TODO
111# ====
112#
113# ++ option bavarde
114#
115# ++ machine dependant
116#
117# ++ besoin de posix
118#
119# ++ pas de MANPATH defini par défaut sur zeus et cerbere
120#
121# EVOLUTIONS
122# ==========
123#
124# $Id$
125#
126# $URL$
127#
128# - fplod 20120305
129#
130#   * add idl_cmd option
131#   * improve with set -u
132#   * idl version by defaut on cratos is 6.2 !
133#   * short title
134#
135# - fplod 20111104T130726Z cratos (Linux)
136#
137#   * add ${PROJECT}/src/test to FER_GO
138#
139# - fplod 20111010T072623Z aedon.locean-ipsl.upmc.fr (Darwin)
140#
141#   * FER_GO might be undefined
142#
143# - fplod 20110502T155437Z aedon.locean-ipsl.upmc.fr (Darwin)
144#
145#   * complete FER_GO
146#
147# - fplod 20110429T090524Z aedon.locean-ipsl.upmc.fr (Darwin)
148#
149#   * set IDL_STARTUP
150#
151# - fplod 20110413T151541Z cratos.locean-ipsl.upmc.fr (Linux)
152#
153#   * fix uncompleted replacement SAXO_SRC by SAXO_DIR
154#
155# - fplod 20101118T171653Z aedon.locean-ipsl.upmc.fr (Darwin)
156#
157#   * creation
158#
159#-
160system=$(uname)
161case "${system}" in
162    AIX|IRIX64)
163        echo " www : no specific posix checking"
164    ;;
165    *)
166        set -o posix
167    ;;
168esac
169unset system
170#
171set -u
172#
173LANG=C
174#
175# as this script might be launch in .profile, command is forced.
176command=project_profile.sh
177#
178usage=" Usage : ${command} -d directory -i indir -o outdir -t tempdir -s saxo_dir -idl_cmd idl_cmd"
179#
180# default
181idl_cmd=idl
182pb=0
183#
184minargcount=12
185maxargcount=12
186narg=${#}
187#
188if [ ${narg} -lt ${minargcount} ]
189then
190    echo "eee : not enough arguments (${narg} vs ${minargcount})"
191    echo "${usage}"
192    # nb : no exit because this file should be launched by login process
193    pb=1
194fi
195unset minargcount
196#
197if [ ${narg} -gt ${maxargcount} ]
198then
199    echo "eee : too many arguments (${narg} vs ${maxargcount})"
200    echo "${usage}"
201    # nb : no exit because this file should be launched by login process
202    pb=1
203fi
204unset maxargcount
205unset narg
206#
207if [ ${pb} -eq 0 ]
208then
209    while [ ${#} -gt 0 ]
210    do
211        case ${1} in
212            -d)
213                # directory for application chosen by user (see svn checkout command used)
214                directory=${2}
215                shift
216            ;;
217            -i)
218                # directory for inputs chosen by user
219                indir=${2}
220                shift
221            ;;
222            -o)
223                # directory for outputs chosen by user
224                outdir=${2}
225                shift
226            ;;
227            -t)
228                # directory for temporary outputs chosen by user
229                tempdir=${2}
230                shift
231            ;;
232            -s)
233                # directory for SAXO tools
234                saxo_dir=${2}
235                shift
236            ;;
237            -idl_cmd)
238                # command for idl
239                idl_cmd=${2}
240                shift
241            ;;
242            *)
243                # other choice
244                echo "eee : unknown option ${1}"
245                echo "${usage}"
246                # nb : no exit because this file should be launched by login process
247            ;;
248        esac
249        # next flag
250        shift
251    done
252    unset usage
253fi
254#
255if [ ${pb} -eq 0 ]
256then
257    # check for ${directory}
258    if [ ! -d ${directory} ]
259    then
260        echo " eee : ${directory} not found"
261        # nb : no exit because this file should be launched by login process
262    fi
263    #
264    # check for permission on directory
265    if [ ! -x ${directory} ]
266    then
267        echo " eee : ${directory} not reachable"
268        # nb : no exit because this file should be launched by login process
269    fi
270    #
271    PROJECT=${directory}
272    export PROJECT
273    unset directory
274    #
275    # add PROJECT tools to PATH
276    # if not already done
277    suppath=$(echo ${PROJECT}/src | tr -s "/")
278    echo ${PATH} | grep -q "${suppath}:"
279    test_path=${?}
280    if [ ${test_path} -ne 0 ]
281    then
282        PATH=${suppath}:${PATH}
283        export PATH
284    else
285        # option bavarde oui/non pas encore implantée ++
286        echo "${command} : iii : ${suppath} already in \${PATH}"
287    fi
288    unset test_path
289    #
290    # add PROJECT manuals to MANPATH
291    # if not already done
292    suppath=$(echo ${PROJECT}/doc/man | tr -s "/")
293    echo ${MANPATH} | grep -q "${suppath}:"
294    test_manpath=${?}
295    if [ ${test_manpath} -ne 0 ]
296    then
297        MANPATH=${suppath}:${MANPATH}
298        export MANPATH
299    else
300        # option bavarde oui/non pas encore implantée ++
301        echo "${command} : iii : ${suppath} already in \${MANPATH}"
302    fi
303    unset test_manpath
304    unset suppath
305    #
306    PROJECT_LOG=${tempdir}
307    export PROJECT_LOG
308    unset tempdir
309    if [ ! -d ${PROJECT_LOG} ]
310    then
311        mkdir -p ${PROJECT_LOG}
312        status=${?}
313        if [ ${status} -ne 0 ]
314        then
315            echo "${command} : eee : can not create \${PROJECT_LOG}"
316            # nb : no exit because this file should be launched by login process
317        else
318            echo "${command} : iii : creation of \${PROJECT_LOG}"
319        fi
320        unset status
321    fi
322    # check for permission on PROJECT_LOG
323    if [ ! -x ${PROJECT_LOG} ]
324    then
325        echo " eee : ${PROJECT_LOG} not reachable"
326        # nb : no exit because this file should be launched by login process
327    fi
328    #
329    # check for permission on PROJECT_LOG
330    if [ ! -w ${PROJECT_LOG} ]
331    then
332        echo " eee : ${PROJECT_LOG} not writable"
333        # nb : no exit because this file shouldreachable be launched by login process
334    fi
335    #
336    EDITOR=vi
337    export EDITOR
338    #
339    # io directories
340    PROJECT_ID=${indir}
341    export PROJECT_ID
342    unset indir
343    if [ ! -d ${PROJECT_ID} ]
344    then
345        mkdir -p ${PROJECT_ID}
346        echo "${command} : iii : creation of \${PROJECT_ID}"
347    fi
348    # check for permission on PROJECT_ID
349    if [ ! -x ${PROJECT_ID} ]
350    then
351        echo " eee : ${PROJECT_ID} not reachable"
352        # nb : no exit because this file should be launched by login process
353    fi
354    #
355    PROJECT_OD=${outdir}
356    export PROJECT_OD
357    unset outdir
358    if [ ! -d ${PROJECT_OD} ]
359    then
360        mkdir -p ${PROJECT_OD}
361        echo "${command} : iii : creation of \${PROJECT_OD}"
362    fi
363    # check for permission on PROJECT_OD
364    if [ ! -x ${PROJECT_OD} ]
365    then
366        echo " eee : ${PROJECT_OD} not reachable"
367        # nb : no exit because this file should be launched by login process
368    fi
369    if [ ! -w ${PROJECT_OD} ]
370    then
371        echo " eee : ${PROJECT_OD} not writable"
372        # nb : no exit because this file should be launched by login process
373    fi
374    #
375    # setup for ferret
376    set +u
377    if [ "${FER_GO}" = "" ]
378    then
379        FER_GO="${FER_DIR}/go ${FER_GO} ${PROJECT}/src"
380    else
381        FER_GO="${FER_DIR}/go ${PROJECT}/src"
382    fi
383    set -u
384    FER_GO="${FER_GO} ${PROJECT}/src/test"
385    export FER_GO
386    #
387    # set up for idl
388    IDL_CMD=${idl_cmd}
389    export IDL_CMD
390    unset idl_cmd
391    #
392    SAXO_DIR=${saxo_dir}
393    export SAXO_DIR
394    unset saxo_dir
395    #
396    # IDL startup
397    IDL_STARTUP=${PROJECT}/src/project_init.pro
398    export IDL_STARTUP
399fi
400unset pb
401# end
402unset command
403# nb : no exit because this file should be launched by login process
Note: See TracBrowser for help on using the repository browser.