{"id":7937,"date":"2017-08-25T16:21:15","date_gmt":"2017-08-25T20:21:15","guid":{"rendered":"http:\/\/blog.originlab.com\/?p=7937"},"modified":"2018-09-18T12:49:53","modified_gmt":"2018-09-18T16:49:53","slug":"centralizing-originc-files-on-a-network","status":"publish","type":"post","link":"https:\/\/blog.originlab.com\/ja\/centralizing-originc-files-on-a-network","title":{"rendered":"Centralizing OriginC Files on a Network"},"content":{"rendered":"<h4><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-8016\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles.png\" alt=\"\" width=\"400\" height=\"400\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles.png 400w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles-150x150.png 150w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles-300x300.png 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles-365x365.png 365w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/a>Introduction<\/h4>\n<p>We recently had a Tech Support request from a researcher with students who use Origin for graphing and data analysis. The researcher uses <a href=\"http:\/\/www.originlab.com\/doc\/OriginC\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>OriginC<\/strong><\/a> to create custom functions and makes them available for his students to use. Because he frequently updates his OriginC code, he wanted a method to ensure the latest functions are available to his students with the minimal amount of effort on his part, as well as avoiding requiring his students to get involved with OriginC file management, workspace configuration, and compilation. The students don&#8217;t have to <em>modify<\/em> the files, just <em>use<\/em> the functions provided in them.<\/p>\n<p>In this blog, I will describe a method that builds on the solution given to the researcher. The goal is to provide a flexible method to centralize OriginC files and workspaces on a server and make the functions they contain available to Origin running on local PCs connected to the network. It is assumed that the reader is already comfortable with OriginC and <a href=\"http:\/\/www.originlab.com\/doc\/LabTalk\/guide\" target=\"_blank\" rel=\"noopener noreferrer\"><strong> LabTalk<\/strong> <\/a>coding, the structure of <a href=\"https:\/\/en.wikipedia.org\/wiki\/INI_file\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>INI<\/strong><\/a> files, use of a plain text editor, and basic networking.<\/p>\n<p>A zip file containing example files that illustrate how this method works is available here: <strong><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/Centralizing-OriginC-Files.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Centralizing-OriginC-Files.zip<\/a><\/strong>. <em>It is suggested that the Zip file be downloaded and decompressed, so that the files can be referenced as you read this post.<\/em><\/p>\n<p>&nbsp;<\/p>\n<h4>Step 1: Organizing Source Code Files<\/h4>\n<p>After you have created and tested your OriginC files as usual on a development PC, make sure they are removed from any existing <a href=\"http:\/\/www.originlab.com\/doc\/CodeBuild\/Working-With-Workspaces\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Workspaces<\/strong> <\/a>in Origin <a href=\"http:\/\/www.originlab.com\/doc\/Tutorials\/OC-CodeBuilder\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Code Builder<\/strong><\/a> on the PC.<\/p>\n<p>Then, create a folder on a network drive to contain your OriginC source code files and move the files to it. The folder must be readable by all the local PCs that need access to the files. In the example Zip file, a folder entitled <em>&#8220;Files on Server&#8221;<\/em>\u00a0 is already provided for you to learn with- for now, you could copy those files to your server if you wished.<\/p>\n<p>Next, an Origin <em>Workspace<\/em> file (<strong>OCW<\/strong>) must be created in the same folder on the server. An example Workspace file, &#8220;<em>Workspace1.ocw&#8221;<\/em>, is included in the <em>&#8220;Files on Server&#8221;<\/em> folder in the example Zip file. A Workspace file is essentially a plain text <strong>INI<\/strong> file containing a list of source code files that are grouped (in this case) for the purpose of compiling all together. For example, the contents of <em>&#8220;Workspace1.ocw&#8221;<\/em> are:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Workspace1.ocw\">[Workspace]\r\nFile1=\"File 1.c\"\r\nFile2=\"File 2.c\"\r\nFile3=\"File 3.c\"\r\nFile4=\"Subfolder\\File 4.c\"\r\nFileCount=4\r\n<\/pre>\n<p>In the <span class=\"lang:default decode:true crayon-inline \">[Workspace]<\/span>\u00a0 section, there is 1 line per source code file. File names are enclosed in quotes and paths are relative (important!) to the location of the <strong>OCW<\/strong> file (e.g. <span class=\"lang:default decode:true crayon-inline\">File4=&#8221;Subfolder\\File 4.c&#8221;<\/span>\u00a0above). There is also a line in the <span class=\"lang:default decode:true crayon-inline\">[Workspace]<\/span> section for <span class=\"lang:default decode:true crayon-inline \">FileCount<\/span>\u00a0.<\/p>\n<p>While an <strong>OCW<\/strong> file can be generated from within <strong>Code Builder<\/strong>, it is frankly simpler to use a plain text editor to create the file giving it\u00a0 an <em>.ocw<\/em> extension. Even simpler, just copy and modify the <em>&#8220;Workspace1.ocw&#8221;<\/em> provided in the <em>&#8220;Files on Server&#8221;<\/em> folder in the example Zip file. <strong>Notepad<\/strong> can be used to do this, but the excellent and free plain text editor <a href=\"https:\/\/notepad-plus-plus.org\/\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Notepad++<\/strong><\/a> is even better (and is well worth installing in general).<\/p>\n<p>Include a line in the <span class=\"lang:default decode:true crayon-inline \">[Workspace]<\/span>\u00a0section for each source code file you want to compile using relative paths (important!) and enclosing the entire path and file name in quotes. Also make sure to modify <span class=\"lang:default decode:true crayon-inline \">FileCount<\/span>\u00a0 in the <span class=\"lang:default decode:true crayon-inline \">[Workspace]<\/span>\u00a0 section to reflect the number of source code files. Then save the file.<\/p>\n<p>&nbsp;<\/p>\n<h4>Step 2: Create LabTalk File to Compile the Source Code Files<\/h4>\n<p>Next, using a plain text editor (<strong>Notepad<\/strong> or <strong>Notepad++<\/strong>), create a LabTalk Script file (<strong>OGS<\/strong>) in the same folder as the <strong>OCW<\/strong> and source code files on the server. The LabTalk <a href=\"http:\/\/www.originlab.com\/doc\/LabTalk\/ref\/Run-obj\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>run.loadOC()<\/strong><\/a> function can be used to load the <strong>OCW<\/strong> file and thus compile the source code files. An example file, <em>&#8220;Loader.ogs&#8221;<\/em> is included in the <em>&#8220;Files on Server&#8221;<\/em> folder of the example Zip file. It&#8217;s contents are:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Loader.ogs\">int nErr =\u00a0 run.loadOC(\"Q:\\Files on Server\\Workspace1.ocw\", 16);\r\nif (1 == nErr)\r\n    type -b \"Server OCW file not found.\";\r\nelse if (2 == nErr)\r\n    type -b \"Compiling one or more server files failed.\";\r\n\/\/ else success.\r\n<\/pre>\n<p><strong>run.loadOC()<\/strong> returns <span class=\"lang:default decode:true crayon-inline\"> 0 <\/span>\u00a0 upon success, <span class=\"lang:default decode:true crayon-inline \"> 1 <\/span>\u00a0 if the <strong>OCW<\/strong> file was not found, and <span class=\"lang:default decode:true crayon-inline \"> 2 <\/span>\u00a0 if any source code files could not be compiled. Hence the error messages for <span class=\"lang:default decode:true crayon-inline \"> 1 <\/span>\u00a0 &amp; <span class=\"lang:default decode:true crayon-inline \"> 2 <\/span>\u00a0. Notice that, for this case, a quoted <em>absolute<\/em> path (important!) to the <strong>OCW<\/strong> file must be passed into the function.<\/p>\n<p>You can either create your own <strong>OGS<\/strong> file or modify <em>&#8220;Loader.ogs&#8221;<\/em>. Just be sure to follow the aforementioned items about absolute paths and quotes when specifying the path to your <strong>OCW<\/strong> file.<\/p>\n<p><span style=\"color: #800080;\"><strong>Hint!<\/strong> You can even load multiple <strong>OCW<\/strong> files by repeating the above code in the <strong>OGS<\/strong> file pointing to the different <strong>OCW<\/strong> files. However, it is important to <em>not<\/em> include the same source code files in multiple <strong>OCW<\/strong> files if you plan to load more than one.<\/span><\/p>\n<p>With the <strong>OGS<\/strong> file created, we can move on to the next step- configuring Origin installations on local PCs to utilize the files on the server.<\/p>\n<p>&nbsp;<\/p>\n<h4>Step 3: Configuring Origin on Local PCs<\/h4>\n<p>Origin installations on local PCs can be configured to load and compile the OriginC files on the remote server. This involves two actions: Adding an <em>&#8220;OEvents.ogs&#8221;<\/em> file to the<strong> <a href=\"http:\/\/www.originlab.com\/doc\/Origin-Help\/UserFilesFolder\" target=\"_blank\" rel=\"noopener noreferrer\">User Files Folder<\/a><\/strong> <em>(UFF)<\/em> and modifying the <em>&#8220;Origin.ini&#8221;<\/em> file in the <em>UFF<\/em>. These two actions need to be done only one time however.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Adding an <em>&#8220;OEvents.ogs&#8221;<\/em> File<\/strong><\/p>\n<p><em>&#8220;OEvents.ogs&#8221;<\/em> is a LabTalk script that Origin optionally uses to allow users to perform various actions when events occur in Origin. A default version of the file exists in Origin&#8217;s program folder, but one has also been provided for you in the example Zip file. This file must be copied to the UFF. Then a certain<em> [section]<\/em> of the file must be edited. The example in the Zip file is:<\/p>\n<pre class=\"lang:default decode:true\" title=\"OEvents.ogs\">[AfterCompileSystem]\r\n\/\/ This event is triggered after Origin finishes startup compilation of system folder.\r\n\/\/ Use this event for additional customization of Origin that requires Origin C functions\r\n\/\/ that are compiled on startup.\r\n\/\/ %1 = 1 if compilation is successful otherwise %1 = 0.\r\n\r\nrun.file(\"Q:\\Files on Server\\Loader.ogs\");\r\n\r\n<\/pre>\n<p>The <span class=\"lang:default decode:true crayon-inline\">[AfterCompileSystem]<\/span> section is edited to add a call to the LabTalk <a href=\"http:\/\/www.originlab.com\/doc\/LabTalk\/ref\/Run-obj\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>run.file()<\/strong><\/a> function, passing it the absolute path to the <strong>OGS<\/strong> file created in <strong>Step 2<\/strong> above. Code in this section runs immediately after Origin compiles system OriginC files, so this is a good place to make the call to compile the OriginC files on the remote server. You will, of course, need to modify the path to be correct for the location of your files on the sever.\u00a0 Now save the file.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Editing <em>&#8220;Origin.ini&#8221;<\/em> File<\/strong><\/p>\n<p>After first shutting down Origin, a plain text editor (<strong>Notepad<\/strong> or <strong>Notepad++<\/strong>) can be used to edit <em>&#8220;Origin.ini&#8221;<\/em> file in the <em>UFF<\/em>. The edit consists of uncommenting one line in the file. The semi-colon (<span class=\"lang:default decode:true crayon-inline \"> ; <\/span>) should be removed from the line:<\/p>\n<p><span class=\"lang:default decode:true crayon-inline\"> ; Ogs1 = OEvents <\/span><\/p>\n<p>as follows:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Origin.ini\">Ogs1 = OEvents\r\n; Ogs2 = OEvents\r\n; Origin can trigger multiple system events\r\n; Uncomment this line and implement event handlers in OEvents.ogs\r\n<\/pre>\n<p>Once the edit is complete, the file can be saved.<\/p>\n<p>With these two actions complete, the final step is to test the setup.<\/p>\n<p>&nbsp;<\/p>\n<h4>Testing the Setup<\/h4>\n<p>With the above steps complete, it is time to test the setup. Simply start Origin and wait a few moments for the system Originc files to compile. If all if configured correctly, the OriginC files on the server will then compile correctly as well. If you used the files supplied in the example Zip file, you could run the following code in the <a href=\"http:\/\/www.originlab.com\/doc\/LabTalk\/guide\/From-Script-and-Command-Window\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Script Window<\/strong><\/a> to see if the functions are indeed available:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Script window\">test1();\r\ntest2();\r\ntest3();\r\ntest4();\r\n<\/pre>\n<p>The output should be:<\/p>\n<pre class=\"lang:default decode:true\" title=\"Script window\">test1() from \"File 1.c\" ran.\r\ntest2() from \"File 2.c\" ran.\r\ntest3() from \"File 3.c\" ran.\r\ntest4() from \"File 4.c\" ran.\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>But It Doesn&#8217;t Work!?!?<\/strong><\/p>\n<p>If the setup does not appear to work, probably the number one culprit is the paths either in the <em>&#8220;Loader.ogs&#8221;<\/em> file or in<em> &#8220;OEvents.ogs&#8221;:<\/em><\/p>\n<ol>\n<li>Make sure the paths are correct;<\/li>\n<li>Make sure they are properly enclosed in double-quotes;<\/li>\n<li>Sometimes paths need to use forward slashes instead of backslashes for networks. These are known as UNC paths. To see if that is necessary, look at the path to the server in Windows File Explorer.<\/li>\n<\/ol>\n<p>Otherwise, problems may include that the OriginC files themselves cannot compile due to some error. However, if one tests them on a local development PC, this should not be an issue. If you cannot isolate the problem, feel free to send an email to tech@originlab.com referencing this blog post, and we can help diagnose the issue.<\/p>\n<p>&nbsp;<\/p>\n<h4>Conclusion<\/h4>\n<p>Hopefully this system will work well for you if you want such a centralized location for OriginC files. It can, of course, be modified to suit other needs or situations. There is no obligation to perform <strong>Step 3: Configuring Origin on Local PCs<\/strong>. You could just as easily issue the <span class=\"lang:default decode:true crayon-inline \"> run.file(&#8220;Q:\\\\Files on Server\\\\Loader.ogs&#8221;); <\/span> LabTalk command some other way.<\/p>\n<p>The flexibility of the system is best illustrated by the fact that the files on the local PCs with Origin will rarely (if ever) need to be modified; only files on the server such as <em>&#8220;Loader.ogs&#8221;<\/em> or the <strong>OCW<\/strong> files would need to be modified.<\/p>\n<p>Really, the only limitation of this method is that it relies on the client PC being connected to the server. That is, it will not work if the local PC is disconnected from the relevant network.<\/p>\n<p>Thank you for taking the time to read this post!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction We recently had a Tech Support request from a &hellip; <\/p>","protected":false},"author":492,"featured_media":8016,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5],"tags":[],"class_list":["post-7937","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-oc"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7DvU2-241","jetpack_likes_enabled":true,"jetpack_featured_media_url":"https:\/\/blog.originlab.com\/wp-content\/uploads\/2017\/05\/CentOCFiles.png","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/7937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/users\/492"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/comments?post=7937"}],"version-history":[{"count":87,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/7937\/revisions"}],"predecessor-version":[{"id":9318,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/7937\/revisions\/9318"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/media\/8016"}],"wp:attachment":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/media?parent=7937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/categories?post=7937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/tags?post=7937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}