Subversion Repositories shark

Rev

Blame | Last modification | View Log | RSS feed

//package first_filter;

import java.io.*;
import java.net.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import java.util.regex.*;
import java.util.Random;

/**
 * <p>Title: First XML filter</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: Retis Lab</p>
 * @author not attributable
 * @version 1.0
 */


public class Application {
  private int numElements = 0;
  final String LOADFILE_DIR="../loadfile/";
  final String EVENT_DEFINE="event.c";
  final String ACT_LIST="event.c";
  private int servernumber=0;
  private timespec simulation_time=new timespec();
  ArrayList local_scheduler=new ArrayList();
  ArrayList Task_Section=new ArrayList();
  private int task_group=0;
  private int task_server=0;
  private int current_scheduler=0;



  //Construct the frame
  public Application() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception  {
  }

  public void process (String url) throws MalformedURLException {
  try {
    //  Use SAXBuilder
    SAXBuilder builder =  new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
    builder.setFeature("http://apache.org/xml/features/validation/schema", true);


    Document doc = builder.build(url);
    Element root = doc.getRootElement();

    try {
      // Funzione per il salvataggio del file XML
      OutputStream fout = new FileOutputStream(EVENT_DEFINE);
      OutputStream bout = new BufferedOutputStream(fout);
      OutputStreamWriter out = new OutputStreamWriter(bout, "8859_1");
      out.write("\n#include \"func.h\"\n");

      processElement (root,out);
      out.flush();
      out.close();
    } catch (UnsupportedEncodingException e) {
    System.out.println("Non sono supportati i caratteri latini");
    System.exit(1);

   } catch (IOException e){
    System.out.println("Salvatagio fallito");
    System.exit(1);
   }



    System.out.println ("Total Number of Elements Processed:  "
      +numElements);
  } catch (JDOMException e) {
    System.out.println ("JDOM Exception:  "+e.getMessage());
  } catch (java.io.IOException e) {
    System.out.println ("File Exception:  "+e.getMessage());

  }
}

//  Recursive Function to Process Elements
//  Prints the Element Name and keeps a running count
//  out total number of elements.
private void processElement(Element element, OutputStreamWriter out) {
  numElements++;
  String elementName = element.getName();

  System.out.println(elementName);
  List servers = element.getChildren();
  Iterator iterator = servers.iterator();
  /* get simulation parameter */
  Element SimulationInfo = (Element) iterator.next();

  Pattern pattern = Pattern.compile("[us\\s]+");
  try {
    /*simulation time */

    String[] stime = pattern.split(SimulationInfo.getChild("time").getText());
    out.write("struct timespec total_time={" + stime[0] + "," + stime[1] +
              "};\n\n");
    simulation_time.tv_sec = Long.valueOf(stime[0].trim()).longValue();
    simulation_time.tv_nsec = Long.valueOf(stime[1].trim()).longValue() /
        1000;
//float f = Float.valueOf(s.trim()).floatValue();
    /* server section start */
    out.write("struct loader_contract loader_contract_list[] = {\n");
    int total_server=0;
    while (iterator.hasNext()) {
      /* get server */
      Element server = (Element) iterator.next();
      process_server_section(server, out);
      total_server++;
    }

    out.write("};\n\n");

    out.write("int total_loader_contract="+total_server+";\n\n");
    iterator = local_scheduler.iterator();
    while (iterator.hasNext()) {
      /* get server */
      Element loc_sched = (Element) iterator.next();
      process_scheduler_section(loc_sched, out);
      task_server++;
    }

    iterator = Task_Section.iterator();
    int total_task_section=0;
    out.write("\nstruct loader_task loader_task_list[] = {\n");
    while (iterator.hasNext()) {
      /* get server */
      task_class tsk_sec = (task_class) iterator.next();
      out.write("   {\"" + tsk_sec.name + "\"," + tsk_sec.task_type + "," +
                tsk_sec.contract +
                "," + tsk_sec.localscheduler + "," + tsk_sec.number + ","
                + tsk_sec.group + ",{" + tsk_sec.deadline.tv_sec +
                "," +
                tsk_sec.deadline.tv_nsec + "}," + "{" +
                tsk_sec.wcet.tv_sec + "," +
                tsk_sec.wcet.tv_nsec + "}," + tsk_sec.act_number +
                ",0,act_" + tsk_sec.name +
                ",exec_" + tsk_sec.name + "},\n");
      total_task_section++;
    }
    out.write("};\n\n");
    out.write("int total_loader_task="+total_task_section+";\n\n");


  }
  catch (java.io.IOException e) {
    System.out.println("File Exception:  " + e.getMessage());

  }

}

void process_scheduler_section(Element e, OutputStreamWriter out) {
  Attribute t;
  t=e.getAttribute("type");

  List localpars = e.getChildren();
  Iterator iterator = localpars.iterator();
  while (iterator.hasNext()) {
    /* get task section */
    Element loc_task = (Element) iterator.next();
    process_task_section(loc_task, out, t);

  }

}

void process_task_section(Element e, OutputStreamWriter out, Attribute loc) {
  Attribute t;
  int act;
  act=1;
  int task_type=0;
  int localscheduler=0;
  timespec time = new timespec();
  Pattern pattern = Pattern.compile("[us\\s]+");
  String scheduler=loc.getValue();
  if (scheduler.equals("POSIX")) {
    localscheduler=30;
  }
  else if (scheduler.equals("EDF")) {
    localscheduler=31;
  }
  else if (scheduler.equals("RM")) {
    localscheduler=32;
  }

    /* get task section */
    t=e.getAttribute("type");

    if (t.getValue().equals("BackTask")) {
        process_back_task(e, out);
        task_type=23;
    } else if (t.getValue().equals("OneShot")) {
        process_oneshot_task(e, out);
        task_type=21;
    } else if (t.getValue().equals("CyclicalTask")) {
        task_type=22;
        act=process_cyclical_task(e, out);
    }

    task_class section=new task_class();
    section.deadline=new timespec();
    section.wcet=new timespec();
    section.name="task"+task_group;
    section.contract=task_server;
    section.group=task_group;
    section.act_number=act;
    section.task_type=task_type;
    section.localscheduler=localscheduler;
    section.number=Integer.valueOf(e.getChild("number").getText()).intValue();

    Element dl = e.getChild("dline");
    if (dl != null) {

      String[] dline=pattern.split(dl.getText());
      time.tv_sec = Long.valueOf(dline[0]).longValue();
      time.tv_nsec = Long.valueOf(dline[1]).longValue() * 1000;
 
      section.deadline.tv_sec=time.tv_sec;
      section.deadline.tv_nsec=time.tv_nsec;

    }


    Element wc = e.getChild("wcet");
    if (wc != null) {
   
      String[] wcet=pattern.split(e.getChild("wcet").getText());
      time.tv_sec = Long.valueOf(wcet[0]).longValue();
      time.tv_nsec = Long.valueOf(wcet[1]).longValue() * 1000;
     
      section.wcet.tv_sec=time.tv_sec;
      section.wcet.tv_nsec=time.tv_nsec;

    }

    Task_Section.add(section);
    task_group++;

}

void process_back_task(Element e, OutputStreamWriter out) {

    Pattern pattern = Pattern.compile("[us\\s]+");

    Element act_section=e.getChild("act_section");
    String[] start_time=pattern.split(act_section.getChild("start_time").getText());
    Element exec_section=e.getChild("exec_section");

    String[] exec_const=pattern.split(exec_section.getChild("exec_time").getText());
    try {
        out.write("struct timespec act_task"+task_group+"[]={{"+start_time[0]+","+start_time[1]+"},};\n\n");
        out.write("struct timespec exec_task"+task_group+"[]={{"+exec_const[0]+","+exec_const[1]+"},};\n\n");

    }
    catch (java.io.IOException ex) {
      System.out.println("File Exception:  " + ex.getMessage());

    }
}
void process_oneshot_task(Element e, OutputStreamWriter out) {
    Pattern pattern = Pattern.compile("[us\\s]+");
   
    Element act_section=e.getChild("act_section");
    String[] start_time=pattern.split(act_section.getChild("start_time").getText());

    Element exec_section=e.getChild("exec_section");
    String[] exec_const=pattern.split(exec_section.getChild("exec_time").getText());

    try {
      out.write("struct timespec act_task"+task_group+"[]={{"+start_time[0]+","+start_time[1]+"},};\n\n");
      out.write("struct timespec exec_task"+task_group+"[]={{"+exec_const[0]+","+exec_const[1]+"},};\n\n");
    }
    catch (java.io.IOException ex) {
      System.out.println("File Exception:  " + ex.getMessage());
    }
}

int process_cyclical_task(Element e, OutputStreamWriter out) {
   
    int activated=1;
    Pattern pattern = Pattern.compile("[us\\s]+");
    Element act_section=e.getChild("act_section");
    String[] start_time=pattern.split(act_section.getChild("start_time").getText());
    String[] period=pattern.split(act_section.getChild("period_time").getText());
    Element deltatime=act_section.getChild("delta_time");
    String[] delta_time;

    long act_delta=0;
    timespec delta_act_ts = new timespec();

    if (deltatime != null) {
        delta_time = pattern.split(deltatime.getText());
        delta_act_ts.tv_sec = Long.valueOf(delta_time[0]).longValue();
        delta_act_ts.tv_nsec = Long.valueOf(delta_time[1]).longValue() * 1000;
        act_delta = delta_act_ts.TIMESPEC2USEC();
    }

    Element exec_section=e.getChild("exec_section");
    String[] exec_const=pattern.split(exec_section.getChild("exec_time").getText());
    Element execdelta=exec_section.getChild("delta_time");
    String[] exec_delta;

    long exec_delta_long = 0;
    timespec exec_delta_ts = new timespec();

    if (execdelta != null) {
        exec_delta=pattern.split(execdelta.getText());
        exec_delta_ts.tv_sec = Long.valueOf(exec_delta[0]).longValue();
        exec_delta_ts.tv_nsec = Long.valueOf(exec_delta[1]).longValue() * 1000;
        exec_delta_long = exec_delta_ts.TIMESPEC2USEC();       
    }

    try {
      out.write("struct timespec act_task"+task_group+"[]={{"+
                start_time[0]+","+start_time[1]+"},\n");

    timespec time = new timespec();
    time.tv_sec = Long.valueOf(period[0]).longValue();
    time.tv_nsec = Long.valueOf(period[1]).longValue() * 1000;

    long usecperiod = time.TIMESPEC2USEC();
    timespec nextact = new timespec();

    time.tv_sec = Long.valueOf(start_time[0]).longValue();
    time.tv_nsec = Long.valueOf(start_time[1]).longValue() * 1000;
   
    Random rd = new Random();

    while (simulation_time.TIMESPEC_A_GT_B(time)) {

      nextact.tv_sec = Long.valueOf(period[0]).longValue();
      nextact.tv_nsec = Long.valueOf(period[1]).longValue() * 1000;

      if (act_delta != 0) {
        nextact.ADDUSEC2TIMESPEC((rd.nextInt() & Integer.MAX_VALUE) % act_delta - act_delta/2);
      }

      time.ADDUSEC2TIMESPEC(usecperiod);
      out.write("   {"+nextact.tv_sec+","+nextact.tv_nsec/1000+"},\n");
      activated++;
    }
    out.write("};\n");

    out.write("struct timespec exec_task"+task_group+"[]={\n");

    timespec nextexec = new timespec();

    for (int i=0; i<activated; i++) {

        nextexec.tv_sec = Long.valueOf(exec_const[0]).longValue();
        nextexec.tv_nsec = Long.valueOf(exec_const[1]).longValue() * 1000;

        if (exec_delta_long != 0) {
          nextexec.ADDUSEC2TIMESPEC((rd.nextInt() & Integer.MAX_VALUE) % exec_delta_long - exec_delta_long/2);
        }
       
        out.write("   {"+nextexec.tv_sec+","+nextexec.tv_nsec/1000+"},\n");

    }
    out.write("};\n");
  }
  catch (java.io.IOException ex) {
    System.out.println("File Exception:  " + ex.getMessage());
  }

  return activated;
}

void process_server_section(Element e, OutputStreamWriter out) {


  List serverpars = e.getChildren();
  Iterator iterator = serverpars.iterator();
  Element serverpar = (Element) iterator.next();
  String current_value;
  current_value=serverpar.getText();
  try {
    out.write("{" + servernumber + ",{");
    servernumber++;

    Pattern pattern = Pattern.compile("[us\\s]+");
    /* cmin */
    String[] cmin = pattern.split(current_value);
    out.write(cmin[0] + "," + Long.valueOf(cmin[1]).longValue()*1000+"},{");

    /* tmax */
    serverpar = (Element) iterator.next();
    current_value=serverpar.getText();
    String[] tmax = pattern.split(current_value);
    out.write(tmax[0] + "," + Long.valueOf(tmax[1]).longValue()*1000+"},{");

    /* cmax */
    serverpar = (Element) iterator.next();
    current_value=serverpar.getText();
    String[] cmax = pattern.split(current_value);
    out.write(cmax[0] + "," + Long.valueOf(cmax[1]).longValue()*1000+"},{");

    /* tmin */
    serverpar = (Element) iterator.next();
    current_value=serverpar.getText();
    String[] tmin = pattern.split(current_value);
    out.write(tmin[0] + "," + Long.valueOf(tmin[1]).longValue()*1000+"},");

    /*work load */
    serverpar = (Element) iterator.next();
    current_value=serverpar.getText();
    out.write(current_value+",");

    serverpar = (Element) iterator.next();
    current_value=serverpar.getName();
    Attribute loc_type=serverpar.getAttribute("type");
    String scheduler=loc_type.getValue();
    if (scheduler.equals("POSIX")) {
      out.write("30");
    }
    else if (scheduler.equals("EDF")) {
      out.write("31");
    }
    else if (scheduler.equals("RM")) {
      out.write("32");
    }
    out.write(",-1},\n");
    local_scheduler.add(servernumber-1,serverpar);

  } catch (java.io.IOException ex) {
    System.out.println ("File Exception:  "+ex.getMessage());
  }

  /*
    fprintf(file_event_header, "  {%d,{%d,%d},{%d,%d},{%d,%d},{%d,%d},%d,%d,-1},\n",
                           (int)c->number,(int)c->cmin.tv_sec,(int)c->cmin.tv_nsec,
                           (int)c->tmax.tv_sec,(int)c->tmax.tv_nsec,
                           (int)c->cmax.tv_sec,(int)c->cmax.tv_nsec,
                           (int)c->tmin.tv_sec,(int)c->tmin.tv_nsec,
                           (int)c->workload,(int)c->local_scheduler);

*/

    //processElement (kid);
  }



public static void main(String[] args) throws Exception {
  System.out.println("Parser Versione 1.0");
  Application app = new Application();
  if (args.length > 0)
    app.process(args[0]);
}

/* Event Generator
 *
 * Giacomo Guidi
 */






/*
int write_basic_par_start(void)
{

  FILE *file_event_header;

  file_event_header = fopen(EVENT_DEFINE,"a+");
  if (file_event_header == NULL) return 1;

  fprintf(file_event_header, "struct loader_task loader_task_list[] = {\n");

  fclose(file_event_header);

  return 0;

}


int write_basic_par(struct loader_task *c)
{

  FILE *file_event_header;

  file_event_header = fopen(EVENT_DEFINE,"a+");
  if (file_event_header == NULL) return 1;

  fprintf(file_event_header, "  {\"%s\",%d,%d,%d,%d,%d,{%d,%d},{%d,%d},%d,0,act_%s,exec_%s},\n",
                             c->name,(int)c->task_type,(int)c->server,(int)c->local_scheduler,(int)c->number,(int)c->group,
                             (int)c->deadline.tv_sec, (int)c->deadline.tv_nsec,
                             (int)c->wcet.tv_sec, (int)c->wcet.tv_nsec,
                             (int)c->act_number, c->name, c->name);

  fclose(file_event_header);

  return 0;

}

int write_contract(struct loader_contract *c)
{

  FILE *file_event_header;

  file_event_header = fopen(EVENT_DEFINE,"a+");
  if (file_event_header == NULL) return 1;

  fprintf(file_event_header, "  {%d,{%d,%d},{%d,%d},{%d,%d},{%d,%d},%d,%d,-1},\n",
                             (int)c->number,(int)c->cmin.tv_sec,(int)c->cmin.tv_nsec,
                             (int)c->tmax.tv_sec,(int)c->tmax.tv_nsec,
                             (int)c->cmax.tv_sec,(int)c->cmax.tv_nsec,
                             (int)c->tmin.tv_sec,(int)c->tmin.tv_nsec,
                             (int)c->workload,(int)c->local_scheduler);

  fclose(file_event_header);

  return 0;

}

int close_loader_task(int total_task_number)
{

  FILE *file_event_header;

  file_event_header = fopen(EVENT_DEFINE,"a+");
  if (file_event_header == NULL) return 1;

  fprintf(file_event_header,"};\n\n");

  fprintf(file_event_header,"int total_loader_task = %d;\n\n",total_task_number);

  fclose(file_event_header);

  return 0;

}

int close_loader_contract(int total_contract_number)
{

  FILE *file_event_header;

  file_event_header = fopen(EVENT_DEFINE,"a+");
  if (file_event_header == NULL) return 1;

  fprintf(file_event_header,"};\n\n");

  fprintf(file_event_header,"int total_loader_contract = %d;\n\n",total_contract_number);

  fclose(file_event_header);

  return 0;

}

int write_simulation_time(struct timespec *total)
{

  FILE *file_event_header;

  file_event_header = fopen(EVENT_DEFINE,"a+");
  if (file_event_header == NULL) return 1;

  fprintf(file_event_header,"struct timespec total_time = {%d,%d};\n\n",(int)total->tv_sec,(int)total->tv_nsec);

  fclose(file_event_header);

  return 0;


}

int write_single_act(struct timespec *t, struct loader_task *c)
{

  FILE *file_act_header;

  file_act_header = fopen(ACT_LIST,"a+");
  if (file_act_header == NULL) return 1;

  if (TIMESPEC_A_GT_B(t,&c->act_par_1)) {
    fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d}};\n\n",c->name,
          (int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);
    c->act_number = 1;
  } else {
    fprintf(file_act_header,"struct timespec act_%s[] = {{0,0}};\n\n",c->name);
    c->act_number = 0;
  }

  fclose(file_act_header);

  return 0;

}

int write_periodic_act(struct timespec *t, struct loader_task *c)
{

  FILE *file_act_header;
  struct timespec tot_time;
  int period;

  file_act_header = fopen(ACT_LIST,"a+");
  if (file_act_header == NULL) return 1;

  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
          (int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);

  c->act_number = 1;
  TIMESPEC_ASSIGN(&tot_time,&c->act_par_1);
  period = TIMESPEC2USEC(&c->act_par_2);
  while (TIMESPEC_A_GT_B(t, &tot_time)) {
    c->act_number++;
    ADDUSEC2TIMESPEC(period,&tot_time);
    fprintf(file_act_header,"  {%d,%d},\n",
            (int)c->act_par_2.tv_sec,(int)c->act_par_2.tv_nsec);
  }

  fprintf(file_act_header,"  };\n\n");

  fclose(file_act_header);

  return 0;

}

int write_mean_act(struct timespec *t,struct loader_task *c)
{

  FILE *file_act_header;
  struct timespec tot_time;
  int next_act;

  file_act_header = fopen(ACT_LIST,"a+");
  if (file_act_header == NULL) return 1;

  fprintf(file_act_header,"struct timespec act_%s[] = {{%d,%d},\n",c->name,
          (int)c->act_par_1.tv_sec,(int)c->act_par_1.tv_nsec);

  c->act_number = 1;
  TIMESPEC_ASSIGN(&tot_time,&c->act_par_1);
  while (TIMESPEC_A_GT_B(t, &tot_time)) {
    c->act_number++;
    next_act = TIMESPEC2USEC(&c->act_par_2) + random() % TIMESPEC2USEC(&c->act_par_3) - TIMESPEC2USEC(&c->act_par_3) / 2;
    ADDUSEC2TIMESPEC(next_act,&tot_time);
    fprintf(file_act_header,"  {%d,%d},\n",
            next_act / 1000000, next_act % 1000000 * 1000);
  }

  fprintf(file_act_header,"  };\n\n");

  fclose(file_act_header);

  return 0;

}

int write_exec_const(struct loader_task *c)
{

  FILE *file_exec_header;
  int i;

  file_exec_header = fopen(ACT_LIST,"a+");
  if (file_exec_header == NULL) return 1;

  fprintf(file_exec_header,"struct timespec exec_%s[] =  {{%d,%d},\n",c->name,
          (int)c->exec_par_1.tv_sec,(int)c->exec_par_1.tv_nsec);

  for (i=0; i< c->act_number-1; i++)
    fprintf(file_exec_header,"  {%d,%d},\n",
          (int)c->exec_par_1.tv_sec,(int)c->exec_par_1.tv_nsec);

  fprintf(file_exec_header,"  };\n\n");

  fclose(file_exec_header);

  return 0;

}

int write_exec_mean(struct loader_task *c)
{

  FILE *file_exec_header;
  int exec_time_usec;
  int i;

  file_exec_header = fopen(ACT_LIST,"a+");
  if (file_exec_header == NULL) return 1;

  exec_time_usec = TIMESPEC2USEC(&c->exec_par_1)
                        + random() % TIMESPEC2USEC(&c->exec_par_2) - TIMESPEC2USEC(&c->exec_par_2) / 2;
  fprintf(file_exec_header,"struct timespec exec_%s[] = {{%d,%d},\n",c->name,
          exec_time_usec / 1000000, exec_time_usec % 1000000 * 1000);

  for (i=0; i< c->act_number-1; i++) {
    exec_time_usec = TIMESPEC2USEC(&c->exec_par_1)
                        + random() % TIMESPEC2USEC(&c->exec_par_2) - TIMESPEC2USEC(&c->exec_par_2) / 2;
    fprintf(file_exec_header,"  {%d,%d},\n",
          exec_time_usec / 1000000, exec_time_usec % 1000000 * 1000);
  }

  fprintf(file_exec_header,"  };\n\n");

  fclose(file_exec_header);

  return 0;

}

void *start;
void *end;

int main(int argc, char **argv) {

  char loadfile[100];
  struct timespec total_time;
  struct loader_task *start_loader_task = NULL, *current_t;
  struct loader_contract *start_loader_contract = NULL, *current_c;
  int err,ldnum;
  int total_task_number;
  int total_contract_number;

  printf("\nEvent Generator\n");

  if (argc < 2) {
    printf("Error: event_gen loadfile.fsf\n");
    exit(1);
  }

  printf("Read loader file %s\n",argv[1]);

  sprintf(loadfile,"%s%s",LOADFILE_DIR,argv[1]);
  err = dos_preload(loadfile,100000,&start,&end);

  if (err != 0) {
    printf("Error: File not found\n");
    exit(1);
  }

  printf("Parsing file\n");

  line_reader(start, end, &total_time, &start_loader_task, &start_loader_contract);

  srandom(time(NULL));

  write_struct();

  current_t = start_loader_task;
  ldnum = 1;

  while(current_t != NULL) {

    sprintf(current_t->name,"ltask%d",ldnum);
    current_t->group = ldnum;
    ldnum++;

    switch (current_t->act_type) {
     case PAR_ACT_SINGLE:
       err = write_single_act(&total_time,current_t);
        if (err != 0) {
          printf("Error writing activation header\n");
          exit(1);
        }
        break;
      case PAR_ACT_PERIODIC:
        err = write_periodic_act(&total_time,current_t);
        if (err != 0) {
          printf("Error writing activation header\n");
          exit(1);
        }
        break;
      case PAR_ACT_MEAN:
        err = write_mean_act(&total_time,current_t);
        if (err != 0) {
          printf("Error writing activation header\n");
          exit(1);
        }
        break;
    }

    switch (current_t->exec_type) {
      case PAR_EXEC_CONST:
        err = write_exec_const(current_t);
        if (err != 0) {
          printf("Error writing exec header\n");
          exit(1);
        }
        break;
      case PAR_EXEC_MEAN:
        err = write_exec_mean(current_t);
        if (err != 0) {
          printf("Error writing exec header\n");
          exit(1);
        }
        break;
    }

    current_t = current_t->next;

  }

  write_basic_par_start();

  total_task_number = 0;
  current_t = start_loader_task;
  while(current_t != NULL) {

    write_basic_par(current_t);

    current_t = current_t->next;

    total_task_number++;

  }

  close_loader_task(total_task_number);

  write_contract_start();

  total_contract_number = 0;
  current_c = start_loader_contract;
  while(current_c != NULL) {

    write_contract(current_c);

    current_c = current_c->next;

    total_contract_number++;

  }

  close_loader_contract(total_contract_number);

  write_simulation_time(&total_time);

  return 0;

}

*/

}