我有一个模型中生成的输出数组以及链接到它的源代码文件。它在这里被引用为输出到文件c编程
struct nrlmsise_output output[ARRAYLENGTH];
我写了下面的函数。我只是试图把这些输出从另一个函数产生
output[i].d[5]
在我的Python程序中工作的文件。我最终会需要它成为Python中的csv文件,所以如果有人知道如何直接将它变成一个.csv,那真是太棒了,但是我还没有找到一个成功的方法,因此.txt很好。这是我到目前为止,当我运行代码和输出文件,我得到我想要的格式,但输出中的数字是关闭的。 (当我使用10^-9时,值为10^-100)。谁能说出为什么会发生这种情况?此外,我已经尝试把输出放在一个单独的数组中,然后从该数组中调用,但它不起作用。我可能不会做它正确但是,这个项目是我第一次不得不使用C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "nrlmsise-00.h"
#define ARRAYLENGTH 10
#define ARRAYWIDTH 7
void test_gtd7(void) {
int i;
struct nrlmsise_output output[ARRAYLENGTH];
for (i=0;i<ARRAYLENGTH;i++)
gtd7(&input[i], &flags, &output[i]);
for (i=0;i<ARRAYLENGTH;i++) {
printf("\nRHO ");
printf(" %2.3e",output[i].d[5]);
printf("\n");
//The output prints accurately with this.
}
}
void outfunc(void){
FILE *fp;
int i;
struct nrlmsise_output output[ARRAYLENGTH]; //I may be calling the output wrong here
fp=fopen("testoutput.txt","w");
if(fp == NULL)
{
printf("There is no such file as testoutput.txt");
}
fprintf(fp,"RHO");
fprintf(fp,"\n");
for (i=0;i<ARRAYLENGTH;i++) {
fprintf(fp, "%E", output[i].d[5]);
fprintf(fp,"\n");
}
fclose(fp);
printf("\n%s file created","testoutput.txt");
printf("\n");
}
以及在功能wheere生成输出,该输出struct被调用,像这样'struct nrlmsise_output output [ARRAYLENGTH];''for(i = 0; i
spacedancechimp
2015-03-30 18:58:19
请包括'struct nrlmsise_output'的定义 – 2015-03-30 19:00:49
是的,包括结构定义,并编辑您的帖子,而不是添加新的代码到评论 – mstbaum 2015-03-30 19:01:47