#ifndef Init_batch_h_DEFINED
#define Init_batch_h_DEFINED


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Init_batch {     

       int num_files;
       char** filenameCr;
       char** filenameCb;
       char** filenameClust;
       char** filenameExpanded;
       char** filenameExprClust;
       char** filenameExprCb;
       char** filenameExprCr;
       char** filenameExpression;


       Init_batch() {

            char name[MAX_LENGTH_FILE];
        
            sprintf(name, "%s%s", INIT_FOLDER, FILES_TO_BE_PROCESSED);
            FILE* f = fopen(name, "r+");
            if (f == 0) {
               PRN(("can't open %s\n", name));
               num_files = 0;
               filenameCr = filenameCb = filenameClust = filenameExpanded =
                            filenameExprClust = filenameExprCb =
                            filenameExprCr = filenameExpression = NULL;
            }
            else {

                fscanf(f, "NUM %d\n", &num_files);
    
                filenameCr = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameCr[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
                
                filenameCb = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameCb[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
                
                filenameClust = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameClust[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
    
                filenameExpanded = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameExpanded[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
                    
                filenameExprClust = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameExprClust[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
                    
                filenameExprCb = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameExprCb[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
                    
                filenameExprCr = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameExprCr[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
                    
                filenameExpression = (char**) calloc(num_files, sizeof(char*));
                for (int i = 0; i < num_files; i++)
                    filenameExpression[i] = (char*) calloc(MAX_LENGTH_FILE, sizeof(char));
    
    
               for (int i = 0; i < num_files; i++)  {       
                   
                    strcat(filenameCr[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameCr[i], name);
                    
                    strcat(filenameCb[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameCb[i], name);
                    
                    strcat(filenameClust[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameClust[i], name);
                    
                    strcat(filenameExpanded[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameExpanded[i], name);
                    
                    strcat(filenameExprClust[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameExprClust[i], name);
                    
                    strcat(filenameExprCb[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameExprCb[i], name);
                    
                    strcat(filenameExprCr[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameExprCr[i], name);
                    
                    strcat(filenameExpression[i], DATA_FOLDER);
                    fscanf(f, "%s\n", name);
                    strcat(filenameExpression[i], name);

                    fscanf(f, "%\n");
               }
    
    
               fclose(f);
           }

       }



};

inline void
FreeBatch(Init_batch& ib)
{

int i;

if (ib.filenameCr != NULL && ib.filenameCb != NULL && ib.filenameClust != NULL &&
    ib.filenameExpanded != NULL && ib.filenameExprClust != NULL &&
    ib.filenameExprCb != NULL && ib.filenameExprCr != NULL && ib.filenameExpression != NULL) {

          for (int i = 0; i < ib.num_files; i++) {
               free(ib.filenameCr[i]);
               free(ib.filenameCb[i]);
               free(ib.filenameClust[i]);
               free(ib.filenameExpanded[i]);
               free(ib.filenameExprClust[i]);
               free(ib.filenameExprCb[i]);
               free(ib.filenameExprCr[i]);
               free(ib.filenameExpression[i]);
          }
          
          free(ib.filenameCr);
          free(ib.filenameCb);
          free(ib.filenameClust);
          free(ib.filenameExpanded);
          free(ib.filenameExprClust);
          free(ib.filenameExprCb);
          free(ib.filenameExprCr);

}


return;

}




#endif // Init_batch_h_DEFINED
