import numpy as np
import spinspy as spy

## Determine simulation parameters and make grid
## Purpose:
##     - Read spins.conf if it exists
##     - Read the grid
##     - Add other grid parameters (such as grid spacing) into parameters object
##
## Usage:
##     paramgrid = spinspy.get_paramgrid()
## ------

# need to test on 2D and if grid style is full

def get_paramgrid(style='vector'):
    # read parameters and grid
    params = spy.get_params()
    gd = spy.get_grid(style=style)    # gd = x,[y],z
    x = gd[0]
    z = gd[-1]
    Nz = params.Nz

    # find other grid parameters
    dx = x[1]-x[0]
    params.dx = dx
    #params.Lx = params.Nx*dx   # do I need this?
    if params.nd == 3:
        y = gd[1]
        dy = y[1]-y[0]
        params.dy = dy
        #gd.Ly = gd.Ny*dy
        print('Data is 3 dimensional.')
    elif params.nd == 2:
        print('Data is 2 dimensional.')

    # check for vertical expansion style
    if np.abs((z[Nz/2]-z[Nz/2-1])/(z[1]-z[0])) > 2:
        print('Chebyshev grid in z.')
        # define clenshaw curtis weights here?
    else:
        print('Linear grid in z.')
        dz = z[1]-z[0]
        params.dz = dz
        #gd.Lz = gd.Nz*dz

    return gd, params

@@ -35,16 +35,64 @@
 as spy%0A%0A
+# need to test on 2D and if grid style is full%0A%0A
 ## Deter
@@ -306,25 +306,30 @@
 %0A##     
+x,y%5B,z%5D,
 param
-grid
+s
  = spins
@@ -361,57 +361,8 @@
 ---%0A
-%0A# need to test on 2D and if grid style is full%0A%0A
 def 
@@ -457,14 +457,101 @@
 s()%0A
+%0A
     
-gd
+# Parse the grid based on which dimensions are used%0A    if params.nd == 3:%0A        x,y,z
  = s
@@ -578,55 +578,246 @@
 yle)
+%0A
     
-# gd = x,%5By%5D,z%0A    x = gd%5B0%5D%0A    z = gd%5B-1%5D
+elif params.nd == 2:%0A        if params.Nz == 1:%0A            x,y = spy.get_grid(style=style)%0A        if params.Ny == 1:%0A            x,z = spy.get_grid(style=style)%0A        if params.Nx == 1:%0A            y,z = spy.get_grid(style=style)
 %0A   
@@ -839,17 +839,17 @@
 %0A%0A    # 
-f
+F
 ind othe
@@ -866,16 +866,42 @@
 ameters%0A
+    if params.Nx %3E 1:%0A    
     dx =
@@ -905,17 +905,19 @@
 x = x%5B1%5D
--
+ - 
 x%5B0%5D%0A   
@@ -913,24 +913,28 @@
  - x%5B0%5D%0A    
+    
 params.dx = 
@@ -944,68 +944,140 @@
     
-#params.Lx = params.Nx*dx   # do I need this?
+    params.xlim = %5Bx%5B0%5D,x%5B-1%5D%5D%0A        params.Lx = np.abs(x%5B-1%5D-x%5B0%5D)%0A    if params.Ny %3E 1:%0A        dy = y%5B1%5D - y%5B0%5D
 %0A    
-if
+   
  params.
 nd =
@@ -1068,32 +1068,31 @@
      params.
-nd == 3:
+dy = dy
 %0A        y =
@@ -1092,63 +1092,130 @@
     
-y = gd%5B1%5D%0A        dy = 
+params.ylim = %5By%5B0%5D,y%5B-1%5D%5D%0A        params.Ly = np.abs(
 y%5B
+-
 1%5D-y%5B0%5D
+)
 %0A   
+ if params.Nz %3E 1:%0A
      
+   
 params.
-dy = dy
+zlim = %5Bz%5B0%5D,z%5B-1%5D%5D
 %0A   
@@ -1223,25 +1223,116 @@
     
-#gd.Ly = gd.Ny*dy
+params.Lz = np.abs(z%5B-1%5D-z%5B0%5D)%0A%0A    # Print dimensionality%0A    # BS: Do we need this?%0A    if params.nd == 3:
 %0A   
@@ -1574,16 +1574,20 @@
        #
+ DD:
  define 
@@ -1616,16 +1616,56 @@
 s here?%0A
+        # BS: if it's easy to do, sure?%0A
     else
@@ -1750,34 +1750,8 @@
 = dz
-%0A        #gd.Lz = gd.Nz*dz
 %0A%0A  

Add more handling for 2d x/y/z stuff