Exemplo n.º 1
0
int main(int argc, char **argv)
{
	int i,sum=0,dt,mnth,yr,days=0;
	
	printf("Enter Date Month Year : ");
	scanf("%d%d%d",&dt,&mnth,&yr);

	for(i=1900;i < yr; i++){
		if(i%4 == 0){
			sum += 366;
			}
		else{
			sum += 365;
			}
		}
	if(dt <= 31 && mnth <= 12){
		if(mnth == 2){
			if((yr % 4 == 0 && dt <= 29)  || (yr % 4 != 0 && dt <= 28)){
				days = day(dt,mnth,yr,sum);
				din(days);
				return 0;
				}
			else{
				printf("ERROR");
				return 0;
		       }
			}
		days = day(dt,mnth,yr,sum);
		din(days);
		}
	else{
		printf("ERROR");
		}
	
	//printf("Su\tM\tT\tW\tTH\tF\tSA");


	return 0;
}
Exemplo n.º 2
0
  // Chops pedigrees up into nuclear families
  // failure=0 == success
  // failure=1 == indicates the output isn't large enough (suggest doubling it, which is what the R code does in a recursive fashion)
  void nuclify_cpp( double *data, int *dimData,
                double *dataOut, int *dimDataOut,
                int *failure ) {
    *failure = 0;

    // set up the DataMatrix objects
    DataMatrix din, dout;
    din.set( data, dimData );
    dout.set( dataOut, dimDataOut );

    // do the nuclification
    int start=-1, end=-1;
    //int cpid = 1; // apparently unused?
    int curRow = 0;
    // start by going across all families
    while( din.getNextFamily(start,end) ) {
      int newPid = (int)din(start,C_PID) * 100;
      // pull out each unique mother father pair
      for( int i=start; i<=end; i++ ) {
        int idfath = (int)din(i,C_FATH);
        int idmoth = (int)din(i,C_MOTH);

        int idfathRow = -1;
        int idmothRow = -1;

        int numSibs = 0;
        int sibs[NUCLIFY_MAX_SIBS];
        bool validFamily = true;
        for( int ii=start; ii<=end && validFamily; ii++ ) {
          // We actually _want_ when i==ii to fall through...

          if( idfath==din(ii,C_FATH) && idmoth==din(ii,C_MOTH) ) {
            // we know it's a new/unique sub-family if it hasn't been found before...
            if( ii < i ) {
              validFamily = false;
            }else{
              // we've got a new family!
              sibs[numSibs] = ii;
              numSibs++;
            }
          }else if( din(ii,C_ID) == idfath ) {
            idfathRow = ii;
          }else if( din(ii,C_ID) == idmoth ) {
            idmothRow = ii;
          }
        }
        if( idfath==0 && idmoth==0 ) validFamily = false;
        if( validFamily ) {
          // Then need to push onto the output

          // the father, inserting one if not in the pedigree
          if( idfathRow != -1 ) {
            curRow = pushDataRow( din, idfathRow, dout, curRow, newPid, true );
            if(curRow == (int)dout.R) {*failure = 1; return;}
          }else{
            curRow = pushEmptyRow( dout, curRow, newPid, idfath, SEX_MALE );
            if(curRow == (int)dout.R) {*failure = 1; return;}
          }

          // the mother, ""
          if( idmothRow != -1 ) {
            curRow = pushDataRow( din, idmothRow, dout, curRow, newPid, true );
            if(curRow == (int)dout.R) {*failure = 1; return;}
          }else{
            curRow = pushEmptyRow( dout, curRow, newPid, idmoth, SEX_FEMALE );
            if(curRow == (int)dout.R) {*failure = 1; return;}
          }

          // and all of their children
          for( int ch=0; ch<numSibs; ch++ ) {
            curRow = pushDataRow( din, sibs[ch], dout, curRow, newPid );
            if(curRow == (int)dout.R) {*failure = 1; return;}
          }

          newPid++;
        }
      }
    }

    // set the dims on the output
    dimDataOut[0] = curRow;
  }
Exemplo n.º 3
0
  // returns a more strata friendly family configuration
  // i.e. a random affected (with env if possible),
  //  their parents ONLY if both present,
  //  otherwise it returns a random sibpair
  //
  // Assumes data has been through the 'nuclify' routine,
  //  so data is in nuclear families and the children have
  //  parents, but their parents' parents are marked
  //  as missing
  void strataReduce_cpp( double *data, int *dimData,
                     double *dataOut, int *dimDataOut,
                     int *pEnvCol, int *pm0, int *pm1,
                     int *pMaxSib ) { // new 04/08/2008

    rndAttach(); // RANDOM NUMBER GENERATOR SETUP

    int envCol = *pEnvCol;
    int m0 = *pm0, m1 = *pm1;

    int maxSib = *pMaxSib;

    //cout << "c++ dimDataOut " << dimDataOut[0] << " " << dimDataOut[1] << endl;

    // set up the DataMatrix objects
    DataMatrix din, dout;
    din.set( data, dimData );
    dout.set( dataOut, dimDataOut );

    // do the processing
    int start=-1, end=-1;
    //int cpid = 1; // and still unused!!
    int curRow = 0;
    // go across all the families; note some will not be used
    while( din.getNextFamily(start,end) ) {
      int pid = (int)din(start,C_PID);

      // find the mother/father id's
      int idmoth=-1;
      int idfath=-1;
      int i;
      for( i=start; i<=end; i++ ) {
        if( din(i,C_MOTH)!=0 )
          idmoth = (int)din(i,C_MOTH);
        if( din(i,C_FATH)!=0 )
          idfath = (int)din(i,C_FATH);
      }

      // find all children and parents locations for current family
      // - basic children/parents loc
      //int childRow[100];   // not actually
      int childRowSize=0;  //  needed?
      int parentRow[20];
      int parentRowSize=0;
      // - affected, environmental info, genotyped
      int childRowAffected[100];
      int childRowAffectedSize=0;
      // - genotyped (for sibpair)
      int childRowGeno[100];
      int childRowGenoSize=0;
      // -- so the childRowAffected set is contained in childRowGeno set
      for( i=start; i<=end; i++ ) {
        if( din(i,C_ID)==idfath || din(i,C_ID)==idmoth ) {
          if( parentRowSize==2 ) {
          }else{
            parentRow[parentRowSize] = i;
            parentRowSize++;
          }
        }else{
          //childRow[childRowSize] = i;
          childRowSize++;

          if( din(i,C_AFF)==2                  // affected
              && !ISNAN(din(i,envCol))         // environment
              && din(i,m0)!=0 && din(i,m1)!=0 // genotyped
          ){
            //cout << "affected, env present, genotyped: " << i << endl;
            childRowAffected[childRowAffectedSize] = i;
            childRowAffectedSize++;
          }

          if( din(i,m0)!=0 && din(i,m1)!=0 ) { // genotyped
            childRowGeno[childRowGenoSize] = i;
            childRowGenoSize++;
          }
        }
      }

      // Now push on the friendlier strata data
      // - are the parents there, and allele's not missing?
      if( parentRowSize==2
          && din(parentRow[0],m0)!=0 && din(parentRow[0],m1)!=0
          && din(parentRow[1],m0)!=0 && din(parentRow[1],m1)!=0 ) {
        // yes, we've got both parents!

        // have at least a usable affected?
        if( childRowAffectedSize>0 ) {
          // push the parents on
          for( int p=0; p<2; p++ )
            curRow = pushDataRow( din, parentRow[p], dout, curRow, pid, true );

          // choose a random affected
          curRow = pushDataRow( din, childRowAffected[RandInt(0,childRowAffectedSize-1)], dout, curRow, pid );
        }
      }else{
        // no, we don't

        // have at least a usable affected, and another genotyped?
        if( childRowAffectedSize>0 && childRowGenoSize>1 ) {

          /* GOOD CODE THAT WORKS FOR SIBPAIRS
          // get a random affected (with env, genoed)
          int raff = RandInt(0,childRowAffectedSize-1);
          // get a random other genotyped individual
          int rother = RandInt(0,childRowGenoSize-1);
          //while( rother==raff ) rother = RandInt(0,childRowGenoSize-1);
          while( childRowAffected[raff] == childRowGeno[rother] ) rother = RandInt(0,childRowGenoSize-1);
          // ABOVE WAS A NASTY LITTLE BUG??

          //cout << "raff " << raff << ", rother " << rother << ", childRowAffectedSize " << childRowAffectedSize << ", childRowGenoSize " << childRowGenoSize << endl;
          //cout << childRowAffected[raff] << " -- " << childRowGeno[rother] << endl;

          // push their parents on (as missing)
          for( int p=0; p<2; p++ )
            curRow = pushDataRow( din, parentRow[p], dout, curRow, pid, true, true );

          // and push them both on
          curRow = pushDataRow( din, childRowAffected[raff], dout, curRow, pid );
          curRow = pushDataRow( din, childRowGeno[rother],   dout, curRow, pid, false, false, true );
          */

          // New code that works for more generalized strata
          int affectedRow = childRowAffected[ RandInt( 0, childRowAffectedSize-1 ) ];
          curRow = pushDataRow( din, affectedRow, dout, curRow, pid );
          strataReduceRemove( childRowGeno, childRowGenoSize, affectedRow );

          if( childRowGenoSize+1 <= maxSib ) { // +1 for affected
            // push all offspring on
            for( int c=0; c<childRowGenoSize; c++ )
              curRow = pushDataRow( din, childRowGeno[c], dout, curRow, pid, false, false, true, envCol );
          }else{
            // random # of offspring to push on
            for( int c=1; c<maxSib && childRowGenoSize>0; c++ ) { // +1 for affected
              int unaffectedRow = childRowGeno[ RandInt( 0, childRowGenoSize-1 ) ]; // not really unaffected, but will be marked that way
              curRow = pushDataRow( din, unaffectedRow, dout, curRow, pid, false, false, true );
              strataReduceRemove( childRowGeno, childRowGenoSize, unaffectedRow );
            }
          }
        }
      }
    }

    // set the dims on the output
    dimDataOut[0] = curRow;
    //cout << "dimDataOut[0] " << dimDataOut[0] << " curRow " << curRow << endl;

    rndDetach(); // RANDOM NUMBER GENERATOR CLEANUP
  }
Exemplo n.º 4
0
int CoreProtocol::wireToTransfer( const QByteArray& wire )
{
	kDebug(YAHOO_RAW_DEBUG) ;
	// processing incoming data and reassembling it into transfers
	// may be an event or a response
	
	uint bytesParsed = 0;
			
	if ( wire.size() < 20 ) // minimal value of a YMSG header
	{
		m_state = NeedMore;
		return bytesParsed;
	}
	
	QByteArray tempWire = wire;
	QDataStream din( &tempWire, QIODevice::ReadOnly );
	
	// look at first four bytes and decide what to do with the chunk
	if ( okToProceed( din ) )
	{
		if ( (wire[0] == 'Y') && (wire[1] == 'M') && (wire[2] == 'S') && (wire[3] == 'G'))
		{
// 			kDebug(YAHOO_RAW_DEBUG) << " - looks like a valid YMSG packet";
			YMSGTransfer *t = static_cast<YMSGTransfer *>(m_YMSGProtocol->parse( wire, bytesParsed ));
// 			kDebug(YAHOO_RAW_DEBUG) << " - YMSG Protocol parsed " << bytesParsed << " bytes";
			if ( t )
			{
				if( wire.size() < t->packetLength() )
				{
					m_state = NeedMore;
					delete t;
					return 0;
				}
				m_inTransfer = t;
// 				kDebug(YAHOO_RAW_DEBUG) << " - got a valid packet ";
				
				m_state = Available;
				emit incomingData();
			}
			else
				bytesParsed = 0;
		}
		else 
		{ 
			kDebug(YAHOO_RAW_DEBUG) << " - not a valid YMSG packet. Trying to recover.";
			QTextStream s( wire, QIODevice::ReadOnly );
			QString remaining = s.readAll();
			int pos = remaining.indexOf( "YMSG", bytesParsed );
			if( pos >= 0 )
			{
				kDebug(YAHOO_RAW_DEBUG) << "Recover successful.";
				bytesParsed += pos;
			}
			else
			{
				kDebug(YAHOO_RAW_DEBUG) << "Recover failed. Dump it!";
				bytesParsed = wire.size();
			}
		}
	}
	return bytesParsed;
}