(* Definitions of functions *) template1 := ToFileName[{dir0, "056-058"}, "template1.htm"]; printf[x_] := ToString[NumberForm[N[x], 11, ExponentFunction -> (Null &)]]; printstop[s__] := ( Print["Fatal error: ", s]; If[Input[ToString[First[{s}]] <> " --- Exiting? (True or False)", True], Exit[]]; ); checkdir[dir_] := If[Head[dir] =!= String, printstop["checkdir: " <> ToString[InputForm[dir]] <> " not a string."], If[FileType[dir] =!= Directory, printstop["checkdir: " <> dir <> " not a directory."]; ]]; checkdir1[dir_] := If[Head[dir] =!= String, printstop["checkdir: " <> ToString[InputForm[dir]] <> " not a string."], If[!DirectoryQ[dir], Print["Creating directory ", dir]; CreateDirectory[dir]]]; checkfile[file_] := If[Head[file] =!= String, printstop["checkfile: " <> ToString[InputForm[file]] <> " not a string."], If[FileType[file] =!= File, printstop["checkfile: " <> file <> " not a file."]; ]]; silentrun[command_String] := Module[{rundir, batchfile, linkfile}, rundir = ToFileName[{dirwork, "temp"}]; checkdir[rundir]; SetDirectory[rundir]; batchfile = "mathcommand.bat"; (* It should be a shortcut to batchfile. Properties should be set as Run minimized. *) linkfile = "linkcommand.lnk"; checkfile /@ {batchfile, linkfile}; Export[batchfile, command, "Text"]; SystemOpen[linkfile]; ResetDirectory[]; ]; wget[url_String, outfile_String, logfile_String] := Module[{useragent, tempfile, url1, command, line2, line3, text}, useragent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9"; tempfile = "c:\\temp\\current.log"; Export[outfile, "", "Text"]; checkfile[outfile]; Export[tempfile, "", "Text"]; checkfile[tempfile]; (* DOS operating system interpretation of % *) url1 = StringReplace[url, "%" -> "%%"]; command = "wget -d -t 30 -U \"" <> useragent <> "\" -O \"" <> outfile <> "\" -o \"" <> tempfile <> "\" \"" <> url1 <> "\""; (* Run[command]; *) line20 = "echo --------------- >> \"" <> logfile <> "\""; line2 = "type \"" <> tempfile <> "\" >> \"" <> logfile <> "\""; line3 = "del \"" <> tempfile <> "\""; silentrun[command <> "\n" <> line20 <> "\n" <> line2 <> "\n" <> line3]; (* Waiting until it finishes *) Do[Pause[0.2]; If[FileType[tempfile] =!= File, Break[]], {5000}]; text = Import[outfile, "Text"]; If[StringLength[text] < 10, Print["Warning: wget: output is too short: ", text]]; text]; proxify[url_String] := StringReplace[url, RegularExpression["^http://([^/]+)/"] -> "http://$1.6a.nl/"]; progname[f_String] := If[FileType[f] =!= File, Print["Error: progname: File ", f, " does not exist. Exiting ..."]; Exit[], pname = StringCases[Import[f, "Text"], RegularExpression["[(][*]\\s*(.*)\\s*[*][)]"] :> "$1"]; pname = If[pname === {}, "Unnamed", First[pname]]]; toslash[s_String] := StringReplace[s, "\\" -> "/"]; tobackslash[s_String] := StringReplace[s, "/" -> "\\"]; stringtrim[s_String] := StringReplace[ StringReplace[s, Whitespace -> " "], {StartOfString ~~ " " -> "", " " ~~ EndOfString -> ""}]; flankblank[s_String] := StringReplace[s, RegularExpression["(^\\s+|\\s+$)"] -> ""]; p[s_] := If[Head[s] === String, Write[of, s], Print["Error: function p[]: attempt to print non-string: ", s]]; (* Adding or removing special HTML-symbols *) addsymb[s_String] := StringReplace[s, { Whitespace -> " ", "<" -> "<", ">" -> ">", "&" -> "&", "\"" -> """, "'" -> "'", "_" -> " " }]; removesymb[s_String]:= StringReplace[s,{ "<" -> " ", ">" -> " ", "&" -> " ", """ -> " ", "'" -> " ", " " -> " " }]; removesymb1[s_String]:= StringReplace[s,{ "<" -> " ", ">" -> " ", "&" -> " ", """ -> " ", "'" -> " ", " " -> " ", "\n" -> " ", "<" -> " ", ">" -> " ", "&" -> " ", "\"" -> " ", "'" -> " ", "_" -> " " }]; shrink[s0_, cleft_Integer, cright_Integer, smiddle_String] := ""; shrink[s0_String, cleft_Integer, cright_Integer, smiddle_String] := Module[{s, slen, ctot, sp, dc, cl, cr, cpleft, spright, sleft, sright, nwords, words}, s = StringReplace[s0, Whitespace -> " "]; slen = StringLength[s]; ctot = cleft + cright; If[ctot + 2 > slen, Return[s]]; sp = StringPosition[s, RegularExpression["\\s\\S+\\s"]]; dc = Floor[StringLength[smiddle]/2]; cl = Max[cleft - dc, 0]; cr = Max[cright - dc, 0]; spleft = Select[sp, #[[2]] <= cl &]; spright = Select[sp, #[[1]] >= slen - cr + 1 &]; sleft = If[spleft === {}, StringTake[s, cl], StringTake[s, Last[spleft][[2]]]]; sright = If[spright === {}, StringTake[s, -cr], StringDrop[s, First[spright][[1]] - 1]]; nwords = Length[sp] - Length[spleft] - Length[spright]; words = If[nwords == 0, "", If[nwords == 1, "1 word", ToString[nwords] <> " words"]]; sleft <> StringReplace[smiddle, "WORDS" -> words] <> sright ]; (* Transformation x->0x *) fixed2[s0_]:=Module[{s}, s=ToString[s0]; If[StringLength[s]<2,s="0"<>s]; s ]; (* Transformation x->00x, xx->0xx *) fixed3[s0_]:=Module[{s}, s=ToString[s0]; If[StringLength[s]<3,s="0"<>s]; If[StringLength[s]<3,s="0"<>s]; s ]; stripext[s_String] := StringDrop[s, -4]; porder[s1_String, s2_String] := OrderedQ[{StringTake[s1 <> "000", 3], StringTake[s2 <> "000", 3]}]; ifprocessed[photo_] := Module[{dir, file, fileproc}, {dir, file} = photo; fileproc = ToFileName[{dir0, "processed", "img" <> dir}, StringReplace[file, {"dsc" -> "", "_" -> "", "-" -> ""}] <> ".jpg"]; ifprocessed[photo] = (FileType[fileproc] === File) ]; hex[c_] :=(* Converting to hexadecimal form *) StringJoin @@ ((ToString /@ IntegerDigits[Round[255. c], 16, 2]) /. {"10" -> "A", "11" -> "B", "12" -> "C", "13" -> "D", "14" -> "E", "15" -> "F"}); shortenname[name_String] := StringReplace[StringReplace[ StringReplace[name//StringTrim, " \[Times] " -> " "], "<" ~~ Shortest[__] ~~ ">" -> ""], RegularExpression["(.*? .*?) .*"] -> "$1"];