Index: /issm/trunk-jpl/src/android/ISSM/.classpath
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/.classpath	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/.classpath	(revision 14046)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="gen"/>
-	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
-	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
 	<classpathentry kind="output" path="bin/classes"/>
 </classpath>
Index: /issm/trunk-jpl/src/android/ISSM/AndroidManifest.xml
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/AndroidManifest.xml	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/AndroidManifest.xml	(revision 14046)
@@ -7,5 +7,5 @@
         android:minSdkVersion="10"
         android:targetSdkVersion="15" />
-
+	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <application
         android:icon="@drawable/ic_launcher"
@@ -16,6 +16,5 @@
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
-
-                <category android:name="android.intent.category.LAUNCHER" />
+				<category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
             </activity>
Index: /issm/trunk-jpl/src/android/ISSM/bin/AndroidManifest.xml
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/bin/AndroidManifest.xml	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/bin/AndroidManifest.xml	(revision 14046)
@@ -5,19 +5,21 @@
 
     <uses-sdk
-        android:minSdkVersion="15"
+        android:minSdkVersion="10"
         android:targetSdkVersion="15" />
-
+	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <application
         android:icon="@drawable/ic_launcher"
         android:label="@string/app_name"
         android:theme="@style/AppTheme" >
-        <activity
+        <activity android:name=".MapSelection"
+            	  android:label="@string/title_activity_issm" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+				<category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+            </activity>
+            <activity
             android:name=".ISSM"
             android:label="@string/title_activity_issm" >
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-
-                <category android:name="android.intent.category.LAUNCHER" />
-            </intent-filter>
         </activity>
     </application>
Index: /issm/trunk-jpl/src/android/ISSM/jni/Android.mk
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/jni/Android.mk	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/jni/Android.mk	(revision 14046)
@@ -11,5 +11,5 @@
 LOCAL_PATH := $(my_LOCAL_PATH)
 LOCAL_ALLOW_UNDEFINED_SYMBOLS := true
-LOCAL_CFLAGS := -Wno-psabi
+LOCAL_CFLAGS := -Wno-psabi -DHAVE_CONFIG_H
 LOCAL_LDLIBS := -llog -ldl
 LOCAL_MODULE := IssmJni
Index: /issm/trunk-jpl/src/android/ISSM/jni/Application.mk
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/jni/Application.mk	(revision 14046)
+++ /issm/trunk-jpl/src/android/ISSM/jni/Application.mk	(revision 14046)
@@ -0,0 +1,3 @@
+APP_STL:=stlport_static
+APP_CPPFLAGS := -frtti
+APP_CPPFLAGS += -fexceptions
Index: /issm/trunk-jpl/src/android/ISSM/jni/Main.cpp
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/jni/Main.cpp	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/jni/Main.cpp	(revision 14046)
@@ -1,21 +1,37 @@
 #include <jni.h>
 #include "../../../c/android/fac.h"
+#include "../../../c/issm.h"
 #include <cstddef>
+#include <stdio.h>
 ///////////////////////////////////////////////////////////////////////////////////////////
 namespace com_example_issm
 {
 	fac* f;
+	//FemModel *fm;
 //------------------------------------------------------------------------------------
-	void initilizeObject(JNIEnv *env, jclass clazz)
+	jint initilize(JNIEnv *env, jclass clazz, jstring file)
 	{
+		const char *nativefile = env->GetStringUTFChars(file,0);
+
 		f = new fac();
+
+		//call Model constructor passing in infile as File Descriptor parameter.
+		// fm  = new FemModel(nativefile);
+
+		env->ReleaseStringUTFChars(file, nativefile); //must realease the char*
+		//jint size = (jint) fm->bufferSize();
+		//return size;
+
+		return 0; //return 0 for now.
 	}
 //------------------------------------------------------------------------------------
 	//fill out the first two slots, extract the same way in java using get(int position)
-	void fillBuffer(JNIEnv *env, jclass clazz , jobject buf)
+	void solve(JNIEnv *env, jclass clazz , jint alpha, jobject buf)
 	{
-		jdouble *bBuf = (jdouble *)env->GetDirectBufferAddress(buf);
-		bBuf[1] = 10.67;
-		bBuf[2] = 100.0;
+		jdouble *dBuf = (jdouble *)env->GetDirectBufferAddress(buf);
+
+		//pass bBuff to fem model to allocate data
+		// fm -> solve(dBuf, alpha);
+
 	}
 //------------------------------------------------------------------------------------
@@ -31,6 +47,6 @@
 	{
 			{"fac"      	,     "(J)J" 	, (void *) factorial},
-			{"initialize"   ,     "()V" 	, (void *) initilizeObject},
-			{"processBuffer", "(Ljava/nio/DoubleBuffer;)V", (void *) fillBuffer}
+			{"createISSMModel"   ,"(Ljava/lang/String;)I"  , (void *) initilize},
+			{"processBuffer", "(ILjava/nio/DoubleBuffer;)V", (void *) solve}
 	};
 }
@@ -55,7 +71,4 @@
     	else return -1;
     }
-
-    // Get jclass with env->FindClass.
-    // Register methods with env->RegisterNatives.
 }
 ///////////////////////////////////////////////////////////////////////////////////////////
Index: /issm/trunk-jpl/src/android/ISSM/jni/issmlib/Android.mk
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/jni/issmlib/Android.mk	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/jni/issmlib/Android.mk	(revision 14046)
@@ -3,11 +3,3 @@
 LOCAL_MODULE    := libISSMCore
 LOCAL_SRC_FILES := libISSMCore.a
-LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
 include $(PREBUILT_STATIC_LIBRARY)
-
-
-#include $(CLEAR_VARS)
-#LOCAL_MODULE    := libTestBuffer
-#LOCAL_SRC_FILES := libTestBuffer.a
-#LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
-#include $(PREBUILT_STATIC_LIBRARY)
Index: /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/ISSM.java
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/ISSM.java	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/ISSM.java	(revision 14046)
@@ -26,6 +26,6 @@
 	private IssmJni issmNative;
 	private String mapName;
-	private String textinFile;
-	private String actualinput;
+	private String issmFolder;
+	private int size;
     @Override
   //------------------------------------------------------------------------------------------------    
@@ -37,4 +37,5 @@
         	{
         		mapName = map.getString("map");
+        		issmFolder = map.getString("pathToFile");
         	}
         }
@@ -44,5 +45,4 @@
         Button button = (Button) super.findViewById(R.id.button1);
         button.setOnClickListener(this);
-        this.readFile(mapName);
         
         //load up the ISSM library and create double buffer in java
@@ -50,42 +50,21 @@
         issmNative = new IssmJni();
         buff = ByteBuffer.allocateDirect(15*8).order(ByteOrder.nativeOrder()).asDoubleBuffer();
-        this.createModel("Model");
+        this.createModel();
     }
 //------------------------------------------------------------------------------------------------    
-    public void createModel(String Model)
+    public void createModel()
     {
-    	issmNative.initialize();
-    }
-//------------------------------------------------------------------------------------------------
-    public void readFile(String mapName)
-    {
-    	AssetManager am = getAssets();
-    	String mapNameFile = "Map/"+mapName+".txt";
-        try {
-			InputStream is = am.open(mapNameFile);
-			int size = is.available();
-			byte[]buffer = new byte[size];
-			is.read(buffer);
-			is.close();
-			
-			textinFile = new String(buffer);
-			
-			//testing on actual file
-			InputStream is1 = am.open("Map/test102.petsc");
-			int size1 = is1.available();
-			byte[]buffer1 = new byte[size1];
-			is1.read(buffer1);
-			System.out.println(buffer1);
-			is1.close();
-			actualinput = new String(buffer1);
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+    	String file = "";
+    	if( mapName.equals("greenland"))
+		{
+    		file = "test102.petsc";
 		}
+    	else file = "test102.petsc";
+    	size = issmNative.createISSMModel(issmFolder + file);
     }
 //------------------------------------------------------------------------------------------------
     public void fillBuffer()
     {
-    	issmNative.processBuffer(buff);
+    	issmNative.processBuffer(5,buff);
     }
  //------------------------------------------------------------------------------------------------   
@@ -104,9 +83,6 @@
 		//print result from fac and the first two slot of filled buffer.
 		this.output.setText("Result = " + resultfromFac + "\n" 
-										+ "First two slot from buffer:\n" 
-										+ buff.get(1) + "          " + buff.get(2) 
-										+ "\nmap name = " + mapName
-										+ "\nTxtFile    " + textinFile
-										+"\nactualFile   " + actualinput);
+										+ "First slot from buffer:\n" 
+										+ buff.get(0) + " size " +  size);
 
 	}
Index: /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/IssmJni.java
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/IssmJni.java	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/IssmJni.java	(revision 14046)
@@ -5,6 +5,6 @@
 {
 	public native long fac(long n);
-	public native void processBuffer(DoubleBuffer buff);
-	public native void initialize();
+	public native void processBuffer(int alpha, DoubleBuffer buff);
+	public native int createISSMModel(String file);
 	static 
 	{
Index: /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/MapSelection.java
===================================================================
--- /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/MapSelection.java	(revision 14045)
+++ /issm/trunk-jpl/src/android/ISSM/src/com/example/issm/MapSelection.java	(revision 14046)
@@ -1,16 +1,30 @@
 package com.example.issm;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.os.Environment;
 import android.text.TextUtils;
+import android.util.Log;
 import android.view.Menu;
 import android.view.View;
 import android.widget.Button;
+import android.widget.Toast;
 import android.content.Intent;
-
+import android.content.SharedPreferences;
+import android.content.res.AssetManager;
+/////////////////////////////////////////////////////////////////////////// 
 public class MapSelection extends Activity
 {
-	private String map;
 	ISSM issm = new ISSM();
+	private static final String PREFERENCE_FIRST_RUN = null;
+	private String extStorageDirectory;
+	private String issmFolder;
+//------------------------------------------------------------------------	
 	public void onCreate(Bundle icicle)
 	{
@@ -18,32 +32,112 @@
 		setContentView(R.layout.activity_mapselection);
 		
+		 SharedPreferences settings = this.getSharedPreferences("ISSM", 0);
+		    boolean firstrun = settings.getBoolean(PREFERENCE_FIRST_RUN, true);
+		    extStorageDirectory = Environment.getExternalStorageDirectory().toString();
+		    
+		    issmFolder = extStorageDirectory + "/ISSM/input_files/";
+		    if (firstrun) 
+		    { // Checks to see if we've ran the application b4
+		        SharedPreferences.Editor e = settings.edit();
+		        e.putBoolean(PREFERENCE_FIRST_RUN, false);
+		        
+		        e.commit();
+		        // If not, run these methods:
+		        SetDirectory(issmFolder);
+		    }
+		    
+	
 		//this button represents greenland and pass signal to issm
 		Button gl = (Button) findViewById(R.id.button1);		
 		gl.setOnClickListener(new View.OnClickListener() 
 		{
-			
 			public void onClick(View v) 
 			{
-				// TODO Auto-generated method stub
 				Intent i = new Intent(MapSelection.this, ISSM.class);
 				i.putExtra("map", "greenland");
+				i.putExtra("pathToFile", issmFolder);
 		        startActivity(i);
 			}
 		});
 		
-		//this button represents artantice and pass signal to issm
+		//this button represents artarctica and pass signal to issm
 		Button art = (Button) findViewById(R.id.button2);
 		art.setOnClickListener(new View.OnClickListener() 
 		{
-			
 			public void onClick(View v) 
 			{
-				// TODO Auto-generated method stub
 				Intent i = new Intent(MapSelection.this, ISSM.class);
 				i.putExtra("map", "antarctica");
+				i.putExtra("pathToFile", issmFolder);
 		        startActivity(i);
 			}
 		});
 	}
+//------------------------------------------------------------------------
+	private void SetDirectory(String directory) 
+	{
+	    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) 
+	    {
+	    	System.out.println(issmFolder);
+	        File txtDirectory = new File(issmFolder);
+	        
+	        // Check and create directory in SDcard
+	        if(!txtDirectory.exists())
+	        {
+	        	txtDirectory.mkdirs();
+	        	System.out.println("making directory");
+	        }
+	        CopyAssets(); // Then run the method to copy the file.
+
+	    } 
+	    else if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED_READ_ONLY)) 
+	    {
+	    	Toast toast = Toast.makeText(this.getApplicationContext(), "Memory is not mounted to device", Toast.LENGTH_LONG);
+	    	toast.show();
+	    }
+
+	}
+//----------------------------------------------------------------------------
+	/**
+	 * -- Copy the file from the assets folder to the sdCard
+	 * ===========================================================
+	 **/
+		private void CopyAssets() 
+		{
+		    AssetManager assetManager = getAssets();
+		    String[] files = null;
+		    try {
+		        files = assetManager.list("Map");
+		    } catch (IOException e) {
+		        Log.e("tag", e.getMessage());
+		    }
+		    for (int i = 0; i < files.length; i++) {
+		        InputStream in = null;
+		        OutputStream out = null;
+		        try {
+		            in = assetManager.open("Map/"+files[i]);
+		            out = new FileOutputStream(issmFolder + files[i]);
+		            copyFile(in, out);
+		            in.close();
+		            in = null;
+		            out.flush();
+		            out.close();
+		            out = null;
+		        } catch (Exception e) {
+		            Log.e("tag", e.getMessage());
+		        }
+		    }
+		    System.out.println("Done");
+		}
+//----------------------------------------------------------------------------
+		private void copyFile(InputStream in, OutputStream out) throws IOException 
+		{
+		    byte[] buffer = new byte[1024];
+		    int read;
+		    while ((read = in.read(buffer)) != -1) {
+		        out.write(buffer, 0, read);
+		    }
+		}
+//----------------------------------------------------------------------------
 }
- 
+/////////////////////////////////////////////////////////////////////////// 
