summaryrefslogtreecommitdiff
path: root/pgplot-for-ifeffit/PGPLOT_install
blob: fe31a8c433fecda52df7f4a4b515ac27c9780e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/bin/sh
#
#  This file will attempt to download the PGPLOT library
#  and then build it for a linux system.
#
#  syntax:    PGPLOT_install --system=system_os --prefix=PREFIX
#
#  where system_os is linux, irix, sun4, etc
#
#  This may need customization for some systems
#
#  verified on: linux
#
prefix='/usr/local/'
system='linux'
dir=`pwd`
logfile=$dir/PGPLOT_install.log
wget=/usr/bin/wget
ncftp=/usr/bin/ncftp
ftp=/usr/bin/ftp

# set pgplot file locales
#
pgp_ftpsite='ftp.astro.caltech.edu'
pgp_ftpdir='pub/pgplot/'
pgp_file='pgplot5.2.tar.gz'

#
# default is to build without gif and with png support
#
with_gif=0
with_png=1
do_clean=1
do_log=1
use_64=0
fcompl=
fflagc='-Wall -O -fPIC'
cflagd='-Wall -O -fPIC'
# get command line options
for opt
do
  option=''
  case "$opt" in
    -*=*) 
         optarg=`echo "$opt" | sed 's/[-_a-zA-Z0-9]*=//'` 
         option=`echo "$opt" | sed 's/=.*//' | sed 's/-*//'`  
         ;;
    *) 
         option=`echo "$opt" | sed 's/^-*//'` 
         optarg= 
         ;;
  esac
  case "$option" in
    prefix)    prefix=$optarg ;;
    system)    system=$optarg ;;
    with-64bit)    use_64=1 ;;
    no-clean)  do_clean=0 ;;
    no-log)    do_log=0 ;;
    with-fortran)    fcompl=$optarg ;;
    with-fflagc)     fflagc=$optarg ;;
    with-png)  with_png=1 ;;
    with-gif)  with_gif=1 ;;
    no-png)    with_png=0 ;;
    no-gif)    with_gif=0 ;;
    -help | --help | help) cat<<EOF
Usage: PGPLOT_install [options] 
Options: 
  --prefix=PREFIX   base directory for installation [$prefix]
  --system=SYSTEM   operating system type for PGPLOT drivers [$system]
                    typical values would be   linux irix sun4 

  --with-png  / --no-png   add/remove PNG driver
  --with-gif  / --no-gif   add/remove GIF driver

  --with-64bit      use for 64bit linux machines (links to X libs in /usr/X11R6/lib64)

  --with-fortran    explicitly set fortran compiler executable
  --with-fflagc     explicitly set fortran compilation flags

  --no-log          do NOT generate PGPLOT_install.log
  --no-clean        do not remove any files created during build

EOF
    exit 0
    ;;

   *) 
       echo " unknown option "  $opt
       exit 1
        ;; 
  esac
done




echo " = = = = = = = = = = = = = = = = = = = = = = = = = = "
echo " = PGPLOT installation script"
echo " ="
#
# place to put pgplot  and the final libraries
#
pgp_dir=$prefix/share/ifeffit/pgplot/

pgp_sys=$system

if test $system = linux ;  then 
    pgp_sys="linux g77_gcc"
fi 

if test $system = sol2 ;  then 
    pgp_sys="sol2 f90_cc"
fi

echo " system = " $system " == "  $pgp_sys
echo " prefix = " $prefix


if test $do_log = 1 ;  then 
  echo "#!/bin/sh " >  $logfile
  echo "# PGPLOT install log " >>  $logfile
  echo "# system = " $system " == "  $pgp_sys >> $logfile
  echo "# prefix = " $prefix    >> $logfile
fi

#
#-----------------------------------------
##
## try wget, ncftp, and then ftp to get file

echo " = Looking for PGPLOT file: $pgp_file"
if [ -f $pgp_file ] ; then
   x=1
else
  echo " = PGPLOT file not found "
  echo " = I'll try to download it for you..."
  if [ -f $wget  ] ; then
     echo " trying with wget"
     tmp="ftp://$pgp_ftpsite/$pgp_ftpdir$pgp_file"
     echo "getting $tmp"
     wget --tries=2 $tmp 
  fi
fi

if [ -f $pgp_file ]; then 
    x=1
else
  if [ -f $ncftp ] ; then
     echo " trying with ncftp"
     $ncftp $pgp_ftpsite<<EOF
     set confirm-exit  no
     set confirm-close no
     cd  $pgp_ftpdir
     get $pgp_file
     exit
EOF
  fi
fi
if [ -f $pgp_file ]; then
   x=1
else
   if [ -f $ftp ] ; then
     echo "  trying with regular old ftp "
     echo "  you may have to hit return here for this to work --  "
     echo "  Really, you won't need to enter 'anonymous' or a valid"
     echo "  username --- just hit return"
     $ftp $pgp_ftpsite<<EOF
anonymous
ifeffit@cars.uchicago.edu
cd  $pgp_ftpdir
hash
get $pgp_file
exit
EOF
   fi
fi

##
## if we still don't have the file, croak
if [ -f $pgp_file ]; then
   echo " = I see the PGPLOT tar file.  Good."
else
   echo " = Sorry, I couldn't download the PGPLOT tar file."
   echo " = You'll have to download it yourself. Try this: "
   echo " =   ftp $pgp_ftpsite"
   echo " =   cd  $pgp_ftpdir"
   echo " =   get $pgp_file"
   echo " = then run this script again"    
 
   if test $do_log = 1 ;  then 
      echo "# pgplot tar file not found! " >>  $logfile
   fi
   exit 1
fi


##
echo " = Preparing PGPLOT Installation: "
echo " = Looking for X libraries "
x11_loc=''
if [ -d /usr/X11 ] ; then
     echo " =   X libraries found at /usr/X11 "
     x11_loc='/usr/X11'
else
  if [ -d /usr/X11R6 ] ; then
     echo " =   X libraries found at /usr/X11R6 "
     x11_loc='/usr/X11R6'
  else
     echo " =   X libraries not found: could be serious! = "
  fi
fi

##
echo " = Looking for fortran compiler "

if test x$fcompl = 'x' ; then
    f77 -v > /dev/null 2>&1
    if [ $? = 0 ] ; then  fcompl='g77' ; fi

    g95 -v > /dev/null 2>&1
    if [ $? = 0 ] ; then  fcompl='g95' ; fi
    
    g77 -v > /dev/null 2>&1
    if [ $? = 0 ] ; then  fcompl='g77' ; fi
    
    gfortran -v > /dev/null 2>&1
    if [ $? = 0 ] ; then  fcompl='gfortran'; fi
   
fi

echo "        fortran compiler = " $fcompl
if test $do_log = 1 ;  then 
     echo "# fortran compiler = " $fcompl >>  $logfile
fi

if test x$fcompl = 'x' ; then
   echo ' No fortran compiler found -- cannot install PGPLOT!'
   exit 1
fi


## unpack kit

echo " = Unpacking PGPLOT: "

gzip -dc  $pgp_file | tar xf - 
if test $do_log = 1 ;  then 
    echo "gzip -dc  $pgp_file | tar xf -" >> $logfile
fi

cd pgplot
patch -p0 -i ../pndriv.c.patch
cd ..
#
# copy Fortran90 gidriv.f for modern fortrans -- yick!
if [ x$fcompl != 'xg77' ] ; then 
   echo 'copying fortran90 gif driver to PGPLOT'
   # cp -fp pgplot_extras/gidriv.f pgplot/drivers/gidriv.f
   # fflagc='-ffixed-form -ffixed-line-length-none -u -fPIC -O -fcray-pointer'
fi

echo " = Creating $pgp_dir and drivers.list "
mkdir -p $pgp_dir
if test $do_log = 1 ;  then 
    echo "mkdir -p $pgp_dir" >> $logfile
fi

##
## create drivers.list

echo '! PGPLOT drivers created by PGPLOT_install for ifeffit: ' > $pgp_dir/drivers.list
if test $with_gif = 1 ; then
  echo ' GIDRIV 1 /GIF      '>>$pgp_dir/drivers.list
  echo ' GIDRIV 2 /VGIF     '>>$pgp_dir/drivers.list
fi
if test $with_png = 1 ; then
  echo ' PNDRIV 1 /PNG      '>>$pgp_dir/drivers.list
  echo ' PNDRIV 2 /TPNG     '>>$pgp_dir/drivers.list
fi

echo ' NUDRIV 0 /NULL     '>>$pgp_dir/drivers.list
echo ' PSDRIV 1 /PS       '>>$pgp_dir/drivers.list
echo ' PSDRIV 2 /VPS      '>>$pgp_dir/drivers.list
echo ' PSDRIV 3 /CPS      '>>$pgp_dir/drivers.list
echo ' PSDRIV 4 /VCPS     '>>$pgp_dir/drivers.list
echo ' XWDRIV 1 /XWINDOW  '>>$pgp_dir/drivers.list
echo ' XWDRIV 2 /XSERVE   '>>$pgp_dir/drivers.list

if test $do_log = 1 ;  then 
   echo "# driver.list written to  " $pgp_dir/drivers.list  >>  $logfile
   echo "# starting build"  >>  $logfile
   echo " "  >>  $logfile
fi

echo  " = Running the PGPGLOT makemake script "
cd $pgp_dir/
rm -f grfont.dat pgplot.doc pgxwin_server lib*pgplot* pgdemo* *.o
$dir/pgplot/makemake $dir/pgplot $pgp_sys



if test $do_log = 1 ;  then 
   echo "cd  $pgp_dir/"  >>  $logfile
   echo 'rm -f grfont.dat pgplot.doc pgxwin_server lib*pgplot* pgdemo* '>> $logfile
   echo $dir/pgplot/makemake $dir/pgplot $pgp_sys   >>  $logfile
fi

# hack grgfil to use $pgp_dir as default location 
sed 's|/usr/local/pgplot/|'$pgp_dir'|g' $dir/pgplot/src/grgfil.f >  $dir/pgplot/src/grgfil_iff.f
mv makefile Tmp
sed 's|grgfil|grgfil_iff|g' Tmp > makefile

sed 's|libpgplot|libpgplot_iff|g' makefile > Tmp
sed 's|-lpgplot|-lpgplot_iff|g'   Tmp > makefile

echo 'customized grgfil.f for ifeffit'
if test $do_log = 1 ;  then 
    echo "# customizing grgil.f for ifeffit " >> $logfile
    echo "sed 's|/usr/local/pgplot/|$pgp_dir|g' $dir/pgplot/src/grgfil.f >  $dir/pgplot/src/grgfil_iff.f" >> $logfile
    echo "mv makefile Tmp"     >>  $logfile
    echo "sed 's|grgfil|grgfil_iff|g' Tmp > makefile" >>  $logfile
    echo "sed 's|libpgplot|libpgplot_iff|g' makefile > Tmp"  >>  $logfile
    echo "sed 's|-lpgplot|-lpgplot_iff|g'   Tmp > makefile"  >>  $logfile
fi


# hack xwdriv.c to use $pgp_dir a
sed 's|getenv("PGPLOT_DIR")|'\"$pgp_dir\"'|g' $dir/pgplot/drivers/xwdriv.c >  $dir/pgplot/drivers/xwdriv_iff.c
mv makefile Tmp
sed 's|xwdriv|xwdriv_iff|g' Tmp > makefile

echo 'customized xwdriv.c for ifeffit'
if test $do_log = 1 ;  then 
    echo "# customizing xwdriv.c for ifeffit " >> $logfile
    echo " sed 's|getenv(\"PGPLOT_DIR\")|'\"$pgp_dir\"'|g' $dir/pgplot/drivers/xwdriv.c >  $dir/pgplot/drivers/xwdriv_iff.c" >> $logfile
    echo "mv makefile Tmp" >> $logfile
    echo "sed 's|xwdriv|xwdriv_iff|g' Tmp > makefile" >> $logfile
fi

# for 64-bit systems
if test  $use_64 = 1; then
  sed 's|/usr/X11R6/lib|/usr/X11R6/lib64|g' makefile > Tmp
  sed 's|/usr/X11/lib|/usr/X11/lib64|g'     Tmp > makefile
  if test $do_log = 1 ;  then 
     echo "# 64-bit  " >> $logfile
     echo " sed 's|/usr/X11R6/lib|/usr/X11R6/lib64|g' makefile > Tmp " >> $logfile
     echo " sed 's|/usr/X11/lib|/usr/X11/lib64|g'     Tmp > makefile  " >> $logfile
  fi
fi


if test $with_png = 1 ; then
  mv makefile Tmp
  sed 's|pndriv.o : ./png.h|#### pndriv.o : ./png.h|g' Tmp > makefile

 if test $do_log = 1 ;  then 
    echo "# fix png driver"  >>  $logfile
    echo "mv makefile Tmp " >> $logfile
    echo "sed 's|pndriv.o : ./png.h|#### pndriv.o : ./png.h|g' Tmp > makefile "  >>  $logfile
 fi
fi

sed "s|^FCOMPL=.*|FCOMPL=$fcompl|g" makefile | sed "s|^FFLAGC=.*|FFLAGC=$fflagc|g" | sed "s|^CFLAGD=.*|CFLAGD=$cflagd|g" > Tmp
mv Tmp makefile


echo  " = Running make for PGPLOT "

make libpgplot_iff.a  grfont.dat prog pgxwin_server cpg

 if test $do_log = 1 ;  then 
    echo "make libpgplot_iff.a  grfont.dat prog pgxwin_server cpg " >> $logfile
 fi

if test $do_clean = 1 ; then
  echo " = Cleaning up and preparing for test"
  make clean
  if test $do_log = 1 ;  then 
     echo "make clean  " >> $logfile
  fi
fi

cd  $dir
ls  $pgp_dir/ > Tmp_file.lis

echo " = = = = = = = = = = = = = = = = = = = = = = = = = = "
if ((grep "pgxwin_server"  Tmp_file.lis >/dev/null)  && 
    (grep "rgb.txt"        Tmp_file.lis >/dev/null)  &&
    (grep "libpgplot_iff.a" Tmp_file.lis >/dev/null)  &&
    (grep "pgdemo1"        Tmp_file.lis >/dev/null)  &&
    (grep "grfont.dat"     Tmp_file.lis >/dev/null)) ; then
 if test $do_clean = 1 ; then
   rm -rf pgplot/
 fi
 echo " = PGPLOT appears to be correctly installed!"
 echo " ="
 echo " = Please read README.PGPLOT for more on setting up " 
 echo " = PGPLOT for your system and try running the demo"
 echo " = programs in  $pgp_dir "

else
 echo " = Uh-oh.  PGPLOT is missing some important files!"
 echo " = It looks like PGPLOT failed during building or"
 echo " = is only partially installed."
 echo " = "
 echo " = Please consult the PGPLOT installation instructions"
 echo " = in the subdirectory  pgplot/, and the log file:"
 echo " =    $logfile"
 echo " = which contains a full list of commands run."
 echo " ="
 echo " = You may want to repeat these steps by hand or "
 echo " = consult the PGPLOT installations instructions "
 echo " = in install-unix.txt"
fi

if test $do_clean = 1 ; then
 rm -f Tmp_file.lis
fi


echo " = = = = = = = = = = = = = = = = = = = = = = = = = = "
echo " "

# done