Task: Implement SetValues.c for CactusTest/TestPar thorn

thorn_name: CactusTest/TestPar
src_filename: SetValues.c
interface: # Interface definition for thorn TestPar

IMPLEMENTS: TestPar

schedule: # Schedule definitions for thorn TestPar

SCHEDULE TestPar_PrintStrings AT initial
{
  LANG: C
} "Output string parameters"

SCHEDULE TestPar_SetValues AT initial
{
  LANG: C
} "Set values based on parameters"

param: # Parameter definitions for thorn TestPar

STRING string1 ""
{
  ".*" :: "Any string"
} ""

STRING string2 ""
{
  ".*" :: "Any string"
} ""

STRING string3 ""
{
  ".*" :: "Any string"
} ""

STRING string4 ""
{
  ".*" :: "Any string"
} ""

STRING string5 ""
{
  ".*" :: "Any string"
} ""

STRING string6 ""
{
  ".*" :: "Any string"
} ""

STRING string7 ""
{
  ".*" :: "Any string"
} ""

STRING string8 ""
{
  ".*" :: "Any string"
} ""

STRING string9 ""
{
  ".*" :: "Any string"
} ""

STRING out_dir "Where to write output"
{
  ".*" :: "Any valid path"
} ""

INT int1[10] ""
{
  *:* :: "Any integer"
} 12

INT int2[10] ""
{
  *:* :: "Any integer"
} 1

REAL real1[10] ""
{
  *:* :: "Any number"
} 42.d0

REAL real2[10] ""
{
  *:* :: "Any number"
} 23

BOOLEAN bool1[10] ""
{
} yes

BOOLEAN bool2[10] ""
{
} 0

context: make.code.defn:
```
# Main make.code.defn file for thorn TestPar

# Source files in this directory
SRCS = PrintStrings.c SetValues.c

# Subdirectories containing source files
SUBDIRS = 

```

PrintStrings.c:
```
#include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>

void TestPar_PrintStrings (CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;
  
  CCTK_VInfo (CCTK_THORNSTRING, "String 1: \"%s\"", string1);
  CCTK_VInfo (CCTK_THORNSTRING, "String 2: \"%s\"", string2);
  CCTK_VInfo (CCTK_THORNSTRING, "String 3: \"%s\"", string3);
  CCTK_VInfo (CCTK_THORNSTRING, "String 4: \"%s\"", string4);
  CCTK_VInfo (CCTK_THORNSTRING, "String 5: \"%s\"", string5);
  CCTK_VInfo (CCTK_THORNSTRING, "String 6: \"%s\"", string6);
  CCTK_VInfo (CCTK_THORNSTRING, "String 7: \"%s\"", string7);
  CCTK_VInfo (CCTK_THORNSTRING, "String 8: \"%s\"", string8);
  CCTK_VInfo (CCTK_THORNSTRING, "String 9: \"%s\"", string9);
}

```


combined_doc_context: ## README (README):
```
Cactus Code Thorn TestPar
Author(s)    : Erik Schnetter <schnetter@cct.lsu.edu>
Maintainer(s): Cactus team
Licence      : LGPL
--------------------------------------------------------------------------

1. Purpose

Test parameter file syntax.

```

## Documentation (.tex files):
Files: documentation.tex

```tex
=== documentation.tex ===
% *======================================================================*
%  Cactus Thorn template for ThornGuide documentation
%  Author: Ian Kelley
%  Date: Sun Jun 02, 2002
%  $Header$
%
%  Thorn documentation in the latex file doc/documentation.tex
%  will be included in ThornGuides built with the Cactus make system.
%  The scripts employed by the make system automatically include
%  pages about variables, parameters and scheduling parsed from the
%  relevant thorn CCL files.
%
%  This template contains guidelines which help to assure that your
%  documentation will be correctly added to ThornGuides. More
%  information is available in the Cactus UsersGuide.
%
%  Guidelines:
%   - Do not change anything before the line
%       % START CACTUS THORNGUIDE",
%     except for filling in the title, author, date, etc. fields.
%        - Each of these fields should only be on ONE line.
%        - Author names should be separated with a \\ or a comma.
%   - You can define your own macros, but they must appear after
%     the START CACTUS THORNGUIDE line, and must not redefine standard
%     latex commands.
%   - To avoid name clashes with other thorns, 'labels', 'citations',
%     'references', and 'image' names should conform to the following
%     convention:
%       ARRANGEMENT_THORN_LABEL
%     For example, an image wave.eps in the arrangement CactusWave and
%     thorn WaveToyC should be renamed to CactusWave_WaveToyC_wave.eps
%   - Graphics should only be included using the graphicx package.
%     More specifically, with the "\includegraphics" command.  Do
%     not specify any graphic file extensions in your .tex file. This
%     will allow us to create a PDF version of the ThornGuide
%     via pdflatex.
%   - References should be included with the latex "\bibitem" command.
%   - Use \begin{abstract}...\end{abstract} instead of \abstract{...}
%   - Do not use \appendix, instead include any appendices you need as
%     standard sections.
%   - For the benefit of our Perl scripts, and for future extensions,
%     please use simple latex.
%
% *======================================================================*
%
% Example of including a graphic image:
%    \begin{figure}[ht]
% 	\begin{center}
%    	   \includegraphics[width=6cm]{MyArrangement_MyThorn_MyFigure}
% 	\end{center}
% 	\caption{Illustration of this and that}
% 	\label{MyArrangement_MyThorn_MyLabel}
%    \end{figure}
%
% Example of using a label:
%   \label{MyArrangement_MyThorn_MyLabel}
%
% Example of a citation:
%    \cite{MyArrangement_MyThorn_Author99}
%
% Example of including a reference
%   \bibitem{MyArrangement_MyThorn_Author99}
%   {J. Author, {\em The Title of the Book, Journal, or periodical}, 1 (1999),
%   1--16. {\tt http://www.nowhere.com/}}
%
% *======================================================================*

% If you are using CVS use this line to give version information
% $Header$

\documentclass{article}

% Use the Cactus ThornGuide style file
% (Automatically used from Cactus distribution, if you have a
%  thorn without the Cactus Flesh download this from the Cactus
%  homepage at www.cactuscode.org)
\usepackage{../../../../doc/latex/cactus}

\begin{document}

% The author of the documentation
\author{Erik Schnetter \textless schnetter@cct.lsu.edu\textgreater}

% The title of the document (not necessarily the name of the Thorn)
\title{TestPar}

% the date your document was last changed, if your document is in CVS,
% please use:
%    \date{$ $Date: 2004-01-07 14:12:39 -0600 (Wed, 07 Jan 2004) $ $}
\date{June 28 2010}

\maketitle

% Do not delete next line
% START CACTUS THORNGUIDE

% Add all definitions used in this documentation here
%   \def\mydef etc

% Add an abstract for this thorn's documentation
\begin{abstract}

\end{abstract}

% The following sections are suggestive only.
% Remove them or add your own.

\section{Introduction}

\section{Physical System}

\section{Numerical Implementation}

\section{Using This Thorn}

\subsection{Obtaining This Thorn}

\subsection{Basic Usage}

\subsection{Special Behaviour}

\subsection{Interaction With Other Thorns}

\subsection{Examples}

\subsection{Support and Feedback}

\section{History}

\subsection{Thorn Source Code}

\subsection{Thorn Documentation}

\subsection{Acknowledgements}


\begin{thebibliography}{9}

\end{thebibliography}

% Do not delete next line
% END CACTUS THORNGUIDE

\end{document}

```



Reference answer:
src_code: #include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>
#include <cctk_File.h>

#include <util_String.h>

#include <stdio.h>
#include <stdlib.h>

void TestPar_SetValues (CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS;
  DECLARE_CCTK_PARAMETERS;
  
  int i;
  FILE *fh = NULL;
  char *buf = NULL;
  
  if(CCTK_MyProc(cctkGH) != 0)
    return;

  if(Util_asprintf(&buf, "%s/ParamEval.asc", out_dir) == 0  || 
     CCTK_CreateDirectory(0777, out_dir) < 0 ||
     (fh = fopen(buf, "w+")) == NULL)
  {
    CCTK_VWarn(CCTK_WARN_ABORT, __LINE__, __FILE__, CCTK_THORNSTRING,
               "Could not open file '%s' for output", buf);
  }

  fprintf(fh,"#  %5s %5s %8s %8s %5s %5s\n","int1","int2","real1","real2","bool1","bool2");
  for(i = 0 ; i < 10 ; i++)
  {
    fprintf(fh, "%2d %5d %5d %8g %8g %5d %5d\n", i, (int)int1[i], (int)int2[i],
            (double)real1[i], (double)real2[i], (int)bool1[i], (int)bool2[i]);
  }

  if(fh)
    fclose(fh);
  if(buf)
    free(buf);
}