/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** ** ** ** ** ** ** ** ** ** ** ********* ** ** ** ********** ********** *** *** ** ** ** ********** ** **** **** ** ********** ** ** ** ** ** ** ** ** ** ********** ** ** ** ******** ** ** ** ** ** ** ** ** ****** ******** ** ** ** ** ** ** ** ****** *** ** ** ** ************** ** ** ** *** ** ********** ** ************** ** ** ** *** ***************** ******** ** ** ** *********** ********* ** ********* ** ** ** *********** ** ** ** *** ** ********** ** ** ** ** ** ****** ** ** ********** ** ** ** ** ** ****** ******** ** ** ** * ** ** ********* ** ** ** * ** ** ** ** ** ** ** *** ********** ** ** ** ** ** *** ********** ********** ** ** ********* ** ** ** ** ** ** 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 __COMMON_HEADER__ #define __COMMON_HEADER__ /* Common and usefull functions utilized by C programs for ENSEMBLE */ /* Function definitions */ int deepTrim (char *text) { /* Remove any space and tabulation at the beginning and end of text. */ counter textSeek, rightBlankNb = 0; unsigned int lenText = strlen(text); if (text == NULL) return 1; // From the end to the beginning for (textSeek=lenText-1; textSeek>=0; textSeek--) { if (isspace(text[textSeek])) { text[textSeek] = '\0'; } else { break; } } // From the beginning to the end for (textSeek=0; textSeek 57) // 30 and 39 are ASCII code for 0 and 9 { return 0; } } return 1; } int sort(const void *x, const void *y) { return (*(int*)x - *(int*)y); } float distance(coordinates A, coordinates B) { return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y)+(A.z-B.z)*(A.z-B.z)); } unsigned int IsNumber(char *value) { unsigned int count; unsigned int point = 0; for (count=0; count 39) { return 0; } } return 1; } char *randomFileName(int size, char *path) { FILE *fileTest; counter letterCount; unsigned int isPathNull = 0; char *fileName; char firstRandLetters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuwxyz"}; char randLetters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuwxyz_132456789"}; unsigned int frlLen = strlen(firstRandLetters), rlLen = strlen(randLetters), pathLen; srand(time(NULL)); if (size == 0) size = (rand() % 30) + 1; if (path == NULL) { ++isPathNull; path = malloc(2 * CHAR_SIZE); strcpy(path, "."); } pathLen = strlen(path); fileName = malloc((size + pathLen + 2) * CHAR_SIZE); // '+2': one for '/' and one for '\0' strcpy(fileName, path); fileName[pathLen] = '/'; fileName[pathLen+1] = firstRandLetters[rand()%frlLen]; for (letterCount=pathLen+2; letterCount<=pathLen+size;) { fileName[letterCount] = randLetters[rand()%rlLen]; ++letterCount; } fileName[letterCount] = '\0'; if ((fileTest = fopen(fileName, "r")) != NULL) fileName = randomFileName(size, path); // If the file already exists, another one is generated if (isPathNull) free(path); // Releasing memory if necessary return fileName; } int copy (char *source, char *destination) { FILE *s, *d; int c; if ((s = fopen(source, "rb")) == NULL) { return 1; } if ((d = fopen(destination, "wb")) == NULL) { return 1; } while ((c = fgetc(s)) != EOF) { fputc(c, d); } fclose(s); fclose(d); return 0; } /* reverse: reverse string s in place */ // void reverse(char s[]) // { // int i, j; // char c; // // for (i = 0, j = strlen(s)-1; i 0); // delete it // // if (sign < 0) s[i++] = '-'; // s[i] = '\0'; // reverse(s); // } #endif