gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b553085 01/16: Template for creating a new uti


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b553085 01/16: Template for creating a new utility added
Date: Wed, 24 Aug 2016 22:27:43 +0000 (UTC)

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

    Template for creating a new utility added
    
    All the utilities share the same basic source code and general options
    structure. Until now, to add new utilities we would have to copy the files
    of an existing utility and change all the relevant parts (the HEADER
    utility was arguably the easiest).
    
    To make things more clear and easy, a new `src/TEMPLATE' directory was
    added which contains only the bare essentials of a utility. Any where that
    we have to deal with the utility name, the word `TEMPLATE' is used. This
    makes it really easy to start working on a new utility. It can also help
    new developers see the bare minimum structure and start developing faster.
---
 Makefile.am                   |   20 ++-
 configure.ac                  |   13 +-
 src/TEMPLATE/Makefile.am      |   40 +++++
 src/TEMPLATE/TEMPLATE.c       |   52 +++++++
 src/TEMPLATE/TEMPLATE.h       |   39 +++++
 src/TEMPLATE/args.h           |  220 +++++++++++++++++++++++++++
 src/TEMPLATE/astTEMPLATE.conf |   23 +++
 src/TEMPLATE/cite.h           |   48 ++++++
 src/TEMPLATE/main.c           |   66 ++++++++
 src/TEMPLATE/main.h           |   71 +++++++++
 src/TEMPLATE/ui.c             |  336 +++++++++++++++++++++++++++++++++++++++++
 src/TEMPLATE/ui.h             |   42 ++++++
 12 files changed, 964 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index aeab85b..1559349 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -88,14 +88,24 @@ endif
 if COND_SUBTRACTSKY
   MAYBE_SUBTRACTSKY = src/subtractsky
 endif
+#if COND_TEMPLATE
+#  MAYBE_TEMPLATE = src/TEMPLATE
+#endif
 if COND_GNULIBCHECK
   MAYBE_GNULIBCHECK = bootstrapped/tests
 endif
-SUBDIRS = bootstrapped/lib $(MAYBE_GNULIBCHECK) lib $(MAYBE_ARITHMETIC)    \
-$(MAYBE_CONVERTT) $(MAYBE_CONVOLVE) $(MAYBE_COSMICCAL) $(MAYBE_HEADER)    \
-$(MAYBE_IMGCROP) $(MAYBE_IMGSTAT) $(MAYBE_IMGWARP) $(MAYBE_MKCATALOG)     \
-$(MAYBE_MKNOISE) $(MAYBE_MKPROF) $(MAYBE_NOISECHISEL) $(MAYBE_SUBTRACTSKY) \
-doc tests
+
+# Note that by default `COND_TEMPLATE' is not set in configure, it is
+# commented, and exists only as a template for you to copy and paste to
+# name your new utility. The same rule is applied here (in the `if'
+# conditions above). When `MAYBE_TEMPLATE' is not defined, then Make
+# will see it as a blank string and igonore it, so there is no problem with
+# having an uncommented `MAYBE_TEMPLATE' as a value in `SUBDIRS'.
+SUBDIRS = bootstrapped/lib $(MAYBE_GNULIBCHECK) lib $(MAYBE_ARITHMETIC)     \
+$(MAYBE_CONVERTT) $(MAYBE_CONVOLVE) $(MAYBE_COSMICCAL) $(MAYBE_HEADER)      \
+$(MAYBE_IMGCROP) $(MAYBE_IMGSTAT) $(MAYBE_IMGWARP) $(MAYBE_MKCATALOG)       \
+$(MAYBE_MKNOISE) $(MAYBE_MKPROF) $(MAYBE_NOISECHISEL) $(MAYBE_SUBTRACTSKY)  \
+$(MAYBE_TEMPLATE) doc tests
 
 
 
diff --git a/configure.ac b/configure.ac
index be27df7..33b40cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -303,6 +303,12 @@ AC_ARG_ENABLE([subtractsky],
              [AS_IF([test "x$enable_subtractsky" != xno],
                      [enable_subtractsky=yes; ayes=true])],
               [enable_subtractsky=notset])
+#AC_ARG_ENABLE([TEMPLATE],
+#              [AS_HELP_STRING([--enable-TEMPLATE],
+#                  [Install TEMPLATE and other enabled packages only.])],
+#            [AS_IF([test "x$enable_TEMPLATE" != xno],
+#                     [enable_TEMPLATE=yes; ayes=true])],
+#              [enable_TEMPLATE=notset])
 
 
 
@@ -331,6 +337,7 @@ AS_IF([test $ayes = true ],
        AS_IF([test $enable_mkprof = notset], [enable_mkprof=no])
        AS_IF([test $enable_noisechisel = notset], [enable_noisechisel=no])
        AS_IF([test $enable_subtractsky = notset], [enable_subtractsky=no])
+#      AS_IF([test $enable_TEMPLATE = notset], [enable_TEMPLATE=no])
        ],
 
       [AS_IF([test $enable_convertt = notset], [enable_convertt=yes])
@@ -346,6 +353,7 @@ AS_IF([test $ayes = true ],
        AS_IF([test $enable_mkprof = notset], [enable_mkprof=yes])
        AS_IF([test $enable_noisechisel = notset], [enable_noisechisel=yes])
        AS_IF([test $enable_subtractsky = notset], [enable_subtractsky=yes])
+#      AS_IF([test $enable_TEMPLATE = notset], [enable_TEMPLATE=yes])
        ]
      )
 
@@ -367,12 +375,15 @@ AM_CONDITIONAL([COND_MKNOISE], [test $enable_mknoise = 
yes])
 AM_CONDITIONAL([COND_MKPROF], [test $enable_mkprof = yes])
 AM_CONDITIONAL([COND_NOISECHISEL], [test $enable_noisechisel = yes])
 AM_CONDITIONAL([COND_SUBTRACTSKY], [test $enable_subtractsky = yes])
+#AM_CONDITIONAL([COND_TEMPLATE], [test $enable_TEMPLATE = yes])
 
 
 
 
 
-# Tell autoconf what to work on:
+# Tell autoconf what to work on: TEMPLATE cannot be put and then
+# commented here like the cases above, so don't forget to add your new
+# utility name here.
 AC_CONFIG_FILES([Makefile
                  doc/Makefile
                  lib/Makefile
diff --git a/src/TEMPLATE/Makefile.am b/src/TEMPLATE/Makefile.am
new file mode 100644
index 0000000..29fecb6
--- /dev/null
+++ b/src/TEMPLATE/Makefile.am
@@ -0,0 +1,40 @@
+## Process this file with automake to produce Makefile.inx
+##
+## Original author:
+##          Your name <address@hidden>
+## Contributing author(s):
+## Copyright (C) YYYY, Free Software Foundation, Inc.
+##
+## Gnuastro is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Gnuastro is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+
+
+
+
+
+## Utility and its sources
+bin_PROGRAMS = astTEMPLATE
+
+astTEMPLATE_SOURCES = main.c main.h cite.h ui.c ui.h args.h    \
+TEMPLATE.c TEMPLATE.h
+
+astTEMPLATE_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la         \
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist
+
+
+
+
+
+# To destribute the defaults file.
+# NOTE: the man page is created in doc/Makefile.am
+dist_sysconf_DATA = asttable.conf
diff --git a/src/TEMPLATE/TEMPLATE.c b/src/TEMPLATE/TEMPLATE.c
new file mode 100644
index 0000000..ba567e9
--- /dev/null
+++ b/src/TEMPLATE/TEMPLATE.c
@@ -0,0 +1,52 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <gnuastro/fits.h>
+#include <gnuastro/linkedlist.h>
+
+#include "main.h"
+
+
+
+void
+TEMPLATE(struct TEMPLATEparams *p)
+{
+
+}
diff --git a/src/TEMPLATE/TEMPLATE.h b/src/TEMPLATE/TEMPLATE.h
new file mode 100644
index 0000000..823db66
--- /dev/null
+++ b/src/TEMPLATE/TEMPLATE.h
@@ -0,0 +1,39 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef TEMPLATE_H
+#define TEMPLATE_H
+
+void
+TEMPLATE(struct TEMPLATEparams *p);
+
+#endif
diff --git a/src/TEMPLATE/args.h b/src/TEMPLATE/args.h
new file mode 100644
index 0000000..288aaf9
--- /dev/null
+++ b/src/TEMPLATE/args.h
@@ -0,0 +1,220 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef ARGS_H
+#define ARGS_H
+
+#include <argp.h>
+
+#include <gnuastro/commonargs.h>
+#include <gnuastro/linkedlist.h>
+#include <gnuastro/fixedstringmacros.h>
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/**************        argp.h definitions       ***************/
+/**************************************************************/
+
+
+
+
+/* Definition parameters for the argp: */
+const char *argp_program_version=SPACK_STRING"\n"GAL_STRINGS_COPYRIGHT
+  "\n\nWritten by Mohammad Akhlaghi";
+const char *argp_program_bug_address=PACKAGE_BUGREPORT;
+static char args_doc[] = "ASTRdata";
+
+
+
+
+
+const char doc[] =
+  /* Before the list of options: */
+  GAL_STRINGS_TOP_HELP_INFO
+  SPACK_NAME" description, add a description here. \n"
+  GAL_STRINGS_MORE_HELP_INFO
+  /* After the list of options: */
+  "\v"
+  PACKAGE_NAME" home page: "PACKAGE_URL;
+
+
+
+
+
+/* Available letters for short options:
+
+   a b c d e f g i j k l m n p r s t u v w x y z
+   A B C E F G H I J L M O Q R T U W X Y Z
+
+   Number keys used: Nothing!
+
+   Options with keys (second structure element) larger than 500 do not
+   have a short version.
+ */
+static struct argp_option options[] =
+  {
+    {
+      0, 0, 0, 0,
+      "Input:",
+      1
+    },
+
+
+
+
+    {
+      0, 0, 0, 0,
+      "Output:",
+      2
+    },
+
+
+
+    {
+      0, 0, 0, 0,
+      "Operating modes:",
+      -1
+    },
+
+
+    {0}
+  };
+
+
+
+
+
+/* Parse a single option: */
+static error_t
+parse_opt(int key, char *arg, struct argp_state *state)
+{
+  /* Save the arguments structure: */
+  struct TEMPLATEparams *p = state->input;
+
+  /* Set the pointer to the common parameters for all programs
+     here: */
+  state->child_inputs[0]=&p->cp;
+
+  /* In case the user incorrectly uses the equal sign (for example
+     with a short format or with space in the long format, then `arg`
+     start with (if the short version was called) or be (if the long
+     version was called with a space) the equal sign. So, here we
+     check if the first character of arg is the equal sign, then the
+     user is warned and the program is stopped: */
+  if(arg && arg[0]=='=')
+    argp_error(state, "incorrect use of the equal sign (`=`). For short "
+               "options, `=` should not be used and for long options, "
+               "there should be no space between the option, equal sign "
+               "and value");
+
+  switch(key)
+    {
+
+
+    /* Input: */
+
+
+    /* Output: */
+
+
+    /* Operating modes: */
+
+
+    /* Read the non-option arguments: */
+    case ARGP_KEY_ARG:
+
+      /* See what type of input value it is and put it in. */
+      if( gal_fits_name_is_fits(arg) )
+        {
+          if(p->up.inputname)
+            argp_error(state, "only one input image should be given");
+          else
+            p->up.inputname=arg;
+        }
+      else
+        argp_error(state, "%s is not a valid file type", arg);
+      break;
+
+
+
+
+
+    /* The command line options and arguments are finished. */
+    case ARGP_KEY_END:
+      if(p->cp.setdirconf==0 && p->cp.setusrconf==0
+         && p->cp.printparams==0)
+        {
+          if(state->arg_num==0)
+            argp_error(state, "no argument given");
+          if(p->up.inputname==NULL)
+            argp_error(state, "no input FITS image(s) provided");
+        }
+      break;
+
+
+
+
+
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+
+
+
+
+/* Specify the children parsers: */
+struct argp_child children[]=
+  {
+    {&commonargp, 0, NULL, 0},
+    {0, 0, 0, 0}
+  };
+
+
+
+
+
+/* Basic structure defining the whole argument reading process. */
+static struct argp thisargp = {options, parse_opt, args_doc,
+                               doc, children, NULL, NULL};
+
+#endif
diff --git a/src/TEMPLATE/astTEMPLATE.conf b/src/TEMPLATE/astTEMPLATE.conf
new file mode 100644
index 0000000..2fef1e9
--- /dev/null
+++ b/src/TEMPLATE/astTEMPLATE.conf
@@ -0,0 +1,23 @@
+# Default parameters (System) for TEMPLATE.
+# TEMPLATE is part of GNU Astronomy Utitlies.
+#
+# Use the long option name of each paramter followed by
+# a value. The name and value should be separated by
+# atleast one of the following charaacters:
+# space, `,`, `=` or `:`
+#
+# Run with `--help` option or read the manual for a full
+# explanation of what each option means.
+#
+# NOTE I:  All counting is from zero, not one.
+# NOTE II: Lines starting with `#` are ignored.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+# Input:
+ hdu            0
+
+# Output:
\ No newline at end of file
diff --git a/src/TEMPLATE/cite.h b/src/TEMPLATE/cite.h
new file mode 100644
index 0000000..c57e149
--- /dev/null
+++ b/src/TEMPLATE/cite.h
@@ -0,0 +1,48 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef CITE_H
+#define CITE_H
+
+#define TEMPLATEBIBTEX ""
+
+#define PRINTCITEABORT {                                                \
+    printf("\nWe hope %s has been useful for your research.\n"          \
+           "Citations are vital for the continued work on %s.\n"        \
+           "Thank you for citing it in your research paper.\n"          \
+           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
+           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
+           GAL_STRINGS_MAIN_BIBTEX, TEMPLATEBIBTEX);                    \
+    exit(EXIT_SUCCESS);                                                 \
+  }
+
+#endif
diff --git a/src/TEMPLATE/main.c b/src/TEMPLATE/main.c
new file mode 100644
index 0000000..7492955
--- /dev/null
+++ b/src/TEMPLATE/main.c
@@ -0,0 +1,66 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <progname.h>
+
+#include <gnuastro/timing.h>    /* Includes time.h and sys/time.h */
+
+#include "main.h"
+
+#include "ui.h"                 /* needs main.h.                  */
+#include "TEMPLATE.h"           /* needs main.h.                  */
+
+int
+main (int argc, char *argv[])
+{
+  struct TEMPLATEparams p={{0}, {0}, 0};
+
+  /* Set the program name (needed by non-gnu operating systems): */
+  time(&p.rawtime);
+  set_program_name(argv[0]);
+
+  /* Read the input parameters. */
+  setparams(argc, argv, &p);
+
+  /* Run MakeProfiles */
+  TEMPLATE(&p);
+
+  /* Free all non-freed allocations. */
+  freeandreport(&p);
+
+  /* Return successfully.*/
+  return EXIT_SUCCESS;
+}
diff --git a/src/TEMPLATE/main.h b/src/TEMPLATE/main.h
new file mode 100644
index 0000000..4ebd0f5
--- /dev/null
+++ b/src/TEMPLATE/main.h
@@ -0,0 +1,71 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef MAIN_H
+#define MAIN_H
+
+#include <gnuastro/fits.h>
+#include <gnuastro/commonparams.h>
+
+/* Progarm name macros: */
+#define SPACK           "astTEMPLATE" /* Subpackage executable name. */
+#define SPACK_NAME      "TEMPLATE"    /* Subpackage full name.       */
+#define SPACK_STRING    SPACK_NAME" ("PACKAGE_NAME") "PACKAGE_VERSION
+
+
+
+
+
+
+struct uiparams
+{
+  char                     *inputname;  /* Name of input file.             */
+};
+
+
+
+
+
+struct TEMPLATEparams
+{
+  /* Other structures: */
+  struct uiparams          up;  /* User interface parameters.         */
+  struct gal_commonparams  cp;  /* Common parameters.                 */
+
+  /* Input: */
+
+
+  /* Internal: */
+  time_t              rawtime;  /* Starting time of the program.      */
+};
+
+#endif
diff --git a/src/TEMPLATE/ui.c b/src/TEMPLATE/ui.c
new file mode 100644
index 0000000..2f8352a
--- /dev/null
+++ b/src/TEMPLATE/ui.c
@@ -0,0 +1,336 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) YYYY, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <math.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fitsio.h>
+
+#include <nproc.h>               /* From Gnulib.                   */
+
+#include <gnuastro/fits.h>
+#include <gnuastro/timing.h>     /* Includes time.h and sys/time.h */
+#include <gnuastro/checkset.h>
+#include <gnuastro/txtarray.h>
+#include <gnuastro/commonargs.h>
+#include <gnuastro/configfiles.h>
+
+#include "main.h"
+
+#include "ui.h"                  /* Needs main.h                   */
+#include "args.h"                /* Needs main.h, includes argp.h. */
+
+
+/* Set the file names of the places where the default parameters are
+   put. */
+#define CONFIG_FILE SPACK CONF_POSTFIX
+#define SYSCONFIG_FILE SYSCONFIG_DIR "/" CONFIG_FILE
+#define USERCONFIG_FILEEND USERCONFIG_DIR CONFIG_FILE
+#define CURDIRCONFIG_FILE CURDIRCONFIG_DIR CONFIG_FILE
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/**************       Options and parameters    ***************/
+/**************************************************************/
+void
+readconfig(char *filename, struct TEMPLATEparams *p)
+{
+  FILE *fp;
+  size_t lineno=0, len=200;
+  char *line, *name, *value;
+  /*struct uiparams *up=&p->up;*/
+  struct gal_commonparams *cp=&p->cp;
+  char key='a';        /* Not used, just a place holder. */
+
+  /* When the file doesn't exist or can't be opened, it is ignored. It
+     might be intentional, so there is no error. If a parameter is
+     missing, it will be reported after all defaults are read. */
+  fp=fopen(filename, "r");
+  if (fp==NULL) return;
+
+
+  /* Allocate some space for `line` with `len` elements so it can
+     easily be freed later on. The value of `len` is arbitarary at
+     this point, during the run, getline will change it along with the
+     pointer to line. */
+  errno=0;
+  line=malloc(len*sizeof *line);
+  if(line==NULL)
+    error(EXIT_FAILURE, errno, "ui.c: %lu bytes in readdefaults",
+          len * sizeof *line);
+
+  /* Read the tokens in the file:  */
+  while(getline(&line, &len, fp) != -1)
+    {
+      /* Prepare the "name" and "value" strings, also set lineno. */
+      GAL_CONFIGFILES_START_READING_LINE;
+
+
+
+
+      /* Inputs: */
+      if(strcmp(name, "hdu")==0)
+        {
+          if(cp->hduset) continue;
+          errno=0;
+          cp->hdu=malloc(strlen(value)+1);
+          if(cp->hdu==NULL)
+            error(EXIT_FAILURE, errno, "space for HDU");
+          strcpy(cp->hdu, value);
+          cp->hduset=1;
+        }
+
+
+
+      /* Outputs */
+
+
+
+
+      /* Operating modes: */
+      /* Read options common to all programs */
+      GAL_CONFIGFILES_READ_COMMONOPTIONS_FROM_CONF
+
+
+      else
+        error_at_line(EXIT_FAILURE, 0, filename, lineno,
+                      "`%s` not recognized.\n", name);
+    }
+
+  free(line);
+  fclose(fp);
+}
+
+
+
+
+
+void
+printvalues(FILE *fp, struct TEMPLATEparams *p)
+{
+  /*struct uiparams *up=&p->up;*/
+  struct gal_commonparams *cp=&p->cp;
+
+
+  /* Print all the options that are set. Separate each group with a
+     commented line explaining the options in that group. */
+  fprintf(fp, "\n# Input image:\n");
+  if(cp->hduset)
+    GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("hdu", cp->hdu);
+
+
+  /* For the operating mode, first put the macro to print the common
+     options, then the (possible options particular to this
+     program). */
+  fprintf(fp, "\n# Operating mode:\n");
+  GAL_CONFIGFILES_PRINT_COMMONOPTIONS;
+}
+
+
+
+
+
+
+/* Note that numthreads will be used automatically based on the
+   configure time. */
+void
+checkifset(struct TEMPLATEparams *p)
+{
+  /*struct uiparams *up=&p->up;*/
+  struct gal_commonparams *cp=&p->cp;
+
+  int intro=0;
+  if(cp->hduset==0)
+    GAL_CONFIGFILES_REPORT_NOTSET("hdu");
+
+
+  GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/***************       Sanity Check         *******************/
+/**************************************************************/
+void
+sanitycheck(struct TEMPLATEparams *p)
+{
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/***************       Preparations         *******************/
+/**************************************************************/
+void
+preparearrays(struct TEMPLATEparams *p)
+{
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************         Set the parameters          *************/
+/**************************************************************/
+void
+setparams(int argc, char *argv[], struct TEMPLATEparams *p)
+{
+  struct gal_commonparams *cp=&p->cp;
+
+  /* Set the non-zero initial values, the structure was initialized to
+     have a zero value for all elements. */
+  cp->spack         = SPACK;
+  cp->verb          = 1;
+  cp->numthreads    = num_processors(NPROC_CURRENT);
+  cp->removedirinfo = 1;
+
+  /* Read the arguments. */
+  errno=0;
+  if(argp_parse(&thisargp, argc, argv, 0, 0, p))
+    error(EXIT_FAILURE, errno, "parsing arguments");
+
+  /* Add the user default values and save them if asked. */
+  GAL_CONFIGFILES_CHECK_SET_CONFIG;
+
+  /* Check if all the required parameters are set. */
+  checkifset(p);
+
+  /* Print the values for each parameter. */
+  if(cp->printparams)
+    GAL_CONFIGFILES_REPORT_PARAMETERS_SET;
+
+  /* Do a sanity check. */
+  sanitycheck(p);
+
+  /* Make the array of input images. */
+  preparearrays(p);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************      Free allocated, report         *************/
+/**************************************************************/
+void
+freeandreport(struct TEMPLATEparams *p)
+{
+  /* Free the allocated arrays: */
+  free(p->cp.hdu);
+  free(p->cp.output);
+
+  /* Close the FITS file:
+  if(fits_close_file(p->fptr, &status))
+    gal_fits_io_error(status, NULL);
+  */
+
+}
diff --git a/src/TEMPLATE/ui.h b/src/TEMPLATE/ui.h
new file mode 100644
index 0000000..1e48777
--- /dev/null
+++ b/src/TEMPLATE/ui.h
@@ -0,0 +1,42 @@
+/*********************************************************************
+TEMPLATE - Source code for a blank utility for easy creation of new
+           utilities, just copy and paste all the files here replacing
+           TEMPLATE with the new utility name (in the source code and
+           file names).
+
+         - Add the utility name to `configure.ac' and `Makefile.am' in the
+           top Gnuastro source directory.
+
+         - Correct these top comments in all the files, don't forget the
+           `astTEMPLATE.conf' and `Makefile.am' files.
+
+TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Your name <address@hidden>
+Contributing author(s):
+Copyright (C) 2016, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef UI_H
+#define UI_H
+
+void
+setparams(int argc, char *argv[], struct TEMPLATEparams *p);
+
+void
+freeandreport(struct TEMPLATEparams *p);
+
+#endif



reply via email to

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