|
Answer» Here is a text (inf) file I am using INSIDE a BATCH file (call it warp.inf) with 339 and ne as replaceable parameters somehow
[Source] Type = GeoTiff SourceDir = "C:\WRK_STD_TIFS" SourceFile = "339_ne" Layer = Imagery Variation = Day NullValue = 0,0,0 [Destination] DestDir = "C:\WRK_BGLS" DestBaseFileName = "339_ne" DestFileType = BGL LOD = Auto
I want to loop through the batch file, bumping a parameter %1 (339) to 339,340,341... and a parameter %2 to ne,se,SW,..my PROBLEM is, I need to bump the text (339, .. ne) inside my text file while I am bumping the replaceable parameters OUTSIDE in the batch file itself.
So partway through the batch file, I have to replace the text (339,ne) to (340,ne) inside warp inf, then continue on.
joe 339 ne line 1 blah line 2 .....warp.inf...blah blah line n blah
joe 340 sw line 1 blah line 2 .....warp.inf...blah blah now I have to use a changed txt file (warp inf), changing 339 to 340 INSIDE..etc line n blah
Could you be a bit clearer about this INSIDE and OUTSIDE thing? I see you've written them in capital letters, but that doesn't make it any easier to know what you are getting at.I have a series of routines I want to run on a sequentially numbered set of files.
I want to bump the ID number of the file and one by one put the outputs in a storage folder. So far so good. No problem However........
One of the routines requires the use of a text file which inside itself needs the ID number of the file I'm working on.
routine 1 ......... routine 2 .......... routine 3 ........... .......warp.inf ........... routine 4 .......... etc.
I need to know if it is possible in the middle of a series of routines, to bump the ID number INSIDE the file with a replaceable parameter, then use the file (to continue the routine). It's a text file nested INSIDE a routine collection of steps, where I need to bump (write) the number IN the text file.. Hope this helps.
In short, how do you edit a file on the fly with a replaceable parameter, then close the file and immediately use it.let me get this, you have sequential numbered files ( you should have provided samples of the format in your question) example , "some_name_001.txt" , and then you want to get the "001" into a variable. Then you want to place this "001" into the text file , right? Otherwise, you really want to try providing more clear sample/examples of input and output (use actual data and not "blah blah" or dots .... ) of what you want to do. After reading 2 posts from your, i still don't fully understand what is it you actually want. And what is 'routine' ?, show examples. Any also show any batch you have already written that will provide a more clearer picture.I really blew it with my original question so here is a better way to describe it..
here is a batch file I need to run on hundreds of aerial photos...
echo on resample.exe C:\PHOTOREAL\225_nw.inf resample.exe C:\PHOTOREAL\225_sw.inf etc etc
225_nw.inf is a text file which needs the ID 225_nw INSIDE it in order for resample to work.
here is the text of 225_nw.inf.
[Source] Type = GeoTiff Layer = Imagery SourceDir = "C:\PHOTOREAL" SourceFile = "m_225_nw.tif" Variation = Day NullValue = 0,0,0 [Destination] DestDir = "C:\PHOTOREAL" DestBaseFileName = "m_225_nw" UseSourceDimensions = 1 CompressionQuality = 100
Right now I am faced with producing hundreds of text files like the above each with the ID as the title and having the same ID inside as well.
I was hoping there is a way to create a multiline text file (myfile.inf) on the fly with my single replaceable parameter %1 ...225_nw,...225_sw...just prior to the resample.exe C:\PHOTOREAL\225_nw.inf line.
My batchfile would then look something like
echo on ...code to create inf file for 225_nw resample.exe C:\PHOTOREAL\225_nw.inf ...code to create inf file for 225_sw resample.exe C:\PHOTOREAL\225_sw.inf etc etc
My excuse is (a) my DOS Manual is up north, and (b) I am pretty much a newbie in DOS, and (c) my wife absolutely refuses to do this gruntwork.... The alternative would be to have a batch file to open a text file, find a string(which varies each time) , replace the string and close the file with a new name. Is this possible? well this file can automate the creation of the files
set /a id=1 :A set /a ids=%id% echo [Source] >> %id%_nw.inf echo Type = GeoTiff >> %id%_nw.inf echo Layer = Imagery >> %id%_nw.inf echo SourceDir = "C:\PHOTOREAL" >> %id%_nw.inf echo SourceFile = "m_%id%_nw.tif" >> %id%_nw.inf echo Variation = Day >> %id%_nw.inf echo NullValue = 0,0,0 >> %id%_nw.inf echo [Destination] >> %id%_nw.inf echo DestDir = "C:\PHOTOREAL" >> %id%_nw.inf echo DestBaseFileName = "m_%id%_nw" >> %id%_nw.inf echo UseSourceDimensions = 1 >> %id%_nw.inf echo CompressionQuality = 100 >> %id%_nw.inf if %id%==10 goto :eof set /a id=%ids%+1 goto A
those GLOWING numbers are what you change 1 is the starting number 10 is the ending numer 1 is the interval countThank you..I am partway there. I did not understand the loop syntax you used , so I rewrote your suggestion in two separate (cruder) batch files . (My Inf file names have to be alphanumeric)
makethisinf.bat
echo [Source] >> %1%.inf echo Type = GeoTiff >> %1%.inf echo Layer = Imagery >> %1%.inf echo SourceDir = "C:\PHOTOREAL" >> %1%.inf echo Variation = Day >> %1%.inf echo SourceFile = "%1%.tif" >> %1%.inf echo NullValue = 0,0,0 >> %1%.inf echo [Destination] >> %1%.inf echo DestDir = "C:\PHOTOREAL" >> %1%.inf echo DestBaseFileName = "%1%" >> %1%.inf echo UseSourceDimensions = 1 >> %1%.inf echo CompressionQuality = 100 >> %1%.inf
run_makethisinf.bat makethisinf m_930_nw makethisinf m_930_ne makethisinf m_930_sw makethisinf m_930_se pause
Two problems I do not understand..... One.... echo SourceFile = "%1%.tif " >> %1%.inf echo DestBaseFileName = "%1%" >> %1%.inf
My system produces the first named text file perfectly (many thanks) , but will not produce the lines SourceFile = m_930_nw.tif DestBaseFileName = m_930_nw
Two, the second batch file run_makethisinf.bat only runs the first line. I think I am very close to a solution here but I am mystified about these two remaining issues. Again, much appreciated.here's a Python script if you are open to other languages
Code: [Select]template=""" [Source] Type = GeoTiff Layer = Imagery SourceDir = "C:\PHOTOREAL" SourceFile = "%s.tif" Variation = Day NullValue = 0,0,0 [Destination] DestDir = "C:\PHOTOREAL" DestBaseFileName = "%s" UseSourceDimensions = 1 CompressionQuality = 100 """
mylist = ["m_930_nw","m_930_ne","m_930_sw","m_930_se"] for makeinf in mylist: print "making inf %s ...." % makeinf open("%s.inf" % makeinf,"W").write(template % (makeinf , makeinf))
save as makeinf.py and on command line
Code: [Select] C:\test>python test.py making inf m_930_nw .... making inf m_930_ne .... making inf m_930_sw .... making inf m_930_se ....
C:\test>more m_930_nw.inf
[Source] Type = GeoTiff Layer = Imagery SourceDir = "C:\PHOTOREAL" SourceFile = "m_930_nw.tif" Variation = Day NullValue = 0,0,0 [Destination] DestDir = "C:\PHOTOREAL" DestBaseFileName = "m_930_nw" UseSourceDimensions = 1 CompressionQuality = 100
C:\test>more m_930_ne.inf
[Source] Type = GeoTiff Layer = Imagery SourceDir = "C:\PHOTOREAL" SourceFile = "m_930_ne.tif" Variation = Day NullValue = 0,0,0 [Destination] DestDir = "C:\PHOTOREAL" DestBaseFileName = "m_930_ne" UseSourceDimensions = 1 CompressionQuality = 100
Quote from: brute_force on April 01, 2010, 08:33:24 PM run_makethisinf.bat
makethisinf m_930_nw makethisinf m_930_ne makethisinf m_930_sw makethisinf m_930_se pause
Two, the second batch file run_makethisinf.bat only runs the first line.
I will leave problem (1) for the other guy, but I can see straight away why only the first line of run_makethisinf.bat gets executed. The reason is this:
If you, in a batch file, want to run another batch file, there are two ways of doing it.
1. Use its name alone. In this case control is handed over to the second batch file permanently, and the first batch file terminates. In other words you never go back.
2. Precede its name with the CALL keyword. In this case the first batch hands over control to the second batch file temporarily, and waits for it to finish. When that happens, control is passed back to the calling (first) batch file and execution continues on the next line.
So your run_makethisinf.bat should look like this
Code: [Select]call makethisinf m_930_nw call makethisinf m_930_ne call makethisinf m_930_sw calll makethisinf m_930_se pause
Thanks for the help. If there is no way to get those two lines to resolve themselves, my fallback is this (for northeast,northwest,southeast, and southwest. It requires that I edit each xxx once in notepad once it is done. I'm getting there, but ..........
echo call makethisinf4 m_930_nw m_930_ne m_930_se m_930_sw call makethisinf4 m_931_nw m_931_ne m_931_se m_931_sw pause
echo [Source] >> %1%.inf echo Type = GeoTiff >> %1%.inf echo Layer = Imagery >> %1%.inf echo SourceDir = "C:\PHOTOREAL" >> %1%.inf echo Variation = Day >> %1%.inf echo SourceFile = "m_xxx_nw.tif" >> %1%.inf echo NullValue = 0,0,0 >> %1%.inf echo [Destination] >> %1%.inf echo DestDir = "C:\PHOTOREAL" >> %1%.inf echo DestBaseFileName = "m_xxx_nw" >> %1%.inf echo UseSourceDimensions = 1 >> %1%.inf echo CompressionQuality = 100 >> %1%.inf echo [Source] >> %2%.inf echo Type = GeoTiff >> %2%.inf echo Layer = Imagery >> %2%.inf echo SourceDir = "C:\PHOTOREAL" >> %2%.inf echo Variation = Day >> %2%.inf echo SourceFile = "m_xxx_ne.tif" >> %2%.inf echo NullValue = 0,0,0 >> %2%.inf echo [Destination] >> %2%.inf echo DestDir = "C:\PHOTOREAL" >> %2%.inf echo DestBaseFileName = "m_xxx_ne" >> %2%.inf echo UseSourceDimensions = 1 >> %2%.inf echo CompressionQuality = 100 >> %2%.inf echo [Source] >> %3%.inf echo Type = GeoTiff >> %3%.inf echo Layer = Imagery >> %3%.inf echo SourceDir = "C:\PHOTOREAL" >> %3%.inf echo Variation = Day >> %3%.inf echo SourceFile = "m_xxx_sw.tif" >> %3%.inf echo NullValue = 0,0,0 >> %3%.inf echo [Destination] >> %3%.inf echo DestDir = "C:\PHOTOREAL" >> %3%.inf echo DestBaseFileName = "m_xxx_sw" >> %3%.inf echo UseSourceDimensions = 1 >> %3%.inf echo CompressionQuality = 100 >> %3%.inf echo [Source] >> %4%.inf echo Type = GeoTiff >> %4%.inf echo Layer = Imagery >> %4%.inf echo SourceDir = "C:\PHOTOREAL" >> %4%.inf echo Variation = Day >> %4%.inf echo SourceFile = "m_xxx_se.tif" >> %4%.inf echo NullValue = 0,0,0 >> %4%.inf echo [Destination] >> %4%.inf echo DestDir = "C:\PHOTOREAL" >> %4%.inf echo DestBaseFileName = "m_xxx_se" >> %4%.inf echo UseSourceDimensions = 1 >> %4%.inf echo CompressionQuality = 100 >> %4%.infIt seems to me that your problem because you need to know that (unlike ordinary batch variables) parameters passed to a batch file from the command line or from another batch only have ONE percent sign, placed before the figure. Not after as well. Like this...
echo first parameter is %1 echo second parameter is %2
etc
Also did you realise that >> appends data to an already existing file (if there is one)?
It's working perfectly now.......your point did the trick..
in the example that mat123 posted I interpreted the second % sign erroneously......
This code works perfectly.... I will use Excel to produce the batch file with the numbers bumped thru the entire range in the upgraded run_makethisinf
echo [Source] >> %1%.inf echo Type = GeoTiff >> %1%.inf echo Layer = Imagery >> %1%.inf echo SourceDir = "C:\PHOTOREAL" >> %1%.inf echo Variation = Day >> %1%.inf echo SourceFile = "%1.tif" >> %1%.inf echo NullValue = 0,0,0 >> %1%.inf echo [Destination] >> %1%.inf echo DestDir = "C:\PHOTOREAL" >> %1%.inf echo DestBaseFileName = "%1" >> %1%.inf echo UseSourceDimensions = 1 >> %1%.inf echo CompressionQuality = 100 >> %1%.inf echo [Source] >> %2%.inf echo Type = GeoTiff >> %2%.inf echo Layer = Imagery >> %2%.inf echo SourceDir = "C:\PHOTOREAL" >> %2%.inf echo Variation = Day >> %2%.inf
..................................etc ...................................etc
I am grateful for the help......I do understand about appending to an existing file, which I suspect could be used to shorten the makethisinf.bat program if a large number of lines were simply characters lines with no replaceable parameters....like the first 5 lines here.. bf just because you don't understand how something works doesn't mean it's wrong.
|