[AMBER] fscanf

From: Chris Moth <chris.moth.Vanderbilt.Edu>
Date: Tue, 26 Jan 2010 21:48:38 -0600 (CST)

Dan may have given more C-esque advice than nab-esque.

I note in the AmberToolsi.pdf that the Xscanf examples used "%lf" for
float input, and you pass the object reference, not a pointer. So, it
would be
fscanf(FILE,"%lf",f), not fscanf(FILE,"%f",&f).

>From there, nab should make a ".c" file that uses fscanf with a pointer to
a float or double.

nab is such an elegant idea - ashame it is not written as C++ classes, as
the nab preprocessor sometimes makes it particular difficult to get at the
root cause of errors during the second pass C compiler run.

I would try to make a very simple program if the above does not solve the
problem. When this little program works, you'll be on your way:

float a;
string s;

a=4321.21;

s = "1234.12";
sscanf(s,"%lf",a);
printf("%f\n",a);


Do you get the correct 1234.12?

Best

C




> Dan, thanks for helping. I tried it and the compiling failed.
>
> On Tue, Jan 26, 2010 at 3:12 PM, Daniel Roe <droe.nist.gov> wrote:
>
>> I believe that sscanf and fscanf require that you pass the addresses of
>> the
>> variables you want to set, i.e.
>>
>> float f;
>> fscanf(FILE,"%f",&f);
>>
>> works, but
>>
>> fscanf(FILE,"%f",f);
>>
>> doesn't. You can try using the address operator on your arguments, like
>>
>> fscanf(pf,"%f %f %f",&(a[n].x), &(a[n].y), &(a[n].z));
>>
>> and see if that helps.
>>
>> -Dan
>>
>> Lixia Jin Day wrote:
>>
>>> Below is my testing code. When I compile it give me this warning:
>>> nab -v testing.nab
>>> cpp cmd: /usr/local/amber11/bin/ucpp -l -I/usr/local/amber11/include
>>> testing.nab
>>> nab2c cmd: /usr/local/amber11/bin/nab2c -nfname testing.nab
>>> cc cmd: gcc -I/usr/local/amber11/include testing.c
>>> /usr/local/amber11/lib/libnab.a /usr/local/amber11/lib/libsym.a
>>> /usr/local/amber11/lib/carpack.a /usr/local/amber11/lib/clapack.a
>>> /usr/local/amber11/lib/cblas.a /usr/local/amber11/lib/f2c.a -lm
>>> testing.c: In function ‘main’:
>>> testing.c:30: warning: format ‘%f’ expects type ‘float *’, but argument
>>> 3
>>> has type ‘REAL_T *’
>>> testing.c:30: warning: format ‘%f’ expects type ‘float *’, but argument
>>> 4
>>> has type ‘REAL_T *’
>>> testing.c:30: warning: format ‘%f’ expects type ‘float *’, but argument
>>> 5
>>> has type ‘REAL_T *’
>>>
>>>
>>> When I use sscanf(line, "%f %f %f",a[n].x, a[n].y, a[n].z); instead of
>>> fscanf(pf,"%f %f %f",a[n].x, a[n].y, a[n].z); I get the same warning.
>>> Ignoring the warning I ran the exe to find that all the output was
>>> 0.00000
>>>
>>> Please advice where in the code is wrong. Thank you!
>>>
>>> Lixia
>>>
>>> //////////////////////code
>>> //testing
>>> string line;
>>> point a[4];
>>> int n;
>>> file pf;
>>>
>>>
>>> pf=fopen("data.txt","r");
>>> line=getline(pf);
>>> printf("%s\n",line);
>>> for(n=0;n<4;n=n+1) {
>>> fscanf(pf,"%f %f %f",a[n].x, a[n].y, a[n].z);
>>> printf ("%f, %f, %f",a[n].x,a[n].y,a[n].z);
>>> printf ("\tdone!\n");
>>> }
>>> fclose(pf);
>>> _______________________________________________
>>> AMBER mailing list
>>> AMBER.ambermd.org
>>> http://lists.ambermd.org/mailman/listinfo/amber
>>>
>>>
>>
>> --
>> Daniel R. Roe, Ph.D.
>> Research Chemist
>> National Institute of Standards and Technology
>> 100 Bureau Drive, Stop 8443
>> Gaithersburg, MD 20899-8443
>> (301) 975-8741
>>
>>
>> _______________________________________________
>> AMBER mailing list
>> AMBER.ambermd.org
>> http://lists.ambermd.org/mailman/listinfo/amber
>>
>
>
>
> --
> http://public.fotki.com/lily1907/
> _______________________________________________
> AMBER mailing list
> AMBER.ambermd.org
> http://lists.ambermd.org/mailman/listinfo/amber
>



_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Tue Jan 26 2010 - 20:00:03 PST
Custom Search