Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29331 Обсуждение

LEN_TRIM ok LEN_TRIM not ok

cacciatore
Начинающий
1 487Просмотр.
In the Qwin app I working on I use GetOpenFilename. The full path filename chosen goes to fname, a character*255 variable declared in a module.
To manipulate fname I use L=LEN_TRIM(fname). Up to a few days ago L received the correct size of the filename, but after some changes I made in the program L is now always 255. I can't find what change I made that caused this. Another already working Qwin app uses the same scheme and is working well. The project settings of the new are the same of the old one (so I think, perhaps I am missing something).
Any hint about what is causing this problem?
Thanks
Geraldo
0 баллов
6 Ответы
llynisa
Начинающий
1 487Просмотр.
LEN_TRIM gives the position of the last character that is not a space. Hence if you get any character that is not a space after the full path string, LEN_TRIM will pick that character, whether it normally displays or not. (Note that under debug, NO character after a CHAR(0) displays in the watch window.)

Either use a null-terminated string for the full path, and write a function eg LenCstr to find where the first CHAR(0) is, or write a function eg LenTrimAll to find the position of the last character that does not display. The first alternative is the safer bet.

Regards

Alan
Jugoslav_Dujic
Ценный участник II
1 487Просмотр.
Geraldo,
XFTLite package on my home page contains:

- XStrings.f90 module, with some handy functions when working with C-style functions (See e.g. CLEN -- basically it uses INDEX intrinsic to find length of C-style string)
- XFTFile.f90, with wrappers for common Open/Save/Browse dialogs, including C to Fotran strings conversion. The usage is as simple as:
sDirName = "" !Current directory
sFileName = ""
IF (XGetOpenFile(hWnd, sDirName, nFiles, sFileName, &
   sTypes=(/"XYZ files (*.xyz)"/), sExts=(/"*.xyz"/))) THEN
   OPEN(42, FILE=TRIM(sDirName)//sFileName, ...
Jugoslav
cacciatore
Начинающий
1 487Просмотр.
Alan and Jugoslav,
Thanks for your sugestions.
I will implement one of then ( the easiest one, I am rather lazy).
What amazes me is that LEN_TRIM was working ok in the new project an stoped working, and always worked in the older.
Thanks again
Geraldo


Steven_L_Intel1
Сотрудник
1 487Просмотр.
It may depend on uninitialized data.

Steve
ltabarov
Начинающий
1 487Просмотр.
I agree with HOST. When I faced a similar problem I initialized every bite in FNAME as a SPACE, i.e. ' ', and my program works correctly ever since.
cacciatore
Начинающий
1 487Просмотр.
On the mark. In one of the many changes I made, I have commented the line: FNAME=''. Uncommenting it made things run ok again.
Thanks you all
Geraldo
Ответить