00001 #ifdef FLIB
00002 #ifdef DEBUG_MEM
00003 #include "xmem.h"
00004 #endif
00005 #include "cfortran.h"
00006 #include "jsoc_main.h"
00007 #include "inthandles.h"
00008 #include "drms_env.h"
00009
00010
00011
00012 CmdParams_t cmdparams;
00013 ModuleArgs_t *gModArgs = NULL;
00014
00015
00016
00017
00018 typedef struct {
00019 char name[127];
00020 } MNameB;
00021 #define mnb COMMON_BLOCK(mnb,mname)
00022 COMMON_BLOCK_DEF(MNameB,mnb);
00023 MNameB mnb;
00024
00025 char *module_name;
00026
00027 typedef struct {
00028 char args[128][927];
00029 } MArgsB;
00030 #define mab COMMON_BLOCK(mab,margs)
00031 COMMON_BLOCK_DEF(MArgsB,mab);
00032 MArgsB mab;
00033
00034
00035 PROTOCCALLSFFUN0(INT, DoIt, doit)
00036 #define DoIt() CCALLSFFUN0(DoIt, doit)
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #define kMaxTokenSize 64
00049
00050 static HContainer_t *gMargTokenMap = NULL;
00051
00052
00053
00054 static ModuleArgs_Type_t TokenToArgType (const char *token) {
00055 if (gMargTokenMap == NULL) {
00056
00057 gMargTokenMap = hcon_create(sizeof(int), kMaxTokenSize, NULL, NULL, NULL, NULL, 0);
00058 if (!gMargTokenMap) {
00059
00060 fprintf (stderr, "Couldn't create token map, bailing out\n");
00061 exit (1);
00062 }
00063
00064 int value = ARG_END;
00065 int nArgTypes = 0;
00066 hcon_insert(gMargTokenMap, "end", &value);
00067 nArgTypes++;
00068
00069 value = ARG_FLAG;
00070 hcon_insert(gMargTokenMap, "flag", &value);
00071 nArgTypes++;
00072
00073 value = ARG_TIME;
00074 hcon_insert(gMargTokenMap, "time", &value);
00075 nArgTypes++;
00076
00077 value = ARG_INT;
00078 hcon_insert(gMargTokenMap, "int", &value);
00079 nArgTypes++;
00080
00081 value = ARG_FLOAT;
00082 hcon_insert(gMargTokenMap, "float", &value);
00083 nArgTypes++;
00084
00085 value = ARG_DOUBLE;
00086 hcon_insert(gMargTokenMap, "double", &value);
00087 nArgTypes++;
00088
00089 value = ARG_STRING;
00090 hcon_insert(gMargTokenMap, "string", &value);
00091 nArgTypes++;
00092
00093 value = ARG_VOID;
00094 hcon_insert(gMargTokenMap, "void", &value);
00095 nArgTypes++;
00096
00097 value = ARG_INTS;
00098 hcon_insert(gMargTokenMap, "ints", &value);
00099 nArgTypes++;
00100
00101 value = ARG_FLOATS;
00102 hcon_insert(gMargTokenMap, "floats", &value);
00103 nArgTypes++;
00104
00105 value = ARG_DOUBLES;
00106 hcon_insert(gMargTokenMap, "doubles", &value);
00107 nArgTypes++;
00108
00109 value = ARG_STRINGS;
00110 hcon_insert(gMargTokenMap, "strings", &value);
00111 nArgTypes++;
00112
00113 value = ARG_NUME;
00114 hcon_insert(gMargTokenMap, "nume", &value);
00115 nArgTypes++;
00116
00117 value = ARG_DATASET;
00118 hcon_insert(gMargTokenMap, "dataset", &value);
00119 nArgTypes++;
00120
00121 value = ARG_DATASERIES;
00122 hcon_insert(gMargTokenMap, "dataseries", &value);
00123 nArgTypes++;
00124
00125 value = ARG_NEWDATA;
00126 hcon_insert(gMargTokenMap, "newdata", &value);
00127 nArgTypes++;
00128
00129 if (nArgTypes != ARG_NUMARGS)
00130 {
00131
00132 fprintf(stderr, "Missing items in token map, bailing out");
00133 exit(1);
00134 }
00135 }
00136
00137 char t[kMaxTokenSize];
00138 strncpy(t, token, kMaxTokenSize - 1);
00139 t[kMaxTokenSize - 1] = '\0';
00140 strtolower(t);
00141
00142 ModuleArgs_Type_t *atype = hcon_lookup(gMargTokenMap, t);
00143
00144 if (atype)
00145 {
00146 return *atype;
00147 }
00148 else
00149 {
00150 fprintf(stderr, "Bad argument type in .f file\n");
00151 exit(1);
00152 }
00153 }
00154
00155
00156
00157
00158 void f_cmdparams_get_handle(pFHandleCmdParams handle)
00159 {
00160 int err = 1;
00161
00162 FHandleCmdParams cphandle = kgModCmdParams;
00163 CmdParams_t *pCP = (CmdParams_t *)GetJSOCStructure((void *)&cphandle, kFHandleTypeCmdParams);
00164
00165 if (pCP == NULL)
00166 {
00167
00168
00169 CmdParams_t *cp = GetGlobalCmdParams();
00170 const char *key = NULL;
00171 err = InsertJSOCStructure((void *)&cphandle, (void *)cp, kFHandleTypeCmdParams, &key);
00172 }
00173 else
00174 {
00175 err = 0;
00176 }
00177
00178 if (!err)
00179 {
00180 *handle = kgModCmdParams;
00181 }
00182 else
00183 {
00184 *handle = -1;
00185 }
00186 }
00187
00188 char *f_cmdparams_gethandle2()
00189 {
00190 return "blahblah";
00191 }
00192
00193 FCALLSCSUB1(f_cmdparams_get_handle, cpgethandle, cpgethandle, PINT)
00194 FCALLSCFUN0(STRING, f_cmdparams_gethandle2, CPGETHANDLE2, cpgethandle2)
00195
00196
00197
00198
00199
00200 static void InitFortranInterfaces()
00201 {
00202 InthandlesInit(sizeof(CmdParams_t *));
00203 }
00204
00205
00206
00207
00208
00209 static void TerminateFortranInterfaces()
00210 {
00211 InthandlesTerm();
00212 }
00213
00214 void JSOCMAIN_F_Initialize(int *nargsOut)
00215 {
00216 int iMarg = 0;
00217
00218 char cMArgs[128][928];
00219 char cMArgsCopy[128][928];
00220
00221 module_name = (char *)malloc(128);
00222
00223 FCB2CSTR(mnb.name, module_name, 0);
00224 FCB2CSTR(mab.args, cMArgs, 1);
00225
00226 memcpy(cMArgsCopy, cMArgs, sizeof(cMArgsCopy));
00227
00228
00229 char *oneLine = NULL;
00230 char *thisToken = NULL;
00231
00232
00233 ModuleArgs_Type_t argType = ARG_END;
00234 int nArgs = 0;
00235
00236 while (1) {
00237 argType = TokenToArgType (strtok (cMArgsCopy[nArgs], ","));
00238 if (argType != ARG_END) nArgs++;
00239 else break;
00240 }
00241
00242 gModArgs = (ModuleArgs_t *)malloc (sizeof(ModuleArgs_t) * (nArgs + 1));
00243 memset(gModArgs, 0, sizeof(ModuleArgs_t) * (nArgs +1));
00244
00245 iMarg = 0;
00246 while (iMarg <= nArgs) {
00247 oneLine = cMArgs[iMarg];
00248
00249 thisToken = strtok (oneLine, ",");
00250
00251 if (thisToken) {
00252 gModArgs[iMarg].type = TokenToArgType (strcmp (thisToken, "\"\"") == 0 ? "" : thisToken);
00253 thisToken = strtok (NULL, ",");
00254 }
00255
00256 if (thisToken) {
00257 gModArgs[iMarg].name = strdup (strcmp (thisToken, "\"\"") == 0 ? "" : thisToken);
00258 thisToken = strtok (NULL, ",");
00259 }
00260
00261 if (thisToken) {
00262 gModArgs[iMarg].value = strdup (strcmp (thisToken, "\"\"") == 0 ? "" : thisToken);
00263 thisToken = strtok (NULL, ",");
00264 }
00265
00266 if (thisToken) {
00267 gModArgs[iMarg].description = strdup (strcmp (thisToken, "\"\"") == 0 ? "" : thisToken);
00268 thisToken = strtok (NULL, ",");
00269 }
00270
00271 if (thisToken) {
00272 gModArgs[iMarg].range = strdup (strcmp (thisToken, "\"\"") == 0 ? "" : thisToken);
00273 thisToken = strtok (NULL, ",");
00274 }
00275
00276 iMarg++;
00277 }
00278
00279 InitFortranInterfaces();
00280
00281 if (nargsOut)
00282 {
00283 *nargsOut = nArgs;
00284 }
00285 }
00286
00287 void JSOCMAIN_F_Terminate(int nArgs)
00288 {
00289 TerminateFortranInterfaces();
00290
00291
00292 int iMarg = 0;
00293 while (iMarg < nArgs)
00294 {
00295 ModuleArgs_t *oneArg = gModArgs + iMarg;
00296
00297 free(oneArg->name);
00298 free(oneArg->value);
00299 free(oneArg->description);
00300 free(oneArg->range);
00301
00302 iMarg++;
00303 }
00304
00305 free(gModArgs);
00306
00307 hcon_destroy(&gMargTokenMap);
00308 }
00309
00310 int CallDoIt()
00311 {
00312 return DoIt();
00313 }
00314
00315 int main(int argc, char **argv)
00316 {
00317 int ret = 1;
00318 int nArgs = 0;
00319
00320
00321 memset(&cmdparams, 0, sizeof(CmdParams_t));
00322
00323 JSOCMAIN_F_Initialize(&nArgs);
00324 ret = JSOCMAIN_Main(argc, argv, module_name, CallDoIt);
00325 JSOCMAIN_F_Terminate(nArgs);
00326
00327 _exit(ret);
00328 }
00329
00330 #endif