Layers
Diffusion in heterogeneous environments
extras.c
Go to the documentation of this file.
1 
12 // includes
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <stdarg.h>
16 #include <string.h>
17 #include "header.h"
18 
24 void error(char *errorstring, ...)
25 {
26  va_list ap;
27 
28  va_start(ap, errorstring);
29  fprintf(stderr, "Error: ");
30  vfprintf(stderr, errorstring, ap);
31  fprintf(stderr, "\n");
32  va_end(ap);
33 
34  exit(EXIT_FAILURE);
35 }
36 
37 
43 void print_usage_fit_layer(char *program)
44 {
45  fprintf(stderr, "Usage: %s [options] <input_file> \n\n", program);
46  fprintf(stderr,
47  "Reads an input parameter/data file <input_file> with parameters and \n"
48  "RTI data from a layered environment (3 layers: SR, SP, and SO of the \n"
49  "CA1 region of the hippocampus) and fits alpha, theta, and kappa of SP.\n"
50  "The input filename extension can be anything, but don't use \".dat\".\n"
51  "The output file has the same name as the input file but with the \n"
52  "extension \".dat\".\n\n"
53  );
54  fprintf(stderr, "Options:\n"
55  "\t-h, --help print usage message\n"
56  "\t-v, --verbose be verbose\n"
57  "\t-g, --global_kappa use the same kappa in all layers (= kappa_sp)\n"
58  "\t--nr <nr> specify nr\n"
59  "\t--nz <nz> specify nz\n"
60  "\t--nt <nt> specify nt\n"
61  "\t--nt_scale <factor> specify scale factor for nt\n"
62  "\t--ez1 <ez1> specify z-position of bottom of cylinder (<0)\n"
63  "\t--ez2 <ez2> specify z-position of top of cylinder (>0)\n"
64  "\t--alpha_so <alpha_so> specify alpha_so\n"
65  "\t--alpha_sp <alpha_sp> specify initial alpha_sp\n"
66  "\t--alpha_sr <alpha_sr> specify alpha_sr\n"
67  "\t--theta_so <theta_so> specify theta_so\n"
68  "\t--theta_sp <theta_sp> specify initial theta_sp\n"
69  "\t--theta_sr <theta_sr> specify theta_sr\n"
70  "\t--kappa_so <kappa_so> specify kappa_so\n"
71  "\t--kappa_sp <kappa_sp> specify initial kappa_sp\n"
72  "\t--kappa_sr <kappa_sr> specify kappa_sr\n"
73  "\t--kappa_outside <k_out> specify kappa_outside (mutually excl. with -g)\n"
74  "\t--alpha_step <a_step> specify initial step in alpha_sp direction\n"
75  "\t--theta_step <t_step> specify initial step in theta_sp direction\n"
76  "\t--kappa_step <k_step> specify initial step in kappa_sp direction\n"
77  "\t--minalpha <minalpha> specify minimum value of alpha_sp\n"
78  "\t--maxalpha <maxalpha> specify maximum value of alpha_sp\n"
79  "\t--mintheta <mintheta> specify minimum value of theta_sp\n"
80  "\t--maxtheta <maxtheta> specify maximum value of theta_sp\n"
81  "\t--minkappa <minkappa> specify minimum value of kappa_sp\n"
82  "\t--maxkappa <maxkappa> specify maximum value of kappa_sp\n"
83  "\t--tmax <tmax> specify total duration of experiment\n"
84  "\t--fit_tol <fit_tol> specify stopping criterion (simplex size)\n"
85  "\t--itermax <itermax> specify stopping criterion (max iterations)\n"
86  "\t--outfile <outfile> specify output file (parameters and curves)\n"
87  "\t--pathfile <pathfile> specify simplex path output file (just \n"
88  "\t one vertex of the simplex per iteration)\n"
89  );
90  exit(EXIT_FAILURE);
91 }
92 
103 void check_filename(char *in, char *out)
104 {
105  // The input and output filenames are 4 characters longer than
106  // the base filename, hence the "- 4"
107  if (strlen(in) < (FILENAME_MAX - 4))
108  strcpy(out, in);
109  else
110  error("Filename length is too long");
111 }
112 
113 
124 double *create_array(int N, char *string)
125 {
126  double *a;
127  int i;
128 
129  a = (double *)malloc(sizeof(double) * N);
130  if (a == NULL)
131  error("Cannot allocate memory for %s array", string);
132 
133  for (i=0; i<N; i++)
134  a[i] = 0.0;
135 
136  return a;
137 }
138 
139 
154 int assemble_command(int argc, char *argv[], char *command)
155 {
156  int i, length;
157 
158  strcpy(command,argv[0]);
159  strcat(command, " ");
160  length=strlen(argv[0]) + 1;
161  for (i=1; i<argc; i++) {
162  length += strlen(argv[i]) + 1;
163  if (length > MAX_COMMAND_LENGTH) {
164  printf("Warning: length of command too long to put in struct \n");
165  strcat(command, "...");
166  break;
167  }
168  strcat(command, argv[i]);
169  strcat(command, " ");
170  }
171 
172  return (i);
173 }
174 
Header file for program fit-layer.
void error(char *errorstring,...)
Print an error message to stderr and exit with status EXIT_FAILURE.
Definition: extras.c:20
#define MAX_COMMAND_LENGTH
Maximum number of characters of command to copy to output file.
Definition: header.h:37
double * create_array(int N, char *string)
Create an array of doubles of the specified size.
Definition: extras.c:105
void check_filename(char *in, char *out)
Make sure that the filename is not too long.
Definition: extras.c:103
int assemble_command(int argc, char *argv[], char *command)
Create a string containing the command used to run the program.
Definition: extras.c:154
void print_usage_fit_layer(char *program)
Print usage message and exit with status EXIT_FAILURE.
Definition: extras.c:43