News:

:) Welcome to the Probe Software forum area!

Main Menu

Batch Processing

Started by Gareth D Hatton, February 21, 2014, 04:19:19 AM

Previous topic - Next topic

John Donovan

Quote from: JonF on October 19, 2018, 10:14:07 AM
I was just about to add a batch processing feature to the CalcImage wish list thread... guess I'm behind the curve by 8 months!

Nice, thanks John!

Hi Jon,
No worries.  Glad you were able to discover it!  I guess that's one of the many nice things about this user forum is that it is searchable.

Since you are a relatively new customer you should not blame yourself, there's a lot of cool features in the software for one to discover, as people have been using our Probe software in one form or another and making wonderful suggestions for over 20 years.  I myself even occasionally discover new and useful features that I had completely forgotten about!  :-[

It's worth checking the About menu in one of our apps to see who some of these people are.  They deserve a lot of credit for making this project possible at all. 
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

Gseward

Is there a way to modify the behaviour when a CIP_batch.bat file is executed?

e.g. maybe I have Surfer installed on my PC, but on this occassion I don't want to output all of the calculations to Surfer format. 

or maybe I want to send the calculations to Classify Image Exporter.exe

Cheers,

Gareth

John Donovan

#17
Quote from: Gseward on June 12, 2025, 04:15:32 PMIs there a way to modify the behaviour when a CIP_batch.bat file is executed?

Let's review what the CIP_Batch.bat files does when processed by CalcImage. Here is the command line code:

Sub CalcImageCommandLine(tForm As Form)
' Check for CIP file on command line

ierror = False
On Error GoTo CalcImageCommandLineError

Dim tfilename As String
Dim tSurferPageSecondsDelay As Integer

' Check for command line string
tfilename$ = Command$()
If tfilename$ = vbNullString Then Exit Sub

' Confirm command line argument
If DebugMode Then Call IOWriteLog(vbCrLf & "Raw Command line argument (CIP file): " & tfilename$)

' Remove double quotes from filename (put there by Command function) which causes Dir$ function to fail
If Left$(tfilename$, 1) = VbDquote And Right$(tfilename$, 1) = VbDquote Then    ' no double quotes if drag and drop
tfilename$ = Mid$(tfilename$, 2)
tfilename$ = Left$(tfilename$, Len(tfilename$) - 1)
End If

' Check for valid file
If Dir$(tfilename$) = vbNullString Then GoTo CalcImageCommandLineNotFound
If UCase$(MiscGetFileNameExtensionOnly$(tfilename$)) <> ".CIP" Then GoTo CalcImageCommandLineBadExtension

' Set some globals
UserDataDirectory$ = MiscGetPathOnly2$(tfilename$)
UserDataDirectory2 = UserDataDirectory$     ' to synchronize quant and classify

' Get the standard names, numbers and descriptions from standard database
Call StandardGetMDBIndex
If ierror Then Exit Sub

' Update globals
CalcImageProjectFile$ = tfilename$
CalcImageProjectFileSaved = True
CalcImageSampleNameTitle$ = MiscGetFileNameOnly$(MiscGetFileNameNoExtension$(CalcImageProjectFile$))

' Open passed filename as old file
Call CalcImageOpenOldProjectFile(Int(1), Int(0))
If ierror Then End

' Process maps
CalcImageQuantFlag = True
Call CalcImageUpdateForm
Call CalcImageStartAnalysis(Int(2), FormCALCIMAGE)
CalcImageQuantFlag = False
Call CalcImageUpdateForm
If ierror Then Exit Sub

' Output maps
tSurferPageSecondsDelay% = SurferPageSecondsDelay%
SurferPageSecondsDelay% = 1         ' set to 1 sec for all output
Call CalcImageCreateSurferOutputAll(Int(1))         ' call in silent mode
SurferPageSecondsDelay% = tSurferPageSecondsDelay%
If ierror Then Exit Sub

' Now just end for next command line batch process
End

Exit Sub

' Errors
CalcImageCommandLineError:
MsgBox Error$ & " (command line argument: " & tfilename$ & ")", vbOKOnly + vbCritical, "CalcImageCommandLine"
ierror = True
Exit Sub

CalcImageCommandLineNotFound:
msg$ = "Command line argument string, " & tfilename$ & ", is not a valid file"
MsgBox msg$, vbOKOnly + vbExclamation, "CalcImageCommandLine"
ierror = True
Exit Sub

CalcImageCommandLineBadExtension:
msg$ = "Command line argument filename, " & tfilename$ & ", does not have a CIP extension"
MsgBox msg$, vbOKOnly + vbExclamation, "CalcImageCommandLine"
ierror = True
Exit Sub

End Sub

So CalcImage looks for a command line argument which must be a CIP file. Then it loads the CIP file and starts the quantification for all data types specified.

Once the quant calculations are finished for that CIP file, it attempts to output all data types to Surfer.

Quote from: Gseward on June 12, 2025, 04:15:32 PMe.g. maybe I have Surfer installed on my PC, but on this occasion I don't want to output all of the calculations to Surfer format. 

This post here describes how we modified the code recently to skip outputting calculations to Surfer format if the Surfer app is not installed:

https://smf.probesoftware.com/index.php?topic=948.msg12304#msg12304

Does that help?

Quote from: Gseward on June 12, 2025, 04:15:32 PMor maybe I want to send the calculations to Classify Image Exporter.exe

Here is code to call the Classify Image Exporter with a classify DAT file and a palette file:

Sub CalcImageExportImagesToPNGFiles()
' Launch the Classify Image Exporter application (written by Mia Kraft)

ierror = False
On Error GoTo CalcImageExportImagesToPNGFilesError

Dim n As Integer
Dim taskID As Long
Dim astring As String, tfilename As String, pfilename As String

' Demo file
If CalcImageProjectFile$ = vbNullString Then GoTo CalcImageExportImagesToPNGFilesNoProject
tfilename$ = MiscGetFileNameNoExtension$(CalcImageProjectFile$) & "_Quant_Image_Classify.DAT"

' Get image DAT file from user
If UserDataDirectory2$ <> vbNullString Then tfilename$ = UserDataDirectory2$ & "\" & MiscGetFileNameOnly$(tfilename$)
Call IOGetFileName(Int(2), "DAT", tfilename$, FormCALCIMAGE)
If ierror Then Exit Sub

' Check if file is really a valid classify input file
Close #Temp1FileNumber%
DoEvents
Open tfilename$ For Input As #Temp1FileNumber%
Line Input #Temp1FileNumber%, astring$  ' read 1st line
Line Input #Temp1FileNumber%, astring$  ' read second line
Close #Temp1FileNumber%

n% = 0
If InStr(astring$, "NK") = 0 Then GoTo CalcImageExportImagesToPNGFilesWrongFormat
n% = 1
If InStr(astring$, "X") = 0 Then GoTo CalcImageExportImagesToPNGFilesWrongFormat
n% = 2
If InStr(astring$, "Y") = 0 Then GoTo CalcImageExportImagesToPNGFilesWrongFormat
n% = 3
If InStr(astring$, "NX") = 0 And InStr(astring$, "NS") = 0 Then GoTo CalcImageExportImagesToPNGFilesWrongFormat
n% = 4
If InStr(astring$, "NY") = 0 And InStr(astring$, "NL") = 0 Then GoTo CalcImageExportImagesToPNGFilesWrongFormat
n% = 5
If InStr(astring$, "NXY") = 0 And InStr(astring$, "ND") = 0 Then GoTo CalcImageExportImagesToPNGFilesWrongFormat

' Check that the app exists
astring$ = ProgramPath$ & "Classify Image Exporter.exe"
If DebugMode Then Call IOWriteLog("CalcImageExportImagesToPNGFiles (Dir string): " & astring$)
If Dir$(astring$) = vbNullString Then GoTo CalcImageExportImagesToPNGFilesAppNotFound

' Load the application string with selected classify DAT file
astring$ = VbDquote$ & ProgramPath$ & "Classify Image Exporter.exe" & VbDquote$ & " " & VbDquote$ & tfilename$ & VbDquote$

' Load FC file string
If ImagePaletteNumber% > 0 Then
If ImagePaletteNumber% = 1 Then pfilename$ = ApplicationCommonAppData$ & "THERMAL.FC"
If ImagePaletteNumber% = 2 Then pfilename$ = ApplicationCommonAppData$ & "RAINBOW2.FC"
If ImagePaletteNumber% = 3 Then pfilename$ = ApplicationCommonAppData$ & "BLUERED.FC"
If ImagePaletteNumber% = 4 Then pfilename$ = ApplicationCommonAppData$ & "CUSTOM.FC"
astring$ = astring$ & " " & VbDquote$ & pfilename$ & VbDquote$
End If

' Run Classify Image Exporter
If DebugMode Then Call IOWriteLog("CalcImageExportImagesToPNGFiles (Shell string): " & astring$)
taskID& = Shell(astring$, vbNormalFocus)

Exit Sub

' Errors
CalcImageExportImagesToPNGFilesError:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "CalcImageExportImagesToPNGFiles"
Close #Temp1FileNumber%
ierror = True
Exit Sub

CalcImageExportImagesToPNGFilesNoProject:
msg$ = "No CalcImage Project is open"
MsgBox msg$, vbOKOnly + vbExclamation, "CalcImageExportImagesToPNGFiles"
ierror = True
Exit Sub

CalcImageExportImagesToPNGFilesWrongFormat:
msg$ = "The specified column label for column " & Format$(n%) & " is incorrect for the selected Classify DAT file." & vbCrLf & vbCrLf
msg$ = msg$ & "Please check the file format and try again. The file must be tab delimited and the column labels for the 2nd line of the data file must be NK, X, Y, NX, NY, NXY, <data1>, <data2>, etc..."
MsgBox msg$, vbOKOnly + vbExclamation, "CalcImageExportImagesToPNGFiles"
ierror = True
Exit Sub

CalcImageExportImagesToPNGFilesAppNotFound:
msg$ = "The Classify Image Exporter application was not found." & vbCrLf & vbCrLf
msg$ = msg$ & "This error should not occur. Please contact Probe Sofwtare technical support."
MsgBox msg$, vbOKOnly + vbExclamation, "CalcImageExportImagesToPNGFiles"
ierror = True
Exit Sub

End Sub

Basically it is:

"Classify Image Exporter.exe" <classify DAT filename> <palette FC filename>

The palette file in the command line is optional as it uses a gray scale palette by default. So you could call the Classify Image Exporter yourself from a command line or batch file. Then click the Export All button...

Is that helpful?
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

Gseward

John, Thanks for taking the time to add a detailed explanation.

Perhaps I should have phrased the question as: Is there a way that the User can modify the behaviour when a CIP_batch.bat file is executed.

Perhaps the answer is simply: No!

How are you checking whether Surfer is installed? Perhaps if I knew that I could temporarily make it appear as if Surfer was not installed!

Cheers.

Gareth

John Donovan

#19
Quote from: Gseward on June 27, 2025, 06:37:04 AMPerhaps I should have phrased the question as: Is there a way that the User can modify the behaviour when a CIP_batch.bat file is executed.

The CIP_batch.bat file is not executed by CalcImage. It is executed by the user.  CalcImage only creates the CIP_batch.bat file.

Quote from: Gseward on June 27, 2025, 06:37:04 AMHow are you checking whether Surfer is installed? Perhaps if I knew that I could temporarily make it appear as if Surfer was not installed!

As stated above, CalcImage already checks if the Surfer app is not installed, and does not attempt to output data to Surfer if the app is not installed.

Here is the code we use to check if Surfer is installed:

Function BasCheckSurfer() As Boolean
' Just check if Surfer is installed or not
'  Returns false if not found, true if found

ierror = False
On Error GoTo BasCheckSurferError

Dim SurferApp As Object

' Test code
'BasCheckSurfer = False
'Exit Function

BasCheckSurfer = True

' Skip errors in case app is not installed
On Error Resume Next

' Try to create the Surfer object
Screen.MousePointer = vbHourglass
Set SurferApp = CreateObject("Surfer.Application")
Screen.MousePointer = vbDefault

' Check if object not created
If SurferApp Is Nothing Then BasCheckSurfer = False

' Resume errors
On Error GoTo BasCheckSurferError

Exit Function

' Errors
BasCheckSurferError:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "BasCheckSurfer"
ierror = True
Exit Function

End Function

It just tries to create a Surfer object, and if that fails it knows that Surfer is not installed. You could write similar scripting code in any OLE container application, e.g., Excel, MatLab, etc.
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"