Posts Tagged map

Use sparse data set to create contour map

Problem: We have a sparse array that include some real data. We want to create a contour map for the data. The data set includes x, y, and the measured values.
Solution: I found the following article that provides a complete solution for this problem. Following the link below to read the article.

Software for Exploratory Data Analysis and Statistical Modelling

Then I wrote a R script to create contour map of my measured data.

library(geoR)
temp.df = data.frame(y = mydata$row,
x = mydata$col,
z = mydata$temp)
temp.loess = loess(z ~ x*y, data = temp.df, degree = 2, span = 1)
temp.fit = expand.grid(list(x = seq(1, 16, 0.1), y = seq(1, 4, 0.1)))
z = predict(temp.loess, newdata = temp.fit)
temp.fit$Height = as.numeric(z)

# basic image
image(seq(1, 16, 0.1), seq(1, 4, 0.1), z,
   xlab = "X Coordinate", ylab = "Y Coordinate",
   main = "Surface temp data")
box()

# lattice plot
library(lattice)
levelplot(Height ~ x*y, data = temp.fit,
   xlab = "col", ylab = "row",
   main = "Surface map",
   col.regions = terrain.colors(100)
)
Share

Tags: , , , , ,

Mapping network drives in LAN

In Windows, there are a number of script files with different file extensions as the following:

  • .bat,.cmd MS-DOS/Windows batch file MS-DOS operating system batch file
  • .asp ASP page Active Server Page file
  • .html HTML file Web page
  • .js JScript file Windows script
  • .vbs VBScript file Windows script
  • .wsf Windows Script Host file Container or project file for a Windows script; supported by WSH 2.0 and later.
  • .wsh Windows Script Host files, supported by WSH 1.0 and later.

Each script type meets different needs and has strengths and weaknesses. If you are familiar with DOS, I am sure you know DOS batch files. If you wrote webpages, you may be familiar with HTML, ASP, and/or JS/VBS. If you work with Windows itself, you should be familiar with WSH or WSF. WSF file is more powerful script file that can include several scripts to achieve different, but related functions. WSF file must run under WSH 2.0 and later. If your OS is Windows 2000/Me or later, you already have it. Otherwise, you need go to Microsoft.COM to download a latest version of Windows Script Host.

In the lab I am working, there are a cluster of 11 computers. I used to setup the network drives for each machine individually. The process is tedious and error-prone. I turned to Windows Script Host to write a script project (see following source code) an distributed it to all machines. This script project includes three functional scripts: (1) list all current network drive mapping; (2) remove all current network drive mapping; (3) map all available network drive with fixed drive name.

Although this script is useful, you need run it every time after you reboot your computer. That is nconvenient, especially when you have a cluster of computers. I put a register key to Windows registry. The register key is as the below.

REGEDIT4
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run]
“MapNetDrives”=”c:\\windows\\wscript //job:map c:\\windows\\network.wsf”

To be aware of that the script file (network.wsf) should be put under Windows folder to make the registry key work. After this is done, the computer will map all available network drives every time after computers are rebooted.

If you’d like put a shortcut on your desktop to run the mapping function, you need create a shortcut for the script file and put it on the desktop first. Then you should modify the shortcut property. Change the Target textbox to the following string.

C:\WINDOWS\wscript.exe //job:map C:\WINDOWS\network.wsf

If you’d like put a shortcut link on the desktop to remove network drives, you should change the Target textbox to the following string.

C:\WINDOWS\wscript.exe //job:remove C:\WINDOWS\network.wsf

Ok, this is all what I have for automatically mapping network drives. Source code is listed below. Enjoy!

<package>
   <job id="list">
      <script language="VBScript">
         CRLF = chr(13) & chr(10)
         Set oNet = WScript.CreateObject("WScript.Network")
         Set oDrives = oNet.EnumNetworkDrives
         sString = "Network drive mappings:" + CRLF
         if oDrives.Count = 0 then
            sString = sString + "No network drives."
         else
            For i = 0 to oDrives.Count - 1 Step 2
               sString = sString + "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) + CRLF
            Next
         end if
         Wscript.Echo sString
      </script>
   </job>
   <job id="remove">
      <script language="VBScript">
 	 Dim oNet
	 Set oNet = WScript.CreateObject("WScript.Network")
         Set oDrives = oNet.EnumNetworkDrives
         For i = 0 to oDrives.Count - 1 Step 2
            oNet.RemoveNetworkDrive oDrives.Item(i)
         Next
      </script>
   </job>
   <job id="map">
      <script language="VBScript">
        on error resume next
        dim allmap(12,2)
        allmap(0,1) = "D:"
        allmap(0,2) = "\\lamco_7\maincdrom"
        allmap(1,1) = "E:"
        allmap(1,2) = "\\lamco_7\zip250"
        allmap(2,1) = "G:"
        allmap(2,2) = "\\lamco_7\main-c"
        allmap(3,1) = "M:"
        allmap(3,2) = "\\lamco_1\c"
        allmap(4,1) = "N:"
        allmap(4,2) = "\\lamco_2\c"
        allmap(5,1) = "O:"
        allmap(5,2) = "\\lamco_3\c"
        allmap(6,1) = "P:"
        allmap(6,2) = "\\lamco_4\c"
        allmap(7,1) = "Q:"
        allmap(7,2) = "\\lamco_5\c"
        allmap(8,1) = "R:"
        allmap(8,2) = "\\lamco_6\c"
        allmap(9,1) = "S:"
        allmap(9,2) = "\\lamco_8\c"
        allmap(10,1) = "T:"
        allmap(10,2) = "\\lamco_9\c"
        allmap(11,1) = "U:"
        allmap(11,2) = "\\lamco_10\c"
        allmap(12,1) = "V:"
        allmap(12,2) = "\\lamco_11\c"

        Set oNet = WScript.CreateObject("WScript.Network")
        Set oDrives = oNet.EnumNetworkDrives
        For i = 0 to oDrives.Count - 1 Step 2
            oNet.RemoveNetworkDrive oDrives.Item(i)
        Next
	Set oShell = CreateObject("WScript.Shell")
	ComputerName = UCase(oNet.ComputerName)
	for i = 0 to 12
	   mapStr = UCase(allmap(i,2))
	   pos = inStr(mapStr,ComputerName)
	   if pos>0 then
	   	oShell.Exec("%comspec% /c subst " & allmap(i,1) & " c:\")
	   else
	   	oNet.MapNetworkDrive allmap(i,1), allmap(i,2),"false","","1d2s3z4$"
	   end if
	next
      </script>
   </job>
</package>

We have to change the code every time the network drive mapping updated. In order to separate the data from the code, the above code was improved and now it can read into a text file that includes all network mapping information. The following is the improved code.

'//////////////////////////////////////////////
'//  Author: Zhanshan Dong
'//  Writen in 2001
'//  Modified in 2003, 2004, 2006
'//////////////////////////////////////////////
<package comment="Created by Zhanshan Dong">
<job id="list">
	<script language="VBScript">
		On Error Resume Next
		CRLF = chr(13) & chr(10)
		Set oNet = WScript.CreateObject("WScript.Network")
		Set oDrives = oNet.EnumNetworkDrives
		sString = "Network drive mappings:" + CRLF
		IF oDrives.Count = 0 THEN
			sString = sString + "No network drives."
		Else 
			For i = 0 to oDrives.Count - 1 Step 2
				sString = sString + "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) + CRLF
			Next
		End if
		Wscript.Echo sString
	</script>
</job>
<job id="remove">
	<script language="VBScript">
		On Error Resume Next
		Dim oNet
		Set oNet = WScript.CreateObject("WScript.Network")
		Set oDrives = oNet.EnumNetworkDrives
		For i = 0 to oDrives.Count - 1 Step 2
			oNet.RemoveNetworkDrive oDrives.Item(i)
		Next
	</script>
</job>
<job id="map">
	<script language="VBScript">
		On Error Resume Next
		Const ForReading = 1
		Dim AllMap(26,1)
		Dim oFSO  ' file system object
		Dim oTFS  ' textfile stream
		Dim oNet ' net work object
		Dim i, j, nDrive
		Dim temp, temp1
		Set oFSO = CreateObject("Scripting.FileSystemObject")
		Set oTFS = oFSO.OpenTextFile("DriveMap.Txt", ForReading)
		i = 0
		Do While oTFS.AtEndOfStream <> True
			temp = trim(oTFS.ReadLine)
			temp2 = left(temp,1)
			temp1 = split(temp, ",")
			if (temp2<>"'") and (temp1(0) <> "") then
				AllMap(i, 0) = temp1(0) + ":"
				AllMap(i, 1) = temp1(1)
				i = i + 1
			end if
		Loop
		nDrive = i
		'wscript.echo ndrive
		Set oNet = WScript.CreateObject("WScript.Network")
		FOR i = 0 TO nDrive - 1
			'wscript.echo i & ":" + allmap(i,0)+ "=" + allmap(i,1)
			oNet.MapNetworkDrive allmap(i,0), allmap(i,1), "1d2s3z4$"
		NEXT
	</script>
</job>
</package>

The text file can have multiple rows. Each row includes a network mapping information. First part is a driver letter you want to map to and the second is the network URI. Here is an example.

Z,\\sapphire\samba

You can download the files here – network.zip

Share

Tags: , , , ,