RadioSubTitle::RadioSubTitle(const int MaximumMessageNum, const unsigned long TTL) { if (MaximumMessageNum != 0) MaxMessageNum = MaximumMessageNum; else MaxMessageNum = 20; if (TTL != 0) messageTTL = TTL; else messageTTL = MESSAGE_TTL; theRadioChatterList = new AList(); currentlyEditedNode = (SubTitleNode*)0; LinkedListCount = 0; #ifndef DYNAMIC_LINE_NUM // Retro 11Jan2004 for (int i = 0; i < MAX_FRAG_NUM; i++) { theStrings[i] = 0; } #endif // DYNAMIC_LINE_NUM colour_Flight = TOFROM_FLIGHT_COLOUR; colour_ToPackage = TO_PACKAGE_COLOUR; colour_ToFromPackage= TOFROM_PACKAGE_COLOUR; colour_Team = TO_TEAM_COLOUR; // this is the guard channel colour_Proximity = IN_PROXIMITY_COLOUR; colour_World = TO_WORLD_COLOUR; colour_Tower = TOFROM_TOWER_COLOUR; colour_Standard = STANDARD_COLOUR; // only used in default cases which (shouldn´t happen actually) #ifdef DYNAMIC_LINE_NUM // Retro 11Jan2004 FragCount = CountLinesInFile(THE_INPUT_FILE_NAME); if (FragCount == 0) { throw Init_Error("No frag lines in subtitles input file"); } else { theStrings = (csvLine**)calloc(sizeof(csvLine*),FragCount+100); // Retro 11Jan2004 - accounting for count-errors :p if (theStrings == (csvLine**)0) { throw Init_Error("Could not create strings"); } } #endif // DYNAMIC_LINE_NUM if (!ReadNewFile(THE_INPUT_FILE_NAME)) { throw Init_Error("Error reading the subtitles input file"); } #ifdef WRITE_BACK_STRING_FILE WriteOut(); #endif InitializeCriticalSection(&cs_radiosubtitle); }
char* ReadLineFromFileByRandomIndex(char* path) { if(path) { char* result = (char*)calloc(25, sizeof(char)); int linesInFile = CountLinesInFile(path); int randomIndex = RandomNumberInRange(1, linesInFile); FILE* file; fopen_s(&file, path, "r"); int count = 1; while (++count < randomIndex) { fgets(result, 25, file); } fgets(result, 25, file); fclose(file); return(result); } return(""); }
int main(int argc, char **argv) { char *obsFile, *queFile; FILE *infile=NULL, *outfile=NULL; struct binet *ratings=NULL; gsl_rng *rand_gen; struct query **queries=NULL; int nquery, q; int seed; double *scores; /* Command line parameters */ if (argc < 3) { printf("\nUse: multi_recommend_2.out observation_file query_file seed\n\n"); return; } obsFile = argv[1]; queFile = argv[2]; seed = atoi(argv[3]); rand_gen = gsl_rng_alloc(gsl_rng_mt19937); gsl_rng_set(rand_gen, seed); /* Build the observations */ infile = fopen(obsFile, "r"); ratings = ReadRecommenderObservations(infile); fclose(infile); /* Get the number of queries and build the query set */ nquery = CountLinesInFile(queFile); fprintf(stderr, ">> %d queries\n", nquery); infile = fopen(queFile, "r"); queries = ReadQueries(infile, nquery, ratings); fclose(infile); /* Get the scores of the queries and print them */ /* scores = MultiLinkScore2State(ratings, */ /* queries, nquery, */ /* 10000, rand_gen, 'v', -1); */ scores = MultiLinkScore2State(ratings, queries, nquery, 10000, rand_gen, 'v', -1); fprintf(stdout, "\n\n>>> RESULTS\n\n"); for (q=0; q<nquery; q++) { fprintf(stdout, "%s %s %lf\n", ((queries[q])->n1)->label, ((queries[q])->n2)->label, scores[q]); } /* Finish */ RemoveBipart(ratings); /* NEED TO FREE THE WHOLE QUERYSET!! */ /* FreeQuery(the_query); */ gsl_rng_free(rand_gen); return 0; }