Find the answer to your Linux question:
Results 1 to 2 of 2
hii guys I have problem with writing a c code for the below given situation.... if any one can help i will be thankful... # vtk DataFile Version 2.0 domain ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    1

    Request for a c language code on this problem

    hii guys

    I have problem with writing a c code for the below given situation.... if any one can help i will be thankful...

    # vtk DataFile Version 2.0
    domain (-0.0632896 -0.0907457 0.0352253) (0.0529952 0.0466294 0.36524) Resolution 0.005 0.005 0.005
    ASCII
    DATASET POLYDATA
    POINTS 45024 float
    -0.060867 -0.0882926 0.0376881 -0.0560218 -0.0882926 0.0376881 -0.0511766 -0.0882926 0.0376881 -0.0463314 -0.0882926
    0.0376881 -0.0414862 -0.0882926 0.0376881 -0.036641 -0.0882926 0.0376881 -0.0317958 -0.0882926 0.0376881
    -0.0269506 -0.0882926 0.0376881 -0.0221054 -0.0882926 0.0376881 -0.0172602 -0.0882926 0.0376881 -0.012415
    -0.0882926 0.0376881 -0.00756981 -0.0882926 0.0376881 -0.00272461 -0.0882926 0.0376881 0.00212058 -0.0882926
    0.0376881 0.00696578 -0.0882926 0.0376881 0.011811 -0.0882926 0.0376881 0.0166562 -0.0882926 0.0376881
    0.0215014 -0.0882926 0.0376881 0.0263466 -0.0882926 0.0376881 0.0311918 -0.0882926 0.0376881 0.036037
    -0.0882926 0.0376881 0.0408822 -0.0882926 0.0376881 0.0457274 -0.0882926 0.0376881 0.0505726 -0.0882926
    0.0376881 -0.060867 -0.0833863 0.0376881 -0.0560218 -0.0833863 0.0376881 -0.0511766 -0.0833863 0.0376881
    -0.0463314 -0.0833863 0.0376881 -0.0414862 -0.0833863 0.0376881 -0.036641 -0.0833863 0.0376881 -0.0317958
    -0.0833863 0.0376881 -0.0269506 -0.0833863 0.0376881 -0.0221054 -0.0833863 0.0376881 -0.0172602 -0.0833863
    0.0376881 -0.012415 -0.0833863 0.0376881 -0.00756981 -0.0833863 0.0376881 -0.00272461 -0.0833863 0.0376881
    0.00212058 -0.0833863 0.0376881 0.00696578 -0.0833863 0.0376881 0.011811 -0.0833863 0.0376881 0.0166562
    -0.0833863 0.0376881 0.0215014 -0.0833863 0.0376881 0.0263466 -0.0833863 0.0376881 0.0311918 -0.0833863
    0.0376881 0.036037 -0.0833863 0.0376881 0.0408822 -0.0833863 0.0376881 0.0457274 -0.0833863 0.0376881
    0.0505726 -0.0833863 0.0376881 -0.060867 -0.07848 0.0376881 -0.0560218 -0.07848 0.0376881 -0.0511766
    -0.07848 0.0376881 -0.0463314 -0.07848 0.0376881 -0.0414862 -0.07848 0.0376881 -0.036641 -0.07848
    0.0376881 -0.0317958 -0.07848 0.0376881 -0.0269506 -0.07848 0.0376881 -0.0221054 -0.07848 0.0376881
    -0.0172602 -0.07848 0.0376881 -0.012415 -0.07848 0.0376881 -0.00756981 -0.07848 0.0376881 -0.00272461
    -0.07848 0.0376881 0.00212058 -0.07848 0.0376881 0.00696578 -0.07848 0.0376881 0.011811 -0.07848
    0.0376881 0.0166562 -0.07848 0.0376881 0.0215014 -0.07848 0.0376881 0.0263466 -0.07848 0.0376881
    0.0311918 -0.07848 0.0376881 0.036037 -0.07848 0.0376881 0.0408822 -0.07848 0.0376881 0.0457274
    -0.07848 0.0376881 0.0505726 -0.07848 0.0376881 -0.060867 -0.0735738 0.0376881 -0.0560218 -0.0735738
    0.0376881 -0.0511766 -0.0735738 0.0376881 -0.0463314 -0.0735738 0.0376881 -0.0414862 -0.0735738 0.0376881
    -0.036641 -0.0735738 0.0376881 -0.0317958 -0.0735738 0.0376881 -0.0269506 -0.0735738 0.0376881 -0.0221054
    -0.0735738 0.0376881 -0.0172602 -0.0735738 0.0376881 -0.012415 -0.0735738 0.0376881 -0.00756981 -0.0735738
    0.0376881 -0.00272461 -0.0735738 0.0376881 0.00212058 -0.0735738 0.0376881 0.00696578 -0.0735738 0.0376881
    0.011811 -0.0735738 0.0376881 0.0166562 -0.0735738 0.0376881 0.0215014 -0.0735738 0.0376881 0.0263466
    -0.0735738 0.0376881 0.0311918 -0.0735738 0.0376881 0.036037 -0.0735738 0.0376881 0.0408822 -0.0735738



    now these are supposedly the locations of points in x, y, z co-ordinates starting from the first as x y z x y z x y z etc etc.
    now i would like to arrange these values of x, y , z etc each columns... i.e put the values of x under one column, values of y under one column so on and so forth.

    i need to write a c code to help me do.. can anyone tell me how it is done. or if anyone can give me a pre written program that will be really appreciated

    Thank you

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Well let's think about this.

    You have 3 collections of data: x, y, and z. I assume that the final file is supposed to look like:
    Code:
    ---- X ----   ---- Y ----   ---- Z ----
    x1            y1            z1
    x2            y2            z2
    ...
    So basically, we just need to do 2 things:

    1) Identify when in the file the coords start
    2) Figure out how to store this information

    Step 1), you're on your own. Assuming that "float" is always the last word before the coords, you could just find that line and assume that everything after it is a coord. Up to you.

    2) is the meat of the matter. We know that the values are x y z x y z x y z, etc. So you can just read each value, and keep track of what sort of field it is. So for instance, something like:
    Code:
    enum field_stat = { X, Y, Z };
    char xs[50];
    char ys[50];
    char zs[50];
    field_stat fs = X;
    int x_pos, y_pos, z_pos;
    x_pos = y_pos = z_pos = 0;
    
    while(more_values)
    {
      char *current = get_current_coord_piece();
    
      switch(fs)
      {
        case X:
          xs[x_pos++] = current;
          break;
        case Y:
          ys[y_pos++] = current;
          break;
        case Z:
          zs[z_pos++] = current;
          break;
      }
    
      fs = (fs + 1) % 3;
    Do you understand basically what this code does? It reads each coordinate piece, and adds it to the proper array. Then, once you've gone through the entire file, you can just iterate through the three arrays and print out the values in columns.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...