echo ''
echo 'This script calls all the *ModIvsModII.ncl scripts'
echo 'and produces plots for all available/listed plot_types'
echo 'Note: All ncl scripts assumes that the input data on'
echo 'the listed directories are on a integer number times'
echo '12 nc-files for monthly model data for model I and II,'
echo 'and that no other files are present there.' 
echo ''
echo 'If the number of years is so large that some of the'
echo 'ncl scripts run out of memory, with the error message'
echo 'systemfunc: cannot create child process:[errno=12],'
echo 'then make climatological input for each mponth in,'
echo 'advance, e.g. by use of the ncea command...'
echo ''
echo '     (Created by Alf Kirkevåg, April 2014)'
echo ''

# ncl 'dataFile=addfile("./modelData.nc", "r")' plot_type=0 Emis_ModIvsModII.ncl
#************************* To be edited by the user ********************************************
# Plot type and plot output format:
plotf=png  # chosen output format for figures (ps, eps, pdf, png)
#
# Paths and names of input files from model version I and II (PD case): 
#pthI=/vol/fou/atmos2/alfk/hexagon/aerocomA2noresm_r128/tests/CTRL2000/
#pthI=/media/BackupAK/aerocomA2r128-tester/CTRL2000/
#fnmI=aerocomA2r128_2006.cam2.h0.0007-01.nc     # first file to be used
#fnmpI=aerocomA2r128_2006.cam2.h0.0007-         # all files fnmpI* are used
#pthI=/projects/NS2345K/noresm/cases/7310AMIP20002_mnthclim_yr3-30/
#fnmI=7310AMIP20002.cam.h0.0003-0030_01.nc
#fnmpI=7310AMIP20002.cam.h0.0003-0030_
#
pthII=/projects/NS2345K/noresm/work/adag/casesSO4/F2000_f09_f09_r227test01/atm/hist/CLIMFILES/
fnmII=F2000_f09_f09_r227test01.cam.h0.03_10-01.nc
fnmpII=F2000_f09_f09_r227test01.cam.h0.03_10-
pthI=/projects/NS2345K/noresm/work/adag/casesSO4/F2000_f09_f09_r227test01/atm/hist/CLIMFILES/
fnmI=F2000_f09_f09_r227test01.cam.h0.03_10-01.nc
fnmpI=F2000_f09_f09_r227test01.cam.h0.03_10-
#
# Paths and names of input files necessary for forcing plots (PI case)):
#pthI_PI=/vol/fou/atmos2/alfk/hexagon/aerocomA2noresm_r128/
#fnmI_PI=aerocomA2r128_1850.cam2.h0.0007-01.nc     # first file to be used
#fnmpI_PI=aerocomA2r128_1850.cam2.h0.0007-         # all files fnmpI_PI* are used
pthI_PI=/projects/NS2345K/noresm/work/adag/casesSO4/F1850_f09_f09_r227test01/atm/hist/CLIMFILES/
fnmI_PI=F1850_f09_f09_r227test01.cam.h0.03_10-01.nc
fnmpI_PI=F1850_f09_f09_r227test01.cam.h0.03_10-
#pthII_PI=/media/BackupAK/NorESM2output/PI1850R516/
#fnmII_PI=PI1850R516.cam.h0.1984-12.nc                 # first file to be used
#fnmpII_PI=PI1850R516.cam.h0.19                        # all files fnmpII* are used
pthII_PI=/projects/NS2345K/noresm/work/adag/casesSO4/F1850_f09_f09_r227test01/atm/hist/CLIMFILES/
fnmII_PI=F1850_f09_f09_r227test01.cam.h0.03_10-01.nc
fnmpII_PI=F1850_f09_f09_r227test01.cam.h0.03_10-
#ModelI=CAM4-Oslo  # gives CAM4-Oslo s. new CAM5-Oslo comparison plots
ModelI=CAM5-Oslo  # gives CAM5-Oslo Revision N vs. CAM5-Oslo Revision M comparison plots
#**********************************************************************************************
#No changes by the user should be necessary below...


echo ''
echo 'Running Emis_ModIvsModII.ncl'
echo ''
for I in {0..5};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" Emis_ModIvsModII.ncl
done

echo ''
echo 'Running Cld2d_ModIvsModII.ncl'
echo ''
for I in {0..8};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" Cld2d_ModIvsModII.ncl 
done

echo ''
echo 'Running Load_ModIvsModII.ncl'
echo ''
for I in {0..19};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" Load_ModIvsModII.ncl
done

echo ''
echo 'Running Ext_ModIvsModII.ncl'
echo ''
for I in {1..20};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" Ext_ModIvsModII.ncl 
done

echo ''
echo 'Running AODratio_ModIvsModII.ncl'
echo ''
for I in {0..6};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" AODratio_ModIvsModII.ncl
done

echo ''
echo 'Running AOD_ModIvsModII.ncl'
echo ''
for I in {0..6};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" AOD_ModIvsModII.ncl
done

echo ''
echo 'Running ZonalAero_ModIvsModII.ncl'
echo ''
for I in {0..7};do
 ncl  plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" ZonalAero_ModIvsModII.ncl
done

echo ''
echo 'Running ZonalRHCl_ModIvsModII.ncl'
echo ''
for I in {0..6};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" ZonalRHCl_ModIvsModII.ncl
done

echo ''
echo 'Running Lifetimes_ModIvsModII.ncl'
echo ''
for I in {0..5};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" Lifetimes_ModIvsModII.ncl
done

echo ''
echo 'Running WetDepRat_ModIvsModII.ncl'
echo ''
for I in {0..5};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" WetDepRat_ModIvsModII.ncl
done

echo ''
echo 'Running EffDryRad_ModIvsModII.ncl'
echo ''
for I in {0..2};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" EffDryRad_ModIvsModII.ncl 
done

echo ''
echo 'Running ZonalModepar_ModIvsModII.ncl'
echo ''
for I in {1..9};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" ZonalModepar_ModIvsModII.ncl
done

echo ''
echo 'Running PM_ModIvsModII.ncl'
echo ''
for I in {1..5};do
 ncl  plot_type=$I format=\"$plotf\" filepathPD_I=\"$pthI\" filenamePD_I=\"$fnmI\" filepathPD_II=\"$pthII\" filenamePD_II=\"$fnmII\" filenamepPD_I=\"$fnmpI\" filenamepPD_II=\"$fnmpII\" filepathPI_I=\"$pthI_PI\" filenamePI_I=\"$fnmI_PI\" filepathPI_II=\"$pthII_PI\" filenamePI_II=\"$fnmII_PI\" filenamepPI_I=\"$fnmpI_PI\" filenamepPI_II=\"$fnmpII_PI\" ModI=\"$ModelI\" PM_ModIvsModII.ncl 
done

echo ''
echo 'Running RadBudg_ModIvsModII.ncl'
echo ''
for I in {1..3};do
 ncl  plot_type=$I format=\"$plotf\" filepathPD_I=\"$pthI\" filenamePD_I=\"$fnmI\" filepathPD_II=\"$pthII\" filenamePD_II=\"$fnmII\" filenamepPD_I=\"$fnmpI\" filenamepPD_II=\"$fnmpII\" filepathPI_I=\"$pthI_PI\" filenamePI_I=\"$fnmI_PI\" filepathPI_II=\"$pthII_PI\" filenamePI_II=\"$fnmII_PI\" filenamepPI_I=\"$fnmpI_PI\" filenamepPI_II=\"$fnmpII_PI\" ModI=\"$ModelI\" RadBudg_ModIvsModII.ncl 
done

echo ''
echo 'Running divPD-PI_ModIvsModII.ncl'
echo ''
for I in {0..7};do
 ncl  plot_type=$I format=\"$plotf\" filepathPD_I=\"$pthI\" filenamePD_I=\"$fnmI\" filepathPD_II=\"$pthII\" filenamePD_II=\"$fnmII\" filenamepPD_I=\"$fnmpI\" filenamepPD_II=\"$fnmpII\" filepathPI_I=\"$pthI_PI\" filenamePI_I=\"$fnmI_PI\" filepathPI_II=\"$pthII_PI\" filenamePI_II=\"$fnmII_PI\" filenamepPI_I=\"$fnmpI_PI\" filenamepPI_II=\"$fnmpII_PI\" ModI=\"$ModelI\" divPD-PI_ModIvsModII.ncl 
done

echo ''
echo 'Running divPD-PI_Zonal_ModIvsModII.ncl'
echo ''
for I in {0..6};do
 ncl  plot_type=$I format=\"$plotf\" filepathPD_I=\"$pthI\" filenamePD_I=\"$fnmI\" filepathPD_II=\"$pthII\" filenamePD_II=\"$fnmII\" filenamepPD_I=\"$fnmpI\" filenamepPD_II=\"$fnmpII\" filepathPI_I=\"$pthI_PI\" filenamePI_I=\"$fnmI_PI\" filepathPI_II=\"$pthII_PI\" filenamePI_II=\"$fnmII_PI\" filenamepPI_I=\"$fnmpI_PI\" filenamepPI_II=\"$fnmpII_PI\" ModI=\"$ModelI\" divPD-PI_Zonal_ModIvsModII.ncl 
done

echo ''
echo 'Running ERF_ModIvsModII.ncl'
echo ''
for I in {0..6};do
 ncl  plot_type=$I format=\"$plotf\" filepathPD_I=\"$pthI\" filenamePD_I=\"$fnmI\" filepathPD_II=\"$pthII\" filenamePD_II=\"$fnmII\" filenamepPD_I=\"$fnmpI\" filenamepPD_II=\"$fnmpII\" filepathPI_I=\"$pthI_PI\" filenamePI_I=\"$fnmI_PI\" filepathPI_II=\"$pthII_PI\" filenamePI_II=\"$fnmII_PI\" filenamepPI_I=\"$fnmpI_PI\" filenamepPI_II=\"$fnmpII_PI\" ModI=\"$ModelI\" ERF_ModIvsModII.ncl 
done

echo ''
echo 'Running Mass-budget_ModIvsModII.ncl'
echo ''
for I in {0..5};do
 ncl plot_type=$I format=\"$plotf\" filepath_I=\"$pthI\" filename_I=\"$fnmI\" filepath_II=\"$pthII\" filename_II=\"$fnmII\" filenamep_I=\"$fnmpI\" filenamep_II=\"$fnmpII\" ModI=\"$ModelI\" Mass-budget_ModIvsModII.ncl
done

echo ''
echo 'All ncl script runs completed'
echo ''

echo "trim whitespace in images"
for i in `ls *.png`
do
  convert -trim $i $i
done

exit
