X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 12 Jul 2012 07:49 AM by  anon
Looping procedures?
 4 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
12 Jul 2012 07:49 AM
    Hi there, I am new to IDL so please bear with me if I am asking something silly. I have tried to search through the help files and the internet but cant seem to find what I am looking for. I would like to know if there is a way to wrap a bunch of procedures in a loop? for ex. for a =1,n_elements(number_input_files) do begin pro 1 pro 2 pro 3 endfor I did try the above and (of course) it didnt work. I understand .pro have to be self contained by the keywords 'pro' and 'end'. But what I need to do is to get a .pro to loop but with each iteration use a new input file. Btw the original .pro is not from me and is a hefty bit of coding. The main problem I have is that the .pro file I have contains about 12 .pro routines and more common blocks that I would like to count. The first .pro routine is an input dialog box that takes a single input file and feeds the rest of the model. Since I need to do this about 30 times, it gets a bit cumbersome doing it manually. What I aim to do is automate the process by having a list of the 30 input files that feeds the model for 30 iterations. I have worked with Matlab and I have done similar things with just a loop. But this seems to be extremely difficult to do in IDL. Does anyone have any suggestions or ideas how I might solve this? Thanks. Norris

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Jul 2012 09:00 AM
    Hi Norris, I think what may work is to create a batch process which uses this syntax: @plot02 You'll need to check the IDL Help for details on how to put things together.

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Jul 2012 09:56 AM
    I did look at the batch but I didnt think it to do what I want since in the batch help it states "The batch file should not contain complete program units. Complete program units should be compiled and run by using the .RUN and .RNEW commands in the batch files, as illustrated above." My .pro is a complete program, so I heeded the advice of the help and decided to overlook this option. Also I didnt really see how to replace a variable in a batch file from the help or the examples. Could you shed some light on how variables can be replaced within a .pro using a batch file? Any other suggestions?

    Deleted User



    New Member


    Posts:
    New Member


    --
    13 Jul 2012 02:59 PM
    Not sure what version of IDL you are using but in 8.2 go to the Help and under the Search tab type in: plot01 which should get you to a list of titles. Have a look at the Plot procedure. Basically your file will be a text file with the word 'pro' and 'end' in it. You would make sure IDL is in the directory containing the file and at the commandline type in: @your file name. try this: IDL> cd, 'C:\Program Files\Exelis\IDL82\examples\doc\plot' IDL> @plot01 IDL> @plot02 IDL> Check your variables output and also have a look at all the 'plot0x' files in the 'examples\doc\plot' directory so you can see what is in the files and how they are set up to with internal references @.... to the other files.

    Deleted User



    New Member


    Posts:
    New Member


    --
    20 Jul 2012 06:55 AM
    I'm not sure I understand your question entirely, but perhaps something like this may help. Save the following code in a file called runner.pro, compile and run: pro runner ;hardcode the file names used for input ; is a string like: 'C:\myFile.txt' fileNames = [ , , , + , , ] for i = 0, n_elements(fileNames)-1 do begin currentFile = fileNames[i] pro1 pro2 pro3 endfor end Another thing you can try is to get all the filenames in a folder automatically. Instead of hardcoding the file names do: cd folderContents = fileSearch() now folder contents holds an array of strings representing all the files in the folder.
    You are not authorized to post a reply.