src/io.c
//read dcd header and stores useful parameters in a structure
read dcd header and stores useful parameters in a structure
read dcd header and stores useful parameters in a structure
void read_dcd_header(FILE *dcdf, DCD *dcd)
{
    fseek(dcdf, 0, SEEK_END);
    dcdsize = ftell(dcdf);
    rewind(dcdf);
    printf("Size of DCD is (in Bytes) : %d\n", dcdsize);
    int i = 0;
    unsigned int fortcheck1, fortcheck2;
    fread(&fortcheck1, sizeof (unsigned int), 1, dcdf);
    fread(dcd->HDR, sizeof (char), 4, dcdf);
    fread(dcd->ICNTRL, sizeof (int), 20, dcdf);
    fread(&fortcheck2, sizeof (unsigned int), 1, dcdf);
    if ( fortcheck1 != fortcheck2 )
    {
        puts("Error when reading data from dcd : quantities do not match.");
        printf("fortcheck1 %d \t fortcheck2 %d \n", fortcheck1, fortcheck2);
        printf("File %s Line %d \n", __FILE__, __LINE__);
        exit(DCD_READ_BYTESNUM_ERROR);
    }
    dcd->HDR[4] = '\0';
    printf("HDR : %s \n\n", dcd->HDR);
    printf("ICNTRL : \t");
    for ( i = 0; i < 20; i++ )
        printf("%d\t", dcd->ICNTRL[i]);
    puts("\n");
    dcd->NFILE = dcd->ICNTRL[0];
    dcd->NPRIV = dcd->ICNTRL[1];
    dcd->NSAVC = dcd->ICNTRL[2];
    dcd->NSTEP = dcd->ICNTRL[3];
    dcd->NDEGF = dcd->ICNTRL[7];
    dcd->FROZAT = dcd->ICNTRL[8];
    dcd->DELTA4 = dcd->ICNTRL[9];
    dcd->QCRYS = dcd->ICNTRL[10];
    dcd->CHARMV = dcd->ICNTRL[19];
    fread(&fortcheck1, sizeof (unsigned int), 1, dcdf);
    fread(&dcd->NTITLE, sizeof (int), 1, dcdf);
    printf("NTITLE : %d \n", dcd->NTITLE);
    puts("TITLE : ");
    for ( i = 0; i < dcd->NTITLE; i++ )
    {
        fread(dcd->TITLE, sizeof (char), 80, dcdf);
        dcd->TITLE[80] = '\0';
        puts(dcd->TITLE);
    }
    fread(&fortcheck2, sizeof (unsigned int), 1, dcdf);
    puts("\n");
    if ( fortcheck1 != fortcheck2 )
    {
        puts("Error when reading data from dcd : not match");
        printf("fortcheck1 %d \t fortcheck2 %d \n", fortcheck1, fortcheck2);
        printf("File %s Line %d \n", __FILE__, __LINE__);
        exit(DCD_READ_BYTESNUM_ERROR);
    }
    int NATOM = 0;
    fread(&fortcheck1, sizeof (unsigned int), 1, dcdf);
    fread(&NATOM, sizeof (int), 1, dcdf);
    fread(&fortcheck2, sizeof (unsigned int), 1, dcdf);
    if ( fortcheck1 != fortcheck2 )
    {
        puts("Error when reading data from dcd : not match");
        printf("fortcheck1 %d \t fortcheck2 %d \n", fortcheck1, fortcheck2);
        printf("File %s Line %d \n", __FILE__, __LINE__);
        exit(DCD_READ_BYTESNUM_ERROR);
    }
    dcd->NATOM = NATOM;
    dcd->LNFREAT = dcd->NATOM - dcd->FROZAT;
    if ( (dcd->LNFREAT) != (dcd->NATOM) )
    {
        dcd->FREEAT = ( int* ) malloc(dcd->LNFREAT * sizeof (int));
        fread(&fortcheck1, sizeof (unsigned int), 1, dcdf);
        fread(dcd->FREEAT, sizeof (int), dcd->LNFREAT, dcdf);
        fread(&fortcheck2, sizeof (unsigned int), 1, dcdf);
        if ( fortcheck1 != fortcheck2 )
        {
            puts("Error when reading data from dcd : not match");
            printf("fortcheck1 %d \t fortcheck2 %d \n", fortcheck1, fortcheck2);
            printf("File %s Line %d \n", __FILE__, __LINE__);
            exit(DCD_READ_BYTESNUM_ERROR);
        }
    }
}
void read_dcd_header ( FILE * dcdf , DCD * dcd ) { fseek ( dcdf , 0 , SEEK_END ) ; dcdsize = ftell ( dcdf ) ; rewind ( dcdf ) ; printf ( " \n " , dcdsize ) ; int i = 0 ; unsigned int fortcheck1 , fortcheck2 ; fread ( & fortcheck1 , sizeof ( unsigned int ) , 1 , dcdf ) ; fread ( dcd -> HDR , sizeof ( char ) , 4 , dcdf ) ; fread ( dcd -> ICNTRL , sizeof ( int ) , 20 , dcdf ) ; fread ( & fortcheck2 , sizeof ( unsigned int ) , 1 , dcdf ) ; if ( fortcheck1 != fortcheck2 ) { puts ( " " ) ; printf ( " \t \n " , fortcheck1 , fortcheck2 ) ; printf ( " \n " , __FILE__ , __LINE__ ) ; exit ( DCD_READ_BYTESNUM_ERROR ) ; } dcd -> HDR [ 4 ] = ' \0 ' ; printf ( " \n \n " , dcd -> HDR ) ; printf ( " \t " ) ; for ( i = 0 ; i < 20 ; i ++ ) printf ( " \t " , dcd -> ICNTRL [ i ] ) ; puts ( " \n " ) ; dcd -> NFILE = dcd -> ICNTRL [ 0 ] ; dcd -> NPRIV = dcd -> ICNTRL [ 1 ] ; dcd -> NSAVC = dcd -> ICNTRL [ 2 ] ; dcd -> NSTEP = dcd -> ICNTRL [ 3 ] ; dcd -> NDEGF = dcd -> ICNTRL [ 7 ] ; dcd -> FROZAT = dcd -> ICNTRL [ 8 ] ; dcd -> DELTA4 = dcd -> ICNTRL [ 9 ] ; dcd -> QCRYS = dcd -> ICNTRL [ 10 ] ; dcd -> CHARMV = dcd -> ICNTRL [ 19 ] ; fread ( & fortcheck1 , sizeof ( unsigned int ) , 1 , dcdf ) ; fread ( & dcd -> NTITLE , sizeof ( int ) , 1 , dcdf ) ; printf ( " \n " , dcd -> NTITLE ) ; puts ( " " ) ; for ( i = 0 ; i < dcd -> NTITLE ; i ++ ) { fread ( dcd -> TITLE , sizeof ( char ) , 80 , dcdf ) ; dcd -> TITLE [ 80 ] = ' \0 ' ; puts ( dcd -> TITLE ) ; } fread ( & fortcheck2 , sizeof ( unsigned int ) , 1 , dcdf ) ; puts ( " \n " ) ; if ( fortcheck1 != fortcheck2 ) { puts ( " " ) ; printf ( " \t \n " , fortcheck1 , fortcheck2 ) ; printf ( " \n " , __FILE__ , __LINE__ ) ; exit ( DCD_READ_BYTESNUM_ERROR ) ; } int NATOM = 0 ; fread ( & fortcheck1 , sizeof ( unsigned int ) , 1 , dcdf ) ; fread ( & NATOM , sizeof ( int ) , 1 , dcdf ) ; fread ( & fortcheck2 , sizeof ( unsigned int ) , 1 , dcdf ) ; if ( fortcheck1 != fortcheck2 ) { puts ( " " ) ; printf ( " \t \n " , fortcheck1 , fortcheck2 ) ; printf ( " \n " , __FILE__ , __LINE__ ) ; exit ( DCD_READ_BYTESNUM_ERROR ) ; } dcd -> NATOM = NATOM ; dcd -> LNFREAT = dcd -> NATOM - dcd -> FROZAT ; if ( ( dcd -> LNFREAT ) != ( dcd -> NATOM ) ) { dcd -> FREEAT = ( int * ) malloc ( dcd -> LNFREAT * sizeof ( int ) ) ; fread ( & fortcheck1 , sizeof ( unsigned int ) , 1 , dcdf ) ; fread ( dcd -> FREEAT , sizeof ( int ) , dcd -> LNFREAT , dcdf ) ; fread ( & fortcheck2 , sizeof ( unsigned int ) , 1 , dcdf ) ; if ( fortcheck1 != fortcheck2 ) { puts ( " " ) ; printf ( " \t \n " , fortcheck1 , fortcheck2 ) ; printf ( " \n " , __FILE__ , __LINE__ ) ; exit ( DCD_READ_BYTESNUM_ERROR ) ; } } }
read dcd header and stores useful parameters in a structure
read dcd header and stores useful parameters in a structure