예제 #1
0
파일: iwriter.cpp 프로젝트: andbrain/cfc
void Iwriter::Initialize(string filename)
{
	path_ref = filename + ".ref";
	path_dat = filename + ".dat";
	InitFile(path_ref);
	InitFile(path_dat);
}
예제 #2
0
CLogFile::CLogFile(TCHAR *name)
{
    hLogFile = INVALID_HANDLE_VALUE;//初始化
    memset(file_name,0,MAX_PATH);//名清0

    SetFileName(name);//设置文件名
    InitFile();
}
예제 #3
0
DataManager::DataManager()
{
    Current_Slice_Index = 0;
    //setDataBase();
    InitFile();
    setMemory();
    setDefaultValues();
    ReadSEGYData();
    //GetSurface(800);
}
예제 #4
0
void ORLSkipObj( file_list *list, unsigned long *loc )
/****************************************************/
// skip the object file.
// NYI: add an entry point in ORL for a more efficient way of doing this.
{
    orl_file_handle     filehdl;

    ORLFileSeek( list, *loc, SEEK_SET );
    filehdl = InitFile();               // assumes that entire file is read!
    *loc = ORLFileSeek( list, 0, SEEK_CUR );
    FiniFile( filehdl, list );
}
예제 #5
0
unsigned int CDxSound::GetWaveId(const string &name)
{
	PUSH_CODE_MODE;
	ENTER_MIXED;
	map<string,int>::iterator si;
	if((si=waveid.find(name))==waveid.end()){
		InitFile(name);
		si=waveid.find(name);
	}
	int ret=(si!=waveid.end())?si->second:0;
	POP_CODE_MODE;
	return ret;
}
main()
{   
	void directions(void);   
	FILE *InitFile(const string_t);   
	void FileToArray(el_t item[],    
			int *NumEls_ptr, FILE *infile_ptr);   
	void GroceryList(el_t item[], int NumEls);   
   
	el_t item[MAX_NUM_ELS];	/* array of structures */   
								/* of names and prices */	   
	int NumEls;				/* number of elements in array item */   
	FILE *infile_ptr;			/* pointer to input file */   
   
	directions();
	printf("Give the name of the input file: ");   
	infile_ptr = InitFile("r");   
	FileToArray(item, &NumEls, infile_ptr);   
	fclose(infile_ptr);   
   
	GroceryList(item, NumEls);   
}   
예제 #7
0
void CScript_FM1232::CreateEFS( string strDDF /*= ""*/, string strADF /*= "" */ )
{
	stringstream strsRecords;
	string strLen,strTmp,strDDFFID,strEFType;
	S_ADFINFO struADFInfo;

	transform( strDDF.begin(), strDDF.end(), strDDF.begin(), toupper );
	transform( strADF.begin(), strADF.end(), strADF.begin(), toupper );
	if ( strDDF == "" )
		strDDF = "DDF0";

	vector<S_DDFINFO>::const_iterator iterSDDF = m_vecMFStruct.begin();
	while ( iterSDDF != m_vecMFStruct.end() )//遍历DDF
	{
		strTmp = (*iterSDDF).m_strDDFName;//应用环境简称
		transform(  strTmp.begin(), strTmp.end(), strTmp.begin(), toupper );
		if ( strTmp != strDDF )//不为应用环境简称时继续遍历
		{
			++iterSDDF;
			continue;
		}

		vector<S_ADFINFO>::const_iterator iterSADF = (*iterSDDF).m_vecADFInfo.begin();
		while ( iterSADF!=(*iterSDDF).m_vecADFInfo.end() )//遍历ADF
		{
			strTmp = (*iterSADF).m_strFID;
			transform(  strTmp.begin(), strTmp.end(), strTmp.begin(), toupper );
			if ( strTmp != strADF )//不为ADF文件标识符的话继续遍历(读取的数据中DF00的FID为"")
			{
				++iterSADF;
				continue;
			}

			if ( strDDF == "DDF0" && strADF == "" )//表示建MF下的所有直属EF文件
			{
				LvTwo_Annotations( "创建MF下的EF文件" );
				LvOne_Annotations( "选择MF" );
				cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, "", m_bRefreshFlag );
			}
			else if ( strDDF != "DDF0" && strADF == "" )//表示建MF/DDF下的所有直属EF文件
			{
				m_strTemp = "创建 MF-"+(*iterSDDF).m_strDDFName+" 下的EF文件";
				LvTwo_Annotations( m_strTemp );
				m_strTemp = "选择"+(*iterSDDF).m_strDDFName;
				LvOne_Annotations( m_strTemp );
				cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, "", m_bRefreshFlag );
			}
			else//表示建MF/ADF下的所有直属EF文件 或者 建MF/DDF/ADF下的所有直属EF文件
			{
				if ( (*iterSDDF).m_strFID == "" )
					m_strTemp = "创建 MF-"+(*iterSADF).m_strFID+" 下的EF文件";
				else
					m_strTemp = "创建 MF-"+(*iterSDDF).m_strDDFName+"-"+(*iterSADF).m_strFID+" 下的EF文件";
				LvTwo_Annotations( m_strTemp );
				m_strTemp = "选择"+(*iterSADF).m_strFID;
				LvOne_Annotations( m_strTemp );
				cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, "", m_bRefreshFlag );

				//创建安全文件
				LvOne_Annotations( "创建安全文件" );
				strLen = LoadKeys( (*iterSDDF).m_strDDFName, (*iterSADF).m_strFID, strsRecords );//获取装载密钥的记录和密钥文件空间
				cInst->Create_Internal_EF( "SF", strLen, m_bRefreshFlag  );
				cInfo->Append_Script( strsRecords.str() );//添加所有的装载密钥脚本数据

				//外部认证ADF的主控密钥
				m_strTemp = "外部认证"+(*iterSADF).m_strFID+"的主控密钥";
				LvOne_Annotations( m_strTemp, m_bRefreshFlag );
				cParameter->GetADFInfo( (*iterSDDF).m_strFID, (*iterSADF).m_strFID,  struADFInfo );//获取ADF信息
				cCmd->VAR( struADFInfo.m_strMKvalue, _KEY, m_bRefreshFlag );//将ADF的MK保存到_KEY
				cInst->Get_Challenge( 8, m_bRefreshFlag );
				cCmd->RESP( 0, 8, _VAR10, m_bRefreshFlag );
				cCmd->TDES( VAR_Name(_VAR10), VAR_Name(_KEY), _VAR11, m_bRefreshFlag );
				cCmd->DES( VAR_Name(_VAR10), VAR_Name(_VAR11), _VAR12, m_bRefreshFlag );
				cInst->External_Authenticate( "00", VAR_Name(_VAR12), VAR_Name(_VAR10), 0, m_bRefreshFlag );//MK的密钥标识为00
				//引用全局PIN

				LineFeed(1);
			}

			vector<S_EFINFO>::const_iterator iterEF = (*iterSADF).m_vecEFInfo.begin();
			while ( iterEF!=(*iterSADF).m_vecEFInfo.end() )//遍历EF,建EF文件并初始化文件
			{
				//文件类型
				if ( "1" == (*iterEF).m_strEFType )
					strEFType = "定长文件";
				if ( "2" == (*iterEF).m_strEFType )
					strEFType = "变长文件";
				if ( "3" == (*iterEF).m_strEFType )
					strEFType = "透明文件";
				if ( "4" == (*iterEF).m_strEFType )
					strEFType = "循环文件";
				if ( "5" == (*iterEF).m_strEFType )
					strEFType = "内部文件";
				m_strTemp = "建立基本文件"+(*iterEF).m_strSFI+" 读:"+(*iterEF).m_strReadControl+" 写:"+(*iterEF).m_strWriteControl+" 文件类型:"+strEFType;
				LvOne_Annotations( m_strTemp, m_bRefreshFlag );
				cInst->Create_File( "MF", (*iterSDDF).m_strDDFName, (*iterSADF).m_strFID, (*iterEF).m_strSFI, m_bRefreshFlag );//建EF文件
				cInst->Select_File( "MF", (*iterSDDF).m_strFID, (*iterSADF).m_strFID, (*iterEF).m_strSFI, m_bRefreshFlag );//选当前建的EF文件
				//调用初始化文件接口写记录
				InitFile( (*iterSDDF).m_strFID, (*iterSADF).m_strFID, (*iterEF).m_strSFI );
				LineFeed(1);

				++iterEF;
			}

			break;
		}	

		break;
	}
}
예제 #8
0
void cModelFunction_MT :: Init ( void )
{
	InitFile( );
}
예제 #9
0
void EmptyFile(char const *filename)
{
    InitFile(filename, NULL, 0);
}
예제 #10
0
int main(int argc, char *argv[])
{
    FILE *stardata;
    FILE *planetdata;
    FILE *sectordata;
    FILE *outputtxt = NULL;
    char str[200];
    int c;
    int i;
    int star;
    /*
     * int x;
     */
    /*
     * double att;
     */
    double xspeed[NUMSTARS];
    double yspeed[NUMSTARS];

    /*
     * Empty stars
     */
    int nempty;

    /*
     * How many rows and columns are needed
     */
    int rowcolumns;

    /*
     * Non-empty stars not placed
     */
    int starsleft;

    /*
     * How many planetless systems is in each square
     */
    int emptyrounds;

    /*
     * Size of square
     */
    double displacement;

    /*
     * How many wormholes
     */
    int whcnt;
    int wormholes = -1;
    int wormidx;
    struct w_holes w_holes[NUMSTARS + 1];
    int x;
    int y;
    int z;
    int squaresleft;
    int total;
    int flag = 0;
    struct power power[MAXPLAYERS];
    struct block block[MAXPLAYERS];

    /*
     * Initialize
     */
    /*
     * srandom(getpid());
     */
    Bzero(Sdata);

    /*
     * Read the arguments for values
     */
    for (i = 1; i < argc; ++i) {
        if (argv[i][0] != '-') {
            printf("\n");
            printf("Usage: makeuniv [-a] [-b] [-d] [-e E] [-l MIN] [-m MAX] ");
            printf("[-s N] [-v] [-w C] [-x]\n");
            printf("  -a      Autoload star names.\n");
            printf("  -b      Autoload planet names.\n");
            printf("  -d      Use smashup (asteroid impact routines.\n");
            printf("  -e E    Make E%% of stars have no planets.\n");
            printf("  -l MIN  Other systems will have at least MIN planets.\n");
            printf("  -m MAX  Other systems will have at most MAX planets.\n");
            printf("  -p      Create postscript map file of the univese.\n");
            printf("  -s N    The univers will have N stars.\n");
            printf("  -v      Do no print info and map of planets generated.\n");
            printf("  -w C    The universe will have C wormholes.\n");
            printf("  -x      Do not print info on stars generated.\n");
            printf("\n");

            return 0;
        } else {
            switch (argv[i][1]) {
            case 'a':
                autoname_star = 1;

                break;
            case 'b':
                autoname_plan = 1;

                break;
            case 'd':
                use_smashup = 1;

                break;
            case 'e':
                ++i;
                planetlesschance = atoi(argv[i]);

                break;
            case 'l':
                ++i;
                minplanets = atoi(argv[i]);

                break;
            case 'm':
                ++i;
                maxplanets = atoi(argv[i]);

                break;
            case 'p':
                printpostscript = 1;

                break;
            case 's':
                ++i;
                nstars = atoi(argv[i]);

                break;
            case 'v':
                printplaninfo = 0;

                break;
            case 'x':
                printstarinfo = 0;

                break;
            case 'w':
                ++i;
                wormholes = atoi(argv[i]);

                break;
            default:
                printf("\n");
                printf("Unknown option \"%s\".\n", argv[i]);
                printf("\n");
                printf("Usage: makeuniv [-a] [-b] [-e E] [-l MIN] [-m MAX] ");
                printf("[-s N] [-v] [-w C] [-x]\n");
                printf("  -a      Autoload star names.\n");
                printf("  -b      Autoload planetnames.\n");
                printf("  -d      Use smashup (asteroid impact) routines.\n");
                printf("  -e E    Make E%% of stars have no planets.\n");
                printf("  -l MIN  Other systems will have at least MIN planets.\n");
                printf("  -m MAX  Other systems will have at most MAX planets.\n");
                printf("  -p      Create postscript map file of the universe.\n");
                printf("  -s N    The universe will have N stars.\n");
                printf("  -v      Do not print info and map of planets generated.\n");
                printf("  -w C    The universe will have C wormholes.\n");
                printf("  -x      Do not print info on stars generated.\n");
                printf("\n");

                return 0;
            }
        }
    }

    /*
     * Get values for all the switches that still don't have good values.
     */
    if (autoname_star == -1) {
        printf("\nDo you wish to use the file \"%s\" for star names? [y/n]> ",
               STARLIST);

        c = getchr();

        if (c != '\n') {
            getchr();
        }

        autoname_star = (c == 'y');
    }

    if (autoname_plan == -1) {
        printf("\nDo you wish to use the file \"%s\" for planet names? [y/n]> ",
               PLANETLIST);

        c = getchr();

        if (c != '\n') {
            getchr();
        }

        autoname_plan = (c == 'y');
    }

    if (use_smashup == -1) {
        printf("\nUse the smashup (asteroid impact) routines? [y/n]> ");
        c = getchr();

        if (c != '\n') {
            getchr();
        }

        use_smashup = (c == 'y');
    }

    while ((nstars < 1) || (nstars >= NUMSTARS)) {
        printf("Number of stars [1-%d]:", NUMSTARS - 1);
        scanf("%d", &nstars);
    }

    while ((planetlesschance < 0) || (planetlesschance > 100)) {
        printf("Percentage of empty systems [0-100]:");
        scanf("%d", &planetlesschance);
    }

    while ((minplanets <= 0) || (minplanets > absmaxplan)) {
        printf("Minimum number of planets per system [1-%d]:", absmaxplan);
        scanf("%d", &maxplanets);
    }

    while ((wormholes < 0) || (wormholes > nstars) || ((wormholes % 2) == 1)) {
        printf("Number of wormholes (muse be even number) [0-%d]:", nstars);
        scanf("%d", &wormholes);
    }

    Makeplanet_init();
    Makestar_init();
    Sdata.numstars = nstars;
    sprintf(str, "/bin/mkdir -p %s", DATADIR);
    system(str);
    planetdata = fopen(PLANETDATAFL, "w+");

    if (planetdata == NULL) {
        printf("Unable to open planet data file \"%s\"\n", PLANETDATAFL);

        return -1;
    }

    sectordata = fopen(SECTORDATAFL, "w+");

    if (sectordata == NULL) {
        printf("Unable to open sector data file \"%s\"\n", SECTORDATAFL);

        return -1;
    }

    if (printstarinfo || printplaninfo) {
        outputtxt = fopen(OUTPUTFILE, "w+");

        if (outputtxt == NULL) {
            printf("Unable to open \"%s\" for output.\n", OUTPUTFILE);

            return -1;
        }
    }

    if (!wormholes) {
        whcnt = 0;
    } else {
        whcnt (int)(nstars / wormholes) - 1;
    }

    wormidx = 0;

    for (star = 0; star < nstars; ++star) {
        Stars[star] = Makestar(planetdata, sectordata, outputtxt);
        xspeed[star] = 0;
        yspeed[star] = 0;
        Stars[star]->wh_has_wormhole = 0;
        Stars[star]->wh_dest_starnum = -1;
        Stars[star]->wh_stability = 0;

        /*
         * See if time to put a wormhole in
         */
        if (!whcnt) {
            /*
             * Make a wormhole here. This adds a wormhole planet to this star.
             */
            if (Stars[star]->numplanets == MAXPLANETS) {
                /*
                 * Skip until a star as < MAXPLANETS
                 */
                whcnt = 0;

                continue;
            } else {
                if (!wormholes) {
                    whcnt = 0;
                } else {
                    whcnt = (int)(nstars / wormholes) - 1;
                }

                make_wormhole(Stars[star], planetdata, sectordata, outputtxt);
                w_holes[wormidx].star = Stars[star];
                w_hoels[wormidx].num = star;
                ++wormidx;
            }
        }

        --whcnt;
    }

    /*
     * Data data files to group * readwrite
     */
    chmod(PLANETDATAFL, 00660);
    fclose(planetdata);
    chmod(SECTORDATAFL, 00660);
    fclose(sectordata);

    /*
     * New Gardan code 21.12.1996
     * Changed 27.8.1997: Displacement wasn't set before
     *
     * Start here
     */
    total = nstars;
    nempty = round_rand(((double)nstars * (double)planetlesschance) / 100);

    /*
     * Amount of non-empty stars
     */
    nstars -= nempty;
    rowcolumns = 0;

    while ((rowcolumns * rowcolumns) < (nstars / 2)) {
        ++rowcolumns;
    }

    /*
     * Unhandled squares
     */
    squaresleft = rowcolumns * rowcolumns;
    starsleft = nstars - squaresleft;
    emptyrounds = 0;

    while (nempty > squaresleft) {
        ++emptyrounds;
        nempty -= squaresleft;
    }

    displacement = UNIVSIZE / rowcolumns;

    /*
     * Size of square
     */
    for (x = 0; x < rowcolumns; ++x) {
        for (y = 0; y < rowcolumns; ++y) {
            /*
             * planetlesschance = 0;
             * Stars[starindex] = Makestar(planetdata, sectordata, outputtxt);
             * xspeed[starindex] = 0;
             * yspeed[starindex] = 0;
             */
            Stars[starindex]->xpos = displacement * (x + (1.0 * double_rand()));
            Stars[starindex]->ypos = displacement * (y + (1.0 * double_rand()));
            ++starindex;
            z = int_rand(1, squaresleft);

            /*
             * If there is system with planet
             */
            if (z <= starsleft) {
                /*
                 * Stars[starindex] =
                 *     Makestar(planetdata, sectordata, outputtxt);
                 * xspeed[starindex] = 0;
                 * yspeec[starindex] = 0;
                 */
                Stars[starindex]->xpos =
                    displacement * (x + (1.0 * double_rand()));

                Stars[starindex]->ypos =
                    displacement * (y + (1.0 * double_rand()));
                --starsleft;
                ++starindex;
            }

            /*
             * If there is planetless system
             */
            if (x <= nempty) {
                /*
                 * planetlesschance = 100;
                 * Stars[starindex] =
                 *     Makestar(planetdata, sectordata, outputtxt);
                 * xspeed[starindex] = 0;
                 * yspeed[starindex] = 0;
                 */
                Stars[starindex]->xpos =
                    displacement * (x + (1.0 * double_rand()));

                Stars[starindex]->ypos =
                    displacement * (y + (1.0 * double_rand()));

                /*
                 * sprintf(Stars[starindex]->name, "E%d_%d", x, y);
                 */

                /*
                 * Added -mfw
                 */
                strcpy(Stars[starindex]->name, NextStarName());
                --nempty;
                ++starindex;
            }

            /*
             * Planetless systems equal to all squares
             */
            for (z = 0; z < emptyrounds; ++z) {
                /*
                 * planetlesschance = 100;
                 * Stars[starindex] =
                 *     Makestar(planetdata, sectordata, outputtxt);
                 * xspeed[starindex] = 0;
                 * yspeed[starindex] = 0;
                 */
                Stars[starindex]->xpos =
                    displacement * (x + (1.0 * double_rand()));

                Stars[starindex]->ypos =
                    displacement * (y + (1.0 * double_rand()));

                /*
                 * sprintf(Stars[starindex]->name, "E%d_%d", x, y);
                 */

                /*
                 * Added -mfw
                 */
                strcpy(Stars[starindex]->name, NextStarName());
                ++starindex;
            }

            --squaresleft;
        }
    }

    /*
     * Checks if two stars are too close
     */
    z = 1;

    while (z) {
        z = 0;

        for (x = 2; x < total; ++x) {
            for (y = x + 1; y < total; ++y) {
                dist = sqrt(Distsq(Stars[x]->xpos,
                                   Stars[x]->ypos,
                                   Stars[x]->xpos,
                                   Stars[x]->ypos));

                if (dist < (4 * SYSTEMSIZE)) {
                    z = 1;

                    if (stars[x]->ypos > Stars[y]->ypos) {
                        Stars[x]->ypos += (4 * SYSTEMSIZE);
                    } else {
                        Stars[y]->ypos += (4 * SYSTEMSIZE);
                    }
                }
            }
        }
    }

    for (x = 0; x < starindex; ++x) {
        if (Stars[x]->xpos > UNIVSIZE) {
            Stars[x]->xpos -= UNIVSIZE;
        }

        if (Stars[x]->ypos > UNIVSIZE) {
            Stars[x]->ypos -= UNIVSIZE;
        }
    }

    /*
     * End Gardan code
     */

    /*
     * Calculate worm hole destinations
     */
    for (x = 1; x < wormidx; x += 2) {
        w_holes[x].star->wh_dest_starnum = w_holes[x - 1].num;
        w_holes[x - 1].star->wh_dest_starnum = w_holes[x].num;

        if (printstarinfo) {
            fprintf(outputtxt,
                    "Wormhole[%d], Dest: %d, Star: %d %s, Stab: %d\n",
                    x - 1,
                    w_holes[x - 1].star->wh_test_starnum,
                    w_holes[x - 1].num,
                    w_holes[x - 1].star->name,
                    w_holes[x - 1].star->wh_stability);
        }

        if (printfstarinfo) {
            fprintf(outputtxt,
                    "Wormhole[%d], Dest: %d, Star: %d %s, Stab: %d\n",
                    x,
                    w_holes[x].star->wh_dest_starnum,
                    w_holes[x].num,
                    w_holes[x].star->name,
                    w_holes[x].star->wh_stability);
        }
    }

    if (((double)wormidx / 2) != ((int)wormidx / 2)) {
        /*
         * Odd number so last w_hole points to #1 no return
         */
        w_holes[wormidx - 1].star->wh_dest_starnum = w_holes[0].num;

        if (printstarinfo) {
            fprintf(outputtxt,
                    "Wormhole[%d], Dest: %d, Star: %d %s, Stab: %d\n",
                    wormidx - 1,
                    w_holes[wormidx - 1].star->wh_dest_starnum,
                    w_holes[wormidx - 1].num,
                    w_holes[wormidx - 1].star->name,
                    w_holes[wormidx - 1].star->wh_stability);
        }
    }

    if (printstarinfo) {
        fprintf(outputtxt, "Total Wormholes: %d\n", wormidx);
    }

#if 0
    /*
     * Old code starts
     */

    /*
     * Try to more evenly space stars. Essentially this is an inverse-gravity
     * calculation: The nearer two stars are to each other, the more they
     * repulse each other. Several iterations of this will suffice to move all
     * of the stars nicely apart.
     */

    CLUSTER_COUNTER = 6;
    STAR_COUNTER = 1;
    dist = CLUSTER_FROM_CENTER;

    for (its = 1; its <= 6; ++its) {
        /*
         * Circle of stars
         */
        fprintf(outputtxt, "Grouping [%f]", dist);

        for (clusters = 1; clusters <= CLUSTER_COUNTER; ++clusters) {
            /*
             * Number of clusters in circle
             */
            for (starsinclus = 1; starsinclus <= STAR_COUNTER; ++starsinclus) {
                /*
                 * Number of stars in cluster
                 */
                ange = 2.0 * M_PI * ANGLE;
                cluster_delta_x = int_rand(CLUSTER_STAR_MIN, CLUSTER_STAR_MAX);
                cluster_delta_y = int_rand(CLUSTER_STAR_MIN, CLUSTER_STAR_MAX);
                clusterx = dist * sin(angle);
                clustery = dist * cos(angle);

                if (starindex >= Sdatanumstars) {
                    flag = 1;

                    break;
                }

                fprintf(outputtxt, " %s ", Stars[starindex]->name);

                if ((its == 1) || (its == 3) || (its == 6)) {
                    setbit(Stars[starindex]->explored, 1);
                    setbit(Stars[starindex]->inhabited, 1);
                }

                Stars[starindex]->xpos = clusterx + cluster_delta_x;
                Stars[starindex]->ypos = clustery + cluster_delta_y;

                ANGLE = (ANGLE + 0.15) + double_rand();
                fprintf(outputtxt, "ANGLE 1 %f\n", ANGLE);
                ++starindex;
            }
        }

        if (flag) {
            break;
        }

        switch (its + 1) {
        case 2:
            ANGLE = 0.20 + double_rand();
            CLUSTER_COUNTER = 10;
            dist += 25000;

            break;
        case 3:
            ANGLE = 0.35 + double_rand();
            CLUSTER_COUNTER = 13;
            dist += 27000;

            break;
        case 4:
            ANGLE = 0.40 + double_rand();
            CLUSTER_COUNTER = 15;
            dist += 27000;

            break;
        case 5:
            ANGLE = 0.25 + double_rand();
            CLUSTER_COUNTER = 17;
            dist += 32000;

            break;
        case 6:
            ANGLE = 0.12 + double_rand();
            CLUSTER_COUNTER = 17;
            dist += 32000;

            break;
        }

        fprintf(outputtxt, "\n\n");
        fprintf(outputtxt, "ANGLE 2 %f\n", ANGLE);
    }

    Stars[0]->xpos = 0;
    Stars[0]->ypos = 0;
    strcpy(Stars[0]->name, "Bambi");
#endif

    stardata = fopen(STARDATAFL, "w+");

    if (stardata == NULL) {
        printf("Unable to open star data file \"%s\"\n", STARDATAFL);

        return 01;
    }

    fwrite(&Sdata, sizeof(Sdata), 1, stardata);

    for (star = 0; star < Sdata.numstars; ++star) {
        fwrite(Stars[star], sizeof(startype), 1, stardata);
    }

    chmod(STARDATAFL, 00660);
    fclose(stardata);

    EmptyFile(SHIPDATAFL);
    EmptyFile(SHIPFREEDATAFL);
    EmptyFile(COMMODDATAFL);
    EmptyFile(COMMODFREEDATAFL);
    EmptyFile(PLAYERDATAFL);
    EmptyFile(RACEDATAFL);

    memset((char *)power, 0, sizeof(power));
    InitFile(POWFL, power, sizeof(power));

    memset((char *)block, 0, sizeof(block));
    Initfile(BLOCKDATAFL, block, sizeof(block));

    /*
     * Telegram files: directory and a file for each player.
     */
    sprintf(str, "/bin/mkdir -p %s", MSGDIR);
    system(str);
    chmod(MSGDIR, 00770);

#if 0
    /*
     * Why is this not needed anymore?
     */
    for (i = 1; i < MAXPLAYERS; ++i) {
        sprintf(str, "%s.%d", TELEGRAMFL, i);
        Empyfile(str);
    }
#endif

    /*
     * News files: directory and the 4 types of news.
     */
    sprintf(str, "/bin/mkdir -p %s", NEWSDIR);
    system(str);
    chmod(NEWSDIR, 00770);
    EmptyFile(DECLARATIONFL);
    EmptyFile(TRANSFERFL);
    EmptyFile(COMBATFL);
    EmptyFile(ANNOUNCEFL);

    if (printstarinfo) {
        PrintStatistics(outputtxt);
    }

    if (printpostscript) {
        produce_postscript(DEFAULT_POSTSCRIPT_MAP_FILENAME);
    }

    printf("Universe Created!\n");

    if (printstarinfo || printplaninfo) {
        printf("Summary output written to %s\n", OUTPUTFILE);
        fclose(outputtxt);
    }

    return 0;
}
예제 #11
0
파일: ionization.c 프로젝트: fnevgeny/cfac
int SaveIonization(cfac_t *cfac, int nb, int *b, int nf, int *f, char *fn) {
  int i, j, k;
  int ie, ip;
  FILE *file;
  LEVEL *lev1, *lev2;
  CI_RECORD r;
  CI_HEADER ci_hdr;
  F_HEADER fhdr;
  double delta, emin, emax, e, emax0;
  double qk[MAXNE], qku[MAXNUSR];
  int nq, nqk;  
  ARRAY subte;
  int isub, n_tegrid0, n_egrid0, n_usr0;
  int te_set, e_set, usr_set;
  double c, e0, e1;

  emin = 1E10;
  emax = 1E-10;
  k = 0;
  for (i = 0; i < nb; i++) {
    lev1 = GetLevel(cfac, b[i]);
    for (j = 0; j < nf; j++) {
      lev2 = GetLevel(cfac, f[j]);
      e = lev2->energy - lev1->energy;
      if (e > 0) k++;
      if (e < emin && e > 0) emin = e;
      if (e > emax) emax = e;
    }
  }
  if (k == 0) {
    return 0;
  }

  if (tegrid[0] < 0) {
    te_set = 0;
  } else {
    te_set = 1;
  }
  if (egrid[0] < 0) {
    e_set = 0;
  } else {
    e_set = 1;
  }
  if (usr_egrid[0] < 0) {
    usr_set = 0;
  } else {
    usr_set = 1;
  }
  n_tegrid0 = n_tegrid;
  n_egrid0 = n_egrid;
  n_usr0 = n_usr;

  if (egrid_limits_type == 0) {
    emax0 = 0.5*(emin + emax)*egrid_max;
  } else {
    emax0 = egrid_max;
  }

  ArrayInit(&subte, sizeof(double), 128, NULL, NULL);
  ArrayAppend(&subte, &emin);
  c = TE_MAX_MIN;
  if (!e_set || !te_set) {
    e = c*emin;
    while (e < emax) {
      ArrayAppend(&subte, &e);
      e *= c;
    }
  }
  ArrayAppend(&subte, &emax);

  egrid_type = 1;
  pw_type = 0;
  if (usr_egrid_type < 0) usr_egrid_type = 1;
  nqk = NPARAMS;
  r.params = malloc(sizeof(float)*nqk);
    
  fhdr.type = DB_CI;
  strcpy(fhdr.symbol, cfac_get_atomic_symbol(cfac));
  fhdr.atom = cfac_get_atomic_number(cfac);
  ci_hdr.nele = GetNumElectrons(cfac, b[0]);
  ci_hdr.qk_mode = qk_mode;
  ci_hdr.nparams = nqk;
  ci_hdr.pw_type = pw_type;
  ci_hdr.egrid_type = egrid_type;
  ci_hdr.usr_egrid_type = usr_egrid_type;
  file = OpenFile(fn, &fhdr);

  e0 = emin*0.999;
  for (isub = 1; isub < subte.dim; isub++) {
    e1 = *((double *) ArrayGet(&subte, isub));
    if (isub == subte.dim-1) e1 = e1*1.001;
    emin = e1;
    emax = e0;
    k = 0;
    for (i = 0; i < nb; i++) {
      lev1 = GetLevel(cfac, b[i]);
      for (j = 0; j < nf; j++) {
	lev2 = GetLevel(cfac, f[j]);
	e = lev2->energy - lev1->energy;
	if (e < e0 || e >= e1) continue;
	if (e < emin) emin = e;
	if (e > emax) emax = e;
	k++;
      }
    }
    if (k == 0) {
      e0 = e1;
      continue;
    }

    if (qk_mode == QK_CB) {
      SetIEGrid(1, emin, emax);
    } else {
      if (n_tegrid0 == 0) {
	n_tegrid = 3;
      }
      if (!te_set) {
	e = 2.0*(emax-emin)/(emax+emin);
	if (e < EPS3) {
	  SetIEGrid(1, emin, emax);
	} else if (e < 0.5) {
	  SetIEGrid(2, emin, emax);
	} else {
	  if (k == 2) n_tegrid = 2;
	  SetIEGrid(n_tegrid, emin, emax);
	}
      }
    }

    n_egrid = n_egrid0;
    n_usr = n_usr0;
    if (!usr_set) usr_egrid[0] = -1.0;
    if (!e_set) egrid[0] = -1.0;
    
    e = 0.5*(emin + emax);
    if (egrid_limits_type == 0) {
      emin = egrid_min*e;
      emax = egrid_max*e;
    } else {
      emin = egrid_min;
      emax = egrid_max;
    }
    if (emax < emax0) {
      emax = 50.0*e;
      if (emax > emax0) emax = emax0;
    }
    
    if (n_egrid <= 0) {    
      n_egrid = 6;
    }
    if (egrid[0] < 0.0) {
      SetCIEGrid(n_egrid, emin, emax, e);
    }
    
    usr_different = 1;
    if (n_usr > 0 && usr_egrid[0] < 0.0) {
      SetUsrCIEGrid(n_usr, emin, emax, e);
      usr_egrid_type = 1;
      usr_different = 0;
    }   
    if (n_usr <= 0) {
      SetUsrCIEGridDetail(n_egrid, egrid);
      usr_egrid_type = 1;
      usr_different = 0;
    } 
    
    if (qk_mode != QK_CB) {
      SetTransitionOptions(cfac, G_BABUSHKIN, M_NR, 4, 4);
      SetRRTEGrid(1, e, e);
      SetPEGridLimits(egrid_min, egrid_max, egrid_limits_type);
      SetPEGridDetail(n_egrid, egrid);
      PrepRREGrids(e, emax0);
    }    
		  
    for (ie = 0; ie < n_egrid; ie++) {
      for (i = 0; i < n_tegrid; i++) {
	xegrid[i][ie] = egrid[ie]/tegrid[i];
	if (egrid_type == 1) xegrid[i][ie] += 1.0;
	log_xegrid[i][ie] = log(xegrid[i][ie]);
      }
    }
    yegrid0[0] = log(1E-5);
    delta = (log(0.5) - yegrid0[0])/(NINT-1.0);
    for (i = 1; i < NINT; i++) {
      yegrid0[i] = yegrid0[i-1] + delta;
    }
    for (i = 0; i < NINT; i++) {
      yegrid0[i] = exp(yegrid0[i]);
    }

    if (pw_scratch.nkl == 0) {
      SetCIPWGrid(0, NULL, NULL);
    }

    r.strength = malloc(sizeof(float)*n_usr);

    ci_hdr.n_tegrid = n_tegrid;
    ci_hdr.n_egrid = n_egrid;
    ci_hdr.n_usr = n_usr;
    ci_hdr.tegrid = tegrid;
    ci_hdr.egrid = egrid;
    ci_hdr.usr_egrid = usr_egrid;
    InitFile(file, &fhdr, &ci_hdr);

    for (i = 0; i < nb; i++) {
      lev1 = GetLevel(cfac, b[i]);
      for (j = 0; j < nf; j++) {
	lev2 = GetLevel(cfac, f[j]);
	e = lev2->energy - lev1->energy;
	if (e < e0 || e >= e1) continue;
	
        nq = IonizeStrength(cfac, qku, qk, &e, b[i], f[j]);
	if (nq < 0) continue;
	
        r.b = b[i];
	r.f = f[j];
	r.kl = nq;
	
	for (ip = 0; ip < nqk; ip++) {
	  r.params[ip] = (float) qk[ip];
	}
      
	for (ie = 0; ie < n_usr; ie++) {
	  r.strength[ie] = (float) qku[ie];
	}
	
	WriteCIRecord(file, &r);
      }
    }

    DeinitFile(file, &fhdr);

    free(r.strength);
    ReinitRadial(cfac, 1);
    FreeRecQk();
    FreeRecPk();
    FreeIonizationQk();
    
    e0 = e1;
  }

  free(r.params);

  ReinitRecombination(1);
  ReinitIonization(1);

  ArrayFree(&subte);
  CloseFile(file, &fhdr);

  return 0;
}
예제 #12
0
파일: ionization.c 프로젝트: fnevgeny/cfac
int SaveIonizationMSub(cfac_t *cfac, int nb, int *b, int nf, int *f, char *fn) {
  FILE *file;
  LEVEL *lev1, *lev2;
  CIM_RECORD r;
  CIM_HEADER ci_hdr;
  F_HEADER fhdr;
  double qku[MAXNUSR*MAXMSUB];
  double delta, emin, emax, e, emax0;
  int nq, i, j, k, ie;

  emin = 1E10;
  emax = 1E-10;
  k = 0;
  for (i = 0; i < nb; i++) {
    lev1 = GetLevel(cfac, b[i]);
    for (j = 0; j < nf; j++) {
      lev2 = GetLevel(cfac, f[j]);
      e = lev2->energy - lev1->energy;
      if (e > 0) k++;
      if (e < emin && e > 0) emin = e;
      if (e > emax) emax = e;
    }
  }
  if (k == 0) {
    return 0;
  }

  if (egrid_limits_type == 0) {
    emax0 = 0.5*(emin + emax)*egrid_max;
  } else {
    emax0 = egrid_max;
  }

  e = 0.5*(emin + emax);
  if (egrid_limits_type == 0) {
    emin = egrid_min*e;
    emax = egrid_max*e;
  } else {
    emin = egrid_min;
    emax = egrid_max;
  }
  if (emax < emax0) {
    emax = 50.0*e;
    if (emax > emax0) emax = emax0;
  }

  egrid_type = 1;
  if (usr_egrid_type < 0) usr_egrid_type = 1;
  if (n_egrid <= 0) n_egrid = 6;
  if (egrid[0] < 0.0) {
    SetCIEGrid(n_egrid, emin, emax, e);
  }
  if (n_usr > 0 && usr_egrid[0] < 0.0) {
    SetUsrCIEGrid(n_usr, emin, emax, e);
    usr_egrid_type = 1;
  }    
  if (n_usr <= 0) {
    SetUsrCIEGridDetail(n_egrid, egrid);
    usr_egrid_type = 1;
  }  
    
  fhdr.type = DB_CIM;
  strcpy(fhdr.symbol, cfac_get_atomic_symbol(cfac));
  fhdr.atom = cfac_get_atomic_number(cfac);
  ci_hdr.nele = GetNumElectrons(cfac, b[0]);
  ci_hdr.egrid_type = egrid_type;
  ci_hdr.usr_egrid_type = usr_egrid_type;
  file = OpenFile(fn, &fhdr);

  yegrid0[0] = log(1E-5);
  delta = (log(0.5)-yegrid0[0])/(NINT-1.0);
  for (i = 1; i < NINT; i++) {
    yegrid0[i] = yegrid0[i-1] + delta;
  }
  for (i = 0; i < NINT; i++) {
    yegrid0[i] = exp(yegrid0[i]);
  }

  if (pw_scratch.nkl == 0) {
    SetCIPWGrid(0, NULL, NULL);
  }
    
  ci_hdr.n_egrid = n_egrid;
  ci_hdr.n_usr = n_usr;    
  ci_hdr.egrid = egrid;
  ci_hdr.usr_egrid = usr_egrid;
  InitFile(file, &fhdr, &ci_hdr);
  
  for (i = 0; i < nb; i++) {
    lev1 = GetLevel(cfac, b[i]);
    for (j = 0; j < nf; j++) {
      lev2 = GetLevel(cfac, f[j]);
      e = lev2->energy - lev1->energy;
      nq = IonizeStrengthMSub(cfac, qku, &e, b[i], f[j]);
      if (nq < 0) continue;
      r.b = b[i];
      r.f = f[j];
      r.nsub = nq;
      r.strength = malloc(sizeof(float)*nq*n_usr);
      for (ie = 0; ie < nq*n_usr; ie++) {
	r.strength[ie] = qku[ie];
      }
      WriteCIMRecord(file, &r);
      free(r.strength);
    }
  }
    
  DeinitFile(file, &fhdr);
  CloseFile(file, &fhdr);

  ReinitIonization(1);
  return 0;
}
예제 #13
0
CIpRuleFile::CIpRuleFile(void)
{
	this->m_pszFilePath = _T("IpRule.dat");
	InitFile();
	GetDataFromFile();
}