123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #include <algorithm>
- #include <complex>
- #include <functional>
- #include <iostream>
- #include <stdexcept>
- #include <string>
- #include <vector>
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <string.h>
- #include "nmie.h"
- const double PI=3.14159265358979323846;
- int main(int argc, char *argv[]) {
- try {
- char comment[200];
- int has_comment = 0;
- int i, l, L;
- std::vector<double> x, Theta;
- std::vector<std::complex<double> > m, S1, S2;
- double Qext, Qabs, Qsca, Qbk, Qpr, g, Albedo;
- double ti = 0.0, tf = 90.0;
- int nt = 0;
-
- if (argc < 5) {
- printf("Insufficient parameters.\n");
- printf("Usage: %s -l Layers x1 m1.r m1.i [x2 m2.r m2.i ...] [-t ti tf nt] [-c comment]\n", argv[0]);
- return -1;
- }
-
- strcpy(comment, "");
- for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-l") == 0) {
- i++;
- L = atoi(argv[i]);
- x.resize(L);
- m.resize(L);
- if (argc < 3*(L + 1)) {
- printf("Insufficient parameters.\nUsage: %s -l Layers x1 m1.r m1.i [x2 m2.r m2.i ...] [-t ti tf nt] [-c comment]\n", argv[0]);
- return -1;
- } else {
- for (l = 0; l < L; l++) {
- i++;
- x[l] = atof(argv[i]);
- i++;
- m[l] = std::complex<double>(atof(argv[i]), atof(argv[i + 1]));
- i++;
- }
- }
- } else if (strcmp(argv[i], "-t") == 0) {
- i++;
- ti = atof(argv[i]);
- i++;
- tf = atof(argv[i]);
- i++;
- nt = atoi(argv[i]);
- Theta.resize(nt);
- S1.resize(nt);
- S2.resize(nt);
- } else if (strcmp(argv[i], "-c") == 0) {
- i++;
- strcpy(comment, argv[i]);
- has_comment = 1;
- } else { i++; }
- }
-
- if (nt < 0) {
- printf("Error reading Theta.\n");
- return -1;
- } else if (nt == 1) {
- Theta[0] = ti*PI/180.0;
- } else {
- for (i = 0; i < nt; i++) {
- Theta[i] = (ti + (double)i*(tf - ti)/(nt - 1))*PI/180.0;
- }
- }
- nMie(L, x, m, nt, Theta, &Qext, &Qsca, &Qabs, &Qbk, &Qpr, &g, &Albedo, S1, S2);
- if (has_comment) {
- printf("%6s, %+.5e, %+.5e, %+.5e, %+.5e, %+.5e, %+.5e, %+.5e\n", comment, Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo);
- } else {
- printf("%+.5e, %+.5e, %+.5e, %+.5e, %+.5e, %+.5e, %+.5e\n", Qext, Qsca, Qabs, Qbk, Qpr, g, Albedo);
- }
-
- if (nt > 0) {
- printf(" Theta, S1.r, S1.i, S2.r, S2.i\n");
-
- for (i = 0; i < nt; i++) {
- printf("%6.2f, %+.5e, %+.5e, %+.5e, %+.5e\n", Theta[i]*180.0/PI, S1[i].real(), S1[i].imag(), S2[i].real(), S2[i].imag());
- }
- }
- } catch( const std::invalid_argument& ia ) {
-
- std::cerr << "Invalid argument: " << ia.what() << std::endl;
- return -1;
- }
- return 0;
- }
|