DSPRelated.com
Forums

[CCS] read file

Started by MarioRossi October 27, 2004
In my test project using ccs i want to read a file, using this sample code:

	double a=0.0;
	FILE *f1;
 	f1 = fopen("test.dat","r");	
 	fscanf(f1,"%lf",&a);
	fclose(f1);

where debug

> error: can't allocate .text, size 00013560 (page 0) in PMEM (avail:
0000fe00)
>> error: errors in input - ./Debug/Test.out not built
>> Compilation failure
i try to set build option-> advanced-> memory models -> Far Aggregate Data (-m10) but nothing I dont know what else to try, can anyone make suggestions?
mariorossi69@email.it (MarioRossi) wrote in message news:<88529a72.0410270730.26559b14@posting.google.com>...
> In my test project using ccs i want to read a file, using this sample code: > > double a=0.0; > FILE *f1; > f1 = fopen("test.dat","r"); > fscanf(f1,"%lf",&a); > fclose(f1); > > where debug > > > error: can't allocate .text, size 00013560 (page 0) in PMEM (avail: > 0000fe00) > >> error: errors in input - ./Debug/Test.out not built > > >> Compilation failure > > i try to set build option-> advanced-> memory models -> Far Aggregate Data (-m10) > but nothing > > I dont know what else to try, can anyone make suggestions?
Try to change the declaration of 'a' to double a; With some bad luck, the "a=0.0" declaration tricks the compiler to think that 'a' is a constant number, never to be changed, and not a variable. Other than that, it might be smart to check that the file was actually opened, before attempting to read from it. Try some statement like if ((f1 = fopen("test.dat","r"))==NULL) { fprintf(stderr,"Could not open file 'test.dat'\n"); exit(-1); } Rune
allnor@tele.ntnu.no (Rune Allnor) wrote in message 
> > Try to change the declaration of 'a' to > > double a; > > With some bad luck, the "a=0.0" declaration tricks the compiler > to think that 'a' is a constant number, never to be changed, and > not a variable. > > Other than that, it might be smart to check that the file was actually > opened, before attempting to read from it. Try some statement like > > if ((f1 = fopen("test.dat","r"))==NULL) > { > fprintf(stderr,"Could not open file 'test.dat'\n"); > exit(-1); > } > > Rune
hi Rune tnx for the answer the problem is in the fscanf command not in fopen command the debug doesn't start and it says me always the same: ">> error: can't allocate .text, size 00013620 (page 0) in PMEM (avail: 0000fe00" Anybody have an idea?
allnor@tele.ntnu.no (Rune Allnor) wrote in message news:<f56893ae.0410280117.152d98a@posting.google.com>...
> mariorossi69@email.it (MarioRossi) wrote in message news:<88529a72.0410270730.26559b14@posting.google.com>... > > In my test project using ccs i want to read a file, using this sample code: > > > > double a=0.0; > > FILE *f1; > > f1 = fopen("test.dat","r"); > > fscanf(f1,"%lf",&a); > > fclose(f1); > > > > where debug > > > > > error: can't allocate .text, size 00013560 (page 0) in PMEM (avail: > 0000fe00) > > >> error: errors in input - ./Debug/Test.out not built > > > >> Compilation failure > > > > i try to set build option-> advanced-> memory models -> Far Aggregate Data (-m10) > > but nothing > > > > I dont know what else to try, can anyone make suggestions? > > Try to change the declaration of 'a' to > > double a; > > With some bad luck, the "a=0.0" declaration tricks the compiler > to think that 'a' is a constant number, never to be changed, and > not a variable. > > Other than that, it might be smart to check that the file was actually > opened, before attempting to read from it. Try some statement like > > if ((f1 = fopen("test.dat","r"))==NULL) > { > fprintf(stderr,"Could not open file 'test.dat'\n"); > exit(-1); > } > > Rune
In the section .text, the executable program code is stored. In your case, your program is simply too big for the memory that is available for the section .text. Your program occupies 0x13560 Bytes of memory, but you have only 0xfe00 available in the section PMEM. either *) decrease the size of your program *) put the .text into another memory range *) put some other section that is linked to PMEM to another memory section there is a lot of useful information available in spru186.pdf and spru187.pdf (available at www.ti.com) best regards, Thomas
On 27 Oct 2004 08:30:33 -0700, mariorossi69@email.it (MarioRossi)
wrote in comp.dsp:

> In my test project using ccs i want to read a file, using this sample code: > > double a=0.0; > FILE *f1; > f1 = fopen("test.dat","r"); > fscanf(f1,"%lf",&a); > fclose(f1); > > where debug > > > error: can't allocate .text, size 00013560 (page 0) in PMEM (avail: > 0000fe00) > >> error: errors in input - ./Debug/Test.out not built > > >> Compilation failure > > i try to set build option-> advanced-> memory models -> Far Aggregate Data (-m10) > but nothing > > I dont know what else to try, can anyone make suggestions?
The fscanf() function contains a large amount of code because it must handle all possible formats. Try reading the line with fgets(), and using <stdlib.h> functions atof() (not robust) or strtod() (better) to convert the text into a double. This will probably take a lot less code space and might fit into your memory. -- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Thanks to all.

MARIO ROSSI