예제 #1
0
 bool writeResource(VirtualFile* file, ResourceDatabase* resource) const
 {
   bool ok = true;
   for(unsigned i=0; i<resource->count<Image>(); ++i)
     ok &= savePNG(resource->get<Image>(i), file, compression());
   return ok;
 }
예제 #2
0
 bool writeResource(const String& path, ResourceDatabase* resource) const
 {
   bool ok = true;
   for(unsigned i=0; i<resource->count<Image>(); ++i)
     ok &= savePNG(resource->get<Image>(i), path, compression());
   return ok;
 }
예제 #3
0
int video_pwc_t::compression(int c)
{
  
  if(ioctl(fd,VIDIOCPWCSCQUAL,&c) < 0){
    perror("video_pwc_t, compression setting error");
  }
  return compression();
}
예제 #4
0
파일: huf.c 프로젝트: MeryllEssig/archiver
int main(int argc, char** argv)
{
  if(testFichier(argv[1], argv[2], argc) == 0)
    return 0;
	
  int i = 0; 
  int compteur = 0;
  float tailleCodage = 0.0;
  int iNoeudRacine = 256;
	
  calculFreq(argv[1]);
  construcArbre(&iNoeudRacine);
  parcours(&iNoeudRacine, "");
  unsigned long int *tabTaille;
  tabTaille = compression(argv[1], argv[2]);
	
  printf("Fréquences des caractères présents dans le fichier :\n");
  for(i=0;i<256;i++) {
    if(frequences[i]!=0)
      printf("\t(%d)\t%.2f <=> %.2f%%\n", i, frequences[i],frequences[i]*100);
  }
	
  printf("\nValeurs de l'arbre :\n\n\tNoeud\tPere\tFils G\tFils D\n");
  for(i=0;i<511;i++) {
    if(Arbre[i].fr != 0) {
      printf("\t(%d)\t%d\t%d\t%d\n", i, Arbre[i].pere, Arbre[i].fg, Arbre[i].fd);
    }
  }
  printf("\nCodes Huffman\n");
  for(i=0;i<256;i++) {
    if(tableCodes[i] != NULL){
      if(i>=0 && i<10)
	printf("\t(00%d) : %s\n", i, tableCodes[i]);
      if(i>=10 && i<100)
	printf("\t(0%d) : %s\n", i, tableCodes[i]);
      if(i>=100)
	printf("\t(%d) : %s\n", i, tableCodes[i]);
      ++compteur;
      tailleCodage += (float)strlen(tableCodes[i]);
    }
  }
  tailleCodage /= (float)compteur;
  printf("\nLong. moy. du codage : %.4f\n\n", tailleCodage);
	
  float gain;
  gain = ((float)tabTaille[1])/((float)(tabTaille[0]));
  gain = 1.0 - gain;
	
  printf("Données:\n\tTaille originelle : \t%ld\n\tTaille compressée : \t%ld\n\tGain : \t\t\t%.3f\n\tGain en %% : \t\t%.3f%%\n", tabTaille[0], tabTaille[1], gain, gain*100.0);
  for(i=0;i<256;i++){
    free(tableCodes[i]);
  }
  free(tabTaille); //tabTaille est le tableau retourné par unsigned long int compression()
	
  return 0;
}
예제 #5
0
/*
* Choose which compression algorithm to use
*/
byte TLS_Policy::choose_compression(const std::vector<byte>& c_comp) const
   {
   std::vector<byte> s_comp = compression();

   for(size_t i = 0; i != s_comp.size(); ++i)
      for(size_t j = 0; j != c_comp.size(); ++j)
         if(s_comp[i] == c_comp[j])
            return s_comp[i];

   return NO_COMPRESSION;
   }
예제 #6
0
//---------------------------------------------------------------------------
void File_Exr::Data_Parse()
{
    
    if (CC4(Buffer+Buffer_Offset)==0x762F3101) //"v/1"+1 //Header
        Header();
    else if (name=="comments" && type=="string")
        comments();
    else if (name=="compression" && type=="compression" && Element_Size==1)
        compression();
    else if (name=="dataWindow" && type=="box2i" && Element_Size==16)
        dataWindow();
    else if (name=="displayWindow" && type=="box2i" && Element_Size==16)
        displayWindow();
    else if (name=="pixelAspectRatio" && type=="float" && Element_Size==4)
        pixelAspectRatio();
    else
        Skip_XX(Element_Size,                                   "value");
}
예제 #7
0
void main(int argc, char* argv[])
{
	if(argc != 4)										// 1. 압축 또는 풀기
	{													// 2. target 파일이름.
		printf("Usage : command(c or d) target output\n");		// 3. output 파일이름.
		exit(1);
	}

	char cmd[BUFSIZE] = {0,}; 		// output파일의 권한 설정용 버퍼.
	FILE *fpInput = NULL;
	FILE *fpOutput = NULL;

	fpInput = fopen(argv[2], "rb");

	if(fpInput == NULL)
	{
		printf("There's not a file : %s\n", argv[1]);
		exit(1);
	}
	fpOutput = fopen(argv[3], "wb");	
	if(strcmp(argv[1],"c") == 0)
	{
		compression(fpInput, fpOutput);	// 압축
	}
	else if(strcmp(argv[1], "d") == 0)
	{
		deCompression(fpInput, fpOutput); // 풀기
	}
	else 
	{
		printf("There's not a command such as %s\ncommand : c or d\n", argv[1]); // c,d 이외의 명령어 경우 프로그램 종료.

		fclose(fpInput);
		fclose(fpOutput);
		exit(1);
	}

	fclose(fpInput);
	fclose(fpOutput);

	sprintf(cmd, "chmod 775 %s",argv[3]);		// output파일의 권한 설정.
	system(cmd);
}
예제 #8
0
//---------------------------------------------------------------------------
void File_Exr::Data_Parse()
{
         if (name_End==0)
        ImageData();
    else if (name=="channels" && type=="chlist")
        channels();
    else if (name=="comments" && type=="string")
        comments();
    else if (name=="compression" && type=="compression" && Element_Size==1)
        compression();
    else if (name=="dataWindow" && type=="box2i" && Element_Size==16)
        dataWindow();
    else if (name=="displayWindow" && type=="box2i" && Element_Size==16)
        displayWindow();
    else if (name=="pixelAspectRatio" && type=="float" && Element_Size==4)
        pixelAspectRatio();
    else
        Skip_XX(Element_Size,                                   "value");
}
예제 #9
0
void fazLeitura(FILE *input, FILE *tmp, CHAR *sb, INT count)
{
	CHAR c;
	INT i;

	for(i = count; !feof(input) && i <= 32767; i++)
	{
		c = fgetc(input);
		if((INT)c != 255) // Retirando o char que indica o EOF
			sb[i] = c;
	}

	// Chama função que faz a compressão
	compression(tmp, sb);

	if(i > 32767)
	{
		sb = doJumps(input, sb);
		fazLeitura(input, tmp, sb, count);
	}
}
예제 #10
0
파일: fft.c 프로젝트: ivolkov/geff
void fft_perform()
{
	/* copy fft_real_in buffer to fft_real_compressed */
	memcpy(fft_real_compressed, fft_real_in, sizeof(double) * audio_period_size_frames);

	/* apply compression */
	compression(fft_real_compressed);

	/* execute FFT */
    fftw_execute(fft_plan_forward);
    fftw_execute(fft_plan_forward_compressed);

    int i;

    for (i = 0; i < audio_period_size_frames; i++) {
    	/* copy fft_comp_compressed -> fft_comp_work */
    	fft_comp_equalized[i][0] = fft_comp_compressed[i][0];
    	fft_comp_equalized[i][1] = fft_comp_compressed[i][1];

    	/* apply equalizer */
    	if (i < FFT_LEN) {
    		fft_comp_equalized[i][0] *= ipc_eq[i];
    		fft_comp_equalized[i][1] *= ipc_eq[i];
    	} else {
    		fft_comp_equalized[i][0] *= ipc_eq[FFT_LEN - (i - FFT_LEN + 1)];
    		fft_comp_equalized[i][1] *= ipc_eq[FFT_LEN - (i - FFT_LEN + 1)];
    	}
    }

    /* do a copy of modified FFT data, for fft_data_work will be destroyed during backward FFT transform */
    for (i = 0; i < audio_period_size_frames; i++) {
    	fft_comp_out[i][0] = fft_comp_equalized[i][0];
    	fft_comp_out[i][1] = fft_comp_equalized[i][1];
    }

    fftw_execute(fft_plan_backward);

    for (i = 0; i < audio_period_size_frames; i++)
    	fft_real_out[i] /= (double)audio_period_size_frames;
}
예제 #11
0
bool
Monitor::parseCommand( const char * message )
{
    if ( ! std::strcmp( message, "(dispbye)" ) )
    {
        disable();
        return true;
    }
    else if ( ! std::strcmp( message, "(dispstart)" ) )
    {
        M_stadium.kickOff();
        return true;
    }
    else if ( ! std::strncmp( message, "(dispplayer", 11 ) )
    {
        return dispplayer( message );
    }
    else if ( ! std::strncmp( message, "(dispdiscard", 12 ) )
    {
        return dispdiscard( message );
    }
    else if ( ! std::strncmp( message, "(compression", 12 ) )
    {
        return compression( message );
    }
    else if ( ! std::strncmp( message, "(dispfoul", 9 ) )
    {
        return dispfoul( message );
    }
    else if ( ! std::strncmp( message, "(dispcard", 9 ) )
    {
        return dispcard( message );
    }
    else if ( ServerParam::instance().coachMode()
              || ServerParam::instance().coachWithRefereeMode() )
    {
        if ( ! std::strncmp( message, "(start)", 7 ) )
        {
            M_stadium.kickOff();
            sendMsg( MSG_BOARD, "(ok start)" );
            return true;
        }
        else if ( ! std::strncmp( message, "(change_mode", 12 ) )
        {
            return coach_change_mode( message );
        }
        else if ( ! std::strncmp( message, "(move", 5 ) )
        {
            return coach_move( message );
        }
        else if ( ! std::strncmp( message, "(recover", 8 ) )
        {
            return coach_recover();
        }
        else if ( ! std::strcmp( message, "change_player_type" ) )
        {
            return coach_change_player_type( message );
        }
        else if ( ! std::strncmp( message, "(check_ball", 11 ) )
        {
            return coach_check_ball();
        }
        else
        {
            sendMsg( MSG_BOARD, "(error illegal_command_form)" );
            return false;
        }
    }
    else
    {
        sendMsg( MSG_BOARD, "(error illegal_command_form)" );
        return false;
    }

    return true;
}
예제 #12
0
int main(int argc, char *argv[])
{
    QList<QString> arg;
    for(int i = 0; argv[i]; i++){
        arg += argv[i];
    }


    if(argc == 3 && arg[1] == "-c") {
        QString nameFile = arg[2];
        compression(nameFile, getNameOut(nameFile));
    }

    else if(argc == 5 && arg[1] == "-c" && arg[3] == "-o"){
        QString nameFileIn = arg[2];
        QString nameFileOut = arg[4];
        if(isDotHuff(nameFileOut)){
            compression(nameFileIn, nameFileOut);
        }
        else{
            help();
        }
    }

    else if(argc == 2 && arg[1] != "--gui"){
        QString nameFile = arg[1];
        if(isDotHuff(nameFile)){
            uncompression(nameFile);
        }
        else{
            qDebug() << "O arquivo não é do tipo .huff";
            help();
        }
    }

    else if(argc == 4 && arg[2] == "-d"){
        QString nameFile = arg[1];
        QString localOut = arg[3];
        if(localOut.size() && localOut[localOut.size()-1] != '/') localOut += '/';

        if(isDotHuff(nameFile)){
            uncompression(nameFile, localOut);
        }
        else{
            qDebug() << "O arquivo não é do tipo .huff";
            help();
        }
    }

    else if(argc == 2 && arg[1] == "--gui"){
        QApplication a(argc, argv);
        Gui w;
        w.show();
        return a.exec();
    }

    else if(argc == 2 && (arg[1] == "-h" || arg[1] == "-help")){
        help();
    }

    else if(argc == 3 && arg[1] == "-com"){
        QString nameFile = arg[2];
        QString nameFileOut = getNameOut(nameFile);
        compression(nameFile, nameFileOut);
        compression(nameFileOut, nameFileOut);
    }

    else if(argc == 3 && arg[1] == "-decom"){
        QString nameFile = arg[2];
        if(isDotHuff(nameFile)){
            uncompression(nameFile);
            if(isDotHuff(nameFile)){
                uncompression(nameFile);
            }
            else{
                qDebug() << "O arquivo não foi comprimido duplamente";
            }
        }
        else{
            qDebug() << "O arquivo não é do tipo .huff";
            help();
        }
    }

    else{
        qDebug() << "COMANDO INVALIDO!\n";
        help();
    }
    return 0;
}
예제 #13
0
int main(int argc, char *argv[]){

	// Housekeeping inputs
	int warnings = 0;                  // Display warnings
	int recover = 0;                   // Recover from previous simulation

	int ir = 0;
	int i = 0;
	int j = 0;
	int im = 0;

	int nmoons_max = 100;

	// Grid inputs
    double timestep = 0.0;             // Time step of the sim (yr)
    double speedup = 0.0;              // Speedup factor of the thermal evolution sim (if thermal-orbital sim taks too much time)
	int NR = 0;                        // Number of grid zones
	double total_time = 0.0;           // Total time of sim
	double output_every = 0.0;         // Output frequency
    int NT_output = 0;                 // Time step for writing output

	// Planet inputs
	double Mprim = 0.0;                // Mass of the primary (host planet) (kg)
	double Rprim = 0.0;				   // Radius of the primary (host planet) (km)
	double Qprimi = 0.0;			   // Initial tidal Q of the primary (host planet)
	double Qprimf = 0.0;               // Final tidal Q of the primary
	int Qmode = 0;                     // How Q changes over time between Qprimi and Qprimf. 0:linearly; 1:exponential decay; 2:exponential change
	double k2prim = 0.0;               // k2 tidal Love number of primary (Saturn: 0.39, Lainey et al. 2017?, 1.5 for homogeneous body)
	double J2prim = 0.0;               // 2nd zonal harmonic of gravity field (Saturn: 16290.71±0.27e-6, Jacobson et al., 2006)
	double J4prim = 0.0;               // 4th zonal harmonic of gravity field (-935.83±2.77e-6, Jacobson et al., 2006)
	int nmoons = 0;                    // User-specified number of moons
	double Mring = 0.0;                // Mass of planet rings (kg). For Saturn, 4 to 7e19 kg (Robbins et al. 2010, http://dx.doi.org/10.1016/j.icarus.2009.09.012)
	double aring_in = 0.0;             // Inner orbital radius of rings (km). for Saturn B ring, 92000 km
	double aring_out = 0.0;            // Outer orbital radius of rings (km). for Saturn's A ring, 140000 km

	// Tidal model inputs
    int tidalmodel = 0;                // 1: Elastic model; 2: Maxwell model; 3: Burgers model; 4: Andrade model
    double tidetimes = 0.0;            // Multiply tidal dissipation by this factor, realistically up to 10 (McCarthy & Cooper 2016)

    // Geophysical inputs
	double rhoHydrRock = 0.0;          // Density of hydrated rock endmember (kg m-3)
    double rhoDryRock = 0.0;           // Density of dry rock endmember (kg m-3)
    int chondr = 0;                    // Nature of the chondritic material incorporated (3/30/2015: default=CI or 1=CO), matters
                                                  // for radiogenic heating, see Thermal-state()

    // Icy world inputs
    double r_p[nmoons_max];                // Planetary radius
	double rho_p[nmoons_max];              // Planetary density (g cm-3)
    double Tsurf[nmoons_max];		       // Surface temperature
    double Tinit[nmoons_max];              // Initial temperature
    double tzero[nmoons_max];              // Time of formation (Myr)
    double nh3[nmoons_max];                // Ammonia w.r.t. water
    double salt[nmoons_max];               // Salt w.r.t. water (3/30/2015: binary quantity)
    double Xhydr_init[nmoons_max];         // Initial degree of hydration of the rock (0=fully dry, 1=fully hydrated)
    int hy[nmoons_max];					   // Allow for rock hydration/dehydration?
    double Xfines[nmoons_max];             // Mass or volume fraction of rock in fine grains that don't settle into a core (0=none, 1=all)
    double Xpores[nmoons_max];             // Mass of volume fraction of core occupied by ice and/or liquid (i.e., core porosity filled with ice and/or liquid)
    double porosity[nmoons_max];           // Bulk porosity
    int startdiff[nmoons_max];             // Start differentiated?
	int orbevol[nmoons_max];               // Orbital evolution?
    double aorb[nmoons_max];               // Moon orbital semi-major axis (km)
	double eorb[nmoons_max];               // Moon orbital eccentricity
	for (im=0;im<nmoons_max;im++) {
		tzero[im] = 0.0;
		r_p[im] = 0.0;
		rho_p[im] = 0.0;
		Tsurf[im] = 0.0;
		Tinit[im] = 0.0;
		nh3[im] = 0.0;
		salt[im] = 0.0;
		Xhydr_init[im] = 0.0;
		Xfines[im] = 0.0;
		Xpores[im] = 0.0;
		hy[im] = 0.0;
		porosity[im] = 0.0;
		startdiff[im] = 0.0;
		orbevol[im] = 0.0;
		aorb[im] = 0.0;
		eorb[im] = 0.0;
	}

    // Call specific subroutines
    int run_thermal = 0;               // Run thermal code
    int run_aTP = 0;                   // Generate a table of flaw size that maximize stress (Vance et al. 2007)
    int run_alpha_beta = 0;            // Calculate thermal expansivity and compressibility tables
    int run_crack_species = 0;         // Calculate equilibrium constants of species that dissolve or precipitate
    int run_geochem = 0;               // Run the PHREEQC code for the specified ranges of parameters
    int run_compression = 0;           // Re-calculate last internal structure of Thermal() output by taking into account the effects of compression
    int run_cryolava = 0;              // Calculate gas-driven exsolution

    // Crack subroutine inputs
    int *crack_input = (int*) malloc(5*sizeof(int));
    int *crack_species = (int*) malloc(4*sizeof(int));

    // Geochemistry subroutine inputs
	double Tmax = 0.0;
	double Tmin = 0.0;
	double Tstep = 0.0;

	double Pmax = 0.0;
	double Pmin = 0.0;
	double Pstep = 0.0;

	double pemax = 0.0;
	double pemin = 0.0;
	double pestep = 0.0;

	double WRmax = 0.0;			       // Max water:rock ratio by mass
	double WRmin = 0.0;				   // Min water:rock ratio by mass
	double WRstep = 0.0;			   // Step (multiplicative) in water:rock ratio

    // Cryolava subroutine inputs
    int t_cryolava = 0;                // Time at which to calculate gas exsolution
    double CHNOSZ_T_MIN = 0.0;         // Minimum temperature for the subcrt() routine of CHNOSZ to work
                                       // Default: 235 K (Cryolava), 245 K (Crack, P>200 bar)

	int n_inputs = 200;

	double *input = (double*) malloc(n_inputs*sizeof(double));
	if (input == NULL) printf("IcyDwarf: Not enough memory to create input[%d]\n", n_inputs);
	for (i=0;i<n_inputs;i++) input[i] = 0.0;

	//-------------------------------------------------------------------
	// Startup
	//-------------------------------------------------------------------

	printf("\n");
	printf("-------------------------------------------------------------------\n");
	printf("IcyDwarf v18.6\n");
	if (v_release == 1) printf("Release mode\n");
	else if (cmdline == 1) printf("Command line mode\n");
	printf("-------------------------------------------------------------------\n");

	// Initialize the R environment. We do it here, in the main loop, because this can be done only once.
	// Otherwise, the program crashes at the second initialization.
	setenv("R_HOME","/Library/Frameworks/R.framework/Resources",1);     // Specify R home directory
	Rf_initEmbeddedR(argc, argv);                                       // Launch R
	CHNOSZ_init(1);                                                     // Launch CHNOSZ

	// Get current directory. Works for Mac only! To switch between platforms, see:
	// http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
	char path[1024];
	unsigned int size = sizeof(path);
	path[0] = '\0';

	if (_NSGetExecutablePath(path, &size) == 0)
		printf("\n");
	else
	    printf("IcyDwarf: Couldn't retrieve executable directory. Buffer too small; need size %u\n", size);

	//-------------------------------------------------------------------
	// Read input
	//-------------------------------------------------------------------

	input = icy_dwarf_input (input, path);

	i = 0;
	//-----------------------------
	warnings = (int) input[i]; i++;
	recover = (int) input[i]; i++;
	//-----------------------------
	NR = input[i]; i++;
	timestep = input[i]; i++;          // yr
	speedup = input[i]; i++;
	total_time = input[i]; i++;        // Myr
	output_every = input[i]; i++;      // Myr
	//-----------------------------
	Mprim = input[i]; i++;             // kg
	Rprim = input[i]; i++;             // km
	Qprimi = input[i]; i++; Qprimf = input[i]; i++; Qmode = (int) input[i]; i++;
	k2prim = input[i]; i++; J2prim = input[i]; i++; J4prim = input[i]; i++;
	nmoons = (int) input[i]; i++;
	Mring = input[i]; i++;             // kg
	aring_in = input[i]; i++;          // cm
	aring_out = input[i]; i++;         // cm
	//-----------------------------
	for (im=0;im<nmoons;im++) r_p[im] = input[i+im];             // km
	i=i+nmoons;
	for (im=0;im<nmoons;im++) rho_p[im] = input[i+im];           // g cm-3
	i=i+nmoons;
	for (im=0;im<nmoons;im++) Tsurf[im] = input[i+im];           // K
	i=i+nmoons;
	for (im=0;im<nmoons;im++) Tinit[im] = input[i+im];           // K
	 i=i+nmoons;
	for (im=0;im<nmoons;im++) tzero[im] = input[i+im];           // Myr
	 i=i+nmoons;
	for (im=0;im<nmoons;im++) nh3[im] = input[i+im];             // Fraction w.r.t. H2O
	i=i+nmoons;
	for (im=0;im<nmoons;im++) salt[im] = input[i+im];            // 0 or 1
	i=i+nmoons;
	for (im=0;im<nmoons;im++) Xhydr_init[im] = input[i+im];
	i=i+nmoons;
	for (im=0;im<nmoons;im++) hy[im] = input[i+im];
	i=i+nmoons;
	for (im=0;im<nmoons;im++) porosity[im] = input[i+im];        // vol fraction
	i=i+nmoons;
	for (im=0;im<nmoons;im++) Xfines[im] = input[i+im];          // mass fraction = vol fraction
	i=i+nmoons;
	for (im=0;im<nmoons;im++) Xpores[im] = input[i+im];          // vol fraction
	i=i+nmoons;
	for (im=0;im<nmoons;im++) startdiff[im] = (int) input[i+im];
	i=i+nmoons;
	for (im=0;im<nmoons;im++) aorb[im] = input[i+im];            // km
	i=i+nmoons;
	for (im=0;im<nmoons;im++) eorb[im] = input[i+im];
	i=i+nmoons;
	for (im=0;im<nmoons;im++) orbevol[im] = (int) input[i+im];
	i=i+nmoons;
	//-----------------------------
	rhoDryRock = input[i]; i++;        // g cm-3
	rhoHydrRock = input[i]; i++;       // g cm-3
	chondr = (int) input[i]; i++;
	tidalmodel = (int) input[i]; i++;
	tidetimes = input[i]; i++;
	//-----------------------------
	run_thermal = (int) input[i]; i++;
	run_aTP = (int) input[i]; i++;
	run_alpha_beta = (int) input[i]; i++;
	run_crack_species = (int) input[i]; i++;
	run_geochem = (int) input[i]; i++;
	Tmin = input[i]; i++; Tmax = input[i]; i++; Tstep = input[i]; i++;
	Pmin = input[i]; i++; Pmax = input[i]; i++; Pstep = input[i]; i++;
	pemin = input[i]; i++; pemax = input[i]; i++; pestep = input[i]; i++;
	WRmin = input[i]; i++; WRmax = input[i]; i++; WRstep = input[i]; i++;
	run_compression = (int) input[i]; i++;
	run_cryolava = (int) input[i]; i++;
	t_cryolava = (int) input[i]/output_every; i++; // Myr
	CHNOSZ_T_MIN = input[i]; i++;      // K
	//-----------------------------
	for (j=0;j<4;j++) {
		crack_input[j] = (int) input[i]; i++;
	}
	for (j=0;j<4;j++) {
		crack_species[j] = (int) input[i]; i++;
	}

	if (nmoons > nmoons_max) {
		printf("Too many moons for the code to handle. Increase nmoon_max in the source code\n");
		exit(0);
	}

	//-------------------------------------------------------------------
	// Print input
	//-------------------------------------------------------------------

	printf("1 for Yes, 0 for No\n");
	printf("--------------------------------------------------------------------------------------------------------\n");
	printf("| Housekeeping |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Warnings?                                     | %d\n", warnings);
	printf("| Recover?                                      | %d\n", recover);
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Grid |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Number of grid zones                          | %d\n", NR);
	printf("| Thermal-orbital simulation time step (yr)     | %g\n", timestep);
	printf("| Thermal simulation speedup factor             | %g\n", speedup);
	printf("| Total time of thermal simulation (Myr)        | %g\n", total_time);
	printf("| Output every (Myr)                            | %g\n", output_every);
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Host planet parameters |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Mass (kg) (0 if world is not a moon)          | %g\n", Mprim);
	printf("| Radius (km)                                   | %g\n", Rprim);
	printf("| Tidal Q (initial,today,{0:lin 1:exp 2:1-exp}) | %g %g %d\n", Qprimi, Qprimf, Qmode);
	printf("| Love number k2; zonal gravity harmonics J2, J4| %g %g %g\n", k2prim, J2prim, J4prim);
	printf("| Number of moons                               | %d\n", nmoons);
	printf("| Ring mass (kg) (0 if no rings)                | %g\n", Mring);
	printf("| Ring inner edge (km)                          | %g\n", aring_in);
	printf("| Ring outer edge (km)                          | %g\n", aring_out);
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Icy world parameters |||||||||||||||||||||||||| World 1  | World 2  | World 3  | World 4  | World 5  |\n");
	printf("|-----------------------------------------------|----------|----------|----------|----------|----------|\n");
	printf("| Radius assuming zero porosity (km)              |");
	for (im=0;im<nmoons;im++) printf(" %g \t", r_p[im]);
	printf("\n| Density assuming zero porosity (g cm-3)       |");
	for (im=0;im<nmoons;im++) printf(" %g \t", rho_p[im]);
	printf("\n| Surface temperature (K)                       |");
	for (im=0;im<nmoons;im++) printf(" %g \t", Tsurf[im]);
	printf("\n| Initial temperature (K)                       |");
	for (im=0;im<nmoons;im++) printf(" %g \t", Tinit[im]);
	printf("\n| Time of formation (Myr)                       |");
	for (im=0;im<nmoons;im++) printf(" %g \t", tzero[im]);
	printf("\n| Ammonia w.r.t. water                          |");
	for (im=0;im<nmoons;im++) printf(" %g \t", nh3[im]);
	printf("\n| Briny liquid? y=1, n=0                        |");
	for (im=0;im<nmoons;im++) printf(" %g \t", salt[im]);
	printf("\n| Initial degree of hydration                   |");
	for (im=0;im<nmoons;im++) printf(" %g \t", Xhydr_init[im]);
	printf("\n| Hydrate/dehydrate?                            |");
	for (im=0;im<nmoons;im++) printf(" %d \t", hy[im]);
	printf("\n| Initial porosity volume fraction              |");
	for (im=0;im<nmoons;im++) printf(" %g \t", porosity[im]);
	printf("\n| Fraction of rock in fines                     |");
	for (im=0;im<nmoons;im++) printf(" %g \t", Xfines[im]);
	printf("\n| Core ice/liquid water volume fraction         |");
	for (im=0;im<nmoons;im++) printf(" %g \t", Xpores[im]);
	printf("\n| Start differentiated?                         |");
	for (im=0;im<nmoons;im++) printf(" %d \t", startdiff[im]);
	printf("\n| Initial orbital semi-major axis (km)          |");
	for (im=0;im<nmoons;im++) printf(" %g ", aorb[im]);
	printf("\n| Initial orbital eccentricity                  |");
	for (im=0;im<nmoons;im++) printf(" %g \t", eorb[im]);
	printf("\n| Allow orbit to change?                        |");
	for (im=0;im<nmoons;im++) printf(" %d \t", orbevol[im]);
	printf("\n|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Dry rock density (g cm-3)                     | %g\n", rhoDryRock);
	printf("| Hydrated rock density (g cm-3)                | %g\n", rhoHydrRock);
	printf("| Chondrite type? CI=0 CO=1                     | %d\n", chondr);
	printf("| Tidal rheology? Maxwell=2 Burgers=3 Andrade=4 | %d\n", tidalmodel);
	printf("| Tidal heating x...                            | %g\n", tidetimes);
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Subroutines ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Run thermal code?                             | %d\n", run_thermal);
	printf("| Generate core crack aTP table?                | %d\n", run_aTP);
	printf("| Generate water alpha beta table?              | %d\n", run_alpha_beta);
	printf("| Generate crack species log K with CHNOSZ?     | %d\n", run_crack_species);
	printf("| Run geochemistry code? (min max step)         | %d\n", run_geochem);
	printf("|   Temperature                                 | %g %g %g\n", Tmin, Tmax, Tstep);
	printf("|   Pressure                                    | %g %g %g\n", Pmin, Pmax, Pstep);
	printf("|   pe = FMQ + ...                              | %g %g %g\n", pemin, pemax, pestep);
	printf("|   Water:rock mass ratio                       | %g %g %g\n", WRmin, WRmax, WRstep);
	printf("| Run compression code?                         | %d\n", run_compression);
	printf("| Run cryovolcanism code?                       | %d\n", run_cryolava);
	printf("|   After how many output steps?                | %d\n", t_cryolava);
	printf("|   Minimum temperature to run CHNOSZ (K)       | %g\n", CHNOSZ_T_MIN);
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Core crack options |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\n");
	printf("|-----------------------------------------------|------------------------------------------------------|\n");
	printf("| Include thermal expansion/contrac mismatch?   | %d\n", crack_input[0]);
	printf("| Include pore water expansion?                 | %d\n", crack_input[1]);
	printf("| Include hydration/dehydration vol changes?    | %d\n", crack_input[2]);
	printf("| Include dissolution/precipitation...?         | %d\n", crack_input[3]);
	printf("|   ... of silica?                              | %d\n", crack_species[0]);
	printf("|   ... of serpentine?                          | %d\n", crack_species[1]);
	printf("|   ... of carbonate (magnesite)?               | %d\n", crack_species[2]);
	printf("|------------------------------------------------------------------------------------------------------|\n\n");

	// Conversions to cgs
	total_time = total_time*Myr2sec;
	output_every = output_every*Myr2sec;
	Mprim = Mprim/gram;
	Rprim = Rprim*km2cm;
	Mring = Mring/gram;
	aring_in = aring_in*km2cm;
	aring_out = aring_out*km2cm;
	for (im=0;im<nmoons;im++) {
		r_p[im] = r_p[im]*km2cm;
		tzero[im] = tzero[im]*Myr2sec;
		aorb[im] = aorb[im]*km2cm;
	}
	// Conversions to SI
	rhoDryRock = rhoDryRock*gram/cm/cm/cm;
	rhoHydrRock = rhoHydrRock*gram/cm/cm/cm;
	NT_output = floor(total_time/output_every)+1;

	//-------------------------------------------------------------------
	// Cracking depth calculations
	//-------------------------------------------------------------------

	if (run_aTP == 1) {
		printf("Calculating expansion mismatch optimal flaw size matrix...\n");
		aTP(path, warnings);
		printf("\n");
	}

	if (run_alpha_beta == 1) {
		printf("Calculating alpha(T,P) and beta(T,P) tables for water using CHNOSZ...\n");
		Crack_water_CHNOSZ(argc, argv, path, warnings);
		printf("\n");
	}

	if (run_crack_species == 1) {
		printf("Calculating log K for crack species using CHNOSZ...\n");
		Crack_species_CHNOSZ(argc, argv, path, warnings);
		printf("\n");
	}

	//-------------------------------------------------------------------
	// Run thermal code
	//-------------------------------------------------------------------

    double **Xhydr = (double**) malloc(nmoons*sizeof(double*)); // Degree of hydration, 0=dry, 1=hydrated
    if (Xhydr == NULL) printf("IcyDwarf: Not enough memory to create Xhydr[nmoons]\n");
	for (im=0;im<nmoons;im++) {
		Xhydr[im] = (double*) malloc(NR*sizeof(double));
		if (Xhydr[im] == NULL) printf("Thermal: Not enough memory to create Xhydr[nmoons][NR]\n");
	}

	for (im=0;im<nmoons;im++) {
		for (ir=0;ir<NR;ir++) Xhydr[im][ir] = Xhydr_init[im];
	}

	if (run_thermal == 1) {
		printf("Running thermal evolution code...\n");
		PlanetSystem(argc, argv, path, warnings, recover, NR, timestep, speedup, tzero, total_time, output_every, nmoons, Mprim, Rprim, Qprimi, Qprimf,
				Qmode, k2prim, J2prim, J4prim, Mring, aring_out, aring_in, r_p, rho_p, rhoHydrRock, rhoDryRock, nh3, salt, Xhydr, porosity, Xpores,
				Xfines, Tinit, Tsurf, startdiff, aorb, eorb, tidalmodel, tidetimes, orbevol, hy, chondr, crack_input, crack_species);
		printf("\n");
	}

	//-------------------------------------------------------------------
	// Water-rock reactions
	//-------------------------------------------------------------------

	if (run_geochem == 1) {
		printf("Running PHREEQC across the specified range of parameters...\n");
		ParamExploration(path, Tmin, Tmax, Tstep,
				Pmin, Pmax, Pstep,
				pemin, pemax, pestep,
				WRmin, WRmax, WRstep);
		printf("\n");
	}

	//-------------------------------------------------------------------
	// Compression
	//-------------------------------------------------------------------

	if (run_compression == 1) {
		printf("Running Compression routine...\n");
		// Read thermal output
		thermalout **thoutput = (thermalout**) malloc(NR*sizeof(thermalout*));        // Thermal model output
		if (thoutput == NULL) printf("IcyDwarf: Not enough memory to create the thoutput structure\n");
		for (ir=0;ir<NR;ir++) {
			thoutput[ir] = (thermalout*) malloc(NT_output*sizeof(thermalout));
			if (thoutput[ir] == NULL) printf("IcyDwarf: Not enough memory to create the thoutput structure\n");
		}
		thoutput = read_thermal_output (thoutput, NR, NT_output, path);

		compression(NR, NT_output, thoutput, NT_output-1, 205, 302, 403, 0, path, rhoHydrRock, rhoDryRock, Xhydr[0]);

		for (ir=0;ir<NR;ir++) free (thoutput[ir]);
		free (thoutput);
		printf("\n");
	}

	//-------------------------------------------------------------------
	// Cryolava calculations
	//-------------------------------------------------------------------

	if (run_cryolava == 1) {
		printf("Calculating gas-driven exsolution at t=%d...\n", t_cryolava);

		// Read thermal output
		thermalout **thoutput = (thermalout**) malloc(NR*sizeof(thermalout*));        // Thermal model output
		if (thoutput == NULL) printf("IcyDwarf: Not enough memory to create the thoutput structure\n");
		for (ir=0;ir<NR;ir++) {
			thoutput[ir] = (thermalout*) malloc(NT_output*sizeof(thermalout));
			if (thoutput[ir] == NULL) printf("IcyDwarf: Not enough memory to create the thoutput structure\n");
		}
		thoutput = read_thermal_output (thoutput, NR, NT_output, path);
		for (ir=0;ir<NR;ir++) Xhydr[0][ir] = thoutput[ir][NT_output].xhydr;

		if (t_cryolava > NT_output) {
			printf("Icy Dwarf: t_cryolava > total time of sim\n");
			return -1;
		}
		Cryolava(argc, argv, path, NR, NT_output, (float) r_p[0], thoutput, t_cryolava, CHNOSZ_T_MIN, warnings, rhoHydrRock, rhoDryRock, Xhydr[0]);

		for (ir=0;ir<NR;ir++) free (thoutput[ir]);
		free (thoutput);
		printf("\n");
	}

	//-------------------------------------------------------------------
	// Exit
	//-------------------------------------------------------------------

	for (im=0;im<nmoons;im++) free(Xhydr[im]);
	free (input);
	free (crack_input);
	free (crack_species);
	free (Xhydr);

	Rf_endEmbeddedR(0);                                     // Close R and CHNOSZ

	printf("Exiting IcyDwarf...\n");
	return 0;
}
예제 #14
0
파일: options.c 프로젝트: Istvan1655/ttar
int createArchive(char** files, int nb_fichiers) {
    
    if (strcmp(nom_archive, "") == 0 || nom_archive == NULL)
        nom_archive = files[0];

    int archive = open(nom_archive, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
    if (archive == -1) // si on a pas pu ouvrir le fichier
    {
        printf("L'archive n'a pas pu être ouverte\n");
        return EXIT_FAILURE;
    }

    printf("Création de l'archive %s\n", nom_archive);

    ListeDescripteurs descripteurs; // pour mémoriser les descripteurs de tous les fichiers / dossiers + archive (spécial)
    int nb_descripteurs = 0;

    descripteurs = construireListeVide();
    nb_descripteurs = createFiles(files, nb_fichiers, &descripteurs, archive); // on traite tous nos fichiers en paramètre

    tete(descripteurs);

    uint** all_d = getTousLesDescripteursToInt(descripteurs);
    
    int j;
    
    uint premierDescripteur = (uint) lseek(archive, 0, SEEK_CUR);
    int i;

    if (affiche)
        printf("Ecriture de la configuration de l'archive...... ");

    for (i = 0; i < nb_descripteurs; i++) {
        int nb_int = taille(all_d[i]);
        int dernier_int = taille(all_d[0]);
        all_d[0] = (uint*) realloc(all_d[0], nb_int * sizeof(int) * sizeof(all_d[0]));
        for(j=0 ; j<nb_int ; j++){
          all_d[0][j+dernier_int] = all_d[i][j];
        }
         

        int ecrit = write(archive, &all_d[i], nb_int);

        if ((ecrit < 0) || (ecrit != nb_int))
            printf("Erreur lors l'écriture de la configuration de l'archive !\n");
    }
    
    detruireListeInt(all_d, nb_descripteurs);
    detruireListeDescripteurs(descripteurs);

    write(archive, &premierDescripteur, sizeof(uint));

    if (affiche)
        printf("Done\n");

    if (compresse)
        compression(archive);

    if (close(archive) == -1) {
        printf("Attention, l'archive n'a pas pu être fermée... Possibilité de corruption du fichier !");
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}
예제 #15
0
int main(int argc, char *argv[])
{
        int len, ret, fd, mode;
        char *buf = NULL, *infile = NULL, *outfile = NULL;
        unsigned int file_len;
        struct timeval tv_start, tv_end;

        if (argc != 4 || argv[1][0] != '-' || (len = strlen(argv[1])) <= 1) return usage(argv[0]);
        mode = 0;
        ret = 1; // skip '-'
        while (ret < len) {
                switch (argv[1][ret++]) {
                case 'c':
                        if (mode & MODE_DECOMPRESSION) return usage(argv[0]);
                        mode |= MODE_COMPRESSION;
                        break;
                case 'x':
                        if (mode & MODE_COMPRESSION) return usage(argv[0]);
                        mode |= MODE_DECOMPRESSION;
                        break;
                case 'd':
                        mode |= MODE_DELETE;
                        break;
                case 't':
                        mode |= MODE_TIME;
                        break;
                default :
                        return usage(argv[0]);
                        break;
                }
        }
        infile = argv[2];
        outfile = argv[3];

        if ((mode & MODE_TIME) && gettimeofday(&tv_start, NULL)) {
                perror("fail to do gettimeofday");
                return -1; 
        }
        //init_log();
        if (mode & MODE_COMPRESSION) {
                // Compression
                if ((fd = open(infile, O_RDONLY)) < 0
                        || (file_len = lseek(fd, 0, SEEK_END)) == 0
                        || (file_len & 0x80000000)
                        || lseek(fd, 0, SEEK_SET) < 0) {
                        perror("Fail to open SRC_FILE.");
                        return 0;
                }

                if (!(buf= (char *)malloc(file_len * (sizeof(char))))) {
                        perror("Fail to malloc for buf");
                        return 0;
                }

                len = 0;
                while (len < file_len) {
                        if ((ret = read(fd, buf+len, file_len-len)) <= 0) {
                                close(fd);
                                perror("Fail to read SRC_FILE.");
                                return 0;
                        }
                        len += ret;
                }
                close(fd);
                ret = compression(outfile, buf, file_len);
                free(buf);
                if (ret) {
                        printf("Error to ArithmeticCoding\n");
                        return -1;
                }
        } else if (mode & MODE_DECOMPRESSION) {
                // Decompression 
                if (decompression(infile, outfile)) {
                        //log(LOG_USER | LOG_ERR , "%s : Fail to huffman_decompression", __func__);
                        return -1;
                }
        }
#ifdef Debug
        printf("Good !\n");
#else
        //unlink(LOG_FILE);
#endif
        if (mode & MODE_DELETE) unlink(infile);
        if (mode & MODE_TIME) {
                if (gettimeofday(&tv_end, NULL)) {
                        perror("\nArithmeticCoding done, But fail to get time.");
                } else {
                        if (tv_end.tv_usec < tv_start.tv_usec) {
                                tv_end.tv_usec = 1000000 + tv_end.tv_usec - tv_start.tv_usec;
                                tv_end.tv_sec -= tv_start.tv_sec + 1; 
                        } else {
                                tv_end.tv_usec -= tv_start.tv_usec;
                                tv_end.tv_sec -= tv_start.tv_sec; 
                        }
                        fprintf(stderr, "\nArithmeticCoding done time : %us %ums\n", tv_end.tv_sec, (tv_end.tv_usec)/1000);
                        fflush(stderr);
                }
        }

        return 0;
}