gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 5834186 2/2: CosmicCalculator: new --lineatz f


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5834186 2/2: CosmicCalculator: new --lineatz for the wavelength of a line at z
Date: Fri, 9 Aug 2019 14:45:25 -0400 (EDT)

branch: master
commit 583418642356dd3ade54961bd7871ead4a056dd4
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    CosmicCalculator: new --lineatz for the wavelength of a line at z
    
    With this commit, CosmicCalculator has a new option to return the
    wavelength of the given line (as a name/string, or number) at the given
    redshift.
---
 NEWS                      |  5 +++++
 bin/cosmiccal/args.h      | 15 ++++++++++++++
 bin/cosmiccal/cosmiccal.c |  4 ++++
 bin/cosmiccal/main.h      |  1 +
 bin/cosmiccal/ui.c        | 52 +++++++++++++++++++++++++++++++++++++----------
 bin/cosmiccal/ui.h        |  3 ++-
 doc/gnuastro.texi         |  9 ++++++++
 7 files changed, 77 insertions(+), 12 deletions(-)

diff --git a/NEWS b/NEWS
index 88a21c8..e96b712 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,11 @@ See the end of the file for license conditions.
 
 ** New features
 
+  CosmicCalculator:
+   --lineatz: return the observed wavelength of a line if it was emitted at
+     the redshift given to CosmicCalculator. You can either use known line
+     names, or directly give a number as any emitted line's wavelength.
+
 ** Removed features
 
 ** Changed features
diff --git a/bin/cosmiccal/args.h b/bin/cosmiccal/args.h
index d241ca0..1876746 100644
--- a/bin/cosmiccal/args.h
+++ b/bin/cosmiccal/args.h
@@ -301,6 +301,21 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET,
       ui_add_to_single_value,
     },
+    {
+      "lineatz",
+      UI_KEY_LINEATZ,
+      "STR/FLT",
+      0,
+      "Wavelength of given line at chosen redshift",
+      UI_GROUP_SPECIFIC,
+      &p->specific,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_add_to_single_value,
+    },
+
 
 
     {0}
diff --git a/bin/cosmiccal/cosmiccal.c b/bin/cosmiccal/cosmiccal.c
index 9d52a29..a7d665f 100644
--- a/bin/cosmiccal/cosmiccal.c
+++ b/bin/cosmiccal/cosmiccal.c
@@ -255,6 +255,10 @@ cosmiccal(struct cosmiccalparams *p)
                                                         p->oradiation));
             break;
 
+          case UI_KEY_LINEATZ:
+            printf("%g ", gal_list_f64_pop(&p->specific_arg)*(1+p->redshift));
+            break;
+
           default:
             error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to "
                   "fix the problem. The code %d is not recognized as a "
diff --git a/bin/cosmiccal/main.h b/bin/cosmiccal/main.h
index 958a8db..0801aa6 100644
--- a/bin/cosmiccal/main.h
+++ b/bin/cosmiccal/main.h
@@ -55,6 +55,7 @@ struct cosmiccalparams
 
   /* Outputs. */
   gal_list_i32_t     *specific; /* Codes for single row calculations.   */
+  gal_list_f64_t *specific_arg; /* Possible arguments for single calcs. */
 
   /* Internal: */
   time_t               rawtime; /* Starting time of the program.        */
diff --git a/bin/cosmiccal/ui.c b/bin/cosmiccal/ui.c
index a4316d9..0340ae7 100644
--- a/bin/cosmiccal/ui.c
+++ b/bin/cosmiccal/ui.c
@@ -200,6 +200,10 @@ static void *
 ui_add_to_single_value(struct argp_option *option, char *arg,
                       char *filename, size_t lineno, void *params)
 {
+  int linecode;
+  double *dptr, val=NAN;
+  struct cosmiccalparams *p = (struct cosmiccalparams *)params;
+
   /* In case of printing the option values. */
   if(lineno==-1)
     error(EXIT_FAILURE, 0, "currently the options to be printed in one row "
@@ -212,18 +216,43 @@ ui_add_to_single_value(struct argp_option *option, char 
*arg,
 
   /* If this option is given in a configuration file, then `arg' will not
      be NULL and we don't want to do anything if it is `0'. */
-  if(arg)
+  switch(option->key)
     {
-      /* Make sure the value is only `0' or `1'. */
-      if( arg[1]!='\0' && *arg!='0' && *arg!='1' )
-        error_at_line(EXIT_FAILURE, 0, filename, lineno, "the `--%s' "
-                      "option takes no arguments. In a configuration "
-                      "file it can only have the values `1' or `0', "
-                      "indicating if it should be used or not",
-                      option->name);
-
-      /* Only proceed if the (possibly given) argument is 1. */
-      if(arg[0]=='0' && arg[1]=='\0') return NULL;
+    /* Options with arguments. */
+    case UI_KEY_LINEATZ:
+      /* Make sure an argument is given. */
+      if(arg==NULL)
+        error(EXIT_FAILURE, 0, "option `--lineatz' needs an argument");
+
+      /* If the argument is a number, read it, if not, see if its a known
+         specral line name. */
+      dptr=&val;
+      if( gal_type_from_string((void **)(&dptr), arg, GAL_TYPE_FLOAT64) )
+        {
+          linecode=gal_speclines_line_code(arg);
+          if(linecode==GAL_SPECLINES_INVALID)
+            error(EXIT_FAILURE, 0, "`%s' not a known spectral line name",
+                  arg);
+          val=gal_speclines_line_angstrom(linecode);
+        }
+      gal_list_f64_add(&p->specific_arg, val);
+      break;
+
+    /* Options without arguments. */
+    default:
+      if(arg)
+        {
+          /* Make sure the value is only `0' or `1'. */
+          if( arg[1]!='\0' && *arg!='0' && *arg!='1' )
+            error_at_line(EXIT_FAILURE, 0, filename, lineno, "the `--%s' "
+                          "option takes no arguments. In a configuration "
+                          "file it can only have the values `1' or `0', "
+                          "indicating if it should be used or not",
+                          option->name);
+
+          /* Only proceed if the (possibly given) argument is 1. */
+          if(arg[0]=='0' && arg[1]=='\0') return NULL;
+        }
     }
 
   /* Add this option to the print list and return. */
@@ -409,6 +438,7 @@ ui_preparations(struct cosmiccalparams *p)
      control reaches here, the list is finalized. So we should just reverse
      it so the user gets values in the same order they requested them. */
   gal_list_i32_reverse(&p->specific);
+  gal_list_f64_reverse(&p->specific_arg);
 }
 
 
diff --git a/bin/cosmiccal/ui.h b/bin/cosmiccal/ui.h
index dcc57f9..0b36e52 100644
--- a/bin/cosmiccal/ui.h
+++ b/bin/cosmiccal/ui.h
@@ -42,7 +42,7 @@ enum program_args_groups
 
 /* Available letters for short options:
 
-   f i j k n p t w x y
+   f j k n p t w x y
    B E J Q R W X Y
 */
 enum option_keys_enum
@@ -68,6 +68,7 @@ enum option_keys_enum
   UI_KEY_LOOKBACKTIME        = 'b',
   UI_KEY_CRITICALDENSITY     = 'c',
   UI_KEY_VOLUME              = 'v',
+  UI_KEY_LINEATZ             = 'i',
 
   /* Only with long version (start with a value 1000, the rest will be set
      automatically). */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index d5cc3bd..fb8fc3f 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -23242,6 +23242,15 @@ The critical density at given redshift in grams per 
centimeter-cube
 The comoving volume in Megaparsecs cube (Mpc@mymath{^3}) until the desired
 redshift based on the input parameters.
 
+@item -i STR/FLT
+@itemx --lineatz=STR/FLT
+The wavelength of the specified line at the redshift given to
+CosmicCalculator. The line can be specified either by its inside Gnuastro
+(see description of @option{--obsline} in @ref{CosmicCalculator input
+options}), or directly as a number. In the former case (when a name is
+given), the units are in Angstroms. In the latter (when a number is given),
+its the same units of the given number.
+
 @end table
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]