;~ https://www.autoitscript.com/forum/topic/204886-manipulate-large-csv-file/?tab=comments#comment-1472958 ;http://www.hexagora.com/HexUniControls/gen/clsGpSession_GpStatus_Enum.htm #include #include #include #include "image_get_info.au3" #include #requireadmin _GDIPlus_Startup() ;~ PARAMETERS: ;~ Decide if you want to retrieve image dimansions based on exif or windows properties: Local $dimensions = "winprop"; "exif" ;"winprop" Global $maxwidth = 2048, $maxheight = 2048 Global $seperator = 5 ; If set to 5: 4 IMages are saved to the training-folder, 1 to the testing-folder ;Folders Local $outputfolder = "C:\Users\Jost\Downloads\transfer\" Local $trainfolder = $outputfolder & "train\" Local $testfolder = $outputfolder & "test\" Local $ImageDir= "C:\Users\Jost\Documents\RnD\Subsea_Images\" Global $iname_short, $xml, $hxml ;~ Files Local $Inputjson = @ScriptDir & "\input.json" Local $traincsv = $outputfolder & "train_labels.csv" Local $testcsv = $outputfolder & "test_labels.csv" Local $Imagelistcsv = @ScriptDir & "\Imagelist.csv" Global $all_images_on_hdd, $all_images, $imdim[2] Global $log = $outputfolder & "logfile.bat", $hlog Local $test = 1 Local $hFile = FileOpen(@ScriptDir & "\output.csv", $FO_OVERWRITE) Global $origwidth, $origheight, $newwidth, $newheight, $err Local $origYmin, $labelbox_array, $origXmin, $origYmax, $origXmax, $class, $newxmin, $newxmax, $newymin, $newymax Local $k = 0 ;~ =====MAIN ;prepare the logfile $hlog = FileOpen($log, 1) Filewrite($hlog, "@echo off" & @CRLF) FileClose($hlog) ;~ Retrieve Dimension of all images on $ImageDir and save them in @ScriptDir & "\Imagelist.csv" (if not existing already) If FileExists($Imagelistcsv) Then ;Read $Imagelistcsv into array $all_images_on_hdd _FileReadToArray($Imagelistcsv,$all_images_on_hdd,0,",") ;The "0" means: Don't write array dimensions into the first rows Else ;FilesOnly , Recursive, No Sort, relative path $all_images_on_hdd = _FileListToArrayRec($ImageDir, "*.jpg",$FLTAR_FILES,$FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH );*.bmp;*.png;*.raw _ArrayDisplay($all_images_on_hdd, "$all_images_on_hdd") get_all_image_dims($dimensions) $all_images_on_hdd = $all_images $all_images = "" _FileReadToArray($Imagelistcsv,$all_images_on_hdd,0,",") ;The "0" means: Don't write array dimensions into the first rows msgbox (2, "Waiting...", "for you!" & @CRLF & "Done with get_all_image_dims()") EndIf $htraincsv = Create_csv($traincsv) ;creates csv-file, writes header and returns the handle. File remain open for append. $htestcsv = Create_csv($testcsv) ;creates csv-file, writes header and returns the handle. File remain open for append. Global $sep = 1 Local $lastline = _FileCountLines($Inputjson) Local $hinputjson = Fileopen($Inputjson,0) For $i = 400 to $lastline-1 ; $i circles through rows / lines witin $Inputjson $cline = FileReadLine($hinputjson, $i) ;read next line within $Inputjson $iname_short = StringRegExp($cline,'"External ID":"([^"]+)',1)[0];imagename short = "External ID" ConsoleWrite("L" & @ScriptLineNumber & " Processing " & $i & " / 480, image = " & $iname_short & " ") $iIndex = check_image_name() $iname_long = $all_images_on_hdd[$iIndex][0] $origwidth = $all_images_on_hdd[$iIndex][2] ;orig. image width $origheight = $all_images_on_hdd[$iIndex][3] ;orig. image height calc_new_image_dims($iname_long) ;calculates the new (reduced) image dimensions. Returns $newwidth and $newheight $xml = Create_xml($iname_long) ;returns the xml-header as array ;~ class Ymin Xmin Ymax Xmax $labelbox_array = StringRegExp($cline,'"value":"([^"]+).+?:\{"top":([^,]+),"left":([^,]+),"height":([^,]+),"width":([^}]+)', 3) For $j = 0 To UBound($labelbox_array) - 1 Step 5 ;$j circles through the bb's/labels witin a line $class = $labelbox_array[$j] $origYmin = $labelbox_array[$j+1] $origXmin = $labelbox_array[$j+2] $origYmax = $labelbox_array[$j+3] + $labelbox_array[$j+1] $origXmax = $labelbox_array[$j+4] + $labelbox_array[$j+2] If $iname_short = "n101_0431.jpg" OR $iname_short = "n101_0363.jpg" Then ConsoleWrite("L" & @ScriptLineNumber & " " & $class & " " & $origYmin & " " & $origXmin & " " & $origYmax & " " & $origXmax & @CRLF) EndIf calc_bb_coordinates($origxmin, $origxmax, $origymin, $origymax) ;calcluates the new coordinates of bb's/labels check_classname($class) ;checks if there are unknown classnames (anything other then "coded_target" etc. check_bb_dimensions($origXmax, $origymax) ;checks if the bb's coordinates exceed the image dimensions Add2_csv($class, $newxmin, $newymin, $newxmax, $newymax) ;adds 1 bb/label to the xml-files Add2_xml($class, $newXmin, $newYmin, $newXmax, $newYmax) ;adds 1 bb/label to the xml-file Next Fileclose($hxml) $hxml = "" resize_and_save_image($iname_long) ;well, resize and save image If $sep = $seperator Then $sep = 1 ; resets the counter $sep: files have been copied to test-folder. Next set of files go to train-folder again Else $sep = $sep + 1 EndIf $labelbox_array ="" $cline = "" _ReduceMemory() Next FileClose($htraincsv) ;closes the csv-file FileClose($htestcsv) _GDIPlus_Shutdown() ;finalize the logfile $hlog = FileOpen($log, 1) Filewrite($hlog, "exit /b") FileClose($hlog) ;~ runcheck() MsgBox (1,"Remember to...","... check for duplicates and convert to grayscale", 2) Exit ;~ ======== FUNCTIONS Func get_all_image_dims($dimensions) ;~ This Func finds all images in $ImageDir and writes them into a ","-seperated csv in the script directory Local $all_images[Ubound($all_images_on_hdd)][4] Local $sDrive, $sDir, $sFileName, $sExtension If $dimensions = "exif" Then For $I = 1 To $all_images_on_hdd[0] ;~ Get image dimensions from $all_images_on_hdd Array $all_images_on_hdd ;~ 0 = full patth and name; 1 = image_name; 2 = width; 3= height $PathSplit = _PathSplit($all_images_on_hdd[$I], $sDrive, $sDir, $sFileName, $sExtension) $all_images[$I-1][0] = $PathSplit[1] & $PathSplit[2] & $PathSplit[3]& $PathSplit[4] $all_images[$I-1][1] = $PathSplit[3] & $PathSplit[4] $full_image = _ImageGetInfo($all_images_on_hdd[$I]) $all_images[$I-1][2] = _ImageGetParam($full_image, "Width") ; using image_get_info.au3 $all_images[$I-1][3] = _ImageGetParam($full_image, "Height") ; using image_get_info.au3 Next Else ;get image-$dimensions using window properties ("winprop") For $I = 1 To $all_images_on_hdd[0] ;~ Get image dimensions from $all_images_on_hdd Array $all_images_on_hdd ;~ 0 = full patth and name; 1 = image_name; 2 = width; 3= height $Dims = _FileGetProperty($all_images_on_hdd[$I], "Dimensions") ; Returns Dimensions of image and adds them to the array "$all_images_on_hdd" $Dims = StringTrimRight(StringTrimLeft($Dims,1),1) ; Apply format... $PathSplit = _PathSplit($all_images_on_hdd[$I], $sDrive, $sDir, $sFileName, $sExtension) $all_images[$I-1][0] = $PathSplit[1]& $PathSplit[2] & $PathSplit[3]& $PathSplit[4] $all_images[$I-1][1] = $PathSplit[3]& $PathSplit[4] $rpos = StringInStr($Dims, " ") ;Search for delimiter $all_images[$I-1][2] = StringLeft ($Dims, $rpos-1) $lpos = StringInStr($Dims, " ", 0 , -1) ;Search for delimiter $all_images[$I-1][3] = StringTrimLeft ($Dims, $lpos ) Next EndIf ;~ _ArrayDisplay($all_images, "prior sort $all_images_on_hdd") _ArraySort($all_images, 0, 0, 0, 1) ;~ For $i = 0 To 10 ;~ If $all_images_on_hdd[$i][0] = "" Then ;~ _ArrayDelete($all_images_on_hdd, $i) ;~ EndIf ;~ Next _ArrayDisplay($all_images, "post sort $all_images_on_hdd") msgbox(1, "Line 126", _FileWriteFromArray($Imagelistcsv, $all_images, 0, Ubound($all_images, 1) ,",")) EndFunc ;catch_all_image_dims() Func get_image_dims($dimensions, $iname_long) ;~ This Func finds all images in $ImageDir and writes them into a ","-seperated csv in the script directory If $dimensions = "exif" Then $imdim[0] = _ImageGetParam($iname_long, "Width") ; using image_get_info.au3 $imdim[1] = _ImageGetParam($iname_long, "Height") ; using image_get_info.au3 Else ;get image-$dimensions using window properties ("winprop") ;~ Get image dimensions for $iname_long ;~ 0 = full patth and name; 1 = image_name; 2 = width; 3= height $Dims = _FileGetProperty($iname_long, "Dimensions") ; Returns Dimensions of image and adds them to the array "$all_images_on_hdd" $Dims = StringTrimRight(StringTrimLeft($Dims,1),1) ; Apply format... ;~ $PathSplit = _PathSplit($iname_long, $sDrive, $sDir, $sFileName, $sExtension) ;~ $all_images[$I-1][1] = $PathSplit[3] & $PathSplit[4] $rpos = StringInStr($Dims, " ") ;Search for delimiter $imdim[0] = StringLeft ($Dims, $rpos-1) $lpos = StringInStr($Dims, " ", 0 , -1) ;Search for delimiter $imdim[1] = StringTrimLeft ($Dims, $lpos ) EndIf $Dims = "" Return $imdim EndFunc ;get_image_dims() Func check_image_name() $iIndex = _ArrayBinarySearch($all_images_on_hdd, $iname_short, 0, Ubound($all_images_on_hdd,1), 1) If @error Then $iname_short = StringReplace($iname_short, "%20(1)", "") If @extended = "1" Then ConsoleWrite("%20(1) was removed in " & $iname_short & @CRLF) EndIf $iname_short = StringReplace($iname_short, " (1)", "") If @extended = "1" Then ConsoleWrite("(1) was removed in " & $iname_short & @CRLF) EndIf $iIndex = _ArrayBinarySearch($all_images_on_hdd, $iname_short, 1, Ubound($all_images_on_hdd,1), 1) If @error Then MsgBox($MB_SYSTEMMODAL, "Sorry...", '"' & $iname_short & '" was not found on column ' & $i & '.') _ArrayDisplay($all_images_on_hdd, "line " & $i & " troubles $all_images_on_hdd") MsgBox($MB_SYSTEMMODAL, "Aborting", "Aborting") Exit EndIf EndIf Return $iIndex EndFunc ;check_image_name() Func calc_new_image_dims($iname_long) ;calculates the new (reduced) image dimensions. ;~ https://stackoverflow.com/a/45894620 Local $ratio = 0 Local $origwidth_temp = $origwidth Local $origheight_temp = $origheight ;~ msgbox(1, "L90", "$input[$i][1] = " & $input[$i][1]) Local $hBitmap = _GDIPlus_ImageLoadFromFile($iname_long) ;width height If $origwidth > $maxwidth Then $ratio = $maxwidth / $origwidth $origwidth = $maxwidth $origheight = round($origheight * $ratio, 0) EndIf If $origheight > $maxheight Then $ratio = $maxheight / $origheight $origwidth = round($origwidth * $ratio,0) $origheight = $maxheight EndIf $newwidth = $origwidth $newheight = $origheight $origwidth = $origwidth_temp $origheight = $origheight_temp ;~ msgbox(1, "Line " & @ScriptLineNumber, "$newwidth = " & $newwidth & " $newheight = " & $newheight & " $origwidth = " & $origwidth & " $origheight = " & $origheight) EndFunc ;new_image_dims() Func create_csv($outputcsv) If Fileexists($outputcsv) Then FileDelete($outputcsv) EndIf Local $houtputcsv = FileOpen($outputcsv, 9) FileWrite($houtputcsv, "filename,width,height,class,xmin,ymin,xmax,ymax" & @CRLF) Return $houtputcsv EndFunc; create_csv Func Create_xml($iname_long) If $sep = $seperator Then $xml = $testfolder & (StringTrimRight($iname_short, 3) & "xml") Else $xml = $trainfolder & (StringTrimRight($iname_short, 3) & "xml") EndIf $hxml = FileOpen($xml, 10) Local $xml_array_header[13] $xml_array_header[0] = "" $xml_array_header[1] = " Desktop" $xml_array_header[2] = " " & $iname_short & "" $xml_array_header[3] = " " & $iname_long & "" $xml_array_header[4] = " " $xml_array_header[5] = " Unknown" $xml_array_header[6] = " " $xml_array_header[7] = " " $xml_array_header[8] = " " & $newwidth & "" $xml_array_header[9] = " " & $newheight & "" $xml_array_header[10] = " 3" $xml_array_header[11] = " " $xml_array_header[12] = " 0" _FileWriteFromArray($xml, $xml_array_header) If @error <> 0 Then ConsoleWrite("Line: " & @ScriptLineNumber & " @error: " & @error & " @extended: " & @extended & " _FileWriteFromArray()" & " $hxml: " & $hxml & @CRLF) EndIf FileClose($hxml) $xml_array_header = "" Return $xml EndFunc ;Create_xml Func calc_bb_coordinates($origxmin, $origxmax, $origymin, $origymax) If $origwidth > $maxwidth OR $origheight > $maxheight Then Local $x1p = $origxmin / $origwidth Local $x2p = $origxmax / $origwidth Local $y1p = $origymin / $origheight Local $y2p = $origymax / $origheight $newxmin = round($x1p * $newwidth, 0) $newxmax = round($x2p * $newwidth, 0) $newymin = round($y1p * $newheight, 0) $newymax = round($y2p * $newheight, 0) EndIf EndFunc ;calc_bb_coordinates Func check_classname($class) ;~ Check Spelling of classname If $class <> "ocluded_coded_target" AND $class <> "ocluded_uncoded_target" AND $class <> "coded_target" AND $class <> "uncoded_target" Then Local $htemp = FileOpen(@ScriptDir & "\wrong_class.txt", $FO_APPEND) FileWrite($htemp, $iname_short & " has unknown classname: " & $class & @CRLF) Consolewrite($iname_short & " has unknown classname: " & $class & @CRLF) FileClose($htemp) EndIf EndFunc; check_classname Func check_bb_dimensions($origXmax, $origymax) If $origXmax > $origwidth OR $origymax > $origheight Then ConsoleWrite("The Image " & $iname_short & " exceeds image dimensions!" & @CRLF) EndIf EndFunc; check_bb_dimensions Func Add2_xml($class, $xmin, $ymin, $xmax, $ymax);, $width, $height) ;~ ConsoleWrite("$iname = " & $iname & " $class = " & $class & " $xmin = " & $xmin & " $ymin = " & $ymin & " $xmax = " & $xmax & " $ymax = " & $ymax & @CRLF) If Not FileExists($xml) Then msgbox(1, "ERROR", "Your file " & $xml & " does not exists L " & @ScriptLineNumber & ". Abort!") Exit EndIf $hxml = Fileopen($xml) ; delete "" Local $lastline = _FileCountLines($xml) If FileReadLine($hxml, $lastline) = "" Then ;~ ConsoleWrite("remove annotation success" & @CRLF) _FileWriteToLine ( $xml, $lastline, "", True) EndIf FileClose($xml) ; build array with xml-data and write to xml-file Local $xml_array_bb[13] $xml_array_bb[0] = " " $xml_array_bb[1] = " " & $class & "" $xml_array_bb[2] = " Unspecified" $xml_array_bb[3] = " 0" $xml_array_bb[4] = " 0" $xml_array_bb[5] = " " $xml_array_bb[6] = " " & $xmin & "" ;width $xml_array_bb[7] = " " & $ymin & "" ; height $xml_array_bb[8] = " " & $xmax & "" $xml_array_bb[9] = " " & $ymax & "" $xml_array_bb[10] = " " $xml_array_bb[11] = " " $xml_array_bb[12] = "" $hxml = FileOpen($xml, 1) _FileWriteFromArray($hxml, $xml_array_bb) FileClose($hxml) $xml_array_bb = "" $lastline = "" EndFunc ;Add2_xml Func Add2_csv($class, $newxmin, $newymin, $newxmax, $newymax) Local $line = $iname_short & "," & $newwidth & "," & $newheight & "," & $class & "," & $newxmin & "," & $newymin & "," & $newxmax & "," & $newymax If $sep = $seperator Then FileWriteLine($testcsv, $line) Else FileWriteLine($traincsv, $line) EndIf $line = "" EndFunc ;Add2_csv Func resize_and_save_image($iname_long) Local $saveto If $sep = $seperator Then $saveto = $testfolder & $iname_short Else $saveto = $trainfolder & $iname_short EndIf ;Open image! $temp = FileCopy($iname_long, $saveto, 9) If $temp = 1 Then consolewrite("Line "& @ScriptLineNumber & " Filecopy sucess? True ") Else consolewrite("Line "& @ScriptLineNumber & " Filecopy sucess? FALSE ") $hlog = FileOpen($log, 1) Filewrite($hlog, "copy /v " & '"' & $iname_long & '" "' & $saveto & '"' & @CRLF) FileClose($hlog) Return EndIF $hBitmap = _GDIPlus_ImageLoadFromFile($iname_long) If @error <> 0 Then ConsoleWrite("Line: " & @ScriptLineNumber & " @error: " & @error & " @extended: " & @extended & " _GDIPlus_ImageResize()" & " $iname_long: " & $iname_long & " $hBitmap: " & $hBitmap & " $newwidth: " & $newwidth & " $newheight: " & $newheight & @CRLF) $hlog = FileOpen($log, 1) Filewrite($hlog, "copy /v " & '"' & $iname_long & '" "' & $saveto & '"' & @CRLF) FileClose($hlog) Return EndIf ;resize image $imdim = get_image_dims($dimensions, $saveto) ;First, check image dimensions ;~ _Arraydisplay($imdim,"$imdim") If $origwidth > $maxwidth OR $origheight > $maxheight Then Local $hBitmap_Resized = _GDIPlus_ImageResize($hBitmap, $newwidth, $newheight) ;resize image If @error <> 0 Then ConsoleWrite("Line: " & @ScriptLineNumber & " @error: " & @error & " @extended: " & @extended & " _GDIPlus_ImageResize()" & " $iname_long: " & $iname_long & " $hBitmap: " & $hBitmap & " $newwidth: " & $newwidth & " $newheight: " & $newheight & @CRLF) $hlog = FileOpen($log, 1) Filewrite($hlog, "copy /v " & '"' & $iname_long & '" "' & $saveto & '"' & @CRLF) FileClose($hlog) Return EndIf Else $hBitmap_Resized = $hBitmap EndIf ;save image $temp = _GDIPlus_ImageSaveToFile($hBitmap, $saveto) If @error <> 0 Then ConsoleWrite("Line: " & @ScriptLineNumber & " @error: " & @error & " @extended: " & @extended & " _GDIPlus_ImageResize()" & " $iname_long: " & $iname_long & " $hBitmap: " & $hBitmap & " $newwidth: " & $newwidth & " $newheight: " & $newheight & @CRLF) $hlog = FileOpen($log, 1) Filewrite($hlog, "copy /v " & '"' & $iname_long & '" "' & $saveto & '"' & @CRLF) FileClose($hlog) Return EndIf ConsoleWrite(" L" & @ScriptLineNumber & " Image-saving success? " & $temp & @CRLF) ;tidy up _GDIPlus_ImageDispose($hBitmap) _GDIPlus_ImageDispose($hBitmap_Resized) $hBitmap = "" $hBitmap_Resized = "" $temp = "" EndFunc ;==>resize_and_save Func _FileGetProperty($FGP_Path, $FGP_PROPERTY ="", $iPropertyCount = 500) ;=============================================================================== ; Function Name.....: _FileGetProperty ; Description.......: Returns a property or all properties for a file. ; Version...........: 1.0.2 ; Change Date.......: 05-16-2012 ; AutoIt Version....: 3.2.12.1+ ; Parameter(s)......: $FGP_Path - String containing the file path to return the property from. ; $FGP_PROPERTY - [optional] String containing the name of the property to return. (default = "") ; $iPropertyCount - [optional] The number of properties to search through for $FGP_PROPERTY, or the number of items ; returned in the array if $FGP_PROPERTY is blank. (default = 300) ; Requirements(s)...: None ; Return Value(s)...: Success: Returns a string containing the property value. ; If $FGP_PROPERTY is blank, a two-dimensional array is returned: ; $av_array[0][0] = Number of properties. ; $av_array[1][0] = 1st property name. ; $as_array[1][1] = 1st property value. ; $av_array[n][0] = nth property name. ; $as_array[n][1] = nth property value. ; Failure: Returns an empty string and sets @error to: ; 1 = The folder $FGP_Path does not exist. ; 2 = The property $FGP_PROPERTY does not exist or the array could not be created. ; 3 = Unable to create the "Shell.Application" object $objShell. ; Author(s).........: - Simucal ; - Modified by: Sean Hart ; - Modified by: teh_hahn ; - Modified by: BrewManNH ; URL...............: http://www.autoitscript.com/forum/topic/34732-udf-getfileproperty/page__view__findpost__p__557571 ; Note(s)...........: Modified the script that teh_hahn posted at the above link to include the properties that ; Vista and Win 7 include that Windows XP doesn't. Also removed the ReDims for the $av_ret array and ; replaced it with a single ReDim after it has found all the properties, this should speed things up. ; I further updated the code so there's a single point of return except for any errors encountered. ; $iPropertyCount is now a function parameter instead of being hardcoded in the function itself. ;=============================================================================== If $FGP_PROPERTY = Default Then $FGP_PROPERTY = "" $FGP_Path = StringRegExpReplace($FGP_Path, '["'']', "") ; strip the quotes, if any from the incoming string If Not FileExists($FGP_Path) Then Return SetError(1, 0, "") ; path not found Local Const $objShell = ObjCreate("Shell.Application") If @error Then Return SetError(3, 0, "") Local Const $FGP_File = StringTrimLeft($FGP_Path, StringInStr($FGP_Path, "\", 0, -1)) Local Const $FGP_Dir = StringTrimRight($FGP_Path, StringLen($FGP_File) + 1) Local Const $objFolder = $objShell.NameSpace($FGP_Dir) Local Const $objFolderItem = $objFolder.Parsename($FGP_File) Local $Return = "", $iError = 0 If $FGP_PROPERTY Then For $I = 0 To $iPropertyCount If $objFolder.GetDetailsOf($objFolder.Items, $I) = $FGP_PROPERTY Then $Return = $objFolder.GetDetailsOf($objFolderItem, $I) EndIf Next If $Return = "" Then $iError = 2 EndIf Else Local $av_ret[$iPropertyCount + 1][2] = [[0]] For $I = 1 To $iPropertyCount If $objFolder.GetDetailsOf($objFolder.Items, $I) Then $av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1) $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1) ;~ $av_ret[0][0] += 1 $av_ret[0][0] = $I EndIf Next ReDim $av_ret[$av_ret[0][0] + 1][2] If Not $av_ret[1][0] Then $iError = 2 $av_ret = $Return Else $Return = $av_ret EndIf EndIf Return SetError($iError, 0, $Return) EndFunc ;==>_FileGetProperty Func _ArrayCompare_M23(Const ByRef $aArray1, Const ByRef $aArray2, $iMode = 0) ; Check if arrays If Not(IsArray($aArray1)) Or Not(IsArray($aArray2)) Then Return SetError(1, 0, 0) EndIf ; Check if same number of dimensions $iDims = UBound($aArray1, $UBOUND_DIMENSIONS) If $iDims <> UBound($aArray2, $UBOUND_DIMENSIONS) Then Return SetError(2, 0, 0) EndIf ; Check if same size $iRows = UBound($aArray1, $UBOUND_ROWS) $iCols = UBound($aArray1, $UBOUND_COLUMNS) If $iRows <> UBound($aArray2, $UBOUND_ROWS) Or $iCols <> UBound($aArray2, $UBOUND_COLUMNS) Then Return SetError(3, 0, 0) EndIf Local $sString_1, $sString_2 Switch $iMode Case 0 ; Compare each element For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 If $aArray1[$i][$j] <> $aArray1[$i][$j] Then Return SetError(4, 0, 0) EndIf Next Next Case 1 ; Convert rows to strings For $i = 0 To $iRows - 1 For $j = 0 To $iCols - 1 $sString_1 &= $aArray1[$i][$j] $sString_2 &= $aArray2[$i][$j] Next If $sString_1 <> $sString_2 Then Return SetError(4, 0, 0) EndIf Next Case 2 ; Convert columnss to strings For $j = 0 To $iCols - 1 For $i = 0 To $iRows - 1 $sString_1 &= $aArray1[$i][$j] $sString_2 &= $aArray2[$i][$j] Next If $sString_1 <> $sString_2 Then Return SetError(4, 0, 0) EndIf Next Case 3 ; Convert whole array to string If _ArrayToString($aArray1) <> _ArrayToString($aArray2) Then Return SetError(4, 0, 0) EndIf EndSwitch ; Looks as if they match Return 1 EndFunc Func _ReduceMemory($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc ;==>_ReduceMemory