#!/bin/csh -f
##########################################################################
#### This script creates the tar file for the distribution
##########################################################################
###### 

## get the version number in the hat() routine
set ver=$1

## execute tetr with the correct hat
$HOME_TETR/tmake $ver
cat 'build.hat'
pause

##
set list_files = ( *.f90 Makefile Makefile_gfortran symgrp.rep CONTCAR* *.geom* *.fdf* *.inp \
                  README *.xyz *.dat collec* do_tar_improved tmake build.hat \
                   space.grp.intern group.list.intern sym_for_siesta.info job_bash_run \
		    run_tests run_prep_input )
## ask if this is for a user or myself

echo '======= Choose the type of the archive for version ' $ver ': ======='
echo '     1. user archive (smaller)'
echo '     2. my archive (complete)'
echo '     Q. quit - do nothing'
set type=($<)
if ( $type == 1 ) then
   echo '...... OK: archive for a general user (smaller) ........'
   set list_dir = ( REF Model_Eff_Atom SCRIPTS example_1P)
   echo $list_dir
else if  ( $type == 2 ) then
   echo '...... OK: archive for myself (complete) ........'
   set list_dir = ( BSSE MM Symmetry_for_SIESTA Symmetry Stress AFM Born-Charges-siesta CO2 C60-060608-symm Sam_Jarvis_long_file Test_110_surface vasp5.2_India_problem H2O graphene MgO_bulk Fe2O3 surface_4x2_half_for_Bucko QE  from_Natalia  BSSE_cp2k_2_benzene MgO_Vk REF Model_Eff_Atom example_1P)
   echo $list_dir
else if  ( $type == Q ) then
   exit
endif

#################################################################

echo making tar file for tetr ...
echo -n mkdir tetr_$ver .......
mkdir tetr_$ver
echo "done\!"

foreach files ( $list_files )
   echo -n cp $files tetr_$ver/. .......
   cp $files tetr_$ver/.
   echo "done\!"
end

#echo $list_dir

foreach dir ( $list_dir )
    echo '========> doing directory ' $dir ' now <========'
    echo -n tar -czf $dir.tgz $dir .......
    tar -czf $dir.tgz $dir
    echo "done\!"
    echo -n cp $dir.tgz  tetr_$ver/.  .......
    mv $dir.tgz tetr_$ver/
    echo "done\!"
    cd tetr_$ver
    echo -n  tar -xzf $dir.tgz  .......
    tar -xzf $dir.tgz 
    /bin/rm $dir.tgz 
    cd ..
    echo "done\!"
end

#################################################################

echo '========> Doing the final archive <========='
echo -n tar -czf tetr_$ver.tgz tetr_$ver .......
tar -czf tetr_$ver.tgz tetr_$ver
if ( $type == 1 ) mv  tetr_$ver.tgz tetr_$ver-forusers.tgz 
/bin/rm -rf  tetr_$ver
echo "Done\!"


