[MAIN]
// Entry point for User prompt for file
// Menu Import uses APPFILE.OGS for file selection and extension 'steering'
if(run.section(,Init) == 0)
{
	run.section(,Import);
}


[GetFile]
// Let the user pick a file
run.section(file, init);
FDLOG.UseGroup(SigmaPlot);
FDLOG.Message $= "";
FDLOG.DlgName $= $OMRDJNB.Shell.Dialog;
if (FDLOG.open(A) == 0/0) return 1;
FDLOG.DlgName $= "";
return 0;


[Import]
%M = %A;
nn = system.path.findtemp(L,tjnb,*.jnw);
%B = %Ltjnb\;
cdf.inputfilename $= %A;
cdf.outputpath $= %B;
cdf.outputbasefilename $= TEMP;
cdf.outputfileext $= jnw;
jnbwkscount = cdf.extractstreams(JNBContents);
for(ii = 1; ii <= jnbwkscount; ii++)
{
	%A = cdf.outputfilenames$(ii)$;
	nn = readjnb(%A, %H); // 0 = New format, 99 = Old Format, 2 = Text+Binary
	if(nn == 99)
	{
		fid = file.open(%A);
		doc -uw;
		%N = %H;
		file.sigmawin(%N,fid);
		file.close();
	}
	if(nn == 0 || nn == 99)
	{
		page.label $= %M;
		page.title = 3;
	}
	if(ii != jnbwkscount && (nn == 0 || nn == 99)) win -t data origin;
	// No new worksheet for Text+Binary
	if(ii == jnbwkscount && nn == 2) win -c %H;
}
return 0;


[Init]
dll -a cdf odcfl;
if(run.LoadOC("OriginLab\readjnb.ocw",4))
{
	type -b $OMRDJNB.Errors.Load;
	return 1;
}
return 0;


[OnDrop]
// Entry point for Drag-and-Drop (if enabled in DOFILE.OGS)
if(run.section(, Init) == 0)
{
	win -t data origin;
	run.section(,import);
}

