Agustin Lobo <alobo@ija.csic.es> wrote :
>Maybe if you could just let me know the format for
>the output matrices I could do it myself. Or release the source
>for the binary to ascii and ascii to binary programs.
The format of ADE-4 binary files is very simple : they just contain
floats, plus the number of rows and columns appended at the end of
the file.
In the Macintosh version, the rows and columns numbers are written
in the resource fork of the file.
Here is the source code for binary to ascii :
/************************************/
void bintext(char *nfice, int l1, int c1, char *nfics)
{
int i, j;
float v2;
FILE *fice, *fics;
fice = fopen(nfice,"rb");
fics = fopen(nfics,"w");
for (j=1;j<=c1-1;j++) {
fread((char *)&v2, 4, 1, fice);
fprintf(fics, "%.5g\t", v2);
}
fread((char *)&v2, 4, 1, fice);
fprintf(fics, "%.5g\n", v2);
for (i=2;i<=l1-1;i++) {
for (j=1;j<=c1-1;j++) {
fread((char *)&v2, 4, 1, fice);
fprintf(fics, "%.5g\t", v2);
}
fread((char *)&v2, 4, 1, fice);
fprintf(fics, "%.5g\n", v2);
}
for (j=1;j<=c1-1;j++) {
fread((char *)&v2, 4, 1, fice);
fprintf(fics, "%.5g\t", v2);
}
fread((char *)&v2, 4, 1, fice);
fprintf(fics, "%.5g\n", v2);
fclose(fics);
fclose(fice);
}
You have to manage filenames before (this is system dependent).
The ascii to binary is a little more complex since we accept free form
ascii numeric files. The important point is that you just have to write
floats (and nothing else), and then append the number of rows and columns
at the end of the file. For example :
float v2;
...
fwrite((const char *)&v2, 4, 1, fic);
...
SetLC(nfic, l1, c1);
Here are the Windows versions of SetLC and GetLC :
/***********************************************************************/
void SetLC (char *nfic, int l1, int c1)
{
FILE *fic;
fic = fopen(nfic,"a");
fprintf(fic,"\n");
fprintf(fic,"%6.6d\n",l1);
fprintf(fic,"%6.6d\n",c1);
fclose (fic);
}
/**************************************************/
void GetLC (char *nfic, int *l1, int *c1)
FILE *fic;
int err;
fic = fopen(nfic,"rb");
err = fseek(fic, -16L, SEEK_END);
fscanf(fic,"%d", l1);
fscanf(fic,"%d", c1);
fclose (fic);
}
-- Jean Thioulouse - Laboratoire de Biometrie - Universite Lyon 1 69622 Villeurbanne Cedex - France Fax: 04 78 89 27 19 Tel: 04 72 43 29 01 http://pbil.univ-lyon1.fr/ADE-4/JTHome.html
This archive was generated by hypermail 2b30 : Sat Feb 10 2001 - 10:36:01 MET