comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » reading in from multiple files, performing operations and printing them to multiple output file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
reading in from multiple files, performing operations and printing them to multiple output file [message #86533] Sun, 17 November 2013 00:31 Go to next message
bhattacharjee12 is currently offline  bhattacharjee12
Messages: 3
Registered: September 2013
Junior Member
Hi ,
I have a silly question, I feel
I am trying to run a program where I read in bunch of files, all of which have 2 sets of data and then perform the same mathematical operation on those data from each files and then put them the new values into a different set of files. I have come up with so far with this. I am having a problem in creating and printing the data into new files.

pro read_write

;;; will find the input files
files= FINDFILE('day*')

numfiles=n_elements(files)
num=intarr(numfiles)
;;;;creating an array which will have the names of the output files, still havent figured out if this necessary or not
files_out=FINDFILE('new_day*')
FOR m=0, numfiles-1 DO BEGIN
READCOL, files[m],filename1,filename2,format='F'

openw,num[m],files_out,/get_lun ;;;;;;;;;;;;might be totally off on this one.
;;;;;;;;;;;;random math operation
new_data=filename1+2
printf,new_data[m],filename[m]
close,num[m]
ENDFOR

END

I am getting an error on this syntax . I can print the outputs onto screen without any problem. So I think way I am going up with the reading and doing the operations is ok.
Thanks for the help & suggestion in advance.
Anirban
Re: reading in from multiple files, performing operations and printing them to multiple output file [message #86535 is a reply to message #86533] Sun, 17 November 2013 07:35 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
bhattacharjee12@gmail.com writes:

> I have a silly question, I feel
> I am trying to run a program where I read in bunch of files, all of which have 2 sets of data and then perform the same mathematical operation on those data from each files and then put them the new values into a different set of files. I have come up with so far with this. I am having a problem in creating and printing the data into new files.
>
> pro read_write
>
> ;;; will find the input files
> files= FINDFILE('day*')
>
> numfiles=n_elements(files)
> num=intarr(numfiles)
> ;;;;creating an array which will have the names of the output files, still havent figured out if this necessary or not
> files_out=FINDFILE('new_day*')
> FOR m=0, numfiles-1 DO BEGIN
> READCOL, files[m],filename1,filename2,format='F'
>
> openw,num[m],files_out,/get_lun ;;;;;;;;;;;;might be totally off on this one.
> ;;;;;;;;;;;;random math operation
> new_data=filename1+2
> printf,new_data[m],filename[m]
> close,num[m]
> ENDFOR
>
> END
>
> I am getting an error on this syntax . I can print the outputs onto screen without any problem. So I think way I am going up with the reading and doing the operations is ok.
> Thanks for the help & suggestion in advance.

Oh, my goodness! Hard to know where to start here. :-)

Here are some pointers.

1. FINDFILE is an obsolete function for good reason: it returns
erroneous results. Use FILE_SEARCH instead.

2. The variable names "filename1" and "filename2" for floating point
variables are, uh, really poorly chosen. You will understand your code
better if you choose better names for variables.

3. If you choose a file logical unit number with GET_LUN, you will have
to not just close it, but free it up so it can be used over again. Use
the FREE_LUN command to both close and free it at the same time, not the
CLOSE command. If you don't do this you will run out of logical unit
numbers sooner or later.

4. Have a look at the on-line help for the PRINTF command. You are
missing the arguments you need to successfully write to a file.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: reading in from multiple files, performing operations and printing them to multiple output file [message #86537 is a reply to message #86535] Sun, 17 November 2013 10:58 Go to previous message
skymaxwell@gmail.com is currently offline  skymaxwell@gmail.com
Messages: 127
Registered: January 2007
Senior Member
The PRINTF procedure must have destination LUN.

printf,new_data[m],filename[m]
^--must be a LUN

but you have at previous line
new_data=filename1+2
it doesn't LUN
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: scatter plot , intensity colors. Help
Next Topic: Array into binary array

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:19:01 PDT 2025

Total time taken to generate the page: 0.00616 seconds