/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** ** ** ** ** ** ** ** ** ** ** ********* ** ** ** ********** ********** *** *** ** ** ** ********** ** **** **** ** ********** ** ** ** ** ** ** ** ** ** ********** ** ** ** ******** ** ** ** ** ** ** ** ** ****** ******** ** ** ** ** ** ** ** ****** *** ** ** ** ************** ** ** ** *** ** ********** ** ************** ** ** ** *** ***************** ******** ** ** ** *********** ********* ** ********* ** ** ** *********** ** ** ** *** ** ********** ** ** ** ** ** ****** ** ** ********** ** ** ** ** ** ****** ******** ** ** ** * ** ** ********* ** ** ** * ** ** ** ** ** ** ** *** ********** ** ** ** ** ** *** ********** ********** ** ** ********* ** ** ** ** ** ** E N S E M B L E T O O L S ** ** ** ** 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. ** ** ** ** ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #ifndef __FILENSCHK_HEADER__ #define __FILENSCHK_HEADER__ FILE *checkCSPFile(char *fileName, uint32_t *nbConfs, uint32_t *nbAtoms) { /* This functions checks out a CSP file and returns the file handler of the opened file */ FILE *fileHandler = NULL; unsigned long fileSize, expFileSize; char fileType[4] = {"\0"}; // Check out the existence the the origin file if ((fileHandler = fopen(fileName, "rb")) == NULL) { error("NO_FILE", fileName); return NULL; } // Checking whether it is a CSP file fread(&fileType, CHAR_SIZE, 3, fileHandler); if (strcmp(fileType, "Csp")) { fclose(fileHandler); error("CSP_FILE", fileName); return NULL; } // Reading the number of conformers and atoms fread(nbConfs, INT32_SIZE, 1, fileHandler); fread(nbAtoms, INT32_SIZE, 1, fileHandler); // Determining the size of the file // and comparing it with the expected size fseek(fileHandler, 0, SEEK_END); fileSize = ftell(fileHandler); // !! Not more than 4 Gb !! if (!fileSize) { fclose(fileHandler); fatal_error("EMPTY", fileName); } expFileSize = (unsigned long)((3 + 27 * (*nbAtoms)) * CHAR_SIZE + (2 + 3 * (*nbConfs) * (*nbAtoms)) * INT32_SIZE); if (fileSize != expFileSize) { printf ("%s is a corrupted List file (Expected size = %lu; Real size = %lu)!\n", fileName, expFileSize, fileSize); fclose(fileHandler); return NULL; } fseek(fileHandler, 0, SEEK_SET); return fileHandler; } int getConfListNb (confList *confNbsList, char *ENSFileName) { counter confNb; char fileType[4] = {'\0'}; FILE *ENSFile; if ((ENSFile = fopen(ENSFileName, "rb")) == NULL) return 1; // Checking the file type fread(&fileType, CHAR_SIZE, 3, ENSFile); if (strcmp(fileType, "Ens")) fatal_error("ENS_FILE", ENSFileName); // Size of a double data fread(&DOUBLE_SIZE, SHORT_SIZE, 1, ENSFile); if (DOUBLE_SIZE != sizeof(double)) { warning("%s is an Ensemble file type generated on a different machine type!", ENSFileName); return 1; } // Number of conformers fread(&(*confNbsList).nb, INT32_SIZE, 1, ENSFile); if (((*confNbsList).confNb = malloc((*confNbsList).nb * INT32_SIZE)) == NULL) { warning("A problem occured while attempting to instance confListNb variable", NULL); return 1; } for (confNb=0; confNb<(*confNbsList).nb; confNb++) { fread(&(*confNbsList).confNb[confNb], INT32_SIZE, 1, ENSFile); } // Closing the ENSEMBLE file fclose(ENSFile); return 0; } #endif