table.c 1.54 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
2
3
4
/*
  This file is part of CDO. CDO is a collection of Operators to
  manipulate and analyse Climate model Data.

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
  Copyright (C) 2003-2014 Uwe Schulzweida, Uwe.Schulzweida@zmaw.de
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  See COPYING file for copying and redistribution conditions.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

Ralf Mueller's avatar
Ralf Mueller committed
23
#include <cdi.h>
Uwe Schulzweida's avatar
Uwe Schulzweida committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "cdo.h"
#include "error.h"


#ifndef  UNDEFID
#define  UNDEFID  CDI_UNDEFID
#endif


int defineTable(char *tablearg)
{
  char *tablename;
  int tableID = UNDEFID;

  tablename = tablearg;

  tableID = tableRead(tablename);

  if ( tableID == UNDEFID )
    {
      char *tablepath = getenv("CD_TABLEPATH");

      if ( tablepath )
	{
	  char *tablefile = NULL;
	  int len = sizeof(tablepath) + sizeof(tablename) + 3;
	  tablefile = (char *) malloc(len);
	  strcpy(tablefile, tablepath);
	  strcat(tablefile, "/");
	  strcat(tablefile, tablename);
	  tableID = tableRead(tablefile);
	  free(tablefile);
	}
    }

  if ( tableID == UNDEFID )
    tableID = tableInq(-1, 0, tablename);

  if ( tableID == UNDEFID )
63
    Error("table <%s> not found", tablename);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
64
65
66

  return (tableID);
}