Thread: Read ASCII file into matrix in C++

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    8

    Read ASCII file into matrix in C++

    Hello everybody,

    I got a stuck in my work ... I have ASCII file with numerical values, and I need to read them and save them in a matrix of 2 dimensions?.... If anyone can help me please ....!!???

    Looking forward to any help
    Cheers

    P.S. the dimension of ascii data is 68 by 65 and it looks like:
    ;
    ; ENVI ASCII Output of file: [Memory1] (66x68x1) [Tue Nov 02 11:45:08 2010]
    ; File Dimensions: 66 samples x 68 lines x 1 band
    ; Line Format : (66f14.4)
    ;
    0.8442 0.8343 0.8163 0.8261 0.8235 0.8188 0.8204 0.8364 0.8571 0.8490 0.8505 0.8483 0.8528 0.8338 0.8373 0.8462 0.8417 0.8440 0.8538 0.8519 0.8625 0.8471 0.8529 0.8586 0.8720 0.8512 0.8436 0.8356 0.8356 0.8333 0.8483 0.8462 0.8462 0.8092 0.7759 0.7410 0.8000 0.7993 0.8067 0.8436 0.8047 0.8165 0.8182 0.8117 0.8117 0.8261 0.7985 0.8416 0.8362 0.8188 0.8280 0.8489 0.8411 0.8411 0.8258 0.7818 0.7714 0.7436 0.7816 0.8393 0.8381 0.8601 0.8484 0.8364 0.8505 0.8478
    0.8428 0.8343 0.8188 0.8286 0.8261 0.8132 0.8204 0.8380 0.8462 0.8602 0.8589 0.8483 0.8652 0.8496 0.8436 0.8462 0.8498 0.8373 0.8373 0.8333 0.8519 0.8576 0.8544 0.8586 0.8734 0.8560 0.8563 0.8356 0.8440 0.8498 0.8557 0.8333 0.8333 0.8212 0.7507 0.7855 0.8118 0.8067 0.8297 0.8117 0.8373 0.8141 0.8235 0.8169 0.7898 0.8258 0.8356 0.8430 0.8393 0.8398 0.8141 0.8448 0.8393 0.8238 0.8380 0.8304 0.7428 0.6972 0.7799 0.8462 0.8065 0.8484 0.8561 0.8505 0.8520 0.8462
    0.8442 0.8269 0.8269 0.8118 0.8327 0.8327 0.8118 0.8116 0.8428 0.8589 0.8638 0.8586 0.8512 0.8448 0.8395 0.8235 0.8333 0.8373 0.8169 0.8356 0.8457 0.8430 0.8529 0.8560 0.8720 0.8571 0.8667 0.8528 0.8576 0.8436 0.8519 0.8395 0.8498 0.8373 0.8117 0.8188 0.8356 0.8182 0.8226 0.8258 0.8188 0.7993 0.7993 0.7927 0.8329 0.8478 0.8393 0.8362 0.8411 0.8235 0.8436 0.8398 0.8269 0.8085 0.8311 0.8529 0.8092 0.8067 0.8165 0.8329 0.7895 0.8027 0.8362 0.8462 0.8490 0.8364
    0.8513 0.8364 0.8235 0.8103 0.8161 0.7923 0.7840 0.8304 0.8244 0.7982 0.7816 0.8182 0.8182 0.8466 0.8457 0.8417 0.8216 0.8310 0.8356 0.8457 0.8430 0.8380 0.8544 0.8696 0.8720 0.8586 0.8720 0.8667 0.8652 0.8412 0.8483 0.8519 0.8457 0.8338 0.8235 0.8258 0.8258 0.8297 0.8117 0.8235 0.8141 0.8161 0.8212 0.8292 0.8426 0.8544 0.8411 0.8483 0.8512 0.8412 0.8457 0.8226 0.8378 0.8411 0.8601 0.8347 0.8362 0.8362 0.8445 0.8278 0.8380 0.7901 0.8289 0.8362 0.8529 0.8430
    0.8513 0.8520 0.8297 0.8216 0.7752 0.7857 0.7754 0.7947 0.7755 0.7347 0.7460 0.7976 0.8430 0.8457 0.8483 0.8498 0.8310 0.8416 0.8576 0.8545 0.8640 0.8529 0.8720 0.8586 0.8571 0.8544 0.8571 0.8544 0.8560 0.8466 0.8462 0.8235 0.8235 0.8297 0.8395 0.8117 0.8182 0.8457 0.8182 0.8318 0.8165 0.8417 0.8471 0.8324 0.8381 0.8311 0.8428 0.8529 0.8601 0.8560 0.8592 0.8280 0.8457 0.8496 0.8426 0.8411 0.8278 0.8478 0.8535 0.8478 0.8445 0.8380 0.8398 0.8509 0.8416 0.8356
    0.8578 0.8575 0.8512 0.8483 0.8092 0.7923 0.7687 0.7778 0.7791 0.7414 0.7913 0.7985 0.8483 0.8333 0.8333 0.8373 0.8356 0.8519 0.8395 0.8528 0.8652 0.8490 0.8234 0.8182 0.8529 0.8681 0.8571 0.8496 0.8436 0.8417 0.8373 0.8216 0.8118 0.8118 0.8356 0.8118 0.8608 0.8359 0.8182 0.8235 0.8280 0.8457 0.8471 0.8338 0.8182 0.8182 0.8201 0.8292 0.8458 0.8483 0.8529 0.8590 0.8509 0.8496 0.8394 0.8218 0.8380 0.8347 0.8535 0.8520 0.8544 0.8411 0.8496 0.8304 0.8235 0.8356

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM