#!/usr/bin/env perl
use strict;
use lib $ENV{ 'MAIN_CONF'}  ;
use main_config ;

my $conf_file ;
if ( -f "main_config.data" )
{    $conf_file = "main_config.data" ; }
else
{    $conf_file = join ('', $ENV{"MAIN_CONF"}, "main_config.data" ) ; }

my %my_main = main_config::read_main_config_file ( $conf_file ) ; 

my $MACRO_FILE = "multi_deriv_maps.com" ;
my ( $CRYST, $MAP, $GROUP ) ;
############

print "creating \"$MACRO_FILE\" \n" ;
if ( -f $MACRO_FILE ) 
{ 
    my $back = join ('', $MACRO_FILE, ".old" ) ; 
    system ( "mv  $MACRO_FILE $back" ) ; 
}
open ( MACRO,  "> $MACRO_FILE" ) || die "FILE OPEN ERROR: >$MACRO_FILE< \n" ;

for ( $CRYST = 0; $CRYST < $my_main{"SG_NCRYST"}[0] ; $CRYST++ )
{
    $GROUP = join ( '', "SG_CRYST" , $CRYST+1 ) ;
    
    main_config::write_get_diffr_data (*MACRO, \%my_main, $CRYST ) ; 

    print MACRO "refl key PHASE_WORK sele WORK_REFL end\n" ;
    print MACRO "refl key PHASE_TEST sele TEST end\n";

    $MAP = 2*$CRYST+2 ;
    print MACRO "set vari SEGM char global = \" ", 
    join(" ", @{$my_main{$GROUP}}), "\"\n" ;
    print MACRO "four atom sele segm name SEGM end energy  map ",  $MAP, "\n\n" ;
}

print MACRO "return\n" ;

close ( MACRO ) ;
