about summary refs log tree commit diff
path: root/src/c
diff options
context:
space:
mode:
Diffstat (limited to 'src/c')
-rwxr-xr-xsrc/c/readbin13456 -> 0 bytes
-rw-r--r--src/c/read.c133
-rwxr-xr-xsrc/c/runbin13472 -> 13432 bytes
-rw-r--r--src/c/run.c11
-rw-r--r--src/c/stars/1.csv10
-rw-r--r--src/c/testFile.csv110
6 files changed, 27 insertions, 237 deletions
diff --git a/src/c/read b/src/c/read
deleted file mode 100755
index 9724dee..0000000
--- a/src/c/read
+++ /dev/null
Binary files differdiff --git a/src/c/read.c b/src/c/read.c
deleted file mode 100644
index 48ece4b..0000000
--- a/src/c/read.c
+++ /dev/null
@@ -1,133 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <math.h>
-
-// Define some constants
-int range = 100;
-
-// Define some variables
-int sigma = 200;
-float f_0 = 0.1;
-float R_s = 1e4;
-
-// Define some constants
-float pi = M_PI;
-float e = M_E;
-float G = 4.302e-3;
-
-// Prototype pythagoras function
-float pythagoras(int x, int y, int z);
-// More prototypes
-float rho(float r);
-float phi(float x);
-
-int main(int argc, char *argv[] ){
-  // Seed random
-  srand(time(NULL));
-
-  // Define the number of stars that should be generated using command line
-  // arguments
-  long num_of_stars = atoi(argv[1]);
-
-  // define an array to store the coordinates of the stars in
-  int star_arr[num_of_stars][3];
-
-  /*
-    Generate random coordinates
-  */
-
-  // generate the random coordinates
-  for(int i = 0; i < num_of_stars; i++){
-    star_arr[i][0] = rand() % range + 1;
-    star_arr[i][1] = rand() % range + 1;
-    star_arr[i][2] = rand() % range + 1;
-  }
-
-  /*
-    Print out the coordinates
-  */
-
-  // print the content of the array star_arr
-  for(int i = 0; i < num_of_stars; i++){
-    printf("%d, %d, %d\n", star_arr[i][0], star_arr[i][1], star_arr[i][2]);
-    printf("%f\n\n", pythagoras(star_arr[i][0], star_arr[i][1], star_arr[i][2]));
-
-  }
-
-  /*
-    Generate a lookuptable
-  */
-
-  // If the correct amount (2) of command line arguments are given, continue
-  if( argc == 2 ) {
-
-    // Print out how many stars are being generated
-    printf("Generating %s Values...\n", num_of_stars);
-
-    // Open a file into which the lookuptable wil be written
-    FILE * fp = fopen("testFile.csv", "w+");
-
-    // Abourt if no file is specified
-    if(fp == NULL){
-      printf("Error opening the file!\n");
-      exit(1);
-    }
-
-    // generate the lookuptable
-    for(int i = 0; i < num_of_stars; i++){
-      fprintf(fp, "%d, %f\n", i, phi(i));
-    }
-
-    // close the file now containing the lookuptable
-    fclose(fp);
-
-  }
-  // Exception: to many arguments
-  else if( argc > 2 ) {
-    printf("Too many arguments supplied.\n");
-    return 0;
-  }
-  // Exception: no argument specified
-  else {
-    printf("One argument expected.\n");
-    return 0;
-  }
-
-  // Test if the Star should be generated or not
-
-    // If the star should be generated, write it's coordinates to a file
-    // Else do nothing
-
-  return 0;
-}
-
-// Define the Pythagorean theorem
-float pythagoras(int x, int y, int z){
-  float a = pow(x, 2);
-  float b = pow(y, 2);
-  float c = pow(z, 2);
-  float d = a + b + c;
-  float e = sqrt(d);
-  return e;
-}
-
-// Define rho function
-float rho(float r){
-  float a = (1) / ( sqrt(2 * pi) * sigma);
-  float b = exp( - (phi(r) / pow(sigma, 2) ));
-  return a;
-}
-
-// Define phi function
-float phi(float x){
-  if(x == 0) {
-    float a = -4 * pi * f_0 * G * pow(R_s, 2);
-    return(a);
-  }
-  else {
-    float a = - (4 * pi * G * f_0 * pow(R_s, 3) / x);
-    float b = log(1 + (x / R_s) );
-    return(a * b);
-  }
-}
diff --git a/src/c/run b/src/c/run
index 24029d8..993e49e 100755
--- a/src/c/run
+++ b/src/c/run
Binary files differdiff --git a/src/c/run.c b/src/c/run.c
index 838d294..6a95e82 100644
--- a/src/c/run.c
+++ b/src/c/run.c
@@ -32,7 +32,8 @@ int main(int argc, char *argv[] ){
 
   // define an array to store the coordinates of the stars in
 
-  FILE * st = fopen("stars/1.csv", "w+");
+  char *star_file = "stars/1.csv";
+  FILE * st = fopen(star_file, "w+");
 
   /*
     Generate random coordinates
@@ -40,6 +41,9 @@ int main(int argc, char *argv[] ){
 
   printf(">>> Generating %d random coordinates\n", num_of_stars);
 
+  printf("  -> Writing data to '%s'\n", star_file);
+
+
   // generate the random coordinates
   for(int i = 0; i < num_of_stars; i++){
     int x = rand() % (range_max - range_min + 1) + range_min;
@@ -63,6 +67,7 @@ int main(int argc, char *argv[] ){
   */
 
   printf(">>> Generating a lookuptable\n");
+  char *filename = "testFile.csv";
 
   // If the correct amount (2) of command line arguments are given, continue
   if( argc == 2 ) {
@@ -70,8 +75,6 @@ int main(int argc, char *argv[] ){
     // Print out how many stars are being generated
     printf("  -> Generating %d Values...\n", num_of_stars);
 
-    char *filename = "testFile.csv";
-
     printf("  -> Writing data to '%s'\n", filename);
 
     // Open a file into which the lookuptable wil be written
@@ -84,7 +87,7 @@ int main(int argc, char *argv[] ){
     }
 
     // generate the lookuptable
-    for(int i = 0; i < num_of_stars; i++){
+    for(int i = 0; i < range_max; i = i + (range_max) / num_of_stars){
       fprintf(fp, "%d, %f\n", i, phi(i));
     }
 
diff --git a/src/c/stars/1.csv b/src/c/stars/1.csv
new file mode 100644
index 0000000..fb9b0d9
--- /dev/null
+++ b/src/c/stars/1.csv
@@ -0,0 +1,10 @@
+51456, -97765, 23983, 113052.640625
+55805, 99160, 27999, 117178.703125
+75383, 42493, 77742, 116327.429688
+68814, 43189, 54643, 97910.742188
+-37268, -46104, -33714, 68199.093750
+97311, 95117, -78965, 157328.140625
+-72837, 45477, -65655, 108092.390625
+-88442, -58959, 75867, 130590.781250
+4844, -5397, 86597, 86900.125000
+-72760, -89895, -30779, 119676.546875
diff --git a/src/c/testFile.csv b/src/c/testFile.csv
index 3568a06..29bf790 100644
--- a/src/c/testFile.csv
+++ b/src/c/testFile.csv
@@ -1,100 +1,10 @@
-0, -540605.250000
-1, -540668.000000
-2, -540640.937500
-3, -540613.937500
-4, -540425.875000
-5, -540431.062500
-6, -540425.500000
-7, -540413.812500
-8, -540398.375000
-9, -540380.312500
-10, -540360.375000
-11, -540280.750000
-12, -540263.562500
-13, -540244.812500
-14, -540224.875000
-15, -540204.062500
-16, -540182.437500
-17, -540160.187500
-18, -540101.687500
-19, -540080.375000
-20, -540058.500000
-21, -540036.125000
-22, -540013.312500
-23, -539990.187500
-24, -539966.812500
-25, -539943.062500
-26, -539894.375000
-27, -539871.062500
-28, -539847.500000
-29, -539823.750000
-30, -539799.812500
-31, -539775.687500
-32, -539751.312500
-33, -539707.375000
-34, -539683.375000
-35, -539659.125000
-36, -539634.750000
-37, -539610.312500
-38, -539585.687500
-39, -539560.937500
-40, -539520.000000
-41, -539495.562500
-42, -539470.875000
-43, -539446.125000
-44, -539421.312500
-45, -539396.375000
-46, -539371.375000
-47, -539332.625000
-48, -539307.750000
-49, -539282.812500
-50, -539257.812500
-51, -539232.687500
-52, -539207.562500
-53, -539182.312500
-54, -539145.187500
-55, -539120.062500
-56, -539094.937500
-57, -539069.687500
-58, -539044.437500
-59, -539019.125000
-60, -538993.750000
-61, -538968.312500
-62, -538932.562500
-63, -538907.187500
-64, -538881.812500
-65, -538856.375000
-66, -538830.937500
-67, -538805.437500
-68, -538779.937500
-69, -538745.125000
-70, -538719.687500
-71, -538694.125000
-72, -538668.625000
-73, -538643.125000
-74, -538617.500000
-75, -538591.875000
-76, -538557.812500
-77, -538532.312500
-78, -538506.750000
-79, -538481.062500
-80, -538455.437500
-81, -538429.812500
-82, -538404.187500
-83, -538370.750000
-84, -538345.125000
-85, -538319.437500
-86, -538293.750000
-87, -538268.062500
-88, -538242.375000
-89, -538216.625000
-90, -538183.750000
-91, -538158.062500
-92, -538132.312500
-93, -538106.625000
-94, -538080.875000
-95, -538055.125000
-96, -538029.312500
-97, -538003.500000
-98, -537971.187500
-99, -537945.437500
+0, -540605.312500
+10000, -374719.062500
+20000, -296957.812500
+30000, -249812.687500
+40000, -217517.671875
+50000, -193726.921875
+60000, -175328.218750
+70000, -160593.875000
+80000, -148478.906250
+90000, -138309.968750