コード例 #1
0
ファイル: tostd.c プロジェクト: PascalSteger/darcoda
int main( int argc, char *argv[] ) {
    int bError = 0;
    int bDouble = 0;
    int bNative = 0;
    int bHDF5 = 0;
    int bPotential = 0;
    int bDensity = 0;
    uint64_t N, nSph, nDark, nStar, i;
    double dTime;

    uint64_t iOrder;
    double r[3], v[3];
    float fMass, fSoft, fPot, fRho, u, fMetals, fTimer;

    FIO fioIn, fioOut;
    FIO_SPECIES eSpecies;
    int inNameIndex = 0;
    int inNameCount = 0;
    const char *outName = 0;

    //! Parse command line arguments (flags).
    for (;;) {
	int c, option_index=0;

	static struct option long_options[] = {
		{ "double",       0, 0, OPT_DOUBLE},
		{ "native",       0, 0, OPT_NATIVE},
		{ "hdf5",         0, 0, OPT_HDF5},
		{ "potential",    0, 0, OPT_POTENTIAL},
		{ "density"  ,    0, 0, OPT_DENSITY},
		{ NULL,   0, 0, 0 },
	    };

	c = getopt_long( argc, argv, "dn5pr",
			 long_options, &option_index );
	if ( c == -1 ) break;

	switch (c) {
	case OPT_DOUBLE:
	    bDouble = 1;
	    break;
	case OPT_NATIVE:
	    bNative = 1;
	    break;
	case OPT_HDF5:
	    bHDF5 = 1;
	    break;
	case OPT_POTENTIAL:
	    bPotential = 1;
	    break;
	case OPT_DENSITY:
	    bDensity = 1;
	    break;
	default:
	    bError = 1;
	    break;
	    }
	}

    if (bNative && bHDF5) {
	fprintf(stderr, "Specify only one of --hdf5 or --native\n" );
	bError = 1;
	}
#ifndef USE_HDF5
   if (bHDF5) {
        fprintf(stderr, "HDF5 support was not compiled in.\n" );
        bError = 1;
        }
#endif


    if ( optind < argc ) {
	inNameIndex = optind++;
	inNameCount = argc - optind;
	}
    else {
	fprintf(stderr, "Missing input file(s)\n" );
	bError = 1;
	}

    if ( optind < argc )
	outName = argv[argc-1];
    else {
	fprintf(stderr, "Missing Tipsy output file\n" );
	bError = 1;
	}

    if ( bError ) {
	fprintf(stderr, "Usage: %s [-p] <input...> <outtipsy>\n"
		"  -d,--double    Output double precision positions\n"
		"  -n,--native    Output a native tipsy binary\n"
#ifdef USE_HDF5
		"  -5,--hdf5      Output in HDF5 format\n"
		"  -p,--potential Included potentials in HDF5 output\n"
#endif
		,argv[0] );
	exit(1);
	}

    fioIn = fioOpenMany(inNameCount,(const char * const *)&argv[inNameIndex],0.0,0.0);
    if (fioIn==NULL) {
	perror(argv[inNameIndex]);
	exit(errno);
	}
    N     = fioGetN(fioIn,FIO_SPECIES_ALL);
    nSph  = fioGetN(fioIn,FIO_SPECIES_SPH);
    nDark = fioGetN(fioIn,FIO_SPECIES_DARK);
    nStar = fioGetN(fioIn,FIO_SPECIES_STAR);
    if (!fioGetAttr(fioIn,"dTime",FIO_TYPE_DOUBLE,&dTime)) dTime = 0.0;

#ifdef USE_HDF5
    if (bHDF5) {
	int mFlag = FIO_FLAG_COMPRESS_MASS | FIO_FLAG_COMPRESS_SOFT;
	if (bDouble) mFlag |= FIO_FLAG_DOUBLE_POS | FIO_FLAG_DOUBLE_VEL;
	if (bPotential) mFlag |= FIO_FLAG_POTENTIAL;
	if (bDensity) mFlag |= FIO_FLAG_DENSITY;
	fioOut = fioHDF5Create(outName,mFlag);
	}
#else
    if (0) {}
#endif
    else {
	fioOut = fioTipsyCreate(outName,bDouble,!bNative,dTime,nSph,nDark,nStar);
	}

    if (fioOut==NULL) {
	perror(outName);
	exit(errno);
	}
    fioSetAttr(fioOut,"dTime",FIO_TYPE_DOUBLE,&dTime);

    for( i=0; i<N; i++ ) {
        eSpecies = fioSpecies(fioIn);
        switch(eSpecies) {
        case FIO_SPECIES_SPH:
            fioReadSph(fioIn,&iOrder,r,v,&fMass,&fSoft,&fPot,&fRho,&u,&fMetals);
	    fioWriteSph(fioOut,iOrder,r,v,fMass,fSoft,fPot,fRho,u,fMetals);
            break;
        case FIO_SPECIES_DARK:
            fioReadDark(fioIn,&iOrder,r,v,&fMass,&fSoft,&fPot,&fRho);
            fioWriteDark(fioOut,iOrder,r,v,fMass,fSoft,fPot,fRho);
            break;
        case FIO_SPECIES_STAR:
            fioReadStar(fioIn,&iOrder,r,v,&fMass,&fSoft,&fPot,&fRho,&fMetals,&fTimer);
            fioWriteStar(fioOut,iOrder,r,v,fMass,fSoft,fPot,fRho,fMetals,fTimer);
            break;
        default:
            fprintf(stderr,"Unsupported particle type: %d\n",eSpecies);
            abort();
            }
	}

    fioClose(fioOut);
    fioClose(fioIn);

    return 0;
    }
コード例 #2
0
ファイル: tdiff.c プロジェクト: jpcoles/ZM
int main( int argc, char **argv ) {
    int bError = 0;
    int bVelocity = 0;
    int bPosition = 0;
    uint64_t N1, N2, nSph1, nSph2, nDark1, nDark2, nStar1, nStar2, i;
    double dTime1, dTime2;

    uint64_t iOrder1;
    double r1[3], v1[3];
    float fMass1, fSoft1, fPot1, fRho1, u1, fMetals1, fTimer1;

    uint64_t iOrder2;
    double r2[3], v2[3];
    float fMass2, fSoft2, fPot2, fRho2, u2, fMetals2, fTimer2;

    double v, vMin, vMax;

    FIO fioIn1, fioIn2;
    FIO_SPECIES eSpecies;
    const char *inName1, *inName2;

    for (;;) {
        int c, option_index=0;

        static struct option long_options[] = {
            { "position",   0, 0, OPT_POSITION },
            { "velocity",   0, 0, OPT_VELOCITY },
            { NULL,   0, 0, 0 },
        };

        c = getopt_long( argc, argv, "vp",
                         long_options, &option_index );
        if ( c == -1 ) break;

        switch (c) {
        case OPT_POSITION:
            bPosition = 1;
            break;
        case OPT_VELOCITY:
            bVelocity = 1;
            break;
        default:
            bError = 1;
            break;
        }
    }

    if ( optind < argc ) {
        inName1 = argv[optind++];
    }
    else {
        fprintf(stderr, "Missing input file(s)\n" );
        bError = 1;
    }

    if ( optind < argc )
        inName2 = argv[optind++];
    else {
        fprintf(stderr, "Missing input file\n" );
        bError = 1;
    }

    if (bPosition && bVelocity) {
        fprintf(stderr,"Specify --position or --velocity, but not both\n");
        bError = 1;
    }
    else if ( !bPosition && !bVelocity) bPosition = 1;

    if ( bError ) {
        fprintf(stderr, "Usage: %s [-vp] <file1> <file2>\n",
                argv[0] );
        exit(1);
    }

    fioIn1 = fioOpen(inName1,0.0,0.0);
    if (fioIn1==NULL) {
        perror(inName1);
        exit(errno);
    }
    fioIn2 = fioOpen(inName2,0.0,0.0);
    if (fioIn2==NULL) {
        perror(inName2);
        exit(errno);
    }

    N1     = fioGetN(fioIn1,FIO_SPECIES_ALL);
    nSph1  = fioGetN(fioIn1,FIO_SPECIES_SPH);
    nDark1 = fioGetN(fioIn1,FIO_SPECIES_DARK);
    nStar1 = fioGetN(fioIn1,FIO_SPECIES_STAR);
    if (!fioGetAttr(fioIn1,"dTime",FIO_TYPE_DOUBLE,&dTime1)) dTime1 = 0.0;

    N2     = fioGetN(fioIn2,FIO_SPECIES_ALL);
    nSph2  = fioGetN(fioIn2,FIO_SPECIES_SPH);
    nDark2 = fioGetN(fioIn2,FIO_SPECIES_DARK);
    nStar2 = fioGetN(fioIn2,FIO_SPECIES_STAR);
    if (!fioGetAttr(fioIn2,"dTime",FIO_TYPE_DOUBLE,&dTime2)) dTime2 = 0.0;

    fprintf(stderr,"Comparing: %s N=%lu, nSph=%lu, nDark=%lu, nStar=%lu, dTime=%g\n",
            inName1, N1, nSph1, nDark1, nStar1, dTime1);
    fprintf(stderr,"     with: %s N=%lu, nSph=%lu, nDark=%lu, nStar=%lu, dTime=%g\n",
            inName2, N2, nSph2, nDark2, nStar2, dTime2);
    if ( N1!=N2 || nSph1!=nSph2 || nDark1!=nDark2 || nStar1!=nStar2) {
        fprintf(stderr,"File headers do not match!\n");
        exit(1);
    }

    printf("%lu\n",N1);

    vMin = HUGE_VAL;
    vMax = -HUGE_VAL;

    for( i=0; i<N1; i++ ) {
        eSpecies = fioSpecies(fioIn1);
        switch(eSpecies) {
        case FIO_SPECIES_SPH:
            fioReadSph(fioIn1,&iOrder1,r1,v1,&fMass1,&fSoft1,&fPot1,&fRho1,&u1,&fMetals1);
            fioReadSph(fioIn2,&iOrder2,r2,v2,&fMass2,&fSoft2,&fPot2,&fRho2,&u2,&fMetals2);
            break;
        case FIO_SPECIES_DARK:
            fioReadDark(fioIn1,&iOrder1,r1,v1,&fMass1,&fSoft1,&fPot1);
            fioReadDark(fioIn2,&iOrder2,r2,v2,&fMass2,&fSoft2,&fPot2);
            break;
        case FIO_SPECIES_STAR:
            fioReadStar(fioIn1,&iOrder1,r1,v1,&fMass1,&fSoft1,&fPot1,&fMetals1,&fTimer1);
            fioReadStar(fioIn2,&iOrder2,r2,v2,&fMass2,&fSoft2,&fPot2,&fMetals2,&fTimer2);
            break;
        default:
            fprintf(stderr,"Unsupported particle type: %d\n",eSpecies);
            abort();
        }
        if (bPosition) v = mag(r1,r2,1);
        else v = mag(v1,v2,0);

        if (v>vMax) vMax = v;
        if (v<vMin) vMin = v;

        printf("%g\n",v);
    }

    fprintf(stderr,"Min: %g, Max: %g\n", vMin, vMax);

    fioClose(fioIn2);
    fioClose(fioIn1);

    return 0;
}