Пример #1
0
int main()
{
  check_endianess();
  printf("Endianess of this machine: ");
  if(little_endian==1) printf("little\n");
  else printf("big\n");
  
  return 0;
}
Пример #2
0
void MSG_header::read_from( std::ifstream &in )
{
  unsigned char_1 primary_header[MSG_HEADER_PRIMARY_LEN];
  unsigned char_1 *hbuff;

  check_endianess( );
  in.read((char_1 *) primary_header, MSG_HEADER_PRIMARY_LEN);
  if (in.fail( ))
  {
    std::cerr << "Read error from HRIT file: Primary Header." << std::endl;
    throw;
  }
  if (primary_header[0] != MSG_HEADER_PRIMARY)
  {
    std::cerr << "Error: First header type value is not primary." << std::endl;
    throw;
  }
  if (get_ui2(primary_header+1) != MSG_HEADER_PRIMARY_LEN)
  {
    std::cerr << "Error: Primary Header Length mismatch." << std::endl;
    std::cerr << "Header Length: " << get_ui2(primary_header+1) << std::endl;
    throw;
  }
  f_typecode = (t_enum_MSG_filetype) *(primary_header+3);
  total_header_length = get_ui4(primary_header+4);
  data_field_length   = get_ui8(primary_header+8);
  filesize = data_field_length/8+total_header_length;
  size_t hsize = total_header_length-MSG_HEADER_PRIMARY_LEN;
  hbuff = new unsigned char_1[hsize];
  if (!hbuff)
  {
    std::cerr << "Memory allocation error in MSG_header." << std::endl
              << "Requested allocation of " << hsize << " bytes." << std::endl;
    throw;
  }
  in.read((char_1 *) hbuff, hsize);
  if (in.fail( ))
  {
    std::cerr << "Read error from HRIT file: Header body" << std::endl;
    throw;
  }
  unsigned char_1 *pnt = hbuff;
  size_t left = hsize;
  size_t hunk_size = 0;
  size_t hqlen = 0;
  while (left)
  {
    switch(*pnt)
    {
      case MSG_HEADER_IMAGE_STRUCTURE:
        if (get_ui2(pnt+1) != MSG_IMAGE_STRUCTURE_LEN)
        {
          std::cerr << "Error: Image Structure Header mismatch." << std::endl;
          std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl;
          throw;
        }
        image_structure = new MSG_header_image_struct;
        image_structure->read_from(pnt);
        pnt = pnt + MSG_IMAGE_STRUCTURE_LEN;
        left = left - MSG_IMAGE_STRUCTURE_LEN;
        break;
      case MSG_HEADER_IMAGE_NAVIGATION:
        if (get_ui2(pnt+1) != MSG_IMAGE_NAVIGATION_LEN)
        {
          std::cerr << "Error: Image Navigation Header mismatch." << std::endl;
          std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl;
          throw;
        }
        image_navigation = new MSG_header_image_navig;
        image_navigation->read_from(pnt);
        pnt = pnt + MSG_IMAGE_NAVIGATION_LEN;
        left = left - MSG_IMAGE_NAVIGATION_LEN;
        break;
      case MSG_HEADER_IMAGE_DATA_FUNCTION:
        hunk_size = (size_t) get_ui2(pnt+1);
        image_data_function = new MSG_header_image_datafunc;
        image_data_function->read_from(pnt);
        pnt = pnt + hunk_size;
        left = left - hunk_size;
        break;
      case MSG_HEADER_ANNOTATION:
        if (get_ui2(pnt+1) != MSG_ANNOTATION_LEN)
        {
          std::cerr << "Error: Annotation Header mismatch." << std::endl;
          std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl;
          throw;
        }
        annotation = new MSG_header_annotation;
        annotation->read_from(pnt);
        pnt = pnt + MSG_ANNOTATION_LEN;
        left = left - MSG_ANNOTATION_LEN;
        break;
      case MSG_HEADER_TIMESTAMP:
        if (get_ui2(pnt+1) != MSG_TIMESTAMP_LEN)
        {
          std::cerr << "Error: Timestamp Header mismatch." << std::endl;
          std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl;
          throw;
        }
        timestamp = new MSG_header_timestamp;
        timestamp->read_from(pnt);
        pnt = pnt + MSG_TIMESTAMP_LEN;
        left = left - MSG_TIMESTAMP_LEN;
        break;
      case MSG_HEADER_ANCILLARY_TEXT:
        hunk_size = (size_t) get_ui2(pnt+1);
        ancillary_text = new MSG_header_ancillary_text;
        ancillary_text->read_from(pnt);
        pnt = pnt + hunk_size;
        left = left - hunk_size;
        break;
      case MSG_HEADER_KEY:
        if (get_ui2(pnt+1) != MSG_KEY_LEN)
        {
          std::cerr << "Error: Key Header mismatch." << std::endl;
          std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl;
          throw;
        }
        key = new MSG_header_key;
        key->read_from(pnt);
        pnt = pnt + MSG_KEY_LEN;
        left = left - MSG_KEY_LEN;
        break;
      case MSG_HEADER_SEGMENT_IDENTIFICATION:
        if (get_ui2(pnt+1) != MSG_SEGMENT_ID_LEN)
        {
          std::cerr << "Error: Segment Id Header mismatch." << std::endl;
          std::cerr << "Header Length: " << get_ui2(pnt+1) << std::endl;
          throw;
        }
        segment_id = new MSG_header_segment_id;
        segment_id->read_from(pnt);
        pnt = pnt + MSG_SEGMENT_ID_LEN;
        left = left - MSG_SEGMENT_ID_LEN;
        break;
      case MSG_HEADER_IMAGE_SEGMENT_LINE_QUALITY:
        segment_quality = new MSG_header_segment_quality;
        segment_quality->read_from(pnt, image_structure->number_of_lines);
        hqlen = get_ui2(pnt+1);
        pnt = pnt + hqlen;
        left = left - hqlen;
        break;
      default:
        std::cerr << "Unknown header type: " << (uint_2) *pnt << std::endl;
        std::cerr << "Unparsed " << left << " bytes." << std::endl;
        throw;
        break;
      }
   }
   delete [ ] hbuff;
   return;
}
Пример #3
0
int main(int narg,char **arg)
{
  if(narg<2)
    {
      fprintf(stderr,"Error, use: %s run_input\n",arg[0]);
      exit(1);
    }
  
  int big_endian=check_endianess();
  
  FILE *frun_input=open_file(arg[1],"r");
  
  //read the analysis templ
  sun_string analysis_templ_path;
  read_formatted_from_file_expecting(analysis_templ_path,frun_input,"%s","analysis_templ_path");
  FILE *fatempl=open_file(analysis_templ_path,"r");
  read_formatted_from_file_expecting((char*)&nlevel,fatempl,"%d","nlevel");
  //allocate room for the header format
  var_name=(sun_string*)malloc(nlevel*sizeof(sun_string));
  var_value_tot=(int*)malloc(nlevel*sizeof(int));
  var_values=(sun_string**)malloc(nlevel*sizeof(sun_string*));
  level_header_templ=(sun_string*)malloc(nlevel*sizeof(sun_string));
  required_header=(int*)malloc(nlevel*sizeof(int));
  //read the name of the looping variables and their values
  for(int ilevel=0;ilevel<nlevel;ilevel++)
    {
      read_formatted_from_file_expecting(var_name[ilevel],fatempl,"%s","var_name");
      expect_string_from_file(frun_input,var_name[ilevel]);
      read_formatted_from_file_expecting((char*)&(var_value_tot[ilevel]),frun_input,"%d","var_value_tot");

      var_values[ilevel]=(sun_string*)malloc(var_value_tot[ilevel]*sizeof(sun_string));
      expect_string_from_file(frun_input,"list_of_var_values");
      for(int ival=0;ival<var_value_tot[ilevel];ival++)
	read_formatted_from_file(var_values[ilevel][ival],frun_input,"%s","var_value");
      
      read_formatted_from_file_expecting(level_header_templ[ilevel],fatempl,"%s","header");
      required_header[ilevel]=strcmp(level_header_templ[ilevel],"NO");
    }
  fclose(fatempl);
  //read T
  int T;
  read_formatted_from_file_expecting((char*)&T,frun_input,"%d","T");
  //read the output file
  sun_string outpath;
  read_formatted_from_file_expecting(outpath,frun_input,"%s","outfile");
  FILE *fout=open_file(outpath,"w");
  //read the number of jacknives
  unsigned int njack;
  read_formatted_from_file_expecting((char*)&njack,frun_input,"%d","njack");
  //read the path templ
  sun_string path_templ;
  read_formatted_from_file_expecting(path_templ,frun_input,"%s","path_templ");
  //read the number of files to open
  int tfiles;
  read_formatted_from_file_expecting((char*)&tfiles,frun_input,"%d","nfiles");
  //calculate cluster size
  int clus_size=tfiles/njack;
  int nfiles=clus_size*njack;
  printf("Njack: %d, cluster size: %d\n",njack,clus_size);
  //open all the input files, reading each entry
  expect_string_from_file(frun_input,"list_of_files");
  FILE *fdata[nfiles];
  for(int ifile=0;ifile<nfiles;ifile++)
    {
      sun_string chunk;
      read_formatted_from_file(chunk,frun_input,"%s","particular file name");
      sun_string file_path;
      sprintf(file_path,path_templ,chunk);
      fdata[ifile]=open_file(file_path,"r");
      //printf("file %d = %s\n",ifile,file_path);
    }

  /////////////////////////////////////////////////////////////////////////////////

  //calculate the number of combo on which to loop
  int ncombo=1;
  for(int ilevel=0;ilevel<nlevel;ilevel++) ncombo*=var_value_tot[ilevel];
  
  //loop over all the combo
  for(int icombo=0;icombo<ncombo;icombo++)
    {
      int level_entry[nlevel];
      memset(level_entry,0,sizeof(int)*nlevel);
      
      int temp_icombo=icombo;
      for(int ilevel=nlevel-1;ilevel>=0;ilevel--)
	{
	  level_entry[ilevel]=temp_icombo%var_value_tot[ilevel];
	  temp_icombo/=var_value_tot[ilevel];
	}

      //now read all the required header
      for(int ilevel=0;ilevel<nlevel;ilevel++)
	if(required_header[ilevel] && (ilevel==nlevel-1||level_entry[ilevel+1]==0))
	  {
	    sun_string header;
	    prepare_header(header,level_header_templ[ilevel],level_entry);
	    
	    for(int ifile=0;ifile<nfiles;ifile++)
	      {
		sun_string read_header;
		int nchar;
		do
		  {
		    char *read=fgets(read_header,1024,fdata[ifile]);
		    if(read!=read_header)
		      {
			fprintf(stderr,"Error while reading header: %s\n",header);
			exit(1);
		      }
		    
		    nchar=0;
		    do if(*read!=' ' && *read!='\n' && *read!='\0') nchar++;
		    while(*(read++)!='\0' && nchar==0);
		  }
		while(nchar==0);
		  
		  if(strcmp(read_header,header))
		    {
		      fprintf(stderr,"Error while reading header: '%s', obtained: '%s'\n",header,read_header);
		      exit(1);
		    }
	      }
	  }
      
      //now read a whole correlation
      double data[nfiles][T][2];
      for(int ifile=0;ifile<nfiles;ifile++)
	for(int t=0;t<T;t++)
	  for(int ri=0;ri<2;ri++)
	    read_formatted_from_file((char*)&data[ifile][t][ri],fdata[ifile],"%lg","data");
      
      //clusterize
      double clus[2][T][njack+1];
      memset(clus,0,sizeof(double)*2*T*(njack+1));
      for(int ri=0;ri<2;ri++)
	for(int t=0;t<T;t++)
	  {
	    for(int ifile=0;ifile<nfiles;ifile++)
	      {
		int iclus=ifile%njack;
		clus[ri][t][iclus]+=data[ifile][t][ri];
	      }
	    for(unsigned int iclus=0;iclus<njack;iclus++) clus[ri][t][njack]+=clus[ri][t][iclus];
	    for(unsigned int ijack=0;ijack<njack;ijack++) clus[ri][t][ijack]=(clus[ri][t][njack]-clus[ri][t][ijack])/(nfiles-clus_size);
	    clus[ri][t][njack]/=nfiles;
	  }
      
      if(big_endian==0) doubles_to_doubles_changing_endianess((double*)clus,(double*)clus,2*T*(njack+1));
      
      for(int t=0;t<T;t++) printf("%d %lg %lg\n",t,clus[0][t][njack],clus[1][t][njack]);
      
      if(fwrite(clus,sizeof(double),2*T*(njack+1),fout)!=2*T*(njack+1))
	{
	  fprintf(stderr,"Error while writing double!\n");
	  exit(1);
	}

      if(icombo%100==0) printf("Completed correlation: %d\n",icombo);
    }

  return 0;
}
Пример #4
0
static void
check_system (conf_t * conf)
{
  struct utsname un;
  char *p;

  if (uname (&un) == -1)
    {
      perror ("uname");
      exit (-1);
    }

  if (strcmp (un.sysname, "UnixWare") == 0)
    strcpy (un.sysname, "SCO_SV");
  if (strcmp (un.sysname, "Haiku") == 0)
    strcpy (un.sysname, "BeOS");
  printf ("System: %s\n", un.sysname);
  strcpy (conf->system, un.sysname);
  sprintf (this_os, "kernel/OS/%s", un.sysname);
  printf ("Release: %s\n", un.release);
  printf ("Machine: %s\n", un.machine);
  strcpy (conf->arch, un.machine);

#ifdef HAVE_SYSDEP
  check_sysdep (conf, &un);
#else

# if defined(__SCO_VERSION__)
	shlib_ldflags = "-G -lsocket -lnsl";
# endif

  if (strcmp (un.machine, "i386") == 0 ||
      strcmp (un.machine, "i486") == 0 ||
      strcmp (un.machine, "i586") == 0 || strcmp (un.machine, "i686") == 0)
    {
      strcpy (conf->platform, "i86pc");
    }
  else
    {
      fprintf (stderr, "Cannot determine the platform for %s\n", un.machine);
      exit (-1);
    }
#endif

  if (*conf->platform == 0)
    {
      fprintf (stderr, "Panic: No platform\n");
      exit (-1);
    }

  check_endianess (conf);

/*
 * Check virtual mixer configuration (as set by the configure script).
 */

  if ((p=getenv("VMIX_MODE"))!=NULL)
     {
	     vmix_mode = strdup(p);
     }

/*
 * Check MIDI enabled/disabled status
 */

  if ((p=getenv("CONFIG_MIDI"))!=NULL)
     {
	     config_midi = strdup(p);
     }

  produce_local_config_h (conf);
}