# Copyright 2024 SPC-EPFL
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------

# testing installation at GA

# need path for chease: /fusion/projects/codes/chease/bin in $PATH

# using automatic script to execute a geqdsk file from shell (and get eqdsk in cocos_out=11 (ITER)
mkdir /tmp/$USER
run.chease.eqdsk geqdsk_COCOS5 . /tmp/$USER 1 0.5 4 0 5 11

# The output files are in /tmp/$USER for example EQDSK_COCOS_11.OUT.geqdsk_COCOS5

# the profiles from the output file o.geqdsk_COCOS5 are extracted in columns in o.geqdsk_COCOS5.cols
# You can plot them with:

matlab -nodesktop
>> addpath /fusion/projects/codes/chease/src/matlab/CHEASEgui
>> plotdatafile('/tmp/sautero/o.geqdsk_COCOS5.cols');
% then choose fields to plot, CSM=rhopol, other rhos a listed further down the list

# Using the same path you have several tools available, for example to find the cocos of a geqdsk file
>> find_cocos('geqdsk_COCOS5')

gives 5 or 6 as consistent cocos values

>> aa=read_eqdsk('geqdsk_COCOS5',5,1); % gives eqdsk data structure in aa and computes Br, BZ, Grad-Shafranov etc using interpos
>> plot_eqdsk(aa) % plots all subfields

# Note that CHEASE can have pressure, as well as <j.B>/B0 or q as input profiles, in addition to what is listed in the original paper

# read_expeq/eqdsk, manipulate the structure, write_expeq/eqdsk, run_chease can help you
# CHEASEgui (all these in matlab) can help you as well, see http://spc.epfl.ch/chease
