Mentions légales du service

Skip to content
Snippets Groups Projects
cgns2meshb.cpp 3.47 KiB
Newer Older
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <iostream>
using namespace std;

#include <string>

extern "C"
{
#include "msh.h"
}

#include "libmeshb7.h"

static inline int isParameter(char *str)
{
    if (str == NULL)
        return 0;
    if (str[0] == '-')
        return 0;
    return 1;
}

int main(int argc, char **argv)
{

    printf(" \n");
    printf(" ----------------------------------------------------------------------- \n");
    printf("|                                                                       |\n");
    printf("|                             cgns2meshb                                |\n");
    printf("|                                                                       |\n");
    printf(" -----------------------------------------------------------------------\n");
    printf(" \n");

    int i;
    char InpMshNam[1024], noMshNam[1024], noSolNam[1024], OutMshNam[1024], OutSolNam[1024];
    int ierro;
    bool ascii = false;
    VizObject *Obj_surf = NULL;
    VizIntStatus status;

    double t0 = GetWallClock();

    if (argc < 2)
    {
        cout << "  ERROR: missing arguments" << endl;
        goto errormessage;

    errormessage: //-- error message
        printf("\n");
        cout << "  The format is: cgns2meshb xxx.cgns yyy.cgns zzz.cgns (-ascii)" << endl;
        cout << "        several cgns files can be provided" << endl;
        cout << "        -ascii is optional to define ascii output (binary by default otherwise)" << endl;
    //-- read parameters
        if (strcmp(argv[i], "-ascii") == 0)
            ascii = true;
    for (i = 1; i < argc; i++)
        if ((isParameter(argv[i]) == 1))
        {
            sprintf(InpMshNam, "%s", argv[i]);
            sprintf(noMshNam, "%s", InpMshNam);
            if (strstr(InpMshNam, ".cgns") != NULL)
            {
                //-- cgns file found
                printf("Case of cgns file: %s\n", argv[i]);
                noMshNam[strstr(InpMshNam, ".cgns") - InpMshNam] = '\0'; // check if it has the extension .cgns[b] and remove it if it is the case

                sprintf(OutMshNam, "%s", noMshNam);
                sprintf(OutSolNam, "%s", noMshNam);

                if (ascii)
                    strcat(OutMshNam, ".mesh");
                else
                    strcat(OutMshNam, ".meshb");
                if (ascii)
                    strcat(OutSolNam, ".sol");
                else
                    strcat(OutSolNam, ".solb");

                ierro = viz_NewInterface(&Obj_surf);
                if (ierro != 0)
                    printf(" viz_NewInterface  status %d \n", ierro);

                ierro = viz_OpenMesh(Obj_surf, InpMshNam, &status);
                if (ierro != VIZINT_SUCCESS)
                    printf(" viz_OpenMesh failed error %3d : %s\n", ierro, status.ErrMsg);
                else
                    printf("  %%%% %s OPENED\n", status.InfoMsg);
                viz_PrintMeshInfo(Obj_surf, &status);

                ierro = viz_WriteMesh(Obj_surf, OutMshNam, &status);
                if (ierro != VIZINT_SUCCESS)
                    printf(" viz_WriteMesh failed error %3d : %s\n", ierro, status.ErrMsg);
                else
                    printf("  %%%% Mesh written in %s\n", status.InfoMsg);
            }
        }
    }

    double t2 = GetWallClock();
    printf(" Total cpu time %lg (s) \n", t2 - t0);

    cout << "\n  Thank you for using cgns2meshb" << endl;

    return 0;
}