Commit 3a10de37 authored by DeAn_Wei's avatar DeAn_Wei
Browse files

Merge branch 'master' of deanwei:ansijing/prodata

parents 706b4f1e d192f272
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ Set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")  
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")  

#FIND_PACKAGE( OpenMP REQUIRED)  
FIND_PACKAGE( OpenMP REQUIRED)  
if(OPENMP_FOUND)  
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")  
    message(STATUS "OpenMP_C_FLAGS = " ${OpenMP_C_FLAGS})  

custom/Custom.cpp

0 → 100644
+35 −0
Original line number Diff line number Diff line

#include "Home.h"
#include "Util.h"
#include "ProDataIO.h"


void SpecifyEquations1(Table_t &table)
{
        int     i;
        real8   tau;
 
        vector<vector<double> >::iterator   it;
        int colSeparation =  GetColIDFromTable(table, "separation");

        for(it = table.data.begin(); it != table.data.end(); ){

            if((*it)[colSeparation] < 25){
                table.data.erase(it);
                continue;
            }

            it++;
        }

        return;
}

void SpecifyEquations(Table_t &table)
{
        int     i, j;

        SpecifyEquations1(table);
    
        return;
}

dev/reg.cpp

0 → 100644
+161 −0
Original line number Diff line number Diff line

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <regex.h>
#include <assert.h>
#include <string.h>

using namespace std;

int find_first(string input, string pattern, string &out){
    regex_t reg;
    regmatch_t pm[1];
    int  iret = 0;
    out = "";

    /*编译正则表达式*/
    iret = regcomp(&reg, pattern.c_str(), REG_EXTENDED|REG_NEWLINE);
    if (iret != 0){
        return -1;
    }

    iret = regexec(&reg, input.c_str(), 1, pm, 0);
    if (iret == REG_NOMATCH){
        out = "";
        iret = input.length();
    }else if (iret != 0) {
        return -2;

    }else{
        out = input.substr(pm[0].rm_so,pm[0].rm_eo-pm[0].rm_so);
        iret = pm[0].rm_eo;
    }
    regfree(&reg);
    return iret;
}

int find_first(char *buff, char *pattern, char *outdata){
    regex_t reg;
    regmatch_t pm[1];
    int  status = 0;
    /*编译正则表达式*/
    status = regcomp(&reg, pattern, REG_EXTENDED|REG_NEWLINE);  //扩展正则表达式和识别换行符
    if (status != 0){    //成功返回0
        return -1;
    }
    status = regexec(&reg, buff, 1, pm, 0);
    if (status == REG_NOMATCH){
        printf("no match!\n");
        status = -1;
    }
    else if (status != 0) {
        return -2;
    }
    else if (status == 0) {
        int i, j;
        for (i = pm[0].rm_so, j = 0; i < pm[0].rm_eo; i++, j++) {
            outdata[j] = buff[i];
        }
        outdata[i] = '\0';
    }
    regfree(&reg);
    return status;

}

int find_all(char *buff, char *pattern, char result[][20]){   //返回匹配个数
    regex_t reg;
    regmatch_t pm[1];
    int  status = 0;
    char * p = buff;
    int count = 0;

    /*编译正则表达式*/
    status = regcomp(&reg, pattern, REG_EXTENDED|REG_NEWLINE);  //扩展正则表达式和识别换行符
    if (status != 0){    //成功返回0
        return -1;
    }
    int i = 0, j, k;
    while((status = regexec(&reg, p, 1, pm, 0)) == 0) {
        for(j = pm[0].rm_so, k = 0; j < pm[0].rm_eo; j++) {
            result[i][k++] = p[j];
        }
        result[i][k] = '\0';
        i++;
        p += pm[0].rm_eo;
        count++;
        if (*p == '\0')  break;
    }

    regfree(&reg);
    return count;

}

int print_file(const char *file_name, const char *pattern)

{
    regex_t reg;
    regmatch_t pm[1];
    int  status = 0;
    int count = 0;
    FILE *fp = fopen(file_name, "r+");
    assert(fp);
    char buff[1024] = {0};
    char output[1024] = {0};

    /*编译正则表达式*/
    status = regcomp(&reg, pattern, REG_EXTENDED|REG_NEWLINE);  //扩展正则表达式和识别换行符
    assert(status == 0);

    while(fgets(buff, sizeof(buff), fp)) {     //循环读取文件

        char * p = buff;

        while(1) {
            status = regexec(&reg, p, 1, pm, 0);
            if (status == 0) {  //匹配成功
                count++;
                strncpy(output, p + pm[0].rm_so, pm[0].rm_eo - pm[0].rm_so);
                cout<<"匹配:"<<output<<endl;
                p += pm[0].rm_eo;
            }
            else {
                break;
            }
        }
    }
    regfree(&reg);

    return count;
}

int main(int args, char *argv[])

{
    char result[20][20] = {0};
    char buf[] = "1231a4568b789c234";
    char pattern[] = "23";

    char resultfirst[20] = {0};

    if(args != 3)exit(-1);

    find_first(argv[1], argv[2], resultfirst);
    cout<<strlen(resultfirst) << ":" << resultfirst<<endl;
    cout << "***************************" <<endl;

    int count = find_all(argv[1], argv[2], result);
    for (int i = 0; i < count; i++) {
        cout<<"result:"<<"i="<<i+1<<"----"<<result[i]<<endl;
    }
    cout << "***************************" <<endl;
    count = print_file("test.txt", "[0-9]{5}");
    cout<<"匹配的个数:"<<count<<endl;

    return 0;

}
+42 −1
Original line number Diff line number Diff line
@@ -14,6 +14,26 @@
#include <string>
#include <vector>
#include <list>
#include <map>

#ifdef _OPENMP

#include <omp.h>

#define INIT_LOCK(a)    omp_init_lock((a))
#define LOCK(a)         omp_set_lock((a))
#define UNLOCK(a)       omp_unset_lock((a))
#define DESTROY_LOCK(a) omp_destroy_lock((a))

#else /* _OPENMP not defined */

#define INIT_LOCK(a)
#define LOCK(a)
#define UNLOCK(a)
#define DESTROY_LOCK(a)

#endif /* end ifdef _OPENMP */


#define real8 double
using namespace std;
@@ -32,7 +52,7 @@ typedef struct {
typedef struct {
        double  burgMag;
        int     seed;
        int     type;
        int     type, nThreads;
        bool    help;

        vector<string>  inpFiles, outFiles;
@@ -67,6 +87,7 @@ typedef enum{
    OPT_TYPE,
    OPT_PRIVATEVALS,
    OPT_AUXFILE,
    OPT_THREADS,
	OPT_MAX
}OPT_t;

@@ -75,9 +96,15 @@ typedef enum{
    FTYPE_PROC_EXTEND_DIS_DDD,
    FTYPE_PROC_EXTEND_DIS_MD,
    FTYPE_SPECIFY_EQUATIONS,
    FTYPE_GENERATE_DISLOCATION,
	FTYPE_MAX
}FTYPE_t;

typedef enum{
    INT_DATA = 0,
    DOUBLE_DATA,
    STRING_DATA
}DATA_TYPE;
/*
 *      Define a structure to hold a command line option's id (type),
 *      name, the shortest possible unique abbreviation of the option
@@ -91,11 +118,25 @@ typedef struct {
} Option_t;

typedef struct {
        int     type;
        string  name;
        string  val;
}Variable_t;

typedef struct {
    string                  T, F;
    int                     i,j,k;
    double                  solutionTime;
    vector<string>          variables;
    map<string, string>     aux;
    vector<vector<double> > data;
} Table_t;

typedef struct {
    string                  T, F;
    int                     i,j,k;
    double                  solutionTime;
    map<string, string>     aux;
    vector<string>          variables;
    vector<vector<double> > data;
}LineList_t;
+3 −2
Original line number Diff line number Diff line
@@ -28,13 +28,14 @@ typedef struct{

typedef struct {
    int     timestep;
    real8   box[6];

    vector<vector<real8> > box;
    vector<string> bounds;
    vector<string> variables;
    vector<Atom_t> atom;
}MgData_t;
}Dump_t;

void HandleExtendedDislocation_MD(InArgs_t *inArgs);
void GenerateDislocation(InArgs_t *inArgs);

#endif
Loading