Example #1
0
int
main(int argc, char **argv) {
    FILE *file;
    Lib3dsFile *f = 0;
    Lib3dsIo io;
    int result;
    int i;

    parse_args(argc, argv);

    file = fopen(filename, "rb");
    if (!file) {
        fprintf(stderr, "***ERROR***\nFile not found: %s\n", filename);
        exit(1);
    }

    f = lib3ds_file_new();

    memset(&io, 0, sizeof(io));
    io.self = file;
    io.seek_func = fileio_seek_func;
    io.tell_func = fileio_tell_func;
    io.read_func = fileio_read_func;
    io.write_func = fileio_write_func;
    io.log_func = fileio_log_func;

    result =  lib3ds_file_read(f, &io);

    fclose(file);

    if (!result) {
        fprintf(stderr, "***ERROR***\nLoading file failed: %s\n", filename);
        exit(1);
    }

    if (flags & LIB3DSDUMP_MATERIALS) {
        printf("Dumping materials:\n");
        for (i = 0; i < f->nmaterials; ++i) material_dump(f->materials[i]);
        printf("\n");
    }
    if (flags & LIB3DSDUMP_TRIMESHES) {
        printf("Dumping meshes:\n");
        for (i = 0; i < f->nmeshes; ++i) mesh_dump(f->meshes[i]);
        printf("\n");
    }
    if (flags & LIB3DSDUMP_INSTANCES) {
        Lib3dsNode *p;
        printf("Dumping instances:\n");
        for (p = f->nodes; p != 0; p = p->next) {
            dump_instances(p, "");
        }
        printf("\n");
    }
    if (flags & LIB3DSDUMP_CAMERAS) {
        printf("Dumping cameras:\n");
        for (i = 0; i < f->ncameras; ++i) camera_dump(f->cameras[i]);
        printf("\n");
    }
    if (flags & LIB3DSDUMP_LIGHTS) {
        printf("Dumping lights:\n");
        for (i = 0; i < f->nlights; ++i) light_dump(f->lights[i]);
        printf("\n");
    }
    if (flags & LIB3DSDUMP_NODES) {
        Lib3dsNode *p;
        printf("Dumping node hierarchy:\n");
        for (p = f->nodes; p != 0; p = p->next) {
            node_dump(p, 1);
        }
        printf("\n");
    }
    if (output) {
        if (!lib3ds_file_save(f, output)) {
            printf("***ERROR**** Writing %s\n", output);
        }
    }

    lib3ds_file_free(f);
    return 0;
}
Example #2
0
int main(int argc, char *argv[])
{
    cal_path();
    setlocale(LC_MESSAGES, "");
    bindtextdomain("opvdm", get_lang_path());
    textdomain("opvdm");

    timer_init(0);
    timer_init(1);
    dbus_init();
    set_ewe_lock_file("", "");
    cell.onlypos = FALSE;

    char pwd[1000];
    if (getcwd(pwd, 1000) == NULL) {
        ewe("IO error\n");
    }

    dump_init(&cell);
    dump_load_config(&cell);

    remove("snapshots.zip");
    remove("light_dump.zip");

    hard_limit_init();

//char path[PATH_MAX];
//char dest[PATH_MAX];
//pid_t pid = getpid();
//sprintf(path, "/proc/%d/exe", pid);

//if (readlink(path, dest, PATH_MAX) == -1)
//{
//      printf("error\n");
//      exit(1);
//}
//  char *base = strrchr(dest, '/');
//*base='/';
//*(base+1)=0;
    set_plot_script_dir(pwd);

//set_plot_script_dir(char * in)
    if (scanarg(argv, argc, "--help") == TRUE) {
        printf("opvdm_core - Organic Photovoltaic Device Model\n");
        printf(copyright);
        printf("\n");
        printf("Usage: opvdm_core [options]\n");
        printf("\n");
        printf("Options:\n");
        printf("\n");
        printf("\t--outputpath\toutput data path");
        printf("\t--inputpath\t sets the input path\n");
        printf("\t--version\tdisplays the current version\n");
        printf("\t--zip_results\t zip the results\n");
        printf("\t--optics\t runs only optical simulation\n");
        printf("\t--cpus\t sets the number of CPUs\n");
        printf("\n");
        printf
        ("Additional information about opvdm is available at www.opvdm.com.\n");
        printf("\n");
        printf
        ("Report bugs to: [email protected]\n\n");
        exit(0);
    }
    if (scanarg(argv, argc, "--version") == TRUE) {
        printf("opvdm_core, Version %s\n", opvdm_ver);
        printf(copyright);
        printf(this_is_free_software);
        printf
        ("There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or\n");
        printf("FITNESS FOR A PARTICULAR PURPOSE.\n");
        printf("\n");
        exit(0);
    }

    if (geteuid() == 0) {
        ewe("Don't run me as root!\n");
    }

    set_dump_status(dump_stop_plot, FALSE);
    set_dump_status(dump_print_text, TRUE);

    set_io_dump(FALSE);
    srand(time(0));
    textcolor(fg_green);
    randomprint(_("Organic Photovoltaic Device Model (www.opvdm.com)\n"));
    randomprint(_
                ("You should have received a copy of the GNU General Public License\n"));
    randomprint(_
                ("along with this software.  If not, see www.gnu.org/licenses/.\n"));
    randomprint("\n");
    randomprint(_
                ("If you wish to collaborate in anyway please get in touch:\n"));
    randomprint(_("[email protected]\n"));
    randomprint(_("www.roderickmackenzie.eu/contact.html\n"));
    randomprint("\n");
    textcolor(fg_reset);

    globalserver.on = FALSE;
    globalserver.cpus = 1;
    globalserver.readconfig = TRUE;

    if (scanarg(argv, argc, "--outputpath") == TRUE) {
        strcpy(sim_output_path(),
               get_arg_plusone(argv, argc, "--outputpath"));
    } else {
        strcpy(sim_output_path(), pwd);
    }

    if (scanarg(argv, argc, "--inputpath") == TRUE) {
        strcpy(sim_input_path(),
               get_arg_plusone(argv, argc, "--inputpath"));
    } else {
        strcpy(sim_input_path(), sim_output_path());
    }

    dump_load_config(&cell);

    if (scanarg(argv, argc, "--onlypos") == TRUE) {
        cell.onlypos = TRUE;
    }

    char name[200];
    struct inp_file inp;
    inp_init(&inp);
    inp_load_from_path(&inp, sim_input_path(), "ver.inp");
    inp_check(&inp, 1.0);
    inp_search_string(&inp, name, "#core");
    inp_free(&inp);

    if (strcmp(name, opvdm_ver) != 0) {
        printf
        ("Software is version %s and the input files are version %s\n",
         opvdm_ver, name);
        exit(0);
    }

    gui_start();
    if (scanarg(argv, argc, "--optics") == FALSE)
        server_init(&globalserver);

    if (scanarg(argv, argc, "--lock") == TRUE) {
        server_set_dbus_finish_signal(&globalserver,
                                      get_arg_plusone(argv, argc,
                                              "--lock"));
    }

    int ret = 0;

    int do_fit = FALSE;

    if (scanarg(argv, argc, "--fit") == TRUE)
        do_fit = TRUE;

    FILE *f = fopen("fit.inp", "r");
    if (f != NULL) {
        fclose(f);
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "fit.inp");
        int fit_temp;
        inp_search_int(&inp, &fit_temp, "#do_fit");
        if (fit_temp == 1) {
            do_fit = TRUE;
        }

        inp_free(&inp);
    }

    if (do_fit == TRUE) {
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_print_text, FALSE);
        set_dump_status(dump_iodump, FALSE);
        set_dump_status(dump_optics, FALSE);
        set_dump_status(dump_newton, FALSE);
        set_dump_status(dump_plot, FALSE);
        set_dump_status(dump_stop_plot, FALSE);
        set_dump_status(dump_opt_for_fit, FALSE);
        set_dump_status(dump_print_newtonerror, FALSE);
        set_dump_status(dump_print_converge, FALSE);
        set_dump_status(dump_print_pos_error, FALSE);
        set_dump_status(dump_lock, TRUE);
    }
#include "main_args.c"
    if (scanarg(argv, argc, "--optics") == TRUE) {
        gui_start();
        struct light two;
        light_init(&two, &cell, pwd);
        //light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]);
        light_load_config(&two);
        two.disable_transfer_to_electrical_mesh = TRUE;
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_optics, TRUE);
        set_dump_status(dump_optics_verbose, TRUE);
        double Psun;
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "light.inp");
        inp_search_double(&inp, &(Psun), "#Psun");
        Psun = 1.0;	//fabs(Psun);
        inp_free(&inp);

        light_solve_and_update(&cell, &two, Psun, 0.0);
        light_dump(&two);
        light_free(&two);
        complex_solver_free();
    } else {
        gen_dos_fd_gaus_fd();

        server_add_job(&globalserver, cell.outputpath, cell.inputpath);
        print_jobs(&globalserver);
        ret = server_run_jobs(&globalserver);

    }

    server_shut_down(&globalserver);

    if (scanarg(argv, argc, "--zip_results") == TRUE) {
        printf("zipping results\n");
        int ret;
        char temp[200];
        DIR *dir = opendir("snapshots");
        if (dir) {
            closedir(dir);
            ret =
                system("zip -r -j -q snapshots.zip ./snapshots/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "snapshots");
            remove_dir(temp);

        }

        dir = opendir("light_dump");
        if (dir) {
            closedir(dir);
            ret =
                system
                ("zip -r -j -q light_dump.zip ./light_dump/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "light_dump");
            remove_dir(temp);

        }

    }

    hard_limit_free();
    if (ret != 0) {
        return 1;
    }
    return 0;
}