@echo off
rem	Batch file for handling 4nec2 v4.3 in/output files.
rem	
rem	%1	Command, 'cop'/'som'/'ren'
rem	%2	Som2d groundfile name / source for 'rename'
rem	%3	Nec2d executable name / destination for 'rename'
rem	%4	'pause' if wait for DOS-box
rem	rem	%4	Som2d executable name
rem	rem	%5	'pause' if wait for DOS-box

	echo Args: %1, %2, %3
rem
	set nec2d=%3.exe
rem	set som2d=%4.exe
rem
        if "%1" == "cop" goto cop
        if "%1" == "som" goto som
        if "%1" == "ren" goto ren
        goto gen
:som
rem	Call SOMNEC engine and generate 'arg2' ground-parameter file.
rem
	echo.
	echo Generating new %2 ground file...
	cd exe
	if exist som2d.nec del som2d.nec
rem	%som2d% < som2d.tmp
	somnec2d < som2d.tmp
	echo.
	type som2d.tmp
	cd ..
	copy exe\som2d.nec %2
	if "%4" == "pause" pause
	goto gen
:cop
rem	Copy 'arg2' SOMNEC ground-parameter file to som2d.nec to be used.
rem
	echo.
	echo Using existing %2 ground file.
	copy %2 exe\som2d.nec
	goto gen
:gen
rem	Call NEC2 engine with nec2d.tmp input file and optional som2d.nec ground file
rem
	echo.
	echo Generating new NEC output file, please wait...
	echo.   
	cd exe
	type nec2d.tmp
	%nec2d% < nec2d.tmp
	cd ..
	echo.
	echo Ready...
	echo.
	if "%4" == "pause" pause
	exit
:ren
rem	Delete *.npl and Rename *.nou to *.out
rem
	cd out
	if exist %2.npl del %2.npl
	if exist %3 del %3
	rename %2.nou %3
	cd ..
	exit
