Here is a C# method that implements the Fortran comparison operators:
public enum CompareType { NC, EQ, GT, GE, LT, LE, NE };
public static bool VComp(byte[] Lvar, byte[] Rvar, CompareType CT,
uint LSBpos, uint MSBpos)
{
if ((Lvar==null)||(Rvar==null)) return false;
bool done=false,vc=false,rdy=false;
uint lim = MinOf((uint)Lvar.Length, (uint)Rvar.Length);
LSBpos = Range(LSBpos, 0, lim); MSBpos = Range(MSBpos, 0, lim);
int incr=1; uint loc = LSBpos;
int count = (int)MaxOf(LSBpos, MSBpos)-(int)MinOf(LSBpos, MSBpos) + 1;
if (MSBpos>=LSBpos) { incr=-1; loc = MSBpos; }
CompareType cond = CompareType.NC;
do
{
int z = Lvar[loc]-Rvar[loc];
if (z>0) cond=CompareType.GT;
else if (z<0) cond=CompareType.LT;
count--;
done = (count <= 0);
if (done&(cond==CompareType.NC)) cond=CompareType.EQ;
loc=(uint)((long)loc + incr);
rdy = (done|(cond!=CompareType.NC));
} while (!rdy);
switch (cond)
{
case CompareType.GT:
switch (CT)
{
case CompareType.NE: vc=true; break;
case CompareType.GT: vc=true; break;
case CompareType.GE: vc=true; break;
}
break;
case CompareType.LT:
switch (CT)
{
case CompareType.NE: vc=true; break;
case CompareType.LT: vc=true; break;
case CompareType.LE: vc=true; break;
}
break;
case CompareType.EQ:
switch (CT)
{
case CompareType.EQ: vc=true; break;
case CompareType.GE: vc=true; break;
case CompareType.LE: vc=true; break;
}
break;
}
return vc;
}
public static UInt32 MinOf(UInt32 int1, UInt32 int2)
{ if (int1<int2) return int1; else return int2; }
public static UInt32 MaxOf(UInt32 int1, UInt32 int2)
{ if (int1>=int2) return int1; else return int2; }
public static UInt32 Range(UInt32 inval, UInt32 LoVal, UInt32 HiVal)
{ if (inval<LoVal) inval=HiVal; else if (inval>HiVal) inval=LoVal; return inval; }
Writer, designer, inventor, musician, observer, and critic with many years of experience in each of these areas. I can do without the approval of "experts" because I believe candid statements and penetrating analysis bring greater rewards than a "pat on the back". And if I have something to say when you're not listening, I tell someone else about it.