From 1a783c3ef050889bce04fc67a64337fdf908296a Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 1 Jan 2018 14:46:13 +0100 Subject: added the NFW-Function image --- langfassung/figs/lookup_table_rho_r_function_grid.png | Bin 0 -> 20668 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 langfassung/figs/lookup_table_rho_r_function_grid.png diff --git a/langfassung/figs/lookup_table_rho_r_function_grid.png b/langfassung/figs/lookup_table_rho_r_function_grid.png new file mode 100644 index 0000000..75565e6 Binary files /dev/null and b/langfassung/figs/lookup_table_rho_r_function_grid.png differ -- cgit 1.4.1 From 0a5d6714b2676e7c1e348511384db68c68946af2 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 1 Jan 2018 16:56:23 +0100 Subject: implemented writing to file using c --- src/a.out | Bin 0 -> 13200 bytes src/lookup.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100755 src/a.out create mode 100644 src/lookup.c diff --git a/src/a.out b/src/a.out new file mode 100755 index 0000000..6a6368d Binary files /dev/null and b/src/a.out differ diff --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 +#include +#include + +// 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); + } +} -- cgit 1.4.1 From af0b25e9d5c28e6c7062602d0797b2ff983ea9d3 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 1 Jan 2018 18:30:13 +0100 Subject: [milestone] print the lookuptable --- src/a.out | Bin 13200 -> 13168 bytes src/lookup.c | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/a.out b/src/a.out index 6a6368d..f97661d 100755 Binary files a/src/a.out and b/src/a.out differ diff --git a/src/lookup.c b/src/lookup.c index 01b5508..ef13a05 100644 --- a/src/lookup.c +++ b/src/lookup.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[] ){ int x = atoi(argv[1]); for(int i = 0; i < x; i++){ - fprintf(fp, "%d, %f\n", i, phi(i)); + printf("%d, %f\n", i, phi(i)); } // for(int i = 0; i < 1e7; i = i + 1e4){ -- cgit 1.4.1 From f6d0ee87d389bdb9c1cbac7bc9d38dccf989165c Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 1 Jan 2018 18:32:25 +0100 Subject: [milestone] write the lookuptable to a file for further use --- src/a.out | Bin 13168 -> 13200 bytes src/lookup.c | 2 +- src/testFile.csv | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1001 insertions(+), 1 deletion(-) create mode 100644 src/testFile.csv diff --git a/src/a.out b/src/a.out index f97661d..6a6368d 100755 Binary files a/src/a.out and b/src/a.out differ diff --git a/src/lookup.c b/src/lookup.c index ef13a05..01b5508 100644 --- a/src/lookup.c +++ b/src/lookup.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[] ){ int x = atoi(argv[1]); for(int i = 0; i < x; i++){ - printf("%d, %f\n", i, phi(i)); + fprintf(fp, "%d, %f\n", i, phi(i)); } // for(int i = 0; i < 1e7; i = i + 1e4){ diff --git a/src/testFile.csv b/src/testFile.csv new file mode 100644 index 0000000..6089101 --- /dev/null +++ b/src/testFile.csv @@ -0,0 +1,1000 @@ +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 +100, -537919.625000 +101, -537893.875000 +102, -537868.125000 +103, -537842.312500 +104, -537816.437500 +105, -537784.562500 +106, -537758.750000 +107, -537732.937500 +108, -537707.125000 +109, -537681.312500 +110, -537655.437500 +111, -537629.625000 +112, -537598.000000 +113, -537572.187500 +114, -537546.375000 +115, -537520.562500 +116, -537494.687500 +117, -537468.812500 +118, -537442.937500 +119, -537411.687500 +120, -537385.812500 +121, -537360.000000 +122, -537334.125000 +123, -537308.250000 +124, -537282.375000 +125, -537256.500000 +126, -537225.500000 +127, -537199.687500 +128, -537173.812500 +129, -537147.875000 +130, -537122.000000 +131, -537096.125000 +132, -537070.187500 +133, -537039.500000 +134, -537013.687500 +135, -536987.750000 +136, -536961.875000 +137, -536936.000000 +138, -536910.125000 +139, -536884.125000 +140, -536858.250000 +141, -536827.812500 +142, -536801.937500 +143, -536776.062500 +144, -536750.125000 +145, -536724.250000 +146, -536698.312500 +147, -536672.375000 +148, -536642.187500 +149, -536616.250000 +150, -536590.375000 +151, -536564.437500 +152, -536538.562500 +153, -536512.625000 +154, -536486.750000 +155, -536456.687500 +156, -536430.812500 +157, -536404.875000 +158, -536379.000000 +159, -536353.125000 +160, -536327.187500 +161, -536301.250000 +162, -536271.375000 +163, -536245.437500 +164, -536219.625000 +165, -536193.687500 +166, -536167.750000 +167, -536141.812500 +168, -536115.875000 +169, -536086.250000 +170, -536060.375000 +171, -536034.437500 +172, -536008.500000 +173, -535982.625000 +174, -535956.750000 +175, -535930.812500 +176, -535904.875000 +177, -535875.437500 +178, -535849.500000 +179, -535823.562500 +180, -535797.687500 +181, -535771.812500 +182, -535745.875000 +183, -535719.937500 +184, -535690.625000 +185, -535664.750000 +186, -535638.812500 +187, -535612.937500 +188, -535587.000000 +189, -535561.125000 +190, -535535.250000 +191, -535506.000000 +192, -535480.125000 +193, -535454.187500 +194, -535428.375000 +195, -535402.437500 +196, -535376.500000 +197, -535350.625000 +198, -535321.562500 +199, -535295.687500 +200, -535269.812500 +201, -535243.937500 +202, -535218.000000 +203, -535192.125000 +204, -535166.250000 +205, -535137.312500 +206, -535111.437500 +207, -535085.500000 +208, -535059.625000 +209, -535033.812500 +210, -535007.875000 +211, -534982.000000 +212, -534953.187500 +213, -534927.312500 +214, -534901.500000 +215, -534875.562500 +216, -534849.687500 +217, -534823.875000 +218, -534798.000000 +219, -534772.125000 +220, -534743.375000 +221, -534717.562500 +222, -534691.687500 +223, -534665.875000 +224, -534640.000000 +225, -534614.125000 +226, -534588.312500 +227, -534559.625000 +228, -534533.812500 +229, -534508.000000 +230, -534482.125000 +231, -534456.250000 +232, -534430.437500 +233, -534404.625000 +234, -534376.062500 +235, -534350.250000 +236, -534324.437500 +237, -534298.562500 +238, -534272.812500 +239, -534246.937500 +240, -534221.125000 +241, -534192.625000 +242, -534166.875000 +243, -534141.000000 +244, -534115.187500 +245, -534089.437500 +246, -534063.562500 +247, -534037.750000 +248, -534009.437500 +249, -533983.625000 +250, -533957.812500 +251, -533932.000000 +252, -533906.187500 +253, -533880.437500 +254, -533854.562500 +255, -533828.812500 +256, -533800.562500 +257, -533774.750000 +258, -533749.000000 +259, -533723.187500 +260, -533697.437500 +261, -533671.625000 +262, -533645.875000 +263, -533617.687500 +264, -533591.875000 +265, -533566.125000 +266, -533540.312500 +267, -533514.562500 +268, -533488.812500 +269, -533463.000000 +270, -533435.000000 +271, -533409.187500 +272, -533383.437500 +273, -533357.687500 +274, -533331.937500 +275, -533306.187500 +276, -533280.437500 +277, -533252.375000 +278, -533226.625000 +279, -533200.937500 +280, -533175.187500 +281, -533149.437500 +282, -533123.687500 +283, -533098.000000 +284, -533070.000000 +285, -533044.312500 +286, -533018.562500 +287, -532992.812500 +288, -532967.125000 +289, -532941.375000 +290, -532915.687500 +291, -532887.812500 +292, -532862.125000 +293, -532836.375000 +294, -532810.687500 +295, -532784.937500 +296, -532759.312500 +297, -532733.562500 +298, -532707.812500 +299, -532680.062500 +300, -532654.375000 +301, -532628.687500 +302, -532602.937500 +303, -532577.312500 +304, -532551.625000 +305, -532525.875000 +306, -532498.187500 +307, -532472.500000 +308, -532446.875000 +309, -532421.187500 +310, -532395.500000 +311, -532369.812500 +312, -532344.125000 +313, -532316.500000 +314, -532290.812500 +315, -532265.187500 +316, -532239.500000 +317, -532213.875000 +318, -532188.250000 +319, -532162.562500 +320, -532134.937500 +321, -532109.312500 +322, -532083.687500 +323, -532058.062500 +324, -532032.437500 +325, -532006.750000 +326, -531981.125000 +327, -531953.625000 +328, -531927.937500 +329, -531902.312500 +330, -531876.750000 +331, -531851.125000 +332, -531825.500000 +333, -531799.875000 +334, -531774.250000 +335, -531746.750000 +336, -531721.187500 +337, -531695.625000 +338, -531669.937500 +339, -531644.375000 +340, -531618.812500 +341, -531593.187500 +342, -531565.750000 +343, -531540.187500 +344, -531514.562500 +345, -531489.000000 +346, -531463.375000 +347, -531437.812500 +348, -531412.312500 +349, -531384.937500 +350, -531359.312500 +351, -531333.812500 +352, -531308.187500 +353, -531282.687500 +354, -531257.062500 +355, -531231.500000 +356, -531204.250000 +357, -531178.625000 +358, -531153.125000 +359, -531127.625000 +360, -531102.062500 +361, -531076.500000 +362, -531050.937500 +363, -531023.687500 +364, -530998.187500 +365, -530972.625000 +366, -530947.062500 +367, -530921.562500 +368, -530896.062500 +369, -530870.562500 +370, -530843.375000 +371, -530817.875000 +372, -530792.312500 +373, -530766.812500 +374, -530741.312500 +375, -530715.812500 +376, -530690.250000 +377, -530664.812500 +378, -530637.687500 +379, -530612.125000 +380, -530586.687500 +381, -530561.187500 +382, -530535.687500 +383, -530510.250000 +384, -530484.750000 +385, -530457.625000 +386, -530432.187500 +387, -530406.687500 +388, -530381.187500 +389, -530355.750000 +390, -530330.312500 +391, -530304.812500 +392, -530277.750000 +393, -530252.312500 +394, -530226.875000 +395, -530201.437500 +396, -530176.000000 +397, -530150.562500 +398, -530125.062500 +399, -530098.125000 +400, -530072.625000 +401, -530047.250000 +402, -530021.812500 +403, -529996.375000 +404, -529970.937500 +405, -529945.562500 +406, -529920.125000 +407, -529893.125000 +408, -529867.750000 +409, -529842.312500 +410, -529816.937500 +411, -529791.500000 +412, -529766.125000 +413, -529740.687500 +414, -529713.812500 +415, -529688.375000 +416, -529663.000000 +417, -529637.687500 +418, -529612.250000 +419, -529586.812500 +420, -529561.500000 +421, -529534.625000 +422, -529509.312500 +423, -529483.875000 +424, -529458.500000 +425, -529433.125000 +426, -529407.750000 +427, -529382.375000 +428, -529355.625000 +429, -529330.312500 +430, -529304.937500 +431, -529279.562500 +432, -529254.187500 +433, -529228.812500 +434, -529203.562500 +435, -529176.750000 +436, -529151.437500 +437, -529126.062500 +438, -529100.750000 +439, -529075.437500 +440, -529050.125000 +441, -529024.812500 +442, -528998.062500 +443, -528972.750000 +444, -528947.437500 +445, -528922.125000 +446, -528896.812500 +447, -528871.500000 +448, -528846.187500 +449, -528819.562500 +450, -528794.250000 +451, -528768.937500 +452, -528743.687500 +453, -528718.312500 +454, -528693.062500 +455, -528667.812500 +456, -528642.500000 +457, -528615.875000 +458, -528590.625000 +459, -528565.312500 +460, -528540.062500 +461, -528514.812500 +462, -528489.562500 +463, -528464.312500 +464, -528437.687500 +465, -528412.437500 +466, -528387.187500 +467, -528361.937500 +468, -528336.687500 +469, -528311.437500 +470, -528286.187500 +471, -528259.687500 +472, -528234.437500 +473, -528209.187500 +474, -528184.000000 +475, -528158.750000 +476, -528133.500000 +477, -528108.312500 +478, -528081.812500 +479, -528056.625000 +480, -528031.375000 +481, -528006.125000 +482, -527980.937500 +483, -527955.750000 +484, -527930.562500 +485, -527905.375000 +486, -527878.875000 +487, -527853.687500 +488, -527828.500000 +489, -527803.312500 +490, -527778.125000 +491, -527752.937500 +492, -527727.750000 +493, -527701.312500 +494, -527676.187500 +495, -527651.000000 +496, -527625.875000 +497, -527600.687500 +498, -527575.500000 +499, -527550.375000 +500, -527524.000000 +501, -527498.812500 +502, -527473.625000 +503, -527448.500000 +504, -527423.375000 +505, -527398.250000 +506, -527373.125000 +507, -527346.750000 +508, -527321.625000 +509, -527296.500000 +510, -527271.312500 +511, -527246.250000 +512, -527221.125000 +513, -527196.062500 +514, -527169.687500 +515, -527144.562500 +516, -527119.437500 +517, -527094.375000 +518, -527069.250000 +519, -527044.187500 +520, -527019.062500 +521, -526992.812500 +522, -526967.687500 +523, -526942.625000 +524, -526917.562500 +525, -526892.437500 +526, -526867.375000 +527, -526842.312500 +528, -526816.062500 +529, -526790.937500 +530, -526765.937500 +531, -526740.812500 +532, -526715.812500 +533, -526690.687500 +534, -526665.625000 +535, -526640.562500 +536, -526614.375000 +537, -526589.375000 +538, -526564.312500 +539, -526539.250000 +540, -526514.250000 +541, -526489.250000 +542, -526464.187500 +543, -526438.000000 +544, -526413.000000 +545, -526387.937500 +546, -526362.937500 +547, -526337.937500 +548, -526312.937500 +549, -526287.937500 +550, -526261.750000 +551, -526236.750000 +552, -526211.750000 +553, -526186.750000 +554, -526161.750000 +555, -526136.750000 +556, -526111.750000 +557, -526085.687500 +558, -526060.687500 +559, -526035.687500 +560, -526010.750000 +561, -525985.750000 +562, -525960.750000 +563, -525935.750000 +564, -525910.812500 +565, -525884.750000 +566, -525859.812500 +567, -525834.812500 +568, -525809.875000 +569, -525784.937500 +570, -525760.000000 +571, -525735.000000 +572, -525709.000000 +573, -525684.062500 +574, -525659.125000 +575, -525634.187500 +576, -525609.250000 +577, -525584.312500 +578, -525559.375000 +579, -525533.437500 +580, -525508.562500 +581, -525483.625000 +582, -525458.625000 +583, -525433.750000 +584, -525408.875000 +585, -525383.937500 +586, -525358.000000 +587, -525333.062500 +588, -525308.187500 +589, -525283.312500 +590, -525258.375000 +591, -525233.437500 +592, -525208.625000 +593, -525182.687500 +594, -525157.812500 +595, -525132.937500 +596, -525108.000000 +597, -525083.187500 +598, -525058.312500 +599, -525033.437500 +600, -525007.562500 +601, -524982.687500 +602, -524957.812500 +603, -524932.937500 +604, -524908.125000 +605, -524883.250000 +606, -524858.437500 +607, -524832.562500 +608, -524807.750000 +609, -524782.875000 +610, -524758.062500 +611, -524733.250000 +612, -524708.375000 +613, -524683.562500 +614, -524658.750000 +615, -524632.937500 +616, -524608.125000 +617, -524583.312500 +618, -524558.500000 +619, -524533.687500 +620, -524508.875000 +621, -524484.062500 +622, -524458.250000 +623, -524433.500000 +624, -524408.687500 +625, -524383.875000 +626, -524359.125000 +627, -524334.375000 +628, -524309.500000 +629, -524283.781250 +630, -524259.031250 +631, -524234.250000 +632, -524209.500000 +633, -524184.718750 +634, -524159.937500 +635, -524135.187500 +636, -524110.437500 +637, -524084.687500 +638, -524059.937500 +639, -524035.187500 +640, -524010.406250 +641, -523985.656250 +642, -523960.968750 +643, -523936.218750 +644, -523910.531250 +645, -523885.781250 +646, -523861.031250 +647, -523836.312500 +648, -523811.625000 +649, -523786.843750 +650, -523762.187500 +651, -523736.562500 +652, -523711.812500 +653, -523687.062500 +654, -523662.406250 +655, -523637.656250 +656, -523613.031250 +657, -523588.312500 +658, -523562.656250 +659, -523537.968750 +660, -523513.281250 +661, -523488.625000 +662, -523463.906250 +663, -523439.250000 +664, -523414.531250 +665, -523388.968750 +666, -523364.250000 +667, -523339.656250 +668, -523314.968750 +669, -523290.250000 +670, -523265.593750 +671, -523241.000000 +672, -523215.406250 +673, -523190.750000 +674, -523166.125000 +675, -523141.500000 +676, -523116.781250 +677, -523092.187500 +678, -523067.562500 +679, -523042.031250 +680, -523017.406250 +681, -522992.750000 +682, -522968.125000 +683, -522943.468750 +684, -522918.906250 +685, -522894.281250 +686, -522868.750000 +687, -522844.156250 +688, -522819.562500 +689, -522794.937500 +690, -522770.343750 +691, -522745.750000 +692, -522721.156250 +693, -522696.531250 +694, -522671.093750 +695, -522646.500000 +696, -522621.906250 +697, -522597.343750 +698, -522572.781250 +699, -522548.187500 +700, -522523.593750 +701, -522498.156250 +702, -522473.593750 +703, -522449.031250 +704, -522424.500000 +705, -522399.906250 +706, -522375.343750 +707, -522350.843750 +708, -522325.437500 +709, -522300.843750 +710, -522276.312500 +711, -522251.812500 +712, -522227.250000 +713, -522202.687500 +714, -522178.156250 +715, -522153.625000 +716, -522128.281250 +717, -522103.750000 +718, -522079.187500 +719, -522054.718750 +720, -522030.218750 +721, -522005.656250 +722, -521981.156250 +723, -521955.781250 +724, -521931.343750 +725, -521906.812500 +726, -521882.343750 +727, -521857.843750 +728, -521833.312500 +729, -521808.843750 +730, -521783.531250 +731, -521759.000000 +732, -521734.531250 +733, -521710.062500 +734, -521685.625000 +735, -521661.125000 +736, -521636.687500 +737, -521611.406250 +738, -521586.937500 +739, -521562.500000 +740, -521538.000000 +741, -521513.562500 +742, -521489.093750 +743, -521464.625000 +744, -521439.375000 +745, -521414.968750 +746, -521390.500000 +747, -521366.062500 +748, -521341.656250 +749, -521317.218750 +750, -521292.781250 +751, -521267.562500 +752, -521243.156250 +753, -521218.718750 +754, -521194.281250 +755, -521169.906250 +756, -521145.468750 +757, -521121.093750 +758, -521095.843750 +759, -521071.468750 +760, -521047.062500 +761, -521022.718750 +762, -520998.281250 +763, -520973.906250 +764, -520949.531250 +765, -520924.343750 +766, -520899.968750 +767, -520875.593750 +768, -520851.187500 +769, -520826.781250 +770, -520802.468750 +771, -520778.093750 +772, -520753.687500 +773, -520728.593750 +774, -520704.218750 +775, -520679.875000 +776, -520655.531250 +777, -520631.187500 +778, -520606.812500 +779, -520582.468750 +780, -520557.375000 +781, -520533.000000 +782, -520508.687500 +783, -520484.343750 +784, -520460.031250 +785, -520435.687500 +786, -520411.375000 +787, -520386.312500 +788, -520361.968750 +789, -520337.687500 +790, -520313.343750 +791, -520289.031250 +792, -520264.718750 +793, -520240.437500 +794, -520216.156250 +795, -520191.093750 +796, -520166.781250 +797, -520142.468750 +798, -520118.218750 +799, -520093.906250 +800, -520069.593750 +801, -520045.312500 +802, -520020.375000 +803, -519996.031250 +804, -519971.781250 +805, -519947.468750 +806, -519923.250000 +807, -519899.000000 +808, -519874.718750 +809, -519849.718750 +810, -519825.500000 +811, -519801.218750 +812, -519776.968750 +813, -519752.718750 +814, -519728.468750 +815, -519704.218750 +816, -519679.281250 +817, -519655.062500 +818, -519630.781250 +819, -519606.531250 +820, -519582.375000 +821, -519558.125000 +822, -519533.906250 +823, -519508.968750 +824, -519484.750000 +825, -519460.562500 +826, -519436.312500 +827, -519412.093750 +828, -519387.906250 +829, -519363.687500 +830, -519338.781250 +831, -519314.625000 +832, -519290.437500 +833, -519266.250000 +834, -519242.062500 +835, -519217.875000 +836, -519193.687500 +837, -519168.781250 +838, -519144.625000 +839, -519120.437500 +840, -519096.250000 +841, -519072.125000 +842, -519048.000000 +843, -519023.812500 +844, -518998.968750 +845, -518974.750000 +846, -518950.656250 +847, -518926.468750 +848, -518902.343750 +849, -518878.187500 +850, -518854.031250 +851, -518829.906250 +852, -518805.093750 +853, -518780.937500 +854, -518756.812500 +855, -518732.718750 +856, -518708.593750 +857, -518684.468750 +858, -518660.375000 +859, -518635.562500 +860, -518611.406250 +861, -518587.343750 +862, -518563.218750 +863, -518539.125000 +864, -518515.000000 +865, -518490.906250 +866, -518466.125000 +867, -518442.031250 +868, -518417.968750 +869, -518393.875000 +870, -518369.781250 +871, -518345.687500 +872, -518321.625000 +873, -518297.562500 +874, -518272.812500 +875, -518248.718750 +876, -518224.687500 +877, -518200.625000 +878, -518176.562500 +879, -518152.531250 +880, -518128.468750 +881, -518103.750000 +882, -518079.656250 +883, -518055.656250 +884, -518031.625000 +885, -518007.562500 +886, -517983.531250 +887, -517959.500000 +888, -517934.812500 +889, -517910.750000 +890, -517886.718750 +891, -517862.718750 +892, -517838.687500 +893, -517814.687500 +894, -517790.656250 +895, -517766.000000 +896, -517741.968750 +897, -517717.968750 +898, -517693.968750 +899, -517670.000000 +900, -517646.000000 +901, -517622.000000 +902, -517597.312500 +903, -517573.375000 +904, -517549.343750 +905, -517525.375000 +906, -517501.375000 +907, -517477.468750 +908, -517453.468750 +909, -517428.843750 +910, -517404.875000 +911, -517380.937500 +912, -517356.937500 +913, -517333.000000 +914, -517309.000000 +915, -517285.062500 +916, -517260.500000 +917, -517236.562500 +918, -517212.625000 +919, -517188.625000 +920, -517164.718750 +921, -517140.750000 +922, -517116.875000 +923, -517092.281250 +924, -517068.312500 +925, -517044.406250 +926, -517020.468750 +927, -516996.562500 +928, -516972.687500 +929, -516948.718750 +930, -516924.812500 +931, -516900.281250 +932, -516876.406250 +933, -516852.500000 +934, -516828.562500 +935, -516804.687500 +936, -516780.781250 +937, -516756.906250 +938, -516732.406250 +939, -516708.500000 +940, -516684.625000 +941, -516660.750000 +942, -516636.875000 +943, -516613.031250 +944, -516589.125000 +945, -516564.625000 +946, -516540.781250 +947, -516516.906250 +948, -516493.062500 +949, -516469.187500 +950, -516445.343750 +951, -516421.468750 +952, -516397.625000 +953, -516373.125000 +954, -516349.343750 +955, -516325.500000 +956, -516301.625000 +957, -516277.812500 +958, -516253.968750 +959, -516230.125000 +960, -516205.687500 +961, -516181.875000 +962, -516158.093750 +963, -516134.250000 +964, -516110.437500 +965, -516086.593750 +966, -516062.812500 +967, -516038.406250 +968, -516014.593750 +969, -515990.812500 +970, -515967.031250 +971, -515943.187500 +972, -515919.437500 +973, -515895.625000 +974, -515871.218750 +975, -515847.437500 +976, -515823.687500 +977, -515799.906250 +978, -515776.156250 +979, -515752.343750 +980, -515728.625000 +981, -515704.187500 +982, -515680.468750 +983, -515656.718750 +984, -515632.906250 +985, -515609.187500 +986, -515585.406250 +987, -515561.687500 +988, -515537.375000 +989, -515513.625000 +990, -515489.875000 +991, -515466.125000 +992, -515442.406250 +993, -515418.687500 +994, -515394.937500 +995, -515370.656250 +996, -515346.906250 +997, -515323.156250 +998, -515299.437500 +999, -515275.750000 -- cgit 1.4.1 From 7f409708c3ca3e0af213efa4d6f8390b4f46f78e Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 1 Jan 2018 20:11:15 +0100 Subject: update --- src/c/lookup | Bin 0 -> 13200 bytes src/c/lookup.c | 74 +++++++++++++++++++++++++++++++++++++++ src/c/read | Bin 0 -> 12880 bytes src/c/read.c | 52 ++++++++++++++++++++++++++++ src/c/testFile.csv | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 226 insertions(+) create mode 100755 src/c/lookup create mode 100644 src/c/lookup.c create mode 100755 src/c/read create mode 100644 src/c/read.c create mode 100644 src/c/testFile.csv diff --git a/src/c/lookup b/src/c/lookup new file mode 100755 index 0000000..6a6368d Binary files /dev/null and b/src/c/lookup differ diff --git a/src/c/lookup.c b/src/c/lookup.c new file mode 100644 index 0000000..01b5508 --- /dev/null +++ b/src/c/lookup.c @@ -0,0 +1,74 @@ +#include +#include +#include + +// 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); + } +} diff --git a/src/c/read b/src/c/read new file mode 100755 index 0000000..97751d7 Binary files /dev/null and b/src/c/read differ diff --git a/src/c/read.c b/src/c/read.c new file mode 100644 index 0000000..109c603 --- /dev/null +++ b/src/c/read.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +// Define some constants +int range = 100; + +// Prototype pythagoras function +float pythagoras(int x, int y, int z); + +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 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 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])); + + } + + // 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; +} + +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; +} diff --git a/src/c/testFile.csv b/src/c/testFile.csv new file mode 100644 index 0000000..3568a06 --- /dev/null +++ b/src/c/testFile.csv @@ -0,0 +1,100 @@ +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 -- cgit 1.4.1 From eed019682e3d54334fbcb3b9a612086cfb9d4295 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 1 Jan 2018 20:48:48 +0100 Subject: merged the two files langfassung.c and read.c --- src/c/lookup | Bin 13200 -> 0 bytes src/c/lookup.c | 74 ---------------------------------------------------- src/c/read | Bin 12880 -> 13456 bytes src/c/read.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 74 deletions(-) delete mode 100755 src/c/lookup delete mode 100644 src/c/lookup.c diff --git a/src/c/lookup b/src/c/lookup deleted file mode 100755 index 6a6368d..0000000 Binary files a/src/c/lookup and /dev/null differ diff --git a/src/c/lookup.c b/src/c/lookup.c deleted file mode 100644 index 01b5508..0000000 --- a/src/c/lookup.c +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -#include - -// 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); - } -} diff --git a/src/c/read b/src/c/read index 97751d7..9724dee 100755 Binary files a/src/c/read and b/src/c/read differ diff --git a/src/c/read.c b/src/c/read.c index 109c603..48ece4b 100644 --- a/src/c/read.c +++ b/src/c/read.c @@ -6,8 +6,21 @@ // 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 @@ -20,6 +33,10 @@ int main(int argc, char *argv[] ){ // 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; @@ -27,6 +44,10 @@ int main(int argc, char *argv[] ){ 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]); @@ -34,6 +55,45 @@ int main(int argc, char *argv[] ){ } + /* + 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 @@ -42,6 +102,7 @@ int main(int argc, char *argv[] ){ return 0; } +// Define the Pythagorean theorem float pythagoras(int x, int y, int z){ float a = pow(x, 2); float b = pow(y, 2); @@ -50,3 +111,23 @@ float pythagoras(int x, int y, int z){ 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); + } +} -- cgit 1.4.1