找回密码
 注册
Simdroid-非首页
查看: 92|回复: 0

[命令和APDL] 命令流清理 C语言代码 与大家共同探讨完善

[复制链接]
发表于 2012-4-13 16:59:48 | 显示全部楼层 |阅读模式 来自 黑龙江哈尔滨
本帖最后由 webcam 于 2012-4-14 07:38 编辑

看到坛子上hg_boy版主的帖子——命令流清理工具http://forum.simwe.com/thread-821547-1-2.html,但是附件已经不见了,就自己写了一个命令流清理的代码,C语言,VC调试。
思路是:依次读入原来log文件的每一行,然后把以"/"开头和以“!”开头的行全部去掉,剩余的行写到一个新的log文件里面。
但是由于以“/”开头的命令并不都是没用的,把有用的命令例如/prep7、/units等保留。
现在问题来了:以“/”开头且有用的命令(代码紫色部分)在我的代码里可能没完全包含,希望各位大神能够多多补充,以免程序删掉不该删除的命令行。

附件是根据当前可能不完善的代码生成的可执行文件,感兴趣的话可以运行试试。

C代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXPATHLEN 150
#define LINELEN 300
#define LEN 10

void welcome(void){
    printf("**************************************\n");
    printf("*本程序用于处理ANSYS自动生成的log文件*\n");
    printf("*Wish you happy every day with ANSYS!*\n");
    printf("**************************************\n");
}
void getPathAndName(char* pathAndName){
    printf("请输入log文件的完整路径和文件名(包括扩展名.log):");
    gets(pathAndName);
}

int equalOrNot(int matrix1[LEN],int matrix2[LEN]){
    int i;
    int flag=1;
    for(i=0;i<LEN;i++){
        flag=matrix1[ i ]-matrix2[ i ];
        if(flag==0){
            break;
        }
    }
    return flag;
}

void finish(char* pathAndName){
    printf("程序处理完毕,处理后的log文件为%s。\n",pathAndName);
    printf("谢谢使用,请按任意键结束...");
}

int main(){
    char pathAndName[MAXPATHLEN];
    FILE *logIn=NULL;
    FILE *logOut=NULL;
    char tempLine[LINELEN];
    int flag;
    int n[LEN]={0,};
    int flagMatrix[LEN]={0,};

    welcome();
    getPathAndName(pathAndName);
    logIn=fopen(pathAndName,"r");
    if(logIn==NULL){
        printf("无法打开指定的log文件,请检查路径及文件名。\n");
        printf("程序即将退出,请按任意键...\n");
        fflush(stdin);
        getchar();
        exit(0);
    }
    else{

        strcat(pathAndName,".log");
        logOut=fopen(pathAndName,"w");
        do{
            fgets(tempLine,LINELEN,logIn);
            puts(tempLine);
            flag=strncmp(tempLine,"/",1);
            if(flag==0){
                n[0]=strnicmp(tempLine,"/CLEAR",5);
                n[1]=strnicmp(tempLine,"/FILNAM",7);
                n[2]=strnicmp(tempLine,"/PREP7",6);
                n[3]=strnicmp(tempLine,"/AUX",4);
                n[4]=strnicmp(tempLine,"/SOLU",5);
                n[5]=strnicmp(tempLine,"/POST",5);
                n[6]=strnicmp(tempLine,"/RUNST",6);
                n[7]=strnicmp(tempLine,"/PDS",4);
                n[8]=strnicmp(tempLine,"/OPT",4);
                n[9]=strnicmp(tempLine,"/UNITS",6);
                if(equalOrNot(n,flagMatrix)==0){
                    fputs(tempLine,logOut);
                }
            }
            else{
                flag=strncmp(tempLine,"!",1);
                if(flag!=0){
                    fputs(tempLine,logOut);
                }
            }
        }while(!feof(logIn));
        fclose(logIn);
        fclose(logOut);
    }
    finish(pathAndName);
    fflush(stdin);
    getchar();
}

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-6-5 09:47 , Processed in 0.031001 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表