Esempio n. 1
0
    void test_write()
    {
        remove_temp_file();
        
        xlnt::zip_file f;
        auto text_file = PathHelper::GetDataDirectory("/reader/sharedStrings.xml");
        f.write(text_file);
        f.write(text_file, "sharedStrings2.xml");
        f.save(temp_file.GetFilename());
        
        xlnt::zip_file f2(temp_file.GetFilename());

        for(auto &info : f2.infolist())
        {
            if(info.filename == "sharedStrings2.xml")
            {
                TS_ASSERT(f2.read(info) == expected_atxt_string);
            }
            else if(info.filename.substr(info.filename.size() - 17) == "sharedStrings.xml")
            {
                TS_ASSERT(f2.read(info) == expected_atxt_string);
            }
        }
        
        remove_temp_file();
    }
Esempio n. 2
0
void
write_objects()
{
  int             i;

  if (temp_file_mode == 0)
  {
    for (i = 0; i < objects; i++)
      printf("%s\n", object_list[i]);
    return;
  }
  for (i = 0; i < objects_max; i++)
    printf("%s\n", object_list[i]);
  rewind(temp_file);
  while (1)
  {
    if (fgets(buffer, STRING_MAX, temp_file) == NULL)
      if (feof(temp_file))
        break;
      else
      {
        remove_temp_file();
        ABORT("cannot read from temp file");
      }
    fputs(buffer, stdout);
  }
  remove_temp_file();
}
Esempio n. 3
0
 void test_load_file()
 {
     remove_temp_file();
     xlnt::zip_file f(existing_file);
     f.save(temp_file.GetFilename());
     TS_ASSERT(files_equal(existing_file, temp_file.GetFilename()));
     remove_temp_file();
 }
Esempio n. 4
0
 void test_load_stream()
 {
     remove_temp_file();
     {
         std::ifstream in_stream(existing_file, std::ios::binary);
         xlnt::zip_file f(in_stream);
         std::ofstream out_stream(temp_file.GetFilename(), std::ios::binary);
         f.save(out_stream);
     }
     TS_ASSERT(files_equal(existing_file, temp_file.GetFilename()));
     remove_temp_file();
 }
Esempio n. 5
0
 void test_comment()
 {
     remove_temp_file();
     
     xlnt::zip_file f;
     f.comment = "comment";
     f.save(temp_file.GetFilename());
     
     xlnt::zip_file f2(temp_file.GetFilename());
     TS_ASSERT(f2.comment == "comment");
     
     remove_temp_file();
 }
Esempio n. 6
0
int
pce_f (st_ucon64_nfo_t *rominfo)
/*
  Region protection codes are found in (American) TurboGrafx-16 games. It
  prevents those games from running on a PC-Engine. One search pattern seems
  sufficient to fix/crack all TG-16 games. In addition to that, the protection
  code appears to be always somewhere in the first 32 kB.
*/
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX], buffer[32 * 1024];
  int bytesread, n;

  puts ("Attempting to fix region protection code...");

  strcpy (src_name, ucon64.fname);
  strcpy (dest_name, ucon64.fname);
  ucon64_file_handler (dest_name, src_name, 0);
  fcopy (src_name, 0, ucon64.file_size, dest_name, "wb"); // no copy if one file

  if ((bytesread = ucon64_fread (buffer, rominfo->backup_header_len, 32 * 1024, src_name)) <= 0)
    return -1;

  // '!' == ASCII 33 (\x21), '*' == 42 (\x2a)
  if (rominfo->interleaved)
    n = change_mem (buffer, bytesread, "\x94\x02\x0f", 3, '*', '!', "\x01", 1, 0);
  else
    n = change_mem (buffer, bytesread, "\x29\x40\xf0", 3, '*', '!', "\x80", 1, 0);

  ucon64_fwrite (buffer, rominfo->backup_header_len, 32 * 1024, dest_name, "r+b");

  printf ("Found %d pattern%s\n", n, n != 1 ? "s" : "");
  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();
  return n;
}
Esempio n. 7
0
int
pce_swap (st_ucon64_nfo_t *rominfo)
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX];
  unsigned char *rom_buffer;
  int size = ucon64.file_size - rominfo->backup_header_len;

  if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
    {
      fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
      return -1;
    }

  strcpy (src_name, ucon64.fname);
  strcpy (dest_name, ucon64.fname);
  ucon64_file_handler (dest_name, src_name, 0);

  if (rominfo->backup_header_len)                    // copy header (if present)
    fcopy (src_name, 0, rominfo->backup_header_len, dest_name, "wb");

  ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name);
  swapbits (rom_buffer, size);
  ucon64_fwrite (rom_buffer, rominfo->backup_header_len, size, dest_name,
            rominfo->backup_header_len ? "ab" : "wb");
  free (rom_buffer);

  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();
  return 0;
}
Esempio n. 8
0
 void test_writestr()
 {
     remove_temp_file();
     
     xlnt::zip_file f;
     f.writestr("a.txt", "a\na");
     xlnt::zip_info info;
     info.filename = "b.txt";
     info.date_time.year = 2014;
     f.writestr(info, "b\nb");
     f.save(temp_file.GetFilename());
     
     xlnt::zip_file f2(temp_file.GetFilename());
     TS_ASSERT(f2.read("a.txt") == "a\na");
     TS_ASSERT(f2.read(f2.getinfo("b.txt")) == "b\nb");
     
     remove_temp_file();
 }
Esempio n. 9
0
 void test_load_bytes()
 {
     remove_temp_file();
     
     xlnt::zip_file f;
     std::vector<unsigned char> source_bytes, result_bytes;
     std::ifstream in_stream(existing_file, std::ios::binary);
     while(in_stream)
     {
         source_bytes.push_back((unsigned char)in_stream.get());
     }
     f.load(source_bytes);
     f.save(temp_file.GetFilename());
     
     xlnt::zip_file f2;
     f2.load(temp_file.GetFilename());
     result_bytes = std::vector<unsigned char>();
     f2.save(result_bytes);
     
     TS_ASSERT(source_bytes == result_bytes);
     
     remove_temp_file();
 }
Esempio n. 10
0
// header format is specified in src/backup/ffe.h
int
pce_msg (st_ucon64_nfo_t *rominfo)
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX];
  unsigned char *rom_buffer = NULL;
  st_msg_header_t header;
  int size = ucon64.file_size - rominfo->backup_header_len;

  if (rominfo->interleaved)
    if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
      {
        fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
        return -1;
      }

  memset (&header, 0, MSG_HEADER_LEN);
  header.size = (unsigned char) (size / 8192);
  header.emulation = size == 3 * MBIT ? 1 : 0;
  header.id1 = 0xaa;
  header.id2 = 0xbb;
  header.type = 2;

  strcpy (src_name, ucon64.fname);
  strcpy (dest_name, ucon64.fname);
  set_suffix (dest_name, ".msg");
  ucon64_file_handler (dest_name, src_name, 0);

  ucon64_fwrite (&header, 0, MSG_HEADER_LEN, dest_name, "wb");
  if (rominfo->interleaved)
    {
      // Magic Super Griffin files should not be "interleaved"
      ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name);
      swapbits (rom_buffer, size);
      ucon64_fwrite (rom_buffer, MSG_HEADER_LEN, size, dest_name, "ab");
      free (rom_buffer);
    }
  else
    fcopy (src_name, rominfo->backup_header_len, size, dest_name, "ab");

  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();
  return 0;
}
Esempio n. 11
0
static void
create_object()
{
  int             i;

  if (temp_file_mode == 0 AND objects < objects_max)
  {
    CREATE(objects_max, objects, object_list, buffer);
    return;
  }
  if (temp_file_mode == 0)
  {
    temp_file_mode = 1;
    create_temp_file();
  }
  if (fprintf(temp_file, "%s\n", buffer) == EOF)
  {
    remove_temp_file();
    ABORT("cannot write to temp file");
  }
  objects++;
}
Esempio n. 12
0
// see src/backup/mgd.h for the file naming scheme
int
pce_mgd (st_ucon64_nfo_t *rominfo)
{
  char src_name[FILENAME_MAX], dest_name[FILENAME_MAX];
  unsigned char *rom_buffer = NULL;
  int size = ucon64.file_size - rominfo->backup_header_len;

  if (!rominfo->interleaved)
    if ((rom_buffer = (unsigned char *) malloc (size)) == NULL)
      {
        fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size);
        return -1;
      }

  strcpy (src_name, ucon64.fname);
  mgd_make_name (ucon64.fname, UCON64_PCE, size, dest_name);
  ucon64_file_handler (dest_name, src_name, OF_FORCE_BASENAME);

  // bit-swapping images for the MGD2 only makes sense for owners of a TG-16
  //  (American version of the PCE)
  if (!rominfo->interleaved)
    {
      ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name);
      swapbits (rom_buffer, size);
      ucon64_fwrite (rom_buffer, 0, size, dest_name, "wb");
      free (rom_buffer);
    }
  else
    fcopy (src_name, rominfo->backup_header_len, size, dest_name, "wb");

  printf (ucon64_msg[WROTE], dest_name);
  remove_temp_file ();

  mgd_write_index_file ((char *) basename2 (dest_name), 1);
  return 0;
}
Esempio n. 13
0
/*!*****************************************************************************
 *******************************************************************************
\note  init_pp
\date  June 1999
   
\remarks 

    initialize the post processing

 *******************************************************************************
 Function Parameters: [in]=input,[out]=output

 \param[in]     name : name of the post processing file

 ******************************************************************************/
int
init_pp(char *name)

{

  int i,j,n,rc;
  char   string[100];
  FILE  *in;


  /* get the post processing information */

  sprintf(string,"%s%s",PREFS,name);
  in = fopen_strip(string);
  if (in == NULL) {
    printf("ERROR: Cannot open file >%s<!\n",string);
    return FALSE;
  }

  /* find all blobs and read their information */

  sprintf(string,"PREDICT");
  if (find_keyword(in, string)) {
    rc=fscanf(in,"%lf",&predict);
  } else {
    predict = 0.0;
  }

  for (i=1; i<= max_blobs; ++i) {

    sprintf(string,"%s_KALMAN",blob_names[i]);
    if (find_keyword(in, string)) {
      blobpp[i].filter_type = KALMAN;
      for (j= _X_; j<= _Z_; ++j)
	for (n= _X_; n<= _Z_; ++n)
	  rc=fscanf(in,"%lf",&(blobpp[i].kal[j][n]));
    } else {
      for (j= _X_; j<= _Z_; ++j)
	for (n= _X_; n<= _Z_; ++n)
	  blobpp[i].kal[j][n]=1.0;
    }

    sprintf(string,"%s_BUTTER",blob_names[i]);
    if (find_keyword(in, string)) {
      blobpp[i].filter_type = BUTTER;
      for (j= _X_; j<= _Z_; ++j)
	for (n= _X_; n<= _Z_; ++n)
	  rc=fscanf(in,"%d",&(blobpp[i].fblob[j][n].cutoff));
    } else {
      for (j= _X_; j<= _Z_; ++j)
	for (n= _X_; n<= _Z_; ++n)
	  blobpp[i].fblob[j][n].cutoff=100;
    }

    sprintf(string,"%s_ACCELERATION",blob_names[i]);
    if (find_keyword(in, string)) {
      for (j= _X_; j<= _Z_; ++j)
	rc=fscanf(in,"%lf",&(blobpp[i].acc[j]));
    } else {
      for (j= _X_; j<= _Z_; ++j)
	blobpp[i].acc[j]=NOT_USED;
    }

  }

  /* do any blobs coincide with the endeffector? */
  sprintf(string,"ENDEFFECTOR");
  if (find_keyword(in, string)) {
    for (i=1; i<=max_blobs; ++i) {
      rc=fscanf(in,"%d",&blob_is_endeffector[i]);
      if (blob_is_endeffector[i] > n_endeffs || blob_is_endeffector[i] < 0)
	blob_is_endeffector[i] = FALSE;
    }
  } else {
    for (i=1; i<=max_blobs; ++i)
      blob_is_endeffector[i]=FALSE;
  }

  learn_transformation_flag = FALSE;
  for (i=1; i<=max_blobs; ++i) {
    if (blob_is_endeffector[i])
      learn_transformation_flag = TRUE;
  }

  
  fclose(in);
  remove_temp_file();

  /* keep track of which post processing script we are using */
  strcpy(current_pp_name,name);

  return TRUE;

}
Esempio n. 14
0
/*!*****************************************************************************
 *******************************************************************************
  \note  read_sine_script
  \date  June 1999

  \remarks

  parse a script which describes the sine task

 *******************************************************************************
 Function Parameters: [in]=input,[out]=output

  none

 ******************************************************************************/
static int
read_sine_script(void)
{
    int j,i,rc;
    static char string[100];
    static char fname[100] = "default.sine";
    FILE *fp;
    int found = FALSE;
    double total_amp;
    double ratio;

    /* clear the current parameters */
    for (i=1; i<=n_dofs; ++i) {
        off[i] = joint_default_state[i].th;
        n_sine[i] = 0;
        for (j=1; j<=MAX_SINE; ++j) {
            amp[i][j] = phase[i][j] = freq[i][j] = 0.0;
        }
    }

    /* open the script, and parse the parameters */

    while (TRUE) {
        if (!get_string("Name of the Sine Script File\0",fname,fname))
            return FALSE;

        /* try to read this file */
        sprintf(string,"%s%s",PREFS,fname);
        fp = fopen_strip(string);
        if (fp != NULL)
            break;
    }

    for (i=1; i<= n_dofs; ++i) {
        if (find_keyword(fp, &(joint_names[i][0]))) {
            found = TRUE;
            total_amp = 0.0;
            rc=fscanf(fp,"%d %lf",&n_sine[i],&off[i]);
            /* check for out of range */
            if (off[i] > joint_range[i][MAX_THETA]) {
                off[i] = joint_range[i][MAX_THETA];
                printf("Reduced offset of joint %s to %f\n",joint_names[i],off[i]);
            }
            if (off[i] < joint_range[i][MIN_THETA]) {
                off[i] = joint_range[i][MIN_THETA];
                printf("Reduced offset of joint %s to %f\n",joint_names[i],off[i]);
            }
            for (j=1; j<=n_sine[i]; ++j) {
                rc=fscanf(fp,"%lf %lf %lf",&(amp[i][j]),&(phase[i][j]),&(freq[i][j]));
                total_amp += amp[i][j];
            }
            /* check for out of range */
            if (total_amp+off[i] > joint_range[i][MAX_THETA]) {
                ratio = total_amp/(joint_range[i][MAX_THETA]-off[i]+1.e-10);
                for (j=1; j<=n_sine[i]; ++j)
                    amp[i][j] /= ratio;
                printf("Reduced amplitude of joint %s to %f\n",joint_names[i],
                       amp[i][j]);
            }
            if (-total_amp+off[i] < joint_range[i][MIN_THETA]) {
                ratio = total_amp/(off[i]-joint_range[i][MIN_THETA]+1.e-10);
                for (j=1; j<=n_sine[i]; ++j)
                    amp[i][j] /= ratio;
                printf("Reduced amplitude of joint %s to %f\n",joint_names[i],
                       amp[i][j]);
            }
        }
    }

    fclose(fp);
    remove_temp_file();


    return found;

}
Esempio n. 15
0
void
read_script(void)
     
{ 
  
  int     i,j,k,m,rc;
  char    fname[100];
  double  dummy;
  int     idummy;
  FILE   *in,*out;
  int     n_train_data_columns;
  int     n_test_data_columns;
  Vector  row;
  char    identification_string[100];
  char    string[100];
  int     num;
  char    vnames[50][100];
  int     ans = 0;
  double  o_noise, c_noise;
  int     old_indx_flag = FALSE;

  Matrix  D_train=NULL;
  char  **vnames_train=NULL;
  char  **units_train=NULL;
  double  freq_train;
  int     n_cols_train;
  int     n_rows_train;
  
  Matrix  D_test=NULL;
  char  **vnames_test=NULL;
  char  **units_test=NULL;
  double  freq_test;
  int     n_cols_test;
  int     n_rows_test;
  

  /* I need the filename of the script file: first check whether the
     user provided it in the argv_global variables */

  if (argc_global > 0) {
    in = fopen(argv_global[1],"r");
    if (in != NULL) {
      fclose(in);
      strcpy(fname,argv_global[1]);
    } else {
      if (!getFile(fname)) exit(-1);
    }
  } else {
    if (!getFile(fname)) exit(-1);
  }

  /* this allows to generate the LWPR */
  if (argc_global > 1) {
    sscanf(argv_global[2],"%d",&new_model);
  } else {
    get_int("Generate new LWPR = 1; Read from file = 0",ans,&ans);
    if (ans) new_model = TRUE;
  }

  if (!readLWPRScript(fname,new_model,LWPR1)) {

    fprintf(stderr,"Error when reading script file >%s<\n",fname);
    exit(-1);

  }
  

  /* now read additional variables from the script */
  in  = fopen_strip(fname);

  /* check for included files */
  if (find_keyword(in,"include")) {  
    char  fname_include[100];
    FILE *fp_include;

    rc=fscanf(in,"%s",fname_include);
    fp_include = fopen_strip(fname_include);
    fseek(fp_include, 0, SEEK_END);
    rewind(in);
    while ((rc=fgetc(in)) != EOF)
      fputc(rc,fp_include);

    fclose(in);
    in = fp_include;

    rewind(in);
  }
    
  /* All the names in file will be parsed. Here I define the names of the
     variables. Note that the variables defining the dimensionality of
     the LWPR must come first since we need them to allocate other 
     variables */

  i=0; 

  /* this block has all variables needed to create a LWPR */

  sprintf(vnames[++i],"n_in_w");
  sprintf(vnames[++i],"n_in_reg");
  sprintf(vnames[++i],"n_out");
  sprintf(vnames[++i],"lwpr_name");
  sprintf(vnames[++i],"n_in_reg_2nd");
  sprintf(vnames[++i],"n_out_2nd");

  /* this block specifies all variables needed to get the data
     for training and testing, as well as some other parameters */

  sprintf(vnames[++i],"sampling_method");
  sprintf(vnames[++i],"index_function");
  sprintf(vnames[++i],"max_iterations");
  sprintf(vnames[++i],"eval_time");
  sprintf(vnames[++i],"cutoff");
  sprintf(vnames[++i],"blending");

  sprintf(vnames[++i],"file_name_train_data");
  sprintf(vnames[++i],"file_name_test_data");

  sprintf(vnames[++i],"name_train_in_w_columns");
  sprintf(vnames[++i],"name_train_in_reg_columns");
  sprintf(vnames[++i],"name_train_out_columns");
  sprintf(vnames[++i],"name_test_in_w_columns");
  sprintf(vnames[++i],"name_test_in_reg_columns");
  sprintf(vnames[++i],"name_test_out_columns");
  sprintf(vnames[++i],"name_train_in_reg_2nd_columns");
  sprintf(vnames[++i],"name_train_out_2nd_columns");
  sprintf(vnames[++i],"name_test_in_reg_2nd_columns");
  sprintf(vnames[++i],"name_test_out_2nd_columns");


  out = fopen("lwpr_test_varnames","w");
  for (j=1; j<=i; ++j) 
    fprintf(out,"%s\n",vnames[j]);
  fclose(out);
  remove_temp_file();

  /* parse keywords */
  i = 0;

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%d",&n_in_w);

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%d",&n_in_reg);

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%d",&n_out);

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%s",lwpr_name);

  if (!find_keyword(in,vnames[++i])) {
      if (lwprs[LWPR1].use_reg_2nd) {
	printf("Could not find variable >%s<\n",vnames[i]);
	exit(-i);
      }
  } else {
    rc=fscanf(in,"%d",&n_in_reg_2nd);
  }
    
  if (!find_keyword(in,vnames[++i])) {
    if (lwprs[LWPR1].use_reg_2nd) {
      printf("Could not find variable >%s<\n",vnames[i]);
      exit(-i);
    }
  } else {
    rc=fscanf(in,"%d",&n_out_2nd);
  }

  /* at last the parameters need to steer the training and testing of
     the LWPR */
  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%d",&sampling_method);

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%d",&index_function);

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%ld",&max_iterations);

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  rc=fscanf(in,"%ld",&eval_time);

  if (find_keyword(in,vnames[++i])) {
    rc=fscanf(in,"%lf",&cutoff);
  }

  if (find_keyword(in,vnames[++i])) {
    rc=fscanf(in,"%d",&blending);
  }

  if (!find_keyword(in,vnames[++i]) && argc_global <= 2) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  if (argc_global > 2) {
    strcpy(fname_train_data,argv_global[3]);
  } else {
    rc=fscanf(in,"%s",fname_train_data);
  }

  if (!find_keyword(in,vnames[++i]) && argc_global <= 3) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  if (argc_global > 3) {
    strcpy(fname_test_data,argv_global[4]);
  } else {
    rc=fscanf(in,"%s",fname_test_data);
  }


  // at this point the data files can be read -- they are expected to be in
  // MRDPLOT format

  printf("Reading training data from >%s<...",fname_train_data);
  if (!mrdplot_convert(fname_train_data, &D_train, &vnames_train, &units_train, 
		       &freq_train, &n_cols_train, &n_rows_train)) {
    printf("Problems reading MRDPLOT file >%s<\n",fname_train_data);
    exit(-999);
  }
  printf("done\n");
  printf("%d rows with %d columns read\n",n_rows_train,n_cols_train);

  printf("Reading test data from >%s<...",fname_test_data);
  if (!mrdplot_convert(fname_test_data, &D_test, &vnames_test, &units_test, 
		       &freq_test, &n_cols_test, &n_rows_test)) {
    printf("Problems reading MRDPLOT file >%s<\n",fname_test_data);
    exit(-999);
  }
  printf("done\n");
  printf("%d rows with %d columns read\n",n_rows_test,n_cols_test);


  // allocate memory for all arrays
  Xw_train       = my_matrix(1,n_rows_train,1,n_in_w);      
  Xreg_train     = my_matrix(1,n_rows_train,1,n_in_reg);
  Xreg_train_2nd = my_matrix(1,n_rows_train,1,n_in_reg_2nd);
  Xw_test        = my_matrix(1,n_rows_test,1,n_in_w);
  Xreg_test      = my_matrix(1,n_rows_test,1,n_in_reg);
  Xreg_test_2nd  = my_matrix(1,n_rows_test,1,n_in_reg_2nd);
  Y_train        = my_matrix(1,n_rows_train,1,n_out);
  Y_train_2nd    = my_matrix(1,n_rows_train,1,n_out_2nd);
  Y_test         = my_matrix(1,n_rows_test,1,n_out);
  Y_test_2nd     = my_matrix(1,n_rows_test,1,n_out_2nd);
  x_w            = my_vector(1,n_in_w);
  x_reg          = my_vector(1,n_in_reg);
  x_reg_2nd      = my_vector(1,n_in_reg_2nd);
  y              = my_vector(1,n_out);
  y_2nd          = my_vector(1,n_out_2nd);
  conf           = my_vector(1,n_out);
  conf_2nd       = my_vector(1,n_out_2nd);
  var_y          = my_vector(1,n_out);
  var_y_2nd      = my_vector(1,n_out_2nd);
  mean_y         = my_vector(1,n_out);
  mean_y_2nd     = my_vector(1,n_out_2nd);

  // sort the test and training data into the appropriate arrays

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  for (j=1; j<=n_in_w; ++j) {
    rc=fscanf(in,"%s",string);
    if (!(k=findIndex(string,vnames_train,n_cols_train))) {
      printf("Couldn't find column >%s< in training data\n",string);
      exit(-i);
    } else {
      for (m=1; m<=n_rows_train; ++m)
	Xw_train[m][j] = D_train[m][k];
    }
  }

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  for (j=1; j<=n_in_reg; ++j) {
    rc=fscanf(in,"%s",string);
    if (!(k=findIndex(string,vnames_train,n_cols_train))) {
      printf("Couldn't find column >%s< in training data\n",string);
      exit(-i);
    } else {
      for (m=1; m<=n_rows_train; ++m)
	Xreg_train[m][j] = D_train[m][k];
    }
  }
  
  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  for (j=1; j<=n_out; ++j) {
    rc=fscanf(in,"%s",string);
    if (!(k=findIndex(string,vnames_train,n_cols_train))) {
      printf("Couldn't find column >%s< in training data\n",string);
      exit(-i);
    } else {
      for (m=1; m<=n_rows_train; ++m)
	Y_train[m][j] = D_train[m][k];
    }
  }
  

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  for (j=1; j<=n_in_w; ++j) {
    rc=fscanf(in,"%s",string);
    if (!(k=findIndex(string,vnames_test,n_cols_test))) {
      printf("Couldn't find column >%s< in test data\n",string);
      exit(-i);
    } else {
      for (m=1; m<=n_rows_test; ++m)
	Xw_test[m][j] = D_test[m][k];
    }
  }

  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  for (j=1; j<=n_in_reg; ++j) {
    rc=fscanf(in,"%s",string);
    if (!(k=findIndex(string,vnames_test,n_cols_test))) {
      printf("Couldn't find column >%s< in test data\n",string);
      exit(-i);
    } else {
      for (m=1; m<=n_rows_test; ++m)
	Xreg_test[m][j] = D_test[m][k];
    }
  }
  
  if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
  for (j=1; j<=n_out; ++j) {
    rc=fscanf(in,"%s",string);
    if (!(k=findIndex(string,vnames_test,n_cols_test))) {
      printf("Couldn't find column >%s< in test data\n",string);
      exit(-i);
    } else {
      for (m=1; m<=n_rows_test; ++m)
	Y_test[m][j] = D_test[m][k];
    }
  }
  

  if (lwprs[LWPR1].use_reg_2nd) {

    if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
    for (j=1; j<=n_in_reg_2nd; ++j) {
      rc=fscanf(in,"%s",string);
      if (!(k=findIndex(string,vnames_train,n_cols_train))) {
	printf("Couldn't find column >%s< in training data\n",string);
	exit(-i);
      } else {
	for (m=1; m<=n_rows_train; ++m)
	  Xreg_train_2nd[m][j] = D_train[m][k];
      }
    }
    
    if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
    for (j=1; j<=n_out_2nd; ++j) {
      rc=fscanf(in,"%s",string);
      if (!(k=findIndex(string,vnames_train,n_cols_train))) {
	printf("Couldn't find column >%s< in training data\n",string);
	exit(-i);
      } else {
	for (m=1; m<=n_rows_train; ++m)
	  Y_train_2nd[m][j] = D_train[m][k];
      }
    }
    
    if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
    for (j=1; j<=n_in_reg_2nd; ++j) {
      rc=fscanf(in,"%s",string);
      if (!(k=findIndex(string,vnames_test,n_cols_test))) {
	printf("Couldn't find column >%s< in test data\n",string);
      exit(-i);
      } else {
	for (m=1; m<=n_rows_test; ++m)
	  Xreg_test_2nd[m][j] = D_test[m][k];
      }
    }
    
    if (!find_keyword(in,vnames[++i])) {
    printf("Could not find variable >%s<\n",vnames[i]);
    exit(-i);
  }
    for (j=1; j<=n_out_2nd; ++j) {
      rc=fscanf(in,"%s",string);
      if (!(k=findIndex(string,vnames_test,n_cols_test))) {
	printf("Couldn't find column >%s< in test data\n",string);
	exit(-i);
      } else {
	for (m=1; m<=n_rows_test; ++m)
	  Y_test_2nd[m][j] = D_test[m][k];
      }
    }

  }

  fclose(in);

  n_train_data = n_rows_train;
  n_test_data  = n_rows_test;


  if (NORMALIZE_BY_TRAIN) {

    for (i=1; i<=n_train_data; ++i) {
      vec_add_size(mean_y,Y_train[i],n_out,mean_y);
    }
    vec_mult_scalar(mean_y,1./(double)n_train_data,mean_y);

    for (i=1; i<=n_train_data; ++i) {
      for (j=1; j<=n_out; ++j) {
	var_y[j] += sqr(Y_train[i][j]-mean_y[j]);
      }
    }
    vec_mult_scalar(var_y,1./(double)n_train_data,var_y);

    if (lwprs[LWPR1].use_reg_2nd) {

      for (i=1; i<=n_train_data; ++i) {
	vec_add_size(mean_y_2nd,Y_train_2nd[i],n_out,mean_y_2nd);
      }
      vec_mult_scalar(mean_y_2nd,1./(double)n_train_data,mean_y_2nd);
      
      for (i=1; i<=n_train_data; ++i) {
	for (j=1; j<=n_out_2nd; ++j) {
	  var_y_2nd[j] += sqr(Y_train_2nd[i][j]-mean_y_2nd[j]);
	}
      }
      vec_mult_scalar(var_y_2nd,1./(double)n_train_data,var_y_2nd);

    }

  } else {

    for (i=1; i<=n_test_data; ++i) {
      vec_add_size(mean_y,Y_test[i],n_out,mean_y);
    }
    vec_mult_scalar(mean_y,1./(double)n_test_data,mean_y);

    for (i=1; i<=n_test_data; ++i) {
      for (j=1; j<=n_out; ++j) {
	var_y[j] += sqr(Y_test[i][j]-mean_y[j]);
      }
    }
    vec_mult_scalar(var_y,1./(double)n_test_data,var_y);

    if (lwprs[LWPR1].use_reg_2nd) {

      for (i=1; i<=n_test_data; ++i) {
	vec_add_size(mean_y_2nd,Y_test_2nd[i],n_out,mean_y_2nd);
      }
      vec_mult_scalar(mean_y_2nd,1./(double)n_test_data,mean_y_2nd);
      
      for (i=1; i<=n_train_data; ++i) {
	for (j=1; j<=n_out_2nd; ++j) {
	  var_y_2nd[j] += sqr(Y_test_2nd[i][j]-mean_y_2nd[j]);
	}
      }
      vec_mult_scalar(var_y_2nd,1./(double)n_train_data,var_y_2nd);

    }
  }

  
}