int main()
{

    FILE *myFile1;
    FILE *myFile2;
    FILE *myFile3;
    char *filename="c.txt";
    myFile1 = fopen(filename, "r");
    if (myFile1 == NULL)
    {
        printf("Error Reading File\n");
        exit (0);
    }
    printf("all is well \n");

    /*get number of lines in the file*/
    int r=getNumberOfLines(myFile1);
    fclose(myFile1);

    myFile2 = fopen(filename, "r");
    if (myFile2 == NULL)
    {
        printf("Error Reading File\n");
        exit (0);
    }
    int c=getNumberOfColumns(myFile2);
    fclose(myFile2);
    printf("r=%d and c=%d\n",r,c);
    char *line=NULL;
    char *word=NULL;
    int attr;
    int i,j;
    size_t len = 0;
    ssize_t read;
    printf("r=%d and c=%d\n",r,c);

    myFile3 = fopen(filename, "r");
    if (myFile3 == NULL)
    {
        printf("Error Reading File\n");
        exit (0);
    }
    float *dataset[r];
    for (i=0; i<r; i++)
         dataset[i] = (float *)malloc(c * sizeof(float));
    i=0;
    while ((read = getline(&line, &len, myFile3)) != -1) {
        
        j=0;

        do{
            word=strsep(&line,",");
            attr = atoi(word);
            dataset[i][j]=(float)attr;
            j++;
        }while(line!=NULL && word!=NULL);
        i++;           
        
    }
    fclose(myFile3);

    printMatrix(dataset, r,c);

    freeData(dataset, r,c);

    return 0;
}
Exemplo n.º 2
0
/**
 * Used internally by update() to add a text line created with
 * default values and alignment to this text container.
 *
 * @param textLine The text line.
 * @param lineCounter Line number.
 *
 * @return  distance over the text base-line
 */
double RS_MText::updateAddLine(RS_EntityContainer* textLine, int lineCounter) {
    double ls =5.0/3.0;

    RS_DEBUG->print("RS_Text::updateAddLine: width: %f", textLine->getSize().x);

        //textLine->forcedCalculateBorders();
    //RS_DEBUG->print("RS_Text::updateAddLine: width 2: %f", textLine->getSize().x);

    // Move to correct line position:
    textLine->move(RS_Vector(0.0, -9.0 * lineCounter
                             * data.lineSpacingFactor * ls));

    if( ! RS_EntityContainer::autoUpdateBorders) {
        //only update borders when needed
        textLine->forcedCalculateBorders();
    }
    RS_Vector textSize = textLine->getSize();

        RS_DEBUG->print("RS_Text::updateAddLine: width 2: %f", textSize.x);

    // Horizontal Align:
    switch (data.halign) {
    case RS_MTextData::HACenter:
                RS_DEBUG->print("RS_Text::updateAddLine: move by: %f", -textSize.x/2.0);
        textLine->move(RS_Vector(-textSize.x/2.0, 0.0));
        break;

    case RS_MTextData::HARight:
        textLine->move(RS_Vector(-textSize.x, 0.0));
        break;

    default:
        break;
    }

    // Vertical Align:
    double vSize = getNumberOfLines()*9.0*data.lineSpacingFactor*ls
                   - (9.0*data.lineSpacingFactor*ls - 9.0);

    switch (data.valign) {
    case RS_MTextData::VAMiddle:
        textLine->move(RS_Vector(0.0, vSize/2.0));
        break;

    case RS_MTextData::VABottom:
        textLine->move(RS_Vector(0.0, vSize));
        break;

    default:
        break;
    }

    // Scale:
    textLine->scale(RS_Vector(0.0,0.0),
                    RS_Vector(data.height/9.0, data.height/9.0));

    textLine->forcedCalculateBorders();

    // Update actual text size (before rotating, after scaling!):
    if (textLine->getSize().x>usedTextWidth) {
        usedTextWidth = textLine->getSize().x;
    }

    usedTextHeight += data.height*data.lineSpacingFactor*ls;

    // Gets the distance over text base-line (before rotating, after scaling!):
    double textTail = textLine->getMin().y;

    // Rotate:
    textLine->rotate(RS_Vector(0.0,0.0), data.angle);

    // Move:
    textLine->move(data.insertionPoint);
    textLine->setPen(RS_Pen(RS2::FlagInvalid));
    textLine->setLayer(NULL);
    textLine->forcedCalculateBorders();

    addEntity(textLine);
    return textTail;
}
Exemplo n.º 3
0
 void setScrollBarVerticalValueRangeChangedCallback(Callback<long,long,long>::Ptr callback) {
     scrollBarVerticalValueRangeChangedCallback = callback;
     scrollBarVerticalValueRangeChangedCallback->call(getNumberOfLines(), visibleLines, getTopLineNumber());
 }
Exemplo n.º 4
0
ossimProjection* ossimMrSidReader::getGeoProjection()
{
   if (theReader == 0)
      return 0;

   // A local KWL will be filled as items are read from the support data. At the end,
   // the projection factory will be provided with the populated KWL to instantiate proper 
   // map projection. No prefix needed.
   ossimKeywordlist kwl; 

   // Add the lines and samples.
   kwl.add(ossimKeywordNames::NUMBER_LINES_KW, getNumberOfLines(0));
   kwl.add(ossimKeywordNames::NUMBER_SAMPLES_KW, getNumberOfSamples(0));

   ossimString proj_type;
   ossimString datum_type;
   ossimString scale_units;
   ossimString tie_pt_units = "meters";

   ossim_uint32 code = 0;
   ossim_uint32 gcsCode = 0;
   ossim_uint32 pcsCode = 0;

   const LTIGeoCoord& geo = theReader->getGeoCoord();
   LTIMetadataDatabase metaDb = theReader->getMetadata();
   const char* projStr = geo.getWKT();

   // Can only handle non-rotated images since only projection object returned (no 2d transform):
   if( (geo.getXRot() != 0.0) || (geo.getYRot() != 0.0))
      return 0;

   bool gcsFound = getMetadataElement(metaDb, "GEOTIFF_NUM::2048::GeographicTypeGeoKey", &gcsCode);
   bool pcsFound = getMetadataElement(metaDb, "GEOTIFF_NUM::3072::ProjectedCSTypeGeoKey", &pcsCode);

   if (gcsFound && pcsCode == false)
   {
      code = gcsCode;
      kwl.add(ossimKeywordNames::TYPE_KW, "ossimEquDistCylProjection");
      proj_type = "ossimEquDistCylProjection";
      kwl.add(ossimKeywordNames::GCS_CODE_KW, code);
      tie_pt_units = "degrees";

      // Assign units if set in Metadata
      char unitStr[200];
      if (getMetadataElement(metaDb, "GEOTIFF_CHAR::GeogAngularUnitsGeoKey", &unitStr, sizeof(unitStr)) == true)
      {
         ossimString unitTag(unitStr);
         if ( unitTag.contains("Angular_Degree") ) // decimal degrees
            scale_units = "degrees";
         else if ( unitTag.contains("Angular_Minute") ) // decimal minutes
            scale_units = "minutes";
         else if ( unitTag.contains("Angular_Second") ) // decimal seconds
            scale_units = "seconds";
      }
   }
   else 
   {
      if (!pcsFound)
      {
         pcsFound = getMetadataElement(metaDb, "GEOTIFF_NUM::3074::ProjectionGeoKey", &code);
      }
      else
      {
        code = pcsCode;
      }
      if (pcsFound)
      {
         kwl.add(ossimKeywordNames::PCS_CODE_KW, code);
         tie_pt_units = "meters";

         char unitStr[200];
         if (getMetadataElement(metaDb, "GEOTIFF_CHAR::ProjLinearUnitsGeoKey", &unitStr, 
                                sizeof(unitStr)))
         {
            ossimString unitTag(unitStr);
            if ( unitTag.contains("Linear_Meter") ) 
               scale_units = "meters";
            else if ( unitTag.contains("Linear_Foot") ) 
               scale_units = "feet";
            else if ( unitTag.contains("Linear_Foot_US_Survey") ) 
               scale_units = "us_survey_feet";
         }
      }
   }

   char rasterTypeStr[200];
   strcpy( rasterTypeStr, "unnamed" );
   double topLeftX = geo.getX(); // AMBIGUOUS! OLK 5/10
   double topLeftY = geo.getY(); // AMBIGUOUS! OLK 5/10
   if (getMetadataElement(metaDb, "GEOTIFF_CHAR::GTRasterTypeGeoKey", &rasterTypeStr, sizeof(rasterTypeStr)) == true)
   {
      ossimString rasterTypeTag(rasterTypeStr);

      // If the raster type is pixel_is_area, shift the tie point by
      // half a pixel to locate it at the pixel center. 
      if ( rasterTypeTag.contains("RasterPixelIsPoint") )
      {
         topLeftX -= geo.getXRes() / 2.0;  // AMBIGUOUS -- DOESN'T MATCH COMMENT! OLK 5/10
         topLeftY += geo.getYRes() / 2.0;  // AMBIGUOUS! OLK 5/10
      }
   }
   ossimDpt gsd(fabs(geo.getXRes()), fabs(geo.getYRes()));
   ossimDpt tie(topLeftX, topLeftY);

   // CANNOT HANDLE 2D TRANSFORMS -- ONLY REAL PROJECTIONS. (OLK 5/10)
   //std::stringstream mString;
   //// store as a 4x4 matrix
   //mString << ossimString::toString(geo.getXRes(), 20)
   //  << " " << ossimString::toString(geo.getXRot(), 20)
   //  << " " << 0 << " "
   //  << ossimString::toString(geo.getX(), 20)
   //  << " " << ossimString::toString(geo.getYRot(), 20)
   //  << " " << ossimString::toString(geo.getYRes(), 20)
   //  << " " << 0 << " "
   //  << ossimString::toString(geo.getY(), 20)
   //  << " " << 0 << " " << 0 << " " << 1 << " " << 0
   //  << " " << 0 << " " << 0 << " " << 0 << " " << 1;
   //kwl.add(ossimKeywordNames::IMAGE_MODEL_TRANSFORM_MATRIX_KW, mString.str().c_str());

   // if meta data does not have the code info, try to read from .aux file
   if (code == 0)
   {
      ossimFilename auxFile = theImageFile;
      auxFile.setExtension("aux");
      ossimAuxFileHandler auxHandler;
      if (auxFile.exists() && auxHandler.open(auxFile))
      {
         ossimString proj_name = auxHandler.getProjectionName();
         ossimString datum_name = auxHandler.getDatumName();
         ossimString unitType = auxHandler.getUnitType();

         // HACK: Geographic projection is specified in non-WKT format. Intercepting here. OLK 5/10
         // TODO: Need projection factory that can handle miscellaneous non-WKT specs as they are 
         //       encountered. 
         if (proj_name.contains("Geographic"))
         {
            kwl.add(ossimKeywordNames::TYPE_KW, "ossimEquDistCylProjection", false);
            scale_units = "degrees";
            tie_pt_units = "degrees";
         }
         else
         {
            // pass along MrSid's projection name and pray it can be resolved:
            kwl.add(ossimKeywordNames::PROJECTION_KW, proj_name, false);
            if (unitType.empty())
            {
               if (proj_name.downcase().contains("feet"))
               {
                  scale_units = "feet";
                  tie_pt_units = "feet";
               }
            }
            else
            {
               scale_units = unitType;
               tie_pt_units = unitType;
            }
         }

         // HACK: WGS-84 is specified in non-WKT format. Intercepting here. OLK 5/10
         // TODO: Need datum factory that can handle miscellaneous non-WKT specs as they are 
         //       encountered. 
         if (datum_name.contains("WGS") && datum_name.contains("84"))
            kwl.add(ossimKeywordNames::GCS_CODE_KW, "EPSG:4326");
         else
            kwl.add(ossimKeywordNames::DATUM_KW, datum_name, false);
      }
   }

   kwl.add(ossimKeywordNames::PIXEL_SCALE_XY_KW, gsd.toString());
   kwl.add(ossimKeywordNames::PIXEL_SCALE_UNITS_KW, scale_units);
   kwl.add(ossimKeywordNames::TIE_POINT_XY_KW, tie.toString());
   kwl.add(ossimKeywordNames::TIE_POINT_UNITS_KW, tie_pt_units);

   ossimProjection* proj = 
      ossimProjectionFactoryRegistry::instance()->createProjection(kwl);
   return proj;
}
Exemplo n.º 5
0
bool ossimMrSidReader::computeDecimationFactors(
   std::vector<ossimDpt>& decimations) const
{
   bool result = true;

   decimations.clear();

   const ossim_uint32 LEVELS = getNumberOfDecimationLevels();

   for (ossim_uint32 level = 0; level < LEVELS; ++level)
   {
      ossimDpt pt;

      if (level == 0)
      {
         // Assuming r0 is full res for now.
         pt.x = 1.0;
         pt.y = 1.0;
      }
      else
      {
         // Get the sample decimation.
         ossim_float64 r0 = getNumberOfSamples(0);
         ossim_float64 rL = getNumberOfSamples(level);
         if ( (r0 > 0.0) && (rL > 0.0) )
         {
            pt.x = rL / r0;
         }
         else
         {
            result = false;
            break;
         }

         // Get the line decimation.
         r0 = getNumberOfLines(0);
         rL = getNumberOfLines(level);
         if ( (r0 > 0.0) && (rL > 0.0) )
         {
            pt.y = rL / r0;
         }
         else
         {
            result = false;
            break;
         }
      }

      decimations.push_back(pt);
   }

   if (traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimMrSidReader::computeDecimationFactors DEBUG\n";
      for (ossim_uint32 i = 0; i < decimations.size(); ++i)
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "decimation[" << i << "]: " << decimations[i]
            << std::endl;
      }
   }

   return result;
}
Exemplo n.º 6
0
int main(int argc, char* argv[])
{
/**************************** config **********************************/
    int N = 512;
    int scaleby = 16384;
/**********************************************************************/

    if ( argc != 3 ) {
        printf( "usage: %s input-file-name output-file-name\n", argv[0] );
        return 1;
    }
    char* fin = argv[1];
    char* fout = argv[2];
    
    int i,j,axis;
    int nLines = getNumberOfLines(fin);
    int log2nLines = fix_log2(nLines);
    int padLines = (1<<(log2nLines+1)) - nLines;
    int dataLines = 1<<(log2nLines+1);

    // FFT size and input signal size
    int log2n = fix_log2(N);
    int loops = dataLines>>log2n;

    // read CSV and pad with 0's until the next power of 2^m
    readCSV(fin, 6, 0, nLines);
    for ( i=0; i<padLines; ++i ) {
        for ( axis=0; axis<6; ++axis ) {
            dataIn[nLines+i][axis] = 0;
        }
    }

    for ( axis=0; axis<6; ++axis ) {
    
        // remove the mean, keep only signal with amp > 1, and scale the data
        int sum = 0, mean = 0;
        for ( j=0; j<nLines; j++ ) {
            sum += dataIn[j][axis];
        }    
        mean = sum>>log2nLines;
        for ( j=0; j<nLines; j++ ) {
            dataIn[j][axis] -= mean;
        }
        int scalefactor = fix_log2(scaleby);
        for ( j=0; j<nLines; j++ ) {
            if (dataIn[j][axis] != 0) {
                dataIn[j][axis] <<= scalefactor;
            }
        }

        // loop over the data in N segments and FFT
        int re[N], im[N], amp[N];
        for ( j=0; j<N; ++j ) { amp[j] = 0; }
        for ( j=0; j<loops; ++j ) {
            for( i=0; i<N; i++ ) {
                im[i] = 0;
                re[i] = dataIn[N*j+i][axis];
            }

            // compute the FFT of the samples
            fix_fft(re,im,log2n,0);

            for (i=1; i<N; i++){
                amp[i] += re[i]*re[i] + im[i]*im[i];
            }
        }

        // average the frequency-bin amplitudes over nonzero sampled dataset
        int nonzeros = 0;
        for ( j=0; j<N; ++j ) {
            if ( amp[j] != 0 ) ++nonzeros;
        }
        for ( j=1; j<N; j++ ) {
            amp[j] = sqrt(amp[j]);
            amp[j] >>= fix_log2(nonzeros);
        }
        
        // store in six-axis array
        for ( j=0; j<N; ++j ) {
            ampFull[j][axis] = amp[j];
        }
    }

    writeCSV(fout, ampFull, 6, N/2);

    return 0;
}