/***********************************************************************
*                                                                      *
* This file is part of CARAT.                                          *
* Copyright (C) 2015  Tilman Schulz                                    *
*                                                                      *
* CARAT is free software: you can redistribute it and/or modify        *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or    *
* (at your option) any later version.                                  *
*                                                                      *
* This program is distributed in the hope that it will be useful,      *
* but WITHOUT ANY WARRANTY; without even the implied warranty of       *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
* GNU General Public License for more details.                         *
*                                                                      *
* You should have received a copy of the GNU General Public License    *
* along with this program.  If not, see <http://www.gnu.org/licenses/> *
*                                                                      *
***********************************************************************/
#include"typedef.h"


main (int argc, char *argv[])
{

	matrix_TYP **Mat, *vecs, *represent;
        bravais_TYP *G;
        int orb_anz;
        int *subdiv;
        int *c, *f;
        int i,j, anz;

        extern char **FILENAMES;
        extern int FILEANZ;

	extern matrix_TYP **mget_mat();
	extern bravais_TYP *get_bravais();
	extern int *orbit_subdivision();
        extern matrix_TYP *init_mat();
	extern void put_mat ();

        read_header(argc, argv);
        if(FILEANZ != 2)
        {
           printf("usage:   orbrep 'file1' 'file2',\n");
           printf("where  'file1' contains a matrix_TYP and\n");
           printf("       'file2' contains a bravais_TYP\n");
           if (is_option('h')){
              exit(0);
           }
           else{
              exit(31);
           }
        }
	Mat = mget_mat (FILENAMES[0], &anz);
        vecs = Mat[0];
        G = get_bravais(FILENAMES[1]);
        subdiv = orbit_subdivision(vecs, G, &orb_anz);
        represent = init_mat(orb_anz, G->gen[0]->cols, "");
        c = (int *)malloc(orb_anz *sizeof(int));
        f = (int *)malloc(orb_anz *sizeof(int));
        for(i=0;i<orb_anz;i++)
           c[i] = 0;
        for(i=0;i<vecs->rows;i++)
        {
          j = subdiv[i]-1;
          if(c[j] == 0)
            f[j] = i;
          c[j]++;
        }
        for(i=0;i<orb_anz;i++)
        {
           for(j=0;j<G->gen[0]->cols;j++)
             represent->array.SZ[i][j] = vecs->array.SZ[f[i]][j];
        }
        put_mat(represent, NULL, "representatives of the orbits", 0);
        printf(" The length of the i-th orbit is:\n");
        for(i=0;i<orb_anz;i++)
          printf("%d  ", 2  *c[i]);
        printf("\n");


   exit(0);
}
