Punto informatico Network
Login Esegui login | Non sei registrato? Iscriviti ora (è gratuito!)
Username: Password:
  • Annuncio Pubblicitario

lettura file txt per colonna

Il forum per tutti i developer. Leggere attentamente il regolamento di sezione prima di postare.

lettura file txt per colonna

Messaggioda Skidi » gio set 27, 2012 10:19 am

Salve a tutti, dovrei modificare questo codice :

Codice: Seleziona tutto
#include <stdio.h>
#include <string.h>
#include "sac.h"

#define NDMAX 1500

readdata_(
   fname, ndata,
   o_data,
   t_begin, t_end, t_shift,
   const_a, const_c, fs
   )

int *ndata;
float *t_begin, *t_end, *t_shift;
float *const_a, *const_c, *fs;
float o_data[];
char fname[];

{
   struct sac_header sp;
   float dummy[NDMAX], tb, delt;
   int i, ii, nlen;
   int n_begin, n_end;
   FILE *fp;

   if ((fp=fopen(fname,"rb"))==NULL) {
      fprintf(stderr, "Error opening file %s\n", fname);
   }

/* read header */
   fread(&sp, sizeof(struct sac_header), 1, fp);
   
   nlen=sp.npts;
   tb=sp.b;
   delt=sp.delta;
   *fs=1.0/delt;
   *const_a=sp.user0;
   *const_c=sp.user1;

/* read data */

   fread(dummy, nlen*sizeof(float), 1, fp);

   *t_shift=-*t_begin;
   n_begin=(*t_begin-tb)/delt;
   n_end=(*t_end-tb)/delt;
   *ndata=n_end-n_begin+1;
   
   ii=0;
   for (i=n_begin; i<=n_end; i++) {
      o_data[ii++]=dummy[i];
   }

}   /* end of function */


In modo tale che invece del file binario legga dal file txt tutta la colonna U(KM/S) assegnando i valori all'arrey o_data[]

Codice: Seleziona tutto
 RMODE NFREQ    PERIOD(S) FREQUENCY(Hz)  C(KM/S)      U(KM/S)      ENERGY       GAMMA(1/KM)  ELLIPTICITY
    0     1   0.25000       4.0000       2.9683       2.9683      0.57176E-01   0.0000      0.65563   
    0     2   0.25197       3.9688       2.9683       2.9683      0.56730E-01   0.0000      0.65563   
    0     3   0.25397       3.9375       2.9683       2.9683      0.56283E-01   0.0000      0.65563   
    0     4   0.25600       3.9062       2.9683       2.9683      0.55836E-01   0.0000      0.65563   
    0     5   0.25806       3.8750       2.9683       2.9683      0.55390E-01   0.0000      0.65563   
    0     6   0.26016       3.8438       2.9683       2.9683      0.54943E-01   0.0000      0.65563   
    0     7   0.26230       3.8125       2.9683       2.9683      0.54496E-01   0.0000      0.65563   
    0     8   0.26446       3.7813       2.9683       2.9683      0.54050E-01   0.0000      0.65563   
    0     9   0.26667       3.7500       2.9683       2.9683      0.53603E-01   0.0000      0.65563   
    0    10   0.26891       3.7187       2.9683       2.9683      0.53156E-01   0.0000      0.65563   
    0    11   0.27119       3.6875       2.9683       2.9683      0.52709E-01   0.0000      0.65563   
    0    12   0.27350       3.6562       2.9683       2.9683      0.52263E-01   0.0000      0.65563   
    0    13   0.27586       3.6250       2.9683       2.9683      0.51816E-01   0.0000      0.65563   
    0    14   0.27826       3.5938       2.9683       2.9683      0.51369E-01   0.0000      0.65563   
    0    15   0.28070       3.5625       2.9683       2.9683      0.50923E-01   0.0000      0.65563   
    0    16   0.28319       3.5313       2.9683       2.9683      0.50476E-01   0.0000      0.65563   
    0    17   0.28571       3.5000       2.9683       2.9683      0.50029E-01   0.0000      0.65563   
    0    18   0.28829       3.4688       2.9683       2.9683      0.49583E-01   0.0000      0.65563   
    0    19   0.29091       3.4375       2.9683       2.9683      0.49136E-01   0.0000      0.65563   
    0    20   0.29358       3.4063       2.9683       2.9683      0.48689E-01   0.0000      0.65563   
    0    21   0.29630       3.3750       2.9683       2.9683      0.48243E-01   0.0000      0.65563   
    0    22   0.29907       3.3438       2.9683       2.9683      0.47796E-01   0.0000      0.65563   
    0    23   0.30189       3.3125       2.9683       2.9683      0.47349E-01   0.0000      0.65563   
    0    24   0.30476       3.2812       2.9683       2.9683      0.46903E-01   0.0000      0.65563   
    0    25   0.30769       3.2500       2.9683       2.9683      0.46456E-01   0.0000      0.65563   
    0    26   0.31068       3.2188       2.9683       2.9683      0.46009E-01   0.0000      0.65563   
    0    27   0.31373       3.1875       2.9683       2.9683      0.45562E-01   0.0000      0.65563   
    0    28   0.31683       3.1563       2.9683       2.9683      0.45116E-01   0.0000      0.65563   
    0    29   0.32000       3.1250       2.9683       2.9683      0.44669E-01   0.0000      0.65563   
    0    30   0.32323       3.0938       2.9683       2.9683      0.44222E-01   0.0000      0.65563   
    0    31   0.32653       3.0625       2.9683       2.9683      0.43776E-01   0.0000      0.65563   
    0    32   0.32990       3.0313       2.9683       2.9683      0.43329E-01   0.0000      0.65563   
    0    33   0.33333       3.0000       2.9683       2.9683      0.42882E-01   0.0000      0.65563   
    0    34   0.33684       2.9687       2.9683       2.9683      0.42436E-01   0.0000      0.65563   
    0    35   0.34043       2.9375       2.9683       2.9683      0.41989E-01   0.0000      0.65563   
    0    36   0.34409       2.9063       2.9683       2.9683      0.41542E-01   0.0000      0.65563   
    0    37   0.34783       2.8750       2.9683       2.9683      0.41096E-01   0.0000      0.65563   
    0    38   0.35165       2.8438       2.9683       2.9683      0.40649E-01   0.0000      0.65563   
    0    39   0.35556       2.8125       2.9683       2.9683      0.40202E-01   0.0000      0.65563   
    0    40   0.35955       2.7813       2.9683       2.9683      0.39755E-01   0.0000      0.65563   
    0    41   0.36364       2.7500       2.9683       2.9683      0.39309E-01   0.0000      0.65563   
    0    42   0.36782       2.7188       2.9683       2.9683      0.38862E-01   0.0000      0.65563   
    0    43   0.37209       2.6875       2.9683       2.9683      0.38415E-01   0.0000      0.65563   
    0    44   0.37647       2.6563       2.9683       2.9683      0.37969E-01   0.0000      0.65563   
    0    45   0.38095       2.6250       2.9683       2.9683      0.37522E-01   0.0000      0.65563   
    0    46   0.38554       2.5938       2.9683       2.9683      0.37075E-01   0.0000      0.65563   
    0    47   0.39024       2.5625       2.9683       2.9683      0.36629E-01   0.0000      0.65563   
    0    48   0.39506       2.5313       2.9683       2.9683      0.36182E-01   0.0000      0.65563   
    0    49   0.40000       2.5000       2.9683       2.9683      0.35735E-01   0.0000      0.65563   
    0    50   0.40506       2.4688       2.9683       2.9683      0.35289E-01   0.0000      0.65563   
    0    51   0.41026       2.4375       2.9683       2.9683      0.34842E-01   0.0000      0.65563   
    0    52   0.41558       2.4063       2.9683       2.9683      0.34395E-01   0.0000      0.65563   
    0    53   0.42105       2.3750       2.9683       2.9683      0.33949E-01   0.0000      0.65563   
    0    54   0.42667       2.3438       2.9683       2.9683      0.33502E-01   0.0000      0.65563   
    0    55   0.43243       2.3125       2.9683       2.9683      0.33055E-01   0.0000      0.65563   
    0    56   0.43836       2.2813       2.9683       2.9683      0.32608E-01   0.0000      0.65563   
    0    57   0.44444       2.2500       2.9683       2.9683      0.32162E-01   0.0000      0.65563   
    0    58   0.45070       2.2188       2.9683       2.9683      0.31715E-01   0.0000      0.65563   
    0    59   0.45714       2.1875       2.9683       2.9683      0.31268E-01   0.0000      0.65563   
    0    60   0.46377       2.1563       2.9683       2.9683      0.30822E-01   0.0000      0.65563   
Potete aiutarmi?!?!?
grazie in anticipo
Avatar utente
Skidi
Neo Iscritto
Neo Iscritto
 
Messaggi: 1
Iscritto il: gio set 27, 2012 10:11 am

Torna a Programmazione

Chi c’è in linea

Visitano il forum: Nessuno e 3 ospiti

cron
Powered by phpBB © 2002, 2005, 2007, 2008 phpBB Group
Traduzione Italiana phpBB.it

megalab.it: testata telematica quotidiana registrata al Tribunale di Cosenza n. 22/09 del 13.08.2009, editore Master New Media S.r.l.; © Copyright 2008 Master New Media S.r.l. a socio unico - P.I. 02947530784. GRUPPO EDIZIONI MASTER Spa Tutti i diritti sono riservati. Per la pubblicità: Master Advertising