/* ## ## ######### ## ########## ########## ### ### ## ########## ## #### #### ## ########## ## ## ## ## ## ## ## ########## ## ######## ## ## ## ## ## ## ###### ######## ## ## ## ## ## ###### ### ## ## ## ############## ## ### ## ########## ## ############## ## ### ################# ######## ## ########### ######### ## ######### ## ########### ## ## ## ### ## ########## ## ## ## ###### ## ## ########## ## ## ## ###### ######## ## # ## ## ######### ## # ## ## ## ## ## ### ########## ## ## ## ### ########## ########## ######### */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** ** ** ** ** E N S E M B L E ** ** ** ** Version 2.1 ** ** ** ** ** ** Principal Investigator: Julie D. Forman-Kay ** ** ** ** Author: Mickaƫl Krzeminski ** ** ** ** Date: November 2012 ** ** ** ** ** ************************************************************************************* ** ** ** ** ** Copyright (C) The Hospital for Sick Children, 2001 ** ** ** ** Distribution of substantively modified versions of this module is prohibited ** ** without the explicit permission of the copyright holder. ** ** ** ** Any use of this work or derivative works in whole or in part for any ** ** commercial purpose or for monetary gain is prohibited. ** ** ** ** ** ** NO WARRANTY ** ** This software package is provided 'as is' without warranty of any kind, ** ** expressed or implied. ** ** ** ** ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* COMPILATION gcc -O3 -lm -o combine_csp combine_csp.c */ #include "Include/ens.h" enum toolsPrograms TP = __COMBINE_CDP__; int main (int argc, char *argv[]) { /***********************************************************\ |* *| |* *| |* Variables declaration *| |* *| |* *| \***********************************************************/ counter count; unsigned int nbInpFiles = 0; unsigned int maxcdpInpFileNames = 0; char *cdpOutFileName = NULL; char **cdpInpFileNames = NULL; char fileType[4] = {'\0'}; FILE *ENSFile; /***********************************************************\ |* *| |* *| |* Arguments reading and checking *| |* *| |* *| \***********************************************************/ if (argc<4) __USAGE__ for (count=1; countcount) { if ((ENSFile = fopen(argv[count], "r")) == NULL) { if ((cdpOutFileName = malloc((strlen(argv[count]) + 1) * CHAR_SIZE)) == NULL) { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("MEMORY", "create PDBListFileName variable"); } strcpy(cdpOutFileName, argv[count]); } else { fclose(ENSFile); _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("EXIST_FILE", argv[count]); } } else { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("NO_ARGUMENT_FLAG", "-o"); } } else if (!strcmp(argv[count], "-h")) { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); __USAGE__ } else { // Testing the existence and relevance of each provided CDP file // Opening the file if ((ENSFile = fopen(argv[count], "r")) == NULL) { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("NO_FILE", argv[count]); } // Reading in the file type fread(&fileType, CHAR_SIZE, 3, ENSFile); fclose(ENSFile); if (!strcmp(fileType, "Cdp")) { if (nbInpFiles == maxcdpInpFileNames) { maxcdpInpFileNames += 10; if ((cdpInpFileNames = realloc(cdpInpFileNames, maxcdpInpFileNames*sizeof(char *))) == NULL) { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("MEMORY", "re-instance cdpInpFileNames variable"); } } if ((cdpInpFileNames[nbInpFiles] = malloc((strlen(argv[count])+1)*CHAR_SIZE)) == NULL) { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("MEMORY", "instance cdpInpFileNames[nbInpFiles] variable"); } strcpy(cdpInpFileNames[nbInpFiles], argv[count]); ++nbInpFiles; } else { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("CDP_FILE", argv[count]); } } } if ((cdpInpFileNames = realloc(cdpInpFileNames, nbInpFiles*sizeof(char *))) == NULL) { _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); fatal_error("MEMORY", "re-allocate cdpInpFileNames variable"); } if (combineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles)) { printf("Cleaning up... "); if (remove(cdpOutFileName) == -1) { printf("Impossible to remove the file %s! Abandonning.\n\n", cdpOutFileName); } else { printf("DONE\n\n"); } _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); return 1; } // Releasing memory _cleanCombineCDP(cdpOutFileName, cdpInpFileNames, nbInpFiles); return 0; }