22 September 2009

New mkinp_vect



#include "stdlib.h"
#include "stdio.h"
#include "string.h"

int main(int argc, char *argv[])
{
    FILE *fp_IN, *fp_OUT;
    char nume_fis[200], old_nume_fis[200], new_nume_fis[200], delete_command[200];
    char *dummy_char_name, *dummy_nr;
    int file_nr;
    int nr_elem, nr_nodes, nr_data, dummy_int;
    int i;
    int dummy;
    double M_x, M_y, M_z, Hdemag_x, Hdemag_y, Hdemag_z, Hani_x, Hani_y, Hani_z, Hexch_x, Hexch_y, Hexch_z, Hext_x, Hext_y, Hext_z;
    char etapa1_line[250];

    strcpy(nume_fis,argv[1]);
    dummy_char_name = strtok (nume_fis,"."); //nume
    dummy_nr        = strtok (NULL,"."); //numar
    file_nr         = atoi (dummy_nr);

    sprintf(old_nume_fis, "%s.%04d.inp", dummy_char_name, file_nr);
    sprintf(new_nume_fis, "%s_v.%04d.inp", dummy_char_name, file_nr);
    while( (fp_IN  = fopen( old_nume_fis, "r" )) != NULL )
    {
        printf("Working on file %04d\n", file_nr);
        fp_OUT  = fopen( new_nume_fis, "w" );
        fscanf(fp_IN, "%d %d %d %d %d\n", &nr_elem, &nr_nodes, &nr_data, &dummy_int, &dummy_int);
        fprintf(fp_OUT, "%d %d %d %d %d\n", nr_elem, nr_nodes, nr_data+3, dummy_int, dummy_int);

        for (i=0;i < nr_elem;i++)
        {
            fscanf(fp_IN, " %[^\n]", etapa1_line);
            fprintf(fp_OUT, "%s\n", etapa1_line);
        }
        for (i=0;i < nr_nodes;i++)
        {
            fscanf(fp_IN, " %[^\n]", etapa1_line);
            fprintf(fp_OUT, "%s\n", etapa1_line);
        }

        fscanf(fp_IN, " %[^\n]", etapa1_line);
        fprintf(fp_OUT, "16 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", etapa1_line);

        fprintf(fp_OUT, "M, none\n");

        for (i=0;i < nr_data;i++)
        {
            fscanf(fp_IN, " %[^\n]", etapa1_line);
            fprintf(fp_OUT, "%s\n", etapa1_line);
        }

        for (i=0;i < nr_elem;i++)
        {
            fscanf(fp_IN, "%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n", &dummy, &M_x, &M_y, &M_z, &Hdemag_x, &Hdemag_y, &Hdemag_z, &Hani_x, &Hani_y, &Hani_z, &Hexch_x, &Hexch_y, &Hexch_z, &Hext_x, &Hext_y, &Hext_z);
            fprintf(fp_OUT, "%d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",  dummy, M_x, M_y, M_z, M_x, M_y, M_z, Hdemag_x, Hdemag_y, Hdemag_z, Hani_x, Hani_y, Hani_z, Hexch_x, Hexch_y, Hexch_z, Hext_x, Hext_y, Hext_z);
        }

        fclose(fp_IN);
        fclose(fp_OUT);

        sprintf(delete_command, "rm %s", old_nume_fis);
        system(delete_command);

        file_nr++;
        sprintf(old_nume_fis, "%s.%04d.inp", dummy_char_name, file_nr);
        sprintf(new_nume_fis, "%s_v.%04d.inp", dummy_char_name, file_nr);
    }
    return(0);
}


No comments:

Post a Comment

Followers