GROMACS xpm文件格式深度解析及矩阵数据导出方法

/* A pure code for converting xpm to matrix data (N*M) 

* usage: 

* cp xxx.xpm xpm.xpm && gcc *.c -O3

* ./a.out maxval

*

* date: 2022.08.18

*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "xpm.xpm"

};

typedef struct t_code

{

char code[6];

float val;

} t_code;

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

{

static float maxVal = 4.46, minVal = 0;

int i, j, k;

char *token = NULL;

char *str = NULL;

int nx, ny, nc, ncode = 1;

struct t_code *code = NULL;

FILE *fp = NULL;

if (argc == 2)

{

maxVal = (float)atof(argv[1]);

}

else if (argc == 3)

{

minVal = (float)atof(argv[1]);

maxVal = (float)atof(argv[2]);

}

else 

{

fprintf(stderr, "Error! Missing input parameters\n");

getchar();

exit(1);

}

fprintf(stderr, "MinVal = %f, MaxVal = %f\n", minVal, maxVal);

str = strdup(gromacs_xpm[0]);

sscanf(str, "%d %d %d %d", &nx, &ny, &nc, &ncode);

free(str); str = NULL;

fprintf(stderr, "DIM: %d x %d; ncolor= %d; ncode= %d\n", ny, nx, nc, ncode);

code = (t_code *)malloc(sizeof(t_code)*nc);

for (i = 0; i < nc; i++)

{

strncpy(code[i].code, gromacs_xpm[i+1], ncode);

code[i].code[ncode] = '\0';

code[i].val = (maxVal-minVal)/(nc-1) * i;

}

/* read matrix and write new matrix data */

fp = fopen("Matrix.dat", "w");

for (i = ny-1; i >= 0; i--)

{

for (j = 0; j < nx; j++)

{

for (k = 0; k < nc; k++)

{

char *p = &gromacs_xpm[i+nc+1][ncode*j];

if (!strncmp(code[k].code, p, ncode))

{

fprintf(fp, "%6.2f ", code[k].val);

break;

}

}

}

fprintf(fp, "\n");

}

free(code); code = NULL;

fclose(fp);

fprintf(stderr, "\nDone! Matrix data written to Matrix.dat\n");

return 0;

}

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空