about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhanemile <emile.hansmaennel@gmail.com>2018-01-01 16:56:23 +0100
committerhanemile <emile.hansmaennel@gmail.com>2018-01-01 16:56:23 +0100
commit0a5d6714b2676e7c1e348511384db68c68946af2 (patch)
treebb9e24d4657bf3230a87f0beebfc47df1d8bc8b2
parent1a783c3ef050889bce04fc67a64337fdf908296a (diff)
implemented writing to file using c
-rwxr-xr-xsrc/a.outbin0 -> 13200 bytes
-rw-r--r--src/lookup.c74
2 files changed, 74 insertions, 0 deletions
diff --git a/src/a.out b/src/a.out
new file mode 100755
index 0000000..6a6368d
--- /dev/null
+++ b/src/a.out
Binary files differdiff --git a/src/lookup.c b/src/lookup.c
new file mode 100644
index 0000000..01b5508
--- /dev/null
+++ b/src/lookup.c
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+
+// 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;
+
+// Define the directory where the data shall be stored
+
+// Prototype
+float rho(float r);
+float phi(float x);
+
+int main(int argc, char *argv[] ){
+  if( argc == 2 ) {
+    printf("Generating %s Values...\n", argv[1]);
+
+    FILE * fp = fopen("testFile.csv", "w+");
+    if(fp == NULL){
+      printf("Error opening the file!\n");
+      exit(1);
+    }
+
+    int x = atoi(argv[1]);
+
+    for(int i = 0; i < x; i++){
+      fprintf(fp, "%d, %f\n", i, phi(i));
+    }
+
+    // for(int i = 0; i < 1e7; i = i + 1e4){
+    //   printf("%s, %f\n", i, phi(i));
+    // }
+
+    fclose(fp);
+
+  }
+  else if( argc > 2 ) {
+    printf("Too many arguments supplied.\n");
+    return 0;
+  }
+  else {
+    printf("One argument expected.\n");
+    return 0;
+  }
+
+  return 0;
+}
+
+// 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);
+  }
+}