#rm(list=ls())
require(fields)

#      mV1  dC1 ;       mV2 dC2
fnam= 'JGK20140410'
dtype=c('mV0', 'dC')
tag=c('Ca sensor 1','Ca sensor 2')
nsens=1 # The Number of Sensor Electrodes in the Scan
for(j in 1:2) {
for(i in 1:nsens) {

# --------------------------------------------------------------------------- 1
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_12-46-27.csv") #1
zlo=c(38, -0.005 ); zup=c(41 ,0.03  )

attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
quartz(paste(fnam,dtype[j],tag[i]), width=12.5, height=7.50)
set.panel(3,4)
par(mar=c(2,2,0.25,3.5))

surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('A', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)


# --------------------------------------------------------------------------- 1
YY<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_13-19-47.csv") # 2
zlo=c(38, -0.0001 ); zup=c(41 ,0.0011  ) # change dC scale

attach(YY)

ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('B', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
mtext("change scale", side=4)
detach(YY)

# --------------------------------------------------------------------------- 1
ZZ<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_15-46-59.csv") #3
zlo=c(38, -0.0001 ); zup=c(41 ,0.0007  ) # change dC scale
attach(ZZ)

ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('C', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
mtext("change scale", side=4)
detach(ZZ)
# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_16-36-59.csv") #4
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('D', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)

YY<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_17-26-59.csv") #5
attach(YY)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
#quartz()
#set.panel()
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('E', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(YY)

ZZ<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_18-16-59.csv") #6
attach(ZZ)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('F', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(ZZ)
# ---------------------------------------------------------------------------
# XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_20-29-08.csv") #7

# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_21-19-08.csv") #8
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('H', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)

# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_22-09-08.csv") #9
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('I', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)

# ---------------------------------------------------------------------------
#  XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_22-59-08.csv") #10

# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-10_23-50-17.csv") #11
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('K', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)

# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-11_00-40-17.csv") #12
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('L', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)

# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-11_01-30-17.csv") #13
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('M', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
detach(XX)

# ---------------------------------------------------------------------------
XX<-read.csv("http://www.bio.umass.edu/biology/kunkel/pub/probe/ASET/ASET_LV4/2014/Source_2014-04-10_Scans/Source_2014-04-10_Scan_2014-04-11_02-20-17.csv") #14
zlo=c(39, -0.1 ); zup=c(44 ,-0.05  ) # change dC scale
attach(XX)
ts<-round(c(min(Time_sec)/60,max(Time_sec)/60))
LatLon<-data.frame(Y,Z)
if ( j==1) {
if ( i==1) {y=S1mV0} else {y=S2mV0}
           } else { if ( i==1) {y=S1C1-S1C0} else {y=S2C1-S2C0} } 
x=LatLon
fit<- Tps(x,y)
surface(fit, 
       main = '',
       yaxt='n',
       zlim=c(zlo[j],zup[j])) # contour/image plot of the fitted surface
mtext('N', line=-3, adj=0.05, cex=2)
mtext(paste(ts[1],'-',ts[2]),line=-1.25,cex=0.7, adj=0.98)
mtext("change scale", side=4)
detach(XX)

# ---------------------------------------------------------------------------

 } # end of for i
  } # end of for j

