
library('s2dverification')
# The line below should go inside the function Cluster
library('fpc')
# 
# Here you should source as well Cluster and SeaIceModes
source('/home/nevensf/gitrep/s2dverification/R/Load.R')
#source('/home/nevensf/gitrep/s2dverification/R/Cluster.R')
#source('/home/nevensf/gitrep/s2dverification/R/SeaIceModes.R')

# All the lines below should be moved to the SeaIceModes function
# You'll find some tips about how to code the loading more efficiently
# in the SeaIceModes function
sea01=Load('sia_Arctic_Marginal_Seas','i00v',obs=NULL,'19790101')
sea02=Load('sia_Arctic_Ocean','i00v',obs=NULL,'19790101')
#sea03=Load('sia_Arctic_Ocn','i00v',obs=NULL,'19790101')
sea03=Load('sia_Baffin','i00v',obs=NULL,'19790101')
sea04=Load('sia_Baffin_Bay','i00v',obs=NULL,'19790101')
sea05=Load('sia_Baltic_Sea','i00v',obs=NULL,'19790101')
sea06=Load('sia_BarKara','i00v',obs=NULL,'19790101')
sea07=Load('sia_Barents_Sea','i00v',obs=NULL,'19790101')
sea08=Load('sia_Beaufort_Sea','i00v',obs=NULL,'19790101')
#sea09=Load('sia_Bering_Sea','i00v',obs=NULL,'19790101')
sea09=Load('sia_Bering_Strait','i00v',obs=NULL,'19790101')
#sea10=Load('sia_Canadian_Archipelago','i00v',obs=NULL,'19790101')
sea10=Load('sia_Canadian_Waters','i00v',obs=NULL,'19790101')
sea11=Load('sia_Central_Arctic','i00v',obs=NULL,'19790101')
sea12=Load('sia_Chukchi_Sea','i00v',obs=NULL,'19790101')
sea13=Load('sia_East_Siberian_Sea','i00v',obs=NULL,'19790101')
#sea14=Load('sia_Eastern_Central_Arctic','i00v',obs=NULL,'19790101')
sea14=Load('sia_Fram_Strait','i00v',obs=NULL,'19790101')
sea15=Load('sia_Greenland_Sea','i00v',obs=NULL,'19790101')
sea16=Load('sia_Grnland','i00v',obs=NULL,'19790101')
#sea17=Load('sia_Gulf_Saint_Lawrence','i00v',obs=NULL,'19790101')
#sea18=Load('sia_Hudson_Bay','i00v',obs=NULL,'19790101')
sea17=Load('sia_Icelandic_Sea','i00v',obs=NULL,'19790101')
sea18=Load('sia_Kara_Gate_Strait','i00v',obs=NULL,'19790101')
sea19=Load('sia_Kara_Sea','i00v',obs=NULL,'19790101')
sea20=Load('sia_Laptev_Sea','i00v',obs=NULL,'19790101')
sea21=Load('sia_Labrador_Sea','i00v',obs=NULL,'19790101')
sea22=Load('sia_Lincoln_Sea','i00v',obs=NULL,'19790101')
sea23=Load('sia_Nares_Strait','i00v',obs=NULL,'19790101')
sea24=Load('sia_Nordic_Seas','i00v',obs=NULL,'19790101')
sea25=Load('sia_NorthWest_Passage','i00v',obs=NULL,'19790101')
sea26=Load('sia_North_Atlantic_Ocean','i00v',obs=NULL,'19790101')
sea27=Load('sia_Norwegian_Sea','i00v',obs=NULL,'19790101')
#sea28=Load('sia_Okhotsk_Sea','i00v',obs=NULL,'19790101')
sea28=Load('sia_OpenOcean','i00v',obs=NULL,'19790101')
sea29=Load('sia_Serreze_Arctic','i00v',obs=NULL,'19790101')
sea30=Load('sia_TotalArc','i00v',obs=NULL,'19790101')
sea31=Load('sia_Vilkitsky_Strait','i00v',obs=NULL,'19790101')
sea32=Load('sia_Western_Central_Arctic','i00v',obs=NULL,'19790101')

# You'll find also some indications about how to code the
# lines below more efficiently in SeaIceModes 
sea01a=Mean1Dim(sea01$mod,2)
sea02a=Mean1Dim(sea02$mod,2)
sea03a=Mean1Dim(sea03$mod,2)
sea04a=Mean1Dim(sea04$mod,2)
sea05a=Mean1Dim(sea05$mod,2)
sea06a=Mean1Dim(sea06$mod,2)
sea07a=Mean1Dim(sea07$mod,2)
sea08a=Mean1Dim(sea08$mod,2)
sea09a=Mean1Dim(sea09$mod,2)
sea10a=Mean1Dim(sea10$mod,2)
sea11a=Mean1Dim(sea11$mod,2)
sea12a=Mean1Dim(sea12$mod,2)
sea13a=Mean1Dim(sea13$mod,2)
sea14a=Mean1Dim(sea14$mod,2)
sea15a=Mean1Dim(sea15$mod,2)
sea16a=Mean1Dim(sea16$mod,2)
sea17a=Mean1Dim(sea17$mod,2)
sea18a=Mean1Dim(sea18$mod,2)
sea19a=Mean1Dim(sea19$mod,2)
sea20a=Mean1Dim(sea20$mod,2)
sea21a=Mean1Dim(sea21$mod,2)
sea22a=Mean1Dim(sea22$mod,2)
sea23a=Mean1Dim(sea23$mod,2)
sea24a=Mean1Dim(sea24$mod,2)
sea25a=Mean1Dim(sea25$mod,2)
sea26a=Mean1Dim(sea26$mod,2)
sea27a=Mean1Dim(sea27$mod,2)
sea28a=Mean1Dim(sea28$mod,2)
sea29a=Mean1Dim(sea29$mod,2)
sea30a=Mean1Dim(sea30$mod,2)
sea31a=Mean1Dim(sea31$mod,2)
sea32a=Mean1Dim(sea32$mod,2)

bubi=array(dim=c(34,32))

#Similarly, you will find some indications about how
# to code that more efficiently in SeaIceModes

bubi[,1]=sea01a[1,1,seq(1,402,12)]
bubi[,2]=sea02a[1,1,seq(1,402,12)]
bubi[,3]=sea03a[1,1,seq(1,402,12)]
bubi[,4]=sea04a[1,1,seq(1,402,12)]
bubi[,5]=sea05a[1,1,seq(1,402,12)]
bubi[,6]=sea06a[1,1,seq(1,402,12)]
bubi[,7]=sea07a[1,1,seq(1,402,12)]
bubi[,8]=sea08a[1,1,seq(1,402,12)]
bubi[,9]=sea09a[1,1,seq(1,402,12)]
bubi[,10]=sea10a[1,1,seq(1,402,12)]
bubi[,11]=sea11a[1,1,seq(1,402,12)]
bubi[,12]=sea12a[1,1,seq(1,402,12)]
bubi[,13]=sea13a[1,1,seq(1,402,12)]
bubi[,14]=sea14a[1,1,seq(1,402,12)]
bubi[,15]=sea15a[1,1,seq(1,402,12)]
bubi[,16]=sea16a[1,1,seq(1,402,12)]
bubi[,17]=sea17a[1,1,seq(1,402,12)]
bubi[,18]=sea18a[1,1,seq(1,402,12)]
bubi[,19]=sea19a[1,1,seq(1,402,12)]
bubi[,20]=sea20a[1,1,seq(1,402,12)]
bubi[,21]=sea21a[1,1,seq(1,402,12)]
bubi[,22]=sea22a[1,1,seq(1,402,12)]
bubi[,23]=sea23a[1,1,seq(1,402,12)]
bubi[,24]=sea24a[1,1,seq(1,402,12)]
bubi[,25]=sea25a[1,1,seq(1,402,12)]
bubi[,26]=sea26a[1,1,seq(1,402,12)]
bubi[,27]=sea27a[1,1,seq(1,402,12)]
bubi[,28]=sea28a[1,1,seq(1,402,12)]
bubi[,29]=sea29a[1,1,seq(1,402,12)]
bubi[,30]=sea30a[1,1,seq(1,402,12)]
bubi[,31]=sea31a[1,1,seq(1,402,12)]
bubi[,32]=sea32a[1,1,seq(1,402,12)]

# All the lines above from 
# sea01=Load('sia_Arctic_Marginal_Seas','i00v',obs=NULL,'19790101')
# down to that point should be replaced by a simple call to SeaIceModes
#
print(dim(bubi))

# The 3 lines below should be moved to the Cluster function and here you would
# simply have a call to CLuster(bubi) for now without any output returned.
print(kmeans.results<-kmeans(bubi,3,iter.max=5000,nstart=5000))

#print(pmak.results<-pamk(bubi))

#print(pam.results<-pam(bubi,3))
# I don't think it worth coding the computation of clusters with 3 different 
# methods. You should read about the advantages and drawbacks of the various 
# package, choose one and go for it. 
