IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37033


Ignore:
Timestamp:
Jul 17, 2014, 10:07:16 AM (12 years ago)
Author:
eugene
Message:

move INITTIME,MARKTIME to libohana; new parsing functions to deal with string-type FITS columns in ohana

Location:
trunk/Ohana/src/libohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/include/ohana.h

    r35754 r37033  
    7171# endif
    7272
     73# define MARKTIME(MSG,...) {                    \
     74    gettimeofday (&stopTimer, (void *) NULL);   \
     75    float dtime = DTIME (stopTimer, startTimer);        \
     76    fprintf (stderr, MSG, __VA_ARGS__); }
     77
     78# define INITTIME \
     79  struct timeval startTimer, stopTimer; \
     80  gettimeofday (&startTimer, (void *) NULL);
     81
    7382#ifdef __GNUC__
    7483#define OHANA_FORMAT(style, fmt, varargs) __attribute__((format(style, fmt, varargs)))
     
    252261int     scan_line              PROTO((FILE *f, char *line));
    253262int     scan_line_maxlen       PROTO((FILE *f, char *line, int maxlen));
     263char   *parse_nextword         PROTO((char *string));
     264char   *parse_nextword_csv     PROTO((char *string));
    254265int     dparse                 PROTO((double *X, int NX, char *line));
    255266int     dparse_csv             PROTO((double *X, int NX, char *line));
    256267int     iparse                 PROTO((int *X, int NX, char *line));
    257268int     iparse_csv             PROTO((int *X, int NX, char *line));
     269int     charparse_csv          PROTO((char *X, int NX, char *line));
     270char   *ptrparse               PROTO((int NX, char *line));
     271char   *ptrparse_csv           PROTO((int NX, char *line));
    258272int     charparse_csv          PROTO((char *X, int NX, char *line));
    259273int     charparse              PROTO((char *X, int NX, char *line));
     
    266280char   *strip_version          PROTO((char *input));
    267281char   *strsubs                PROTO((char *string, char *match, char *with));
     282
     283char   *getword                PROTO((char *string));
     284char   *skipword               PROTO((char *string));
    268285
    269286/* in findexec.c */
  • trunk/Ohana/src/libohana/src/string.c

    r34753 r37033  
    167167}
    168168
    169 char *_parse_nextword (char *string) {
     169char *parse_nextword (char *string) {
    170170
    171171  if (string == (char *) NULL) return ((char *) NULL);
     
    182182// ,,, : go from , to , to , to 0
    183183
    184 char *_parse_nextword_csv (char *string) {
     184char *parse_nextword_csv (char *string) {
    185185
    186186  if (string == (char *) NULL) return ((char *) NULL);
     
    199199  word = line;
    200200  for (i = 0; i < NX - 1; i++)
    201     word = _parse_nextword (word);
     201    word = parse_nextword (word);
    202202
    203203  *X = strtod (word, &ptr);
     
    215215  word = line;
    216216  for (i = 0; i < NX - 1; i++)
    217     word = _parse_nextword_csv (word);
     217    word = parse_nextword_csv (word);
    218218 
    219219  if (word[0] == '"') word[0] = ' ';
     
    237237  word = line;
    238238  for (i = 0; i < NX - 1; i++)
    239     word = _parse_nextword (word);
     239    word = parse_nextword (word);
    240240
    241241  *X = strtol (word, &ptr, 0);
     
    253253  word = line;
    254254  for (i = 0; i < NX - 1; i++)
    255     word = _parse_nextword_csv (word);
     255    word = parse_nextword_csv (word);
    256256 
    257257  if (word[0] == '"') word[0] = ' ';
     
    274274  word = line;
    275275  for (i = 0; i < NX - 1; i++)
    276     word = _parse_nextword (word);
     276    word = parse_nextword (word);
    277277
    278278  *X = word[0];
     
    287287  word = line;
    288288  for (i = 0; i < NX - 1; i++)
    289     word = _parse_nextword_csv (word);
     289    word = parse_nextword_csv (word);
    290290 
    291291  if (word[0] == '"') word[0] = word[1];
     
    299299}
    300300
     301// return a pointer to the start of the desired field
     302char *ptrparse (int NX, char *line) {
     303
     304  int i;
     305  char *word;
     306
     307  word = line;
     308  for (i = 0; i < NX - 1; i++) {
     309    word = parse_nextword (word);
     310  }
     311  return word;
     312}
     313
     314char *ptrparse_csv (int NX, char *line) {
     315
     316  int i;
     317  char *word;
     318
     319  word = line;
     320  for (i = 0; i < NX - 1; i++)
     321    word = parse_nextword_csv (word);
     322 
     323  if (word[0] == '"') word ++;
     324  if (word[0] == ',') return NULL;
     325  return word;
     326}
     327
    301328int tparse (time_t *X, int NX, char *line) {
    302329
     
    306333  word = line;
    307334  for (i = 0; i < NX - 1; i++)
    308     word = _parse_nextword (word);
     335    word = parse_nextword (word);
    309336
    310337  status = ohana_str_to_time (word, X);
     
    320347  word = line;
    321348  for (i = 0; i < NX - 1; i++)
    322     word = _parse_nextword_csv (word);
     349    word = parse_nextword_csv (word);
    323350 
    324351  if (word[0] == '"') word[0] = ' ';
     
    341368  word = line;
    342369  for (i = 0; i < NX - 1; i++)
    343     word = _parse_nextword (word);
     370    word = parse_nextword (word);
    344371
    345372  *X = strtod (word, &ptr);
     
    402429  return (q);
    403430}
     431
     432// return a newly allocated string containing the first complete set of non-whitespace
     433char *getword (char *string) {
     434
     435  int i, j;
     436  char *word;
     437
     438  if (!string) return (NULL);
     439
     440  // find the end of the whitespace (is there any non-whitespace?)
     441  for (i = 0; OHANA_WHITESPACE (string[i]); i++);
     442  if (!string[i]) return (NULL);
     443
     444  for (j = i; string[j] && !OHANA_WHITESPACE(string[j]); j++);
     445  word = strncreate (&string[i], j - i);
     446  return (word);
     447}
     448
     449// returns a pointer to the next word, or NULL if there is not a next word
     450char *skipword (char *string) {
     451
     452  int i;
     453
     454  if (!string) return (NULL);
     455
     456  // find the end of the whitespace (is there any non-whitespace?)
     457  for (i = 0; OHANA_WHITESPACE (string[i]); i++);
     458  if (!string[i]) return (NULL);
     459
     460  // find the end of the non-whitespace (this word)
     461  while (string[i] && !OHANA_WHITESPACE(string[i])) i++;
     462
     463  // find the end of the following whitespace
     464  while (string[i] &&  OHANA_WHITESPACE(string[i])) i++;
     465  if (!string[i]) return (NULL);
     466
     467  return (&string[i]);
     468}
     469
Note: See TracChangeset for help on using the changeset viewer.