summaryrefslogtreecommitdiff
path: root/src/odutils/refl.c
diff options
context:
space:
mode:
authoradmin <contact@optics-design.com>2025-04-25 21:17:07 +0200
committeradmin <contact@optics-design.com>2025-04-25 21:17:07 +0200
commit4b3b08ecadf8604062c7f801668e641cb024e309 (patch)
tree93614c08b9cfabff25e5c790fcfd50d31663ef53 /src/odutils/refl.c
First Commit
Diffstat (limited to 'src/odutils/refl.c')
-rw-r--r--src/odutils/refl.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/odutils/refl.c b/src/odutils/refl.c
new file mode 100644
index 0000000..dc5c205
--- /dev/null
+++ b/src/odutils/refl.c
@@ -0,0 +1,39 @@
+/**
+ * refl.c - source file for just testing basic optics-related functions.
+ *
+ * Copyright (C) 2025 https://optics-design.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * See the COPYING file for the full license text.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+int main(int argc, char *argv[]) {
+ if (argc != 4){
+ printf("This program calculates the reflection losses and transmission through nsurfs number of surfaces.\n The program is called either with parameters n1 n2 nsurfs and uses the formula Losses = (((n2-n1)/(n2+n1))**2)**nsurfs.");
+ return 1;
+ }
+ char *pn1, *pn2;
+ float n1,n2;
+ int nsurfs;
+ float singsurfrefl;
+
+ n1 = strtof(argv[1], &pn1);
+ n2 = strtof(argv[2], &pn2);
+ nsurfs = atoi(argv[3]);
+ // nsurfs = strtof(argv[3], &pnsurfs);
+ if ( *pn1||*pn2||!nsurfs) {
+ printf("Error! You did not provide n1 n2 nsurfs as numbers.");
+ return 1;
+ }
+ singsurfrefl = pow((n2-n1)/(n2+n1),2);
+
+ printf("Single Surface Loss: %.2f%\nSingle Surface Transmission:%.2f%\n%d-Surface Loss:%.2f%\n%d-Surface Transmission:%.2f%\n",100*singsurfrefl,100*(1-singsurfrefl),nsurfs,100*(1-pow(1-singsurfrefl,nsurfs)),nsurfs,100*pow(1-singsurfrefl,nsurfs));
+ return 0;
+}
Back to https://optics-design.com