source: PSPA/madxPSPA/src/mad_stream.c @ 430

Last change on this file since 430 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 1.9 KB
Line 
1#include "madx.h"
2
3struct in_buffer*
4new_in_buffer(int length)
5{
6  char rout_name[] = "new_in_buffer";
7  struct in_buffer* new =
8    (struct in_buffer*) mycalloc(rout_name,1, sizeof(struct in_buffer));
9  strcpy(new->name, "in_buffer");
10  new->stamp = 123456;
11  if (watch_flag) fprintf(debug_file, "creating ++> %s\n", new->name);
12  new->c_a = new_char_array(length);
13  new->flag = -1;
14  return new;
15}
16
17struct in_buff_list*
18new_in_buff_list(int length)
19{
20  char rout_name[] = "new_inbuf_list";
21  struct in_buff_list* bll =
22    (struct in_buff_list*) mycalloc(rout_name,1, sizeof(struct in_buff_list));
23  strcpy(bll->name, "in_buff_list");
24  bll->stamp = 123456;
25  if (watch_flag) fprintf(debug_file, "creating ++> %s\n", bll->name);
26  bll->buffers =
27    (struct in_buffer**) mycalloc(rout_name,length, sizeof(struct in_buffer*));
28  bll->input_files =
29    (FILE**) mycalloc(rout_name,length, sizeof(FILE*));
30  bll->max = length;
31  return bll;
32}
33
34void
35grow_in_buff_list(struct in_buff_list* p)
36{
37  char rout_name[] = "grow_in_buff_list";
38  struct in_buffer** e_loc = p->buffers;
39  FILE** f_loc = p->input_files;
40  int j, new = 2*p->max;
41  p->max = new;
42  p->buffers
43    = (struct in_buffer**) mycalloc(rout_name,new, sizeof(struct in_buffer*));
44  for (j = 0; j < p->curr; j++) p->buffers[j] = e_loc[j];
45  myfree(rout_name, e_loc);
46  p->input_files = mycalloc(rout_name, new, sizeof(FILE*));
47  for (j = 0; j < p->curr; j++) p->input_files[j] = f_loc[j];
48  myfree(rout_name, f_loc);
49}
50
51int
52down_unit(char* file_name)
53  /* makes a called file the current input unit */
54{
55  FILE* new;
56  if ((new = fopen(file_name, "r")) == NULL)
57  {
58    if (interactive) warning("cannot open input file:", file_name);
59    else             fatal_error("cannot open input file:", file_name);
60    return 0;
61  }
62  if (in->curr+1 == in->max) grow_in_buff_list(in);
63  in->input_files[++in->curr] = new;
64  strcpy(filenames[in->curr],file_name);
65  currentline[in->curr] = 0;
66  return 1;
67}
68
Note: See TracBrowser for help on using the repository browser.