#! /bin/csh -f
#
# C shell program to run crylsq repeatedly, changing Atom xyz parameters
#  e.g.
#compid  AlNd
#cifio arcin
#end
#addatm mixed
#SCALE             .81345   1.00000     PARENT                                  
#UOV               .03500               PARENT                                  
#ATOM Al1    .50000  -.00288  -.00000 $1 1.000 .00331 .00183 .00304             
#ATOM Nd1    .49830   .25000   .50028 $1 1.000 .00029 .00020 .00036             
#UIJ  Nd1    .00258   .00014   .00741   .00061   .00019   .00007                
#SUIJ Nd1    .00028   .00024   .00031   .00020   .00022   .00021                
#ATOM Nd2   -.49884  -.25000  -.49973 $1 1.000 .00028 .00020 .00035             
#UIJ  Nd2    .00168   .00037   .00709   .00023   .00003   .00024                
#SUIJ Nd2    .00026   .00023   .00030   .00019   .00022   .00020                
#end
#CRYLSQ fu 0.5 fr CY 5 bd WS AD TL 0  an L1 p1 ml ax
#end
#finish
#
#    set the list for your structure.   0 indicates variable coord to shift
#    atom      1     2     3       4
#            x y z x y z x y z  x  y  x
#          ( 1 2 3 4 5 6 7 8 9 10 11 12) 
set list = ( 1 2 3 4 0 6 7 0 9  0  0  0 )  #Special position list
#
#
#
if ( $#argv < 1 ) then                     # no arguments so quit
    echo 'Usage:   '$0' delta filename '
    exit
endif
#
#
set  filename = $argv[2]                   # filename (.bak) for xtal
@  delta = $argv[1]                        # shifts to be applied
@ minimum = 1000                           # minimum R-factor
echo '*****Beginning Run*******' > "$filename.cycles"
cp $filename.bak $filename.1               # first level of recursive edit
#
shiftit2 $#list $list $delta 1 $filename   # call main program
#
echo ' '
echo '********End of Run*******' >> "$filename.cycles"
echo 'minimum R-factor was :' >> "$filename.cycles"
awk ' BEGIN { minn = 100 ; set = 0 }\
              {  if ( $1 == "R-factor" )\
		   { \
		     if ( $4 < minn)\
                        {\
		        minn = $4\
                        set = 1\
			temp1 = $0\
                        }\
                   }\
                else\
		   {\
		     if (set == 1)\
		        {temp2 = $0\
			 set = 0\
                        }\
                   }\
              }\
        END   { print  temp2 \
		print  temp1 } '  $filename.cycles >> $filename.cycles
#
echo '********Finished*******' >> "$filename.cycles"
#
exit                                       # quit
